]> gitweb.fluxo.info Git - semanticscuttle.git/commitdiff
make export_csv support filtering to multiple tags
authorcweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f>
Sun, 28 Mar 2010 18:08:38 +0000 (18:08 +0000)
committercweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f>
Sun, 28 Mar 2010 18:08:38 +0000 (18:08 +0000)
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@702 b3834d28-1941-0410-a4f8-b48e95affb8f

tests/Api/ExportCsvTest.php
www/api/export_csv.php

index ee7db4b0cb841770f1ee0cc3e4da810bcafd4cb3..18008e1d6b584f2738b9231dda7802943329cc8d 100644 (file)
@@ -162,6 +162,67 @@ class Api_ExportCsvTest extends TestBaseApi
 
 
 
+    /**
+     * Test CSV export with tag filter
+     */
+    public function testTagFilter()
+    {
+        list($req, $uid) = $this->getAuthRequest('?tag=tag1');
+        $this->addBookmark(
+            $uid, 'http://example.org/tag-1', 0,
+            array('unittest', 'tag1')
+        );
+        $this->addBookmark(
+            $uid, 'http://example.org/tag-2', 0,
+            array('unittest', 'tag2')
+        );
+        $this->addBookmark(
+            $uid, 'http://example.org/tag-3', 0,
+            array('unittest', 'tag1', 'tag2')
+        );
+
+        $body = $req->send()->getBody();
+        $csv  = $this->getCsvArray($body);
+
+        $this->assertEquals(3, count($csv));
+        $this->assertCsvHeader($csv);
+
+        $this->assertEquals('http://example.org/tag-1', $csv[1][0]);
+        $this->assertEquals('http://example.org/tag-3', $csv[2][0]);
+    }
+
+
+
+    /**
+     * Test CSV export with tag filter for multiple tags
+     */
+    public function testTagFilterMultiple()
+    {
+        list($req, $uid) = $this->getAuthRequest('?tag=tag1+tag2');
+        $this->addBookmark(
+            $uid, 'http://example.org/tag-1', 0,
+            array('unittest', 'tag1')
+        );
+        $this->addBookmark(
+            $uid, 'http://example.org/tag-2', 0,
+            array('unittest', 'tag2')
+        );
+        $this->addBookmark(
+            $uid, 'http://example.org/tag-3', 0,
+            array('unittest', 'tag1', 'tag2')
+        );
+
+        $body = $req->send()->getBody();
+        $csv  = $this->getCsvArray($body);
+
+        $this->assertEquals(2, count($csv));
+        $this->assertCsvHeader($csv);
+
+        $this->assertEquals('http://example.org/tag-3', $csv[1][0]);
+    }
+
+
+
     /**
      * Asserts that the CSV array contains the correct header
      *
index b9cf497baf87710d93165be91401e4bf6517e961..43951ecf04b12574896269e5a6b686dcb03d1cab 100644 (file)
@@ -10,13 +10,18 @@ header("Content-disposition: filename=exportBookmarks.csv");
 $bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark');
 
 // Check to see if a tag was specified.
-if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != ''))
-    $tag = trim($_REQUEST['tag']);
-else
-    $tag = NULL;
+if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != '')) {
+    //$_GET vars have + replaced to " " automatically
+    $tag = str_replace(' ', '+', trim($_REQUEST['tag']));
+} else {
+    $tag = null;
+}
 
 // Get the posts relevant to the passed-in variables.
-$bookmarks =& $bookmarkservice->getBookmarks(0, NULL, $userservice->getCurrentUserId(), $tag, NULL, getSortOrder());
+$bookmarks = $bookmarkservice->getBookmarks(
+    0, null, $userservice->getCurrentUserId(),
+    $tag, null, getSortOrder()
+);
 
 //columns titles
 echo 'url;title;tags;description';