From 561684d896adf0e59938acc1a03903059c2d63a0 Mon Sep 17 00:00:00 2001 From: Tobias Sarnowski Date: Sun, 15 Apr 2012 15:07:26 +0000 Subject: initial commit for integration test framework --- _testing/integrationtests.xml | 16 ++++ _testing/integrationtests/basic/basic.test.php | 14 ++++ _testing/integrationtests/basic/hooks.test.php | 20 +++++ _testing/integrationtests/bootstrap.php | 104 +++++++++++++++++++++++++ 4 files changed, 154 insertions(+) create mode 100644 _testing/integrationtests.xml create mode 100644 _testing/integrationtests/basic/basic.test.php create mode 100644 _testing/integrationtests/basic/hooks.test.php create mode 100644 _testing/integrationtests/bootstrap.php diff --git a/_testing/integrationtests.xml b/_testing/integrationtests.xml new file mode 100644 index 000000000..f3beae66d --- /dev/null +++ b/_testing/integrationtests.xml @@ -0,0 +1,16 @@ + + + + + + integrationtests/ + + + ../lib/plugins/*/_testing + + + + + diff --git a/_testing/integrationtests/basic/basic.test.php b/_testing/integrationtests/basic/basic.test.php new file mode 100644 index 000000000..56cef965f --- /dev/null +++ b/_testing/integrationtests/basic/basic.test.php @@ -0,0 +1,14 @@ +execute(); + + $this->assertTrue( + strpos($response->getContent(), 'DokuWiki') >= 0, + 'DokuWiki was not a word in the output' + ); + } +} diff --git a/_testing/integrationtests/basic/hooks.test.php b/_testing/integrationtests/basic/hooks.test.php new file mode 100644 index 000000000..0ba389659 --- /dev/null +++ b/_testing/integrationtests/basic/hooks.test.php @@ -0,0 +1,20 @@ +hookTriggered = true; + } + + function testHookTriggering() { + global $EVENT_HANDLER; + $EVENT_HANDLER->register_hook('TPL_CONTENT_DISPLAY', 'AFTER', $this, 'hookTriggered'); + + $request = new TestRequest(); + $request->execute(); + + $this->assertTrue($this->hookTriggered, 'Hook was not triggered as expected!'); + } +} diff --git a/_testing/integrationtests/bootstrap.php b/_testing/integrationtests/bootstrap.php new file mode 100644 index 000000000..e7029247f --- /dev/null +++ b/_testing/integrationtests/bootstrap.php @@ -0,0 +1,104 @@ + '127.0.0.1', + ); + + var $get_vars = array(); + var $post_vars = array(); + + var $output = ''; + + function __construct($page = '') { + $this->setPage($page); + } + + function setServerVar($varName, $varValue) { + $this->sevrer_vars[$varName] = $varValue; + } + + function setGetVar($varName, $varValue) { + $this->get_vars[$varName] = $varValue; + } + + function setPostVar($varName, $varValue) { + $this->post_vars[$varName] = $varValue; + } + + function setPage($pageName) { + $this->setGetVar('id', $pageName); + } + + function execute() { + global $output_buffer; + $output_buffer = ''; + + // fake php environment + foreach ($this->server_vars as $key => $value) { + $_SERVER[$key] = $value; + } + $_REQUEST = array(); + $_GET = array(); + foreach ($this->get_vars as $key => $value) { + $_GET[$key] = $value; + $_REQUEST[$key] = $value; + } + $_POST = array(); + foreach ($this->post_vars as $key => $value) { + $_POST[$key] = $value; + $_REQUEST[$key] = $value; + } + + // now execute dokuwiki and grep the output + header_remove(); + ob_start('ob_start_callback'); + include(DOKU_INC.'doku.php'); + ob_end_flush(); + + // it's done, return the page result + return new TestResponse( + $output_buffer, + headers_list() + ); + } +} + +// holds a copy of all produced outputs of a TestRequest +class TestResponse { + var $content; + var $headers; + + function __construct($content, $headers) { + $this->content = $content; + $this->headers = $headers; + } + + function getContent() { + return $this->content; + } + + function getHeaders() { + return $this->headers; + } +} -- cgit v1.2.3