From fbb9105e038726f81bd25f31893ef38fe7f06530 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Mon, 25 Jun 2012 14:30:16 +0200 Subject: fixed tests The test suite was missing a global keyword to access the $INPUT class. --- _test/core/TestRequest.php | 3 +++ 1 file changed, 3 insertions(+) (limited to '_test/core') diff --git a/_test/core/TestRequest.php b/_test/core/TestRequest.php index fa3ddec90..9047f7e88 100644 --- a/_test/core/TestRequest.php +++ b/_test/core/TestRequest.php @@ -58,6 +58,9 @@ class TestRequest { global $output_buffer; $output_buffer = ''; + // make globals available as were in a function context here FIXME: any others needed? + global $INPUT; + // now execute dokuwiki and grep the output header_remove(); ob_start('ob_start_callback'); -- cgit v1.2.3 From 0189bd8669742c5290a4f6538f954b81554e26d2 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Thu, 28 Jun 2012 16:43:01 +0200 Subject: make sure all globals are available in test requests --- _test/core/TestRequest.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to '_test/core') diff --git a/_test/core/TestRequest.php b/_test/core/TestRequest.php index 9047f7e88..66760b1e0 100644 --- a/_test/core/TestRequest.php +++ b/_test/core/TestRequest.php @@ -46,6 +46,11 @@ class TestRequest { $post = $_POST; $request = $_REQUEST; + // import all defined globals into the function scope + foreach(array_keys($GLOBALS) as $glb){ + global $$glb; + } + // fake environment global $default_server_vars; $_SERVER = array_merge($default_server_vars, $this->server); @@ -58,9 +63,6 @@ class TestRequest { global $output_buffer; $output_buffer = ''; - // make globals available as were in a function context here FIXME: any others needed? - global $INPUT; - // now execute dokuwiki and grep the output header_remove(); ob_start('ob_start_callback'); -- cgit v1.2.3 From 9e777cee116bd29c51b62ccd1c4353cc00014522 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 30 Jun 2012 01:24:19 +0200 Subject: simplified using the TestRequest class You now can call get() or post() on it and give it all the wanted input variables --- _test/core/TestRequest.php | 65 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) (limited to '_test/core') diff --git a/_test/core/TestRequest.php b/_test/core/TestRequest.php index 66760b1e0..aeda4b892 100644 --- a/_test/core/TestRequest.php +++ b/_test/core/TestRequest.php @@ -84,4 +84,69 @@ class TestRequest { return $response; } + + /** + * Set the virtual URI the request works against + * + * This parses the given URI and sets any contained GET variables + * but will not overwrite any previously set ones (eg. set via setGet()). + * + * It initializes the $_SERVER['REQUEST_URI'] and $_SERVER['QUERY_STRING'] + * with all set GET variables. + * + * @param string $url end URL to simulate, needs to start with /doku.php currently + */ + public function setUri($uri){ + if(substr($uri,0,9) != '/doku.php'){ + throw new Exception("only '/doku.php' is supported currently"); + } + + $params = array(); + list($uri, $query) = explode('?',$uri,2); + if($query) parse_str($query, $params); + + $this->get = array_merge($params, $this->get); + if(count($this->get)){ + $query = '?'.http_build_query($this->get, '', '&'); + $query = str_replace( + array('%3A', '%5B', '%5D'), + array(':', '[', ']'), + $query + ); + $uri = $uri.$query; + } + + $this->setServer('QUERY_STRING', $query); + $this->setServer('REQUEST_URI', $uri); + } + + /** + * Simulate a POST request with the given variables + * + * @param array $post all the POST parameters to use + * @param string $url end URL to simulate, needs to start with /doku.php currently + * @param return TestResponse + */ + public function post($post=array(), $uri='/doku.php') { + $this->setUri($uri); + $this->post = array_merge($this->post, $post); + $this->setServer('REQUEST_METHOD', 'POST'); + return $this->execute(); + } + + /** + * Simulate a GET request with the given variables + * + * @param array $GET all the POST parameters to use + * @param string $url end URL to simulate, needs to start with /doku.php currently + * @param return TestResponse + */ + public function get($get=array(), $uri='/doku.php') { + $this->get = array_merge($this->get, $get); + $this->setUri($uri); + $this->setServer('REQUEST_METHOD', 'GET'); + return $this->execute(); + } + + } -- cgit v1.2.3 From 4d053d04448a73826574eeb5e6be7e4d53c38ae6 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 30 Jun 2012 01:34:21 +0200 Subject: moved URI setup to execute() --- _test/core/TestRequest.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to '_test/core') diff --git a/_test/core/TestRequest.php b/_test/core/TestRequest.php index aeda4b892..172821576 100644 --- a/_test/core/TestRequest.php +++ b/_test/core/TestRequest.php @@ -36,9 +36,10 @@ class TestRequest { /** * Executes the request * + * @param string $url end URL to simulate, needs to start with /doku.php currently * @return TestResponse the resulting output of the request */ - public function execute() { + public function execute($uri='/doku.php') { // save old environment $server = $_SERVER; $session = $_SESSION; @@ -46,6 +47,9 @@ class TestRequest { $post = $_POST; $request = $_REQUEST; + // prepare the right URI + $this->setUri($uri); + // import all defined globals into the function scope foreach(array_keys($GLOBALS) as $glb){ global $$glb; @@ -95,8 +99,9 @@ class TestRequest { * with all set GET variables. * * @param string $url end URL to simulate, needs to start with /doku.php currently + * @todo make this work with other end points */ - public function setUri($uri){ + protected function setUri($uri){ if(substr($uri,0,9) != '/doku.php'){ throw new Exception("only '/doku.php' is supported currently"); } @@ -128,10 +133,9 @@ class TestRequest { * @param return TestResponse */ public function post($post=array(), $uri='/doku.php') { - $this->setUri($uri); $this->post = array_merge($this->post, $post); $this->setServer('REQUEST_METHOD', 'POST'); - return $this->execute(); + return $this->execute($uri); } /** @@ -143,9 +147,8 @@ class TestRequest { */ public function get($get=array(), $uri='/doku.php') { $this->get = array_merge($this->get, $get); - $this->setUri($uri); $this->setServer('REQUEST_METHOD', 'GET'); - return $this->execute(); + return $this->execute($uri); } -- cgit v1.2.3 From 0644090a80cabe51bcee580999ed33913aa24699 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 1 Jul 2012 19:39:07 +0200 Subject: reset the data directory before each test class is run --- _test/core/DokuWikiTest.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to '_test/core') diff --git a/_test/core/DokuWikiTest.php b/_test/core/DokuWikiTest.php index e47c06329..e51f1eeb1 100644 --- a/_test/core/DokuWikiTest.php +++ b/_test/core/DokuWikiTest.php @@ -18,6 +18,25 @@ abstract class DokuWikiTest extends PHPUnit_Framework_TestCase { */ protected $pluginsDisabled = array(); + /** + * Setup the data directory + * + * This is ran before each test class + */ + public static function setUpBeforeClass() { + // just to be safe not to delete something undefined later + if(!defined('TMP_DIR')) die('no temporary directory'); + if(!defined('DOKU_TMP_DATA')) die('no temporary data directory'); + + // remove any leftovers from the last run + if(is_dir(DOKU_TMP_DATA)){ + TestUtils::rdelete(DOKU_TMP_DATA); + } + + // populate default dirs + TestUtils::rcopy(TMP_DIR, dirname(__FILE__).'/../data/'); + } + /** * Reset the DokuWiki environment before each test run. Makes sure loaded config, * language and plugins are correct. @@ -26,6 +45,7 @@ abstract class DokuWikiTest extends PHPUnit_Framework_TestCase { * @return void */ public function setUp() { + // reload config global $conf, $config_cascade; $conf = array(); -- cgit v1.2.3