Ejemplo n.º 1
0
 /**
  * @depends testFirstRun
  */
 function testSecondRun()
 {
     global $conf;
     $this->assertFalse(isset($conf['foo']), 'conf setting');
     $request = new TestRequest();
     $request->execute();
     $this->assertFalse($this->triggered, 'trigger');
 }
Ejemplo n.º 2
0
 /**
  * two requests within the same test case should be possible
  */
 function testMultipleRequests()
 {
     $request = new TestRequest();
     $response = $request->execute();
     $this->assertTrue(strpos($response->getContent(), 'DokuWiki') >= 0, 'DokuWiki was not a word in the output');
     $request = new TestRequest();
     $response = $request->execute();
     $this->assertTrue(strpos($response->getContent(), 'DokuWiki') >= 0, 'DokuWiki was not a word in the output');
 }
 /**
  * @coversNothing
  */
 public function test_no_aprroved_banner()
 {
     global $conf;
     $conf['plugin']['publish']['hide_approved_banner'] = 1;
     saveWikiText('foo', 'bar', 'foobar');
     $request = new TestRequest();
     $response = $request->get(array(), '/doku.php?id=foo&publish_approve=1');
     $this->assertTrue(strpos($response->getContent(), '<div class="approval') === false, 'The approved banner is still showing even so it is supposed not to show.');
 }
Ejemplo n.º 4
0
 /**
  * Verify the toolstrip button was correctly rendered.
  */
 public function test_render_toolstrip_button()
 {
     $thisPlugin = plugin_load('action', 'door43obsdocupload_ExportButtons');
     $request = new TestRequest();
     $response = $request->get(array('id' => 'en:obs'), '/doku.php');
     $content = $response->getContent();
     // output check
     $this->assertNotEmpty($content);
     $this->assertContains($thisPlugin->lang['getTemplate'], $content);
 }
Ejemplo n.º 5
0
 /**
  * Verify the button was correctly rendered.
  */
 public function test_render_button()
 {
     $thisPlugin = plugin_load('syntax', 'door43obs_CreateNow');
     $request = new TestRequest();
     $response = $request->get(array('id' => 'obs-setup'), '/doku.php');
     $content = $response->getContent();
     // output check
     $this->assertNotEmpty($content);
     $this->assertContains($thisPlugin->lang['createButtonText'], $content);
 }
Ejemplo n.º 6
0
 public function setUp()
 {
     parent::setUp();
     saveWikiText('foo', "====== Page-Heading ======", 'summary');
     $req = new TestRequest();
     $req->get(array(), '/doku.php?id=foo');
     saveWikiText('testpage', "---- dataentry Testentry ----\n" . "test1_title: foo|bar\n" . "----\n", 'summary');
     //trigger save to db
     $req = new TestRequest();
     $req->get(array(), '/doku.php?id=testpage');
 }
Ejemplo n.º 7
0
 function testHookTriggering()
 {
     global $EVENT_HANDLER;
     $request = new TestRequest();
     $hookTriggered = false;
     $EVENT_HANDLER->register_hook('TPL_CONTENT_DISPLAY', 'AFTER', null, function () use(&$hookTriggered) {
         $hookTriggered = true;
     });
     $request->execute();
     $this->assertTrue($hookTriggered, 'Hook was not triggered as expected!');
 }
Ejemplo n.º 8
0
 function testTestingPluginDisabledDefault()
 {
     global $EVENT_HANDLER;
     $request = new TestRequest();
     $hookTriggered = false;
     $EVENT_HANDLER->register_hook('TESTING_PLUGIN_INSTALLED', 'AFTER', null, function () use(&$hookTriggered) {
         $hookTriggered = true;
     });
     $request->execute();
     $this->assertFalse($hookTriggered, 'Testing plugin did trigger!');
 }
