]> gitweb.fluxo.info Git - semanticscuttle.git/commitdiff
add test for api/export_csv.php
authorcweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f>
Sun, 28 Mar 2010 18:06:07 +0000 (18:06 +0000)
committercweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f>
Sun, 28 Mar 2010 18:06:07 +0000 (18:06 +0000)
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@700 b3834d28-1941-0410-a4f8-b48e95affb8f

tests/Api/ExportCsvTest.php [new file with mode: 0644]
tests/TestBaseApi.php [new file with mode: 0644]
tests/prepare.php

diff --git a/tests/Api/ExportCsvTest.php b/tests/Api/ExportCsvTest.php
new file mode 100644 (file)
index 0000000..438df7f
--- /dev/null
@@ -0,0 +1,104 @@
+<?php
+/**
+ * SemanticScuttle - your social bookmark manager.
+ *
+ * PHP version 5.
+ *
+ * @category Bookmarking
+ * @package  SemanticScuttle
+ * @author   Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net>
+ * @author   Christian Weiske <cweiske@cweiske.de>
+ * @author   Eric Dane <ericdane@users.sourceforge.net>
+ * @license  GPL http://www.gnu.org/licenses/gpl.html
+ * @link     http://sourceforge.net/projects/semanticscuttle
+ */
+
+require_once dirname(__FILE__) . '/../prepare.php';
+require_once 'HTTP/Request2.php';
+
+if (!defined('PHPUnit_MAIN_METHOD')) {
+    define('PHPUnit_MAIN_METHOD', 'Api_ExportCsvTest::main');
+}
+
+/**
+ * Unit tests for the SemanticScuttle csv export API
+ *
+ * @category Bookmarking
+ * @package  SemanticScuttle
+ * @author   Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net>
+ * @author   Christian Weiske <cweiske@cweiske.de>
+ * @author   Eric Dane <ericdane@users.sourceforge.net>
+ * @license  GPL http://www.gnu.org/licenses/gpl.html
+ * @link     http://sourceforge.net/projects/semanticscuttle
+ */
+class Api_ExportCsvTest extends TestBaseApi
+{
+    protected $us;
+    protected $bs;
+    protected $urlPart = 'api/export_csv.php';
+
+
+
+    /**
+     * Used to run this test class standalone
+     *
+     * @return void
+     */
+    public static function main()
+    {
+        require_once 'PHPUnit/TextUI/TestRunner.php';
+        PHPUnit_TextUI_TestRunner::run(
+            new PHPUnit_Framework_TestSuite(__CLASS__)
+        );
+    }
+
+
+
+    /**
+     * Test if authentication is required when sending no auth data
+     */
+    public function testAuthWithoutAuthData()
+    {
+        $req = $this->getRequest(null, false);
+        $res = $req->send();
+        $this->assertEquals(401, $res->getStatus());
+    }
+
+
+
+    /**
+     * Test if authentication is required when sending wrong user data
+
+     */
+    public function testAuthWrongCredentials()
+    {
+        $req = $this->getRequest(null, false);
+        $req->setAuth('user', 'password', HTTP_Request2::AUTH_BASIC);
+        $res = $req->send();
+        $this->assertEquals(401, $res->getStatus());
+    }
+
+
+
+    /**
+     * Test MIME content type and filename header fields
+     */
+    public function testMimeTypeFilename()
+    {
+        $res = $this->getRequest()->send();
+
+        $this->assertEquals(200, $res->getStatus());
+        //verify MIME content type
+        $this->assertEquals(
+            'application/csv-tab-delimited-table; charset=utf-8',
+            $res->getHeader('content-type')
+        );
+        //we need a file name
+        $this->assertNotNull($res->getHeader('content-disposition'));
+    }
+}
+
+if (PHPUnit_MAIN_METHOD == 'Api_ExportCsvTest::main') {
+    Api_ExportCsvTest::main();
+}
+?>
\ No newline at end of file
diff --git a/tests/TestBaseApi.php b/tests/TestBaseApi.php
new file mode 100644 (file)
index 0000000..03ca016
--- /dev/null
@@ -0,0 +1,78 @@
+<?php
+/**
+ * SemanticScuttle - your social bookmark manager.
+ *
+ * PHP version 5.
+ *
+ * @category Bookmarking
+ * @package  SemanticScuttle
+ * @author   Christian Weiske <cweiske@cweiske.de>
+ * @license  GPL http://www.gnu.org/licenses/gpl.html
+ * @link     http://sourceforge.net/projects/semanticscuttle
+ */
+
+require_once 'PHPUnit/Framework.php';
+
+PHPUnit_Util_Filter::addFileToFilter(__FILE__);
+
+/**
+ * Base unittest class for web API tests.
+ *
+ * @category Bookmarking
+ * @package  SemanticScuttle
+ * @author Christian Weiske <cweiske@cweiske.de>
+ * @license  GPL http://www.gnu.org/licenses/gpl.html
+ * @link     http://sourceforge.net/projects/semanticscuttle
+ */
+class TestBaseApi extends TestBase
+{
+    protected $url;
+    protected $urlPart = null;
+
+
+
+    protected function setUp()
+    {
+        if ($GLOBALS['unittestUrl'] === null) {
+            $this->assertTrue(false, 'Unittest URL not set in config');
+        }
+        if ($this->urlPart === null) {
+            $this->assertTrue(false, 'Set the urlPart variable');
+        }
+        $this->url = $GLOBALS['unittestUrl'] . $this->urlPart;
+
+        $this->us = SemanticScuttle_Service_Factory::get('User');
+        $this->bs = SemanticScuttle_Service_Factory::get('Bookmark');
+        $this->bs->deleteAll();
+    }
+
+
+
+    /**
+     * Gets a HTTP request object
+     *
+     * @param string  $urlSuffix Suffix for the URL
+     * @param boolean $auth      If user authentication is needed
+     *
+     * @return HTTP_Request2 HTTP request object
+     */
+    protected function getRequest($urlSuffix = null, $auth = true)
+    {
+        $req = new HTTP_Request2(
+            $this->url . $urlSuffix,
+            HTTP_Request2::METHOD_GET
+        );
+
+        if ($auth) {
+            $this->addUser('testuser', 'testpassword');
+            $req->setAuth(
+                'testuser', 'testpassword',
+                HTTP_Request2::AUTH_BASIC
+            );
+        }
+
+        return $req;
+    }
+
+}
+?>
\ No newline at end of file
index 835810e6ee54d132ccfaaf6221f0936165b478d8..ce9cd1cddb388f651e3b8b981b55f4660ee60c36 100644 (file)
@@ -21,6 +21,7 @@ define('UNIT_TEST_MODE', true);
 
 require_once dirname(__FILE__) . '/../src/SemanticScuttle/header.php';
 require_once dirname(__FILE__) . '/TestBase.php';
+require_once dirname(__FILE__) . '/TestBaseApi.php';
 
 if ($GLOBALS['debugMode'] == true
     && $GLOBALS['dbtype'] == 'mysql4'