Exemplo n.º 1
0
 function testPostGet()
 {
     $request = new TestRequest();
     $input = array('string' => 'A string', 'array' => array(1, 2, 3));
     $response = $request->post($input, '/doku.php?id=wiki:dokuwiki');
     // server var check
     $this->assertEquals('POST', $request->getServer('REQUEST_METHOD'));
     $this->assertEquals('?id=wiki:dokuwiki', $request->getServer('QUERY_STRING'));
     $this->assertEquals('/doku.php?id=wiki:dokuwiki', $request->getServer('REQUEST_URI'));
     // variable setup check
     $this->assertEquals('A string', $request->getPost('string'));
     $this->assertEquals(array(1, 2, 3), $request->getPost('array'));
     $this->assertEquals('wiki:dokuwiki', $request->getGet('id'));
     // output check
     $this->assertTrue(strpos($response->getContent(), 'Andreas Gohr') >= 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());
 }
 /**
  * @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?
 }