Ejemplo n.º 9
0
 /**
  * Verify the button was correctly rendered.
  */
 public function test_render_button()
 {
     // TODO: fix this test
     $this->markTestSkipped('The test needs fixed');
     $thisPlugin = plugin_load('syntax', 'door43obs_CreateObsNotes');
     $request = new TestRequest();
     $response = $request->get(array('id' => 'obs-setup'), '/doku.php');
     $content = $response->getContent();
     // output check
     $this->assertNotEmpty($content);
     $this->assertContains($thisPlugin->lang['createObsNotesButtonText'], $content);
 }
Ejemplo n.º 10
0
 function testTitle()
 {
     global $conf;
     $request = new TestRequest();
     $response = $request->get();
     $content = $response->queryHTML('title');
     $this->assertTrue(strpos($content, $conf['title']) > 0);
     $conf['title'] = 'Foo';
     $request = new TestRequest();
     $response = $request->get();
     $content = $response->queryHTML('title');
     $this->assertTrue(strpos($content, 'Foo') > 0);
 }
Ejemplo n.º 11
0
 /**
  * Verify the button was correctly rendered.
  */
 public function test_setChapterLabel_bug()
 {
     plugin_load('syntax', 'usfmtag');
     $request = new TestRequest();
     $response = $request->get(array('id' => 'psalm1-1test'), '/doku.php');
     $content = $response->getContent();
     // output check
     $this->assertNotEmpty($content);
     $this->assertContains('<h1 class="sectionedit1" id="psalms_0011-2">Psalms 001:1-2</h1>', $content);
     $this->assertNotContains('<usfm>', $content);
     $this->assertNotContains('\\c', $content);
     $this->assertNotContains('\\v', $content);
 }
Ejemplo n.º 12
0
 /**
  * @dataProvider invalidDataProvider
  */
 public function testHandleRequestWithExistingEntityAndInvalidData($data)
 {
     $initialName = 'Initial namn';
     $this->entity->setId(1)->setName($initialName);
     $this->request->setData($data);
     $this->form->handleRequest($this->request);
     $this->assertFalse($this->form->isValid());
     $this->assertEquals($this->entity->getName(), $initialName);
 }
Ejemplo n.º 13
0
 /**
  * Blackbox integration test of action_plugin_publish_mail::getLastApproved
  *
  * @coversNothing
  */
 public function test_getLastApproved()
 {
     global $ID;
     $ID = 'foo';
     saveWikiText('foo', 'bar old', 'foobar');
     saveWikiText('foo', 'bar approved', 'foobar');
     $data = pageinfo();
     $expected_revision = $data['currentrev'];
     //Make sure we have the rights to actully approve a revision
     $this->assertSame(255, auth_quickaclcheck('foo'));
     $request = new TestRequest();
     $request->get(array(), '/doku.php?id=foo&publish_approve');
     saveWikiText('foo', 'bar new', 'foobar');
     /** @var helper_plugin_publish $helper */
     $helper = plugin_load('helper', 'publish');
     $actual_lastapproved_helper = $helper->getLatestApprovedRevision($ID);
     $this->assertSame($expected_revision, $actual_lastapproved_helper);
 }
Ejemplo n.º 14
0
 /**
  * Regression test: run activity by namespace report, verify correct values
  * appear
  *
  * @return nothing
  */
 public function test_activity_by_namespace()
 {
     $request = new TestRequest();
     $response = $request->get(array('id' => 'test_activity_by_namespace'), '/doku.php');
     $content = $response->getContent();
     $this->assertNotEmpty($content);
     // Verify totals
     $this->assertRegExp("/TOTAL<[^>]*><[^>]*>6<[^>]*><[^>]*>35<[^>]*><[^>]*>30/", $content);
     // need to do this because strtotime uses the timezone on the server
     $start_timestamp = strtotime('2015-07-01');
     $end_timestamp = strtotime('2015-07-04');
     // Verify timestamps were understood correctly
     $this->assertRegExp("/start_timestamp<[^>]*><[^>]*>{$start_timestamp}/", $content);
     $this->assertRegExp("/end_timestamp<[^>]*><[^>]*>{$end_timestamp}/", $content);
     // Verify page counts
     $this->assertRegExp("/debug_num_pages_in_ns<[^>]*><[^>]*>70/", $content);
     $this->assertRegExp("/debug_num_revisions_in_ns<[^>]*><[^>]*>2039/", $content);
     $this->assertRegExp("/debug_num_revisions_within_dates<[^>]*><[^>]*>169/", $content);
 }
