From ef23f01ebab448f10cb3935af4a2723f0e362c38 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Thu, 19 May 2011 07:38:35 +0200 Subject: begin supporting a different database for unit tests --- tests/TestBaseApi.php | 7 ++++--- tests/prepare.php | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/TestBaseApi.php b/tests/TestBaseApi.php index 2caa701..31797c9 100644 --- a/tests/TestBaseApi.php +++ b/tests/TestBaseApi.php @@ -50,8 +50,9 @@ class TestBaseApi extends TestBase $this->url = $GLOBALS['unittestUrl'] . $this->urlPart; //clean up before test - if (file_exists($GLOBALS['datadir'] . '/config.unittest.php')) { - unlink($GLOBALS['datadir'] . '/config.unittest.php'); + $configFile = $GLOBALS['datadir'] . '/config.testing-tmp.php'; + if (file_exists($configFile)) { + unlink($configFile); } $this->us = SemanticScuttle_Service_Factory::get('User'); @@ -230,7 +231,7 @@ class TestBaseApi extends TestBase $this->assertInternalType( 'integer', - file_put_contents($GLOBALS['datadir'] . '/config.unittest.php', $str), + file_put_contents($GLOBALS['datadir'] . '/config.testing-tmp.php', $str), 'Writing config.unittest.php failed' ); } diff --git a/tests/prepare.php b/tests/prepare.php index c80306e..ea4d77d 100644 --- a/tests/prepare.php +++ b/tests/prepare.php @@ -22,7 +22,7 @@ $_SERVER['HTTP_HOST'] = 'http://localhost/'; define('UNIT_TEST_MODE', true); if ('@data_dir@' == '@' . 'data_dir@') { - //non pear-install + //non pear-installation (i.e. git checkout) require_once dirname(__FILE__) . '/../src/SemanticScuttle/header.php'; } else { //pear installation; files are in include path @@ -35,7 +35,7 @@ if ($GLOBALS['debugMode'] == true && $GLOBALS['dbtype'] == 'mysql4' ) { echo "\n" - . '!!! The combination of debugMode and dbtype==mysql4' + . '!! The combination of debugMode and dbtype==mysql4' . ' will wreck some tests' . "\n\n"; } ?> \ No newline at end of file -- cgit v1.2.3-54-g00ecf From 675aa6291a39c0bc77636cca3453b7874e97b6c3 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 20 May 2011 06:58:28 +0200 Subject: automatically append unittestmode parameter to url --- tests/TestBaseApi.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/TestBaseApi.php b/tests/TestBaseApi.php index 31797c9..1f2e8ff 100644 --- a/tests/TestBaseApi.php +++ b/tests/TestBaseApi.php @@ -77,10 +77,14 @@ class TestBaseApi extends TestBase */ protected function getRequest($urlSuffix = null) { - $req = new HTTP_Request2( - $this->url . $urlSuffix, - HTTP_Request2::METHOD_GET - ); + $url = $this->url . $urlSuffix; + if (strpos($urlSuffix, '?') !== false) { + $url .= '&unittestMode=1'; + } else { + $url .= '?unittestMode=1'; + } + + $req = new HTTP_Request2($url, HTTP_Request2::METHOD_GET); return $req; } -- cgit v1.2.3-54-g00ecf From 191f08683edb9970c2ad6c061840292c2df14d61 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 20 May 2011 07:02:52 +0200 Subject: all but one test work now with a different unittest database --- tests/TestBaseApi.php | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/TestBaseApi.php b/tests/TestBaseApi.php index 1f2e8ff..20574f3 100644 --- a/tests/TestBaseApi.php +++ b/tests/TestBaseApi.php @@ -72,10 +72,26 @@ class TestBaseApi extends TestBase * @param string $urlSuffix Suffix for the URL * * @return HTTP_Request2 HTTP request object + */ + protected function getRequest($urlSuffix = null) + { + $url = $this->getTestUrl($urlSuffix); + $req = new HTTP_Request2($url, HTTP_Request2::METHOD_GET); + + return $req; + } + + /** + * Creates an URL from $this->url plus $urlSuffix and an appended + * unittestMode=1 parameter. + * + * @param string $urlSuffix Suffix for the URL + * + * @return string URL * * @uses $url */ - protected function getRequest($urlSuffix = null) + protected function getTestUrl($urlSuffix = null) { $url = $this->url . $urlSuffix; if (strpos($urlSuffix, '?') !== false) { @@ -83,10 +99,7 @@ class TestBaseApi extends TestBase } else { $url .= '?unittestMode=1'; } - - $req = new HTTP_Request2($url, HTTP_Request2::METHOD_GET); - - return $req; + return $url; } @@ -170,7 +183,7 @@ class TestBaseApi extends TestBase $uid = $this->addUser($username, $password); $req = new HTTP_Request2( - $GLOBALS['unittestUrl'] . '/login.php', + $GLOBALS['unittestUrl'] . '/login.php?unittestMode=1', HTTP_Request2::METHOD_POST ); $cookies = $req->setCookieJar()->getCookieJar(); -- cgit v1.2.3-54-g00ecf From 1bbc36f8a4a41fc1a55767fc28921ac44a6a60a7 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 20 May 2011 17:08:39 +0200 Subject: fix test --- tests/www/searchTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/www/searchTest.php b/tests/www/searchTest.php index 1220667..5dce69d 100644 --- a/tests/www/searchTest.php +++ b/tests/www/searchTest.php @@ -41,7 +41,7 @@ class www_SearchTest extends TestBaseApi 'No bookmark found', false ); - $res = $this->getRequest('/all/baz bat')->send(); + $res = $this->getRequest('/all/baz%20bat')->send(); $this->assertSelectCount( '.xfolkentry', false, $res->getBody(), 'Bookmarks found', false -- cgit v1.2.3-54-g00ecf