Ejemplo n.º 15
0
 function testGet()
 {
     $request = new TestRequest();
     $input = array('string' => 'A string', 'array' => array(1, 2, 3), 'test' => 'bar');
     $response = $request->get($input, '/doku.php?id=wiki:dokuwiki&test=foo');
     // server var check
     $this->assertEquals('GET', $request->getServer('REQUEST_METHOD'));
     $this->assertEquals('?id=wiki:dokuwiki&test=bar&string=A+string&array[0]=1&array[1]=2&array[2]=3', $request->getServer('QUERY_STRING'));
     $this->assertEquals('/doku.php?id=wiki:dokuwiki&test=bar&string=A+string&array[0]=1&array[1]=2&array[2]=3', $request->getServer('REQUEST_URI'));
     // variable setup check
     $this->assertEquals('A string', $request->getGet('string'));
     $this->assertEquals(array(1, 2, 3), $request->getGet('array'));
     $this->assertEquals('wiki:dokuwiki', $request->getGet('id'));
     $this->assertEquals('bar', $request->getGet('test'));
     // output check
     $this->assertTrue(strpos($response->getContent(), 'Andreas Gohr') >= 0);
 }
Ejemplo n.º 16
0
 public function test_diff()
 {
     $page = 'test_save_page_without_new_text';
     $assignment = new meta\Assignments();
     $schema = 'schema1';
     $assignment->addPattern($page, $schema);
     $wikitext = 'teststring';
     // first save;
     $request = new \TestRequest();
     $structData = array($schema => array('first' => 'foo', 'second' => 'bar, baz', 'third' => 'foobar', 'fourth' => '42'));
     $request->setPost('struct_schema_data', $structData);
     $request->setPost('wikitext', $wikitext);
     $request->setPost('summary', 'content and struct data saved');
     $request->post(array('id' => $page, 'do' => 'save'), '/doku.php');
     $this->waitForTick(true);
     // second save - only struct data
     $request = new \TestRequest();
     $structData = array($schema => array('first' => 'foo', 'second' => 'bar2, baz2', 'third' => 'foobar2', 'fourth' => '42'));
     $request->setPost('struct_schema_data', $structData);
     $request->setPost('wikitext', $wikitext);
     $request->setPost('summary', '2nd revision');
     $request->post(array('id' => $page, 'do' => 'save'), '/doku.php');
     // diff
     $request = new \TestRequest();
     $response = $request->post(array('id' => $page, 'do' => 'diff'), '/doku.php');
     $pq = $response->queryHTML('table.diff_sidebyside');
     $this->assertEquals(1, $pq->length);
     $added = $pq->find('td.diff-addedline');
     $deleted = $pq->find('td.diff-deletedline');
     $this->assertEquals(2, $added->length);
     $this->assertEquals(2, $deleted->length);
     $this->assertContains('bar', $deleted->eq(0)->html());
     $this->assertContains('baz', $deleted->eq(0)->html());
     $this->assertContains('bar2', $added->eq(0)->html());
     $this->assertContains('baz2', $added->eq(0)->html());
     $this->assertContains('foobar', $deleted->eq(1)->html());
     $this->assertContains('foobar2', $added->eq(1)->html());
 }
Ejemplo n.º 17
0
 public function request($method, $path, $data, $headers = [])
 {
     // Capture STDOUT
     ob_start();
     // Prepare a mock environment
     $options = ['REQUEST_METHOD' => $method, 'SERVER_PORT' => '8000', 'REQUEST_URI' => $path, 'SERVER_NAME' => 'localhost'];
     foreach ($headers as $key => $value) {
         $options['HTTP_' . $key] = $value;
     }
     $env = Environment::mock($options);
     $request = TestRequest::createFromEnvironment($env, $data);
     $container = new \Slim\Container(["environment" => $env, "request" => $request]);
     // Run the application
     // this creates an Slim $app
     $app = new \Slim\App($container);
     require __DIR__ . '/../app/app.php';
     $this->app = $app;
     $this->request = $app->getContainer()->get("request");
     // We fire the routes
     $this->response = $this->app->run();
     // Return STDOUT
     return ob_get_clean();
 }
 /**
  * Test that, if provided, an IP address is logged.
  * @link https://github.com/samwilson/dokuwiki-plugin-log404/issues/1
  */
 public function test_ip_address()
 {
     $log = plugin_load('helper', 'log404');
     // Reset the log
     @unlink($log->filename());
     // Request a page.
     $request1 = new TestRequest();
     //$request1->setServer('HTTP_USER_AGENT', '198.51.100.35');
     $request1->get(array('id' => 'page-that-does-not-exist'));
     // Check the log. This IP is set in _test/bootstrap.php
     $log->load();
     $a = $log->getRecord('page-that-does-not-exist');
     $this->assertEquals('87.142.120.6', $a['hits'][0]['ip']);
 }
 function fetchResponse($token)
 {
     $request = new TestRequest();
     return $request->get(array(), str_replace('{%token%}', $token, $this->getUri()));
 }
Ejemplo n.º 20
0
 function testINPUT()
 {
     $request = new TestRequest();
     $response = $request->get(array('id' => 'mailinglist'), '/doku.php');
     // output check
     // 2015-07-03, Phil Hopper: this is silly and also failing
     //$this->assertTrue(strpos($response->getContent(), 'Netiquette') !== false);
 }
Ejemplo n.º 21
0
 public static function errorFromRequest(TestRequest $request, $message)
 {
     return new TestResult(['testId' => $request->getId(), 'class' => $request->getClass(), 'name' => $request->getName(), 'filename' => $request->getFilename(), 'errors' => [new Error(['message' => $message])]]);
 }
Ejemplo n.º 22
0
 /**
  * @group slow
  */
 public function test_revert_page()
 {
     $page = 'test_revert_page';
     $assignment = new meta\Assignments();
     $schema = 'Schema2';
     $assignment->addPattern($page, $schema);
     $wikitext = 'teststring';
     global $conf;
     $conf['useacl'] = 1;
     $conf['superuser'] = '******';
     $_SERVER['REMOTE_USER'] = '******';
     //now it's testing as admin
     global $default_server_vars;
     $default_server_vars['REMOTE_USER'] = '******';
     //Hack until Issue #1099 is fixed
     $USERINFO['grps'] = array('admin', 'user');
     // first save;
     $request = new \TestRequest();
     $structData = array($schema => array('afirst' => 'foo', 'asecond' => 'bar, baz', 'athird' => 'foobar', 'afourth' => '42'));
     $request->setPost('struct_schema_data', $structData);
     $request->setPost('wikitext', $wikitext);
     $request->setPost('summary', 'content and struct data saved');
     $request->post(array('id' => $page, 'do' => 'save', 'sectok' => getSecurityToken()), '/doku.php');
     $this->waitForTick(true);
     // second save
     $request = new \TestRequest();
     $structData = array($schema => array('afirst' => 'foo2', 'asecond' => 'bar2, baz2', 'athird' => 'foobar2', 'afourth' => '43'));
     $request->setPost('struct_schema_data', $structData);
     $request->setPost('wikitext', $wikitext . $wikitext);
     $request->setPost('summary', 'delete page');
     $request->post(array('id' => $page, 'do' => 'save', 'sectok' => getSecurityToken()), '/doku.php');
     $this->waitForTick(true);
     // revert to first save
     $actpagelog = new \PageChangelog($page);
     $actrevisions = $actpagelog->getRevisions(0, 200);
     $actrevinfo = $actpagelog->getRevisionInfo($actrevisions[0]);
     $request = new \TestRequest();
     $request->setPost('summary', 'revert page');
     $request->post(array('id' => $page, 'do' => 'revert', 'rev' => $actrevinfo['date'], 'sectok' => getSecurityToken()), '/doku.php');
     // assert
     $pagelog = new \PageChangelog($page);
     $revisions = $pagelog->getRevisions(-1, 200);
     $revinfo = $pagelog->getRevisionInfo($revisions[0]);
     $schemaData = meta\AccessTable::byTableName($schema, $page, 0);
     $actual_struct_data = $schemaData->getDataArray();
     $expected_struct_data = array('afirst' => 'foo', 'asecond' => array('bar', 'baz'), 'athird' => 'foobar', 'afourth' => '42');
     $this->assertEquals(3, count($revisions), 'there should be 3 (three) revisions');
     $this->assertContains('restored', $revinfo['sum']);
     $this->assertEquals(DOKU_CHANGE_TYPE_REVERT, $revinfo['type']);
     $this->assertEquals($expected_struct_data, $actual_struct_data);
     // todo: timestamps?
 }
Ejemplo n.º 23
0
 /**
  * Execute the simplest possible request and check the
  * meta generator tag is set to "DokuWiki"
  */
 function testSimpleRun()
 {
     $request = new TestRequest();
     $response = $request->execute();
     $this->assertEquals('DokuWiki', $response->queryHTML('meta[name="generator"]')->attr('content'));
 }
Ejemplo n.º 24
0
 function testINPUT()
 {
     $request = new TestRequest();
     $response = $request->get(array('id' => 'mailinglist'), '/doku.php');
     // output check
     $this->assertTrue(strpos($response->getContent(), 'Netiquette') !== false);
 }
Ejemplo n.º 25
0
 function testHeaders()
 {
     header('X-Test: check headers working');
     $header_check = function_exists('xdebug_get_headers') ? xdebug_get_headers() : headers_list();
     if (empty($header_check)) {
         $this->markTestSkipped('headers not returned, perhaps your sapi does not return headers, try xdebug');
     } else {
         header_remove('X-Test');
     }
     $request = new TestRequest();
     $response = $request->get(array(), '/lib/exe/fetch.php?media=wiki:dokuwiki-128.png');
     $headers = $response->getHeaders();
     $this->assertTrue(!empty($headers));
 }
 /**
  * This is an integration test, which checks the correct working of an entire namespace move.
  * Hence it is not an unittest, hence it @coversNothing
  *
  * @group slow
  */
 function test_move_large_ns()
 {
     $this->markTestSkipped('This test randomly fails with the page "testns:start" being moved, but "start" not being rewritten in the request.');
     global $conf;
     $test = '[[testns:start]] [[testns:test_page17]]';
     $summary = 'testsetup';
     saveWikiText(':start', $test, $summary);
     idx_addPage(':start');
     saveWikiText('testns:start', $test, $summary);
     idx_addPage('testns:start');
     saveWikiText('testns:test_page1', $test, $summary);
     idx_addPage('testns:test_page1');
     saveWikiText('testns:test_page2', $test, $summary);
     idx_addPage('testns:test_page2');
     saveWikiText('testns:test_page3', $test, $summary);
     idx_addPage('testns:test_page3');
     saveWikiText('testns:test_page4', $test, $summary);
     idx_addPage('testns:test_page4');
     saveWikiText('testns:test_page5', $test, $summary);
     idx_addPage('testns:test_page5');
     saveWikiText('testns:test_page6', $test, $summary);
     idx_addPage('testns:test_page6');
     saveWikiText('testns:test_page7', $test, $summary);
     idx_addPage('testns:test_page7');
     saveWikiText('testns:test_page8', $test, $summary);
     idx_addPage('testns:test_page8');
     saveWikiText('testns:test_page9', $test, $summary);
     idx_addPage('testns:test_page9');
     saveWikiText('testns:test_page10', $test, $summary);
     idx_addPage('testns:test_page10');
     saveWikiText('testns:test_page11', $test, $summary);
     idx_addPage('testns:test_page11');
     saveWikiText('testns:test_page12', $test, $summary);
     idx_addPage('testns:test_page12');
     saveWikiText('testns:test_page13', $test, $summary);
     idx_addPage('testns:test_page13');
     saveWikiText('testns:test_page14', $test, $summary);
     idx_addPage('testns:test_page14');
     saveWikiText('testns:test_page15', $test, $summary);
     idx_addPage('testns:test_page15');
     saveWikiText('testns:test_page16', $test, $summary);
     idx_addPage('testns:test_page16');
     saveWikiText('testns:test_page17', $test, $summary);
     idx_addPage('testns:test_page17');
     saveWikiText('testns:test_page18', $test, $summary);
     idx_addPage('testns:test_page18');
     saveWikiText('testns:test_page19', $test, $summary);
     idx_addPage('testns:test_page19');
     $conf['plugin']['move']['autorewrite'] = 0;
     /** @var helper_plugin_move_plan $plan  */
     $plan = plugin_load('helper', 'move_plan');
     $this->assertFalse($plan->inProgress());
     $plan->addPageNamespaceMove('testns', 'foo:testns');
     $plan->commit();
     global $conf;
     $lockfile = $conf['lockdir'] . 'move.lock';
     $this->assertSame(10, $plan->nextStep(), "After processing first chunk of pages, 10 steps should be left");
     $request = new TestRequest();
     $response = $request->get();
     $actual_response = $response->getContent();
     //clean away clutter
     $actual_response = substr($actual_response, strpos($actual_response, "<!-- wikipage start -->") + 23);
     $actual_response = substr($actual_response, strpos($actual_response, 'doku.php'));
     $actual_response = substr($actual_response, 0, strpos($actual_response, "<!-- wikipage stop -->"));
     $actual_response = trim($actual_response);
     $actual_response = rtrim($actual_response, "</p>");
     $actual_response = trim($actual_response);
     $expected_response = 'doku.php?id=foo:testns:start" class="wikilink1" title="foo:testns:start">testns</a> <a href="/./doku.php?id=testns:test_page17" class="wikilink1" title="testns:test_page17">test_page17</a>';
     $this->assertSame($expected_response, $actual_response);
     // todo: this assert fails occaisionally, but not reproduciably. It then has the following oputput: <a href="/./doku.php?id=testns:start" class="wikilink2" title="testns:start" rel="nofollow">testns</a> <a href="/./doku.php?id=testns:test_page17" class="wikilink1" title="testns:test_page17">test_page17</a>
     $expected_file_contents = '[[testns:start]] [[testns:test_page17]]';
     $start_file = file(TMP_DIR . '/data/pages/start.txt');
     $actual_file_contents = $start_file[0];
     $this->assertSame($expected_file_contents, $actual_file_contents);
     /** @var helper_plugin_move_rewrite $rewrite */
     $rewrite = plugin_load('helper', 'move_rewrite');
     $expected_move_meta = array('origin' => 'testns:start', 'pages' => array(array('testns:start', 'foo:testns:start')), 'media' => array());
     $actual_move_media = $rewrite->getMoveMeta('foo:testns:start');
     $this->assertSame($expected_move_meta, $actual_move_media);
     $this->assertFileExists($lockfile);
 }
Ejemplo n.º 27
0
 public function testEncodeDecode()
 {
     $request = new TestRequest(1, 'a', 'b', 'c');
     $recodedRequest = TestRequest::decode($request->encode());
     $this->assertEquals($recodedRequest, $request);
 }