18fed17f3SAndreas Gohr<?php 28fed17f3SAndreas Gohr 38fed17f3SAndreas Gohrnamespace dokuwiki\plugin\struct\test\action; 48fed17f3SAndreas Gohr 5*6a819106SAndreas Gohruse dokuwiki\ChangeLog\PageChangeLog; 68fed17f3SAndreas Gohruse dokuwiki\plugin\struct\meta; 78fed17f3SAndreas Gohruse dokuwiki\plugin\struct\test\mock\action_plugin_struct_edit; 88fed17f3SAndreas Gohruse dokuwiki\plugin\struct\test\mock\Assignments; 98fed17f3SAndreas Gohruse dokuwiki\plugin\struct\test\StructTest; 10850ad33eSAndreas Gohruse DOMWrap\Document; 118fed17f3SAndreas Gohr 128fed17f3SAndreas Gohr/** 138fed17f3SAndreas Gohr * @group plugin_struct 148fed17f3SAndreas Gohr * @group plugins 158fed17f3SAndreas Gohr * 168fed17f3SAndreas Gohr * @covers action_plugin_struct_revert 178fed17f3SAndreas Gohr * @covers action_plugin_struct_edit 188fed17f3SAndreas Gohr */ 198fed17f3SAndreas Gohrclass EditTest extends StructTest 208fed17f3SAndreas Gohr{ 218fed17f3SAndreas Gohr 228fed17f3SAndreas Gohr public function setUp(): void 238fed17f3SAndreas Gohr { 248fed17f3SAndreas Gohr parent::setUp(); 258fed17f3SAndreas Gohr 268fed17f3SAndreas Gohr $this->loadSchemaJSON('schema1'); 278fed17f3SAndreas Gohr $this->loadSchemaJSON('schema2', 'schema2int'); 288fed17f3SAndreas Gohr $this->saveData( 298fed17f3SAndreas Gohr 'page01', 308fed17f3SAndreas Gohr 'schema1', 318fed17f3SAndreas Gohr [ 328fed17f3SAndreas Gohr 'first' => 'first data', 338fed17f3SAndreas Gohr 'second' => ['second data', 'more data', 'even more'], 348fed17f3SAndreas Gohr 'third' => 'third data', 358fed17f3SAndreas Gohr 'fourth' => 'fourth data' 368fed17f3SAndreas Gohr ], 378fed17f3SAndreas Gohr time() 388fed17f3SAndreas Gohr ); 398fed17f3SAndreas Gohr } 408fed17f3SAndreas Gohr 41850ad33eSAndreas Gohr /** 42850ad33eSAndreas Gohr * Check if a field has the correct value 43850ad33eSAndreas Gohr * 44850ad33eSAndreas Gohr * @param Document $pq 45850ad33eSAndreas Gohr * @param string $schema 46850ad33eSAndreas Gohr * @param string $name 47850ad33eSAndreas Gohr * @param string $value 48850ad33eSAndreas Gohr */ 49850ad33eSAndreas Gohr protected function checkField(Document $pq, $schema, $name, $value) 508fed17f3SAndreas Gohr { 51850ad33eSAndreas Gohr $this->assertEquals( 52850ad33eSAndreas Gohr 1, 53850ad33eSAndreas Gohr $pq->find("span.label:contains('$name')")->count(), 54850ad33eSAndreas Gohr "Field $schema.$name not found" 55850ad33eSAndreas Gohr ); 56850ad33eSAndreas Gohr $this->assertEquals( 57850ad33eSAndreas Gohr $value, 58850ad33eSAndreas Gohr $pq->find("input[name='struct_schema_data[$schema][$name]']")->attr('value'), 59850ad33eSAndreas Gohr "Field $schema.$name has wrong value" 60850ad33eSAndreas Gohr ); 618fed17f3SAndreas Gohr } 628fed17f3SAndreas Gohr 638fed17f3SAndreas Gohr public function test_createForm_storedData() 648fed17f3SAndreas Gohr { 658fed17f3SAndreas Gohr $edit = new action_plugin_struct_edit(); 668fed17f3SAndreas Gohr global $ID; 678fed17f3SAndreas Gohr $ID = 'page01'; 688fed17f3SAndreas Gohr $test_html = $edit->createForm('schema1'); 698fed17f3SAndreas Gohr 70850ad33eSAndreas Gohr $doc = new Document(); 7176e537bfSAndreas Gohr $doc->html($test_html); 72850ad33eSAndreas Gohr $this->assertEquals('schema1', $doc->find('legend')->text()); 73850ad33eSAndreas Gohr $this->checkField($doc, 'schema1', 'first', 'first data'); 74850ad33eSAndreas Gohr $this->checkField($doc, 'schema1', 'second', 'second data, more data, even more'); 75850ad33eSAndreas Gohr $this->checkField($doc, 'schema1', 'third', 'third data'); 76850ad33eSAndreas Gohr $this->checkField($doc, 'schema1', 'fourth', 'fourth data'); 778fed17f3SAndreas Gohr } 788fed17f3SAndreas Gohr 798fed17f3SAndreas Gohr public function test_createForm_emptyData() 808fed17f3SAndreas Gohr { 818fed17f3SAndreas Gohr $edit = new action_plugin_struct_edit(); 828fed17f3SAndreas Gohr global $ID; 838fed17f3SAndreas Gohr $ID = 'page02'; 848fed17f3SAndreas Gohr $test_html = $edit->createForm('schema1'); 858fed17f3SAndreas Gohr 86850ad33eSAndreas Gohr $doc = new Document(); 8776e537bfSAndreas Gohr $doc->html($test_html); 88850ad33eSAndreas Gohr $this->assertEquals('schema1', $doc->find('legend')->text()); 89850ad33eSAndreas Gohr $this->checkField($doc, 'schema1', 'first', ''); 90850ad33eSAndreas Gohr $this->checkField($doc, 'schema1', 'second', ''); 91850ad33eSAndreas Gohr $this->checkField($doc, 'schema1', 'third', ''); 92850ad33eSAndreas Gohr $this->checkField($doc, 'schema1', 'fourth', ''); 938fed17f3SAndreas Gohr } 948fed17f3SAndreas Gohr 958fed17f3SAndreas Gohr public function test_createForm_postData() 968fed17f3SAndreas Gohr { 978fed17f3SAndreas Gohr global $INPUT, $ID; 988fed17f3SAndreas Gohr $ID = 'page01'; 998fed17f3SAndreas Gohr $structdata = [ 1008fed17f3SAndreas Gohr 'schema1' => [ 1018fed17f3SAndreas Gohr 'first' => 'first post data', 1028fed17f3SAndreas Gohr 'second' => ['second post data', 'more post data', 'even more post data'], 1038fed17f3SAndreas Gohr 'third' => 'third post data', 1048fed17f3SAndreas Gohr 'fourth' => 'fourth post data' 1058fed17f3SAndreas Gohr ] 1068fed17f3SAndreas Gohr ]; 1078fed17f3SAndreas Gohr $INPUT->set(action_plugin_struct_edit::getVAR(), $structdata); 1088fed17f3SAndreas Gohr 1098fed17f3SAndreas Gohr $edit = new action_plugin_struct_edit(); 1108fed17f3SAndreas Gohr $test_html = $edit->createForm('schema1'); 1118fed17f3SAndreas Gohr 112850ad33eSAndreas Gohr $doc = new Document(); 11376e537bfSAndreas Gohr $doc->html($test_html); 114850ad33eSAndreas Gohr $this->assertEquals('schema1', $doc->find('legend')->text()); 115850ad33eSAndreas Gohr $this->checkField($doc, 'schema1', 'first', 'first post data'); 116850ad33eSAndreas Gohr $this->checkField($doc, 'schema1', 'second', 'second post data, more post data, even more post data'); 117850ad33eSAndreas Gohr $this->checkField($doc, 'schema1', 'third', 'third post data'); 118850ad33eSAndreas Gohr $this->checkField($doc, 'schema1', 'fourth', 'fourth post data'); 1198fed17f3SAndreas Gohr } 1208fed17f3SAndreas Gohr 1218fed17f3SAndreas Gohr public function test_edit_page_wo_schema() 1228fed17f3SAndreas Gohr { 1238fed17f3SAndreas Gohr $page = 'test_edit_page_wo_schema'; 1248fed17f3SAndreas Gohr 1258fed17f3SAndreas Gohr $request = new \TestRequest(); 1268fed17f3SAndreas Gohr $response = $request->get(['id' => $page, 'do' => 'edit'], '/doku.php'); 1278fed17f3SAndreas Gohr $structElement = $response->queryHTML('.struct_entry_form'); 1288fed17f3SAndreas Gohr 1298fed17f3SAndreas Gohr $this->assertCount(1, $structElement); 130*6a819106SAndreas Gohr $this->assertEquals('', $structElement->html()); 1318fed17f3SAndreas Gohr } 1328fed17f3SAndreas Gohr 1338fed17f3SAndreas Gohr public function test_edit_page_with_schema() 1348fed17f3SAndreas Gohr { 1358fed17f3SAndreas Gohr $page = 'test_edit_page_with_schema'; 1368fed17f3SAndreas Gohr $assignment = Assignments::getInstance(); 1378fed17f3SAndreas Gohr $schema = 'schema2'; 1388fed17f3SAndreas Gohr $assignment->addPattern($page, $schema); 1398fed17f3SAndreas Gohr 1408fed17f3SAndreas Gohr $request = new \TestRequest(); 1418fed17f3SAndreas Gohr $response = $request->get(['id' => $page, 'do' => 'edit'], '/doku.php'); 1428fed17f3SAndreas Gohr $test_html = trim($response->queryHTML('.struct_entry_form')->html()); 1438fed17f3SAndreas Gohr 144850ad33eSAndreas Gohr $doc = new Document(); 14576e537bfSAndreas Gohr $doc->html($test_html); 146850ad33eSAndreas Gohr $this->assertEquals('schema2', $doc->find('legend')->text()); 147850ad33eSAndreas Gohr $this->checkField($doc, 'schema2', 'afirst', ''); 148850ad33eSAndreas Gohr $this->checkField($doc, 'schema2', 'asecond', ''); 149850ad33eSAndreas Gohr $this->checkField($doc, 'schema2', 'athird', ''); 150850ad33eSAndreas Gohr $this->checkField($doc, 'schema2', 'afourth', ''); 1518fed17f3SAndreas Gohr } 1528fed17f3SAndreas Gohr 1538fed17f3SAndreas Gohr public function test_preview_page_invaliddata() 1548fed17f3SAndreas Gohr { 1558fed17f3SAndreas Gohr $page = 'test_preview_page_invaliddata'; 1568fed17f3SAndreas Gohr $assignment = Assignments::getInstance(); 1578fed17f3SAndreas Gohr $schema = 'schema2'; 1588fed17f3SAndreas Gohr $assignment->addPattern($page, $schema); 1598fed17f3SAndreas Gohr 1608fed17f3SAndreas Gohr $request = new \TestRequest(); 1618fed17f3SAndreas Gohr $structData = [ 1628fed17f3SAndreas Gohr $schema => [ 1638fed17f3SAndreas Gohr 'afirst' => 'foo', 1648fed17f3SAndreas Gohr 'asecond' => 'bar, baz', 1658fed17f3SAndreas Gohr 'athird' => 'foobar', 1668fed17f3SAndreas Gohr 'afourth' => 'Eve' 1678fed17f3SAndreas Gohr ] 1688fed17f3SAndreas Gohr ]; 1698fed17f3SAndreas Gohr $request->setPost('struct_schema_data', $structData); 170*6a819106SAndreas Gohr $response = $request->post(['id' => $page, 'do' => 'preview']); 1718fed17f3SAndreas Gohr $expected_errormsg = sprintf($this->getLang('validation_prefix') . $this->getLang('Validation Exception Decimal needed'), 'afourth'); 1728fed17f3SAndreas Gohr $actual_errormsg = $response->queryHTML('.error')->html(); 1738fed17f3SAndreas Gohr $test_html = trim($response->queryHTML('.struct_entry_form')->html()); 1748fed17f3SAndreas Gohr 1758fed17f3SAndreas Gohr $this->assertEquals($expected_errormsg, $actual_errormsg, 'If there is invalid data, then there should be an error message.'); 1768fed17f3SAndreas Gohr 177850ad33eSAndreas Gohr $doc = new Document(); 17876e537bfSAndreas Gohr $doc->html($test_html); 179850ad33eSAndreas Gohr $this->assertEquals('schema2', $doc->find('legend')->text()); 180850ad33eSAndreas Gohr $this->checkField($doc, 'schema2', 'afirst', 'foo'); 181850ad33eSAndreas Gohr $this->checkField($doc, 'schema2', 'asecond', 'bar, baz'); 182850ad33eSAndreas Gohr $this->checkField($doc, 'schema2', 'athird', 'foobar'); 183850ad33eSAndreas Gohr $this->checkField($doc, 'schema2', 'afourth', 'Eve'); 1848fed17f3SAndreas Gohr } 1858fed17f3SAndreas Gohr 1868fed17f3SAndreas Gohr public function test_preview_page_validdata() 1878fed17f3SAndreas Gohr { 1888fed17f3SAndreas Gohr $page = 'test_preview_page_validdata'; 1898fed17f3SAndreas Gohr $assignment = Assignments::getInstance(); 1908fed17f3SAndreas Gohr $schema = 'schema2'; 1918fed17f3SAndreas Gohr $assignment->addPattern($page, $schema); 1928fed17f3SAndreas Gohr 1938fed17f3SAndreas Gohr $request = new \TestRequest(); 1948fed17f3SAndreas Gohr $structData = [ 1958fed17f3SAndreas Gohr $schema => [ 1968fed17f3SAndreas Gohr 'afirst' => 'foo', 1978fed17f3SAndreas Gohr 'asecond' => 'bar, baz', 1988fed17f3SAndreas Gohr 'athird' => 'foobar', 1998fed17f3SAndreas Gohr 'afourth' => '42' 2008fed17f3SAndreas Gohr ] 2018fed17f3SAndreas Gohr ]; 2028fed17f3SAndreas Gohr $request->setPost('struct_schema_data', $structData); 203850ad33eSAndreas Gohr $response = $request->post(['id' => $page, 'do' => 'preview']); 204850ad33eSAndreas Gohr $actual_errormsg = $response->queryHTML('.error')->get(0); 205850ad33eSAndreas Gohr $this->assertNull($actual_errormsg, "If all data is valid, then there should be no error message."); 206850ad33eSAndreas Gohr 2078fed17f3SAndreas Gohr $test_html = trim($response->queryHTML('.struct_entry_form')->html()); 2088fed17f3SAndreas Gohr 209850ad33eSAndreas Gohr $doc = new Document(); 21076e537bfSAndreas Gohr $doc->html($test_html); 211850ad33eSAndreas Gohr $this->assertEquals('schema2', $doc->find('legend')->text()); 212850ad33eSAndreas Gohr $this->checkField($doc, 'schema2', 'afirst', 'foo'); 213850ad33eSAndreas Gohr $this->checkField($doc, 'schema2', 'asecond', 'bar, baz'); 214850ad33eSAndreas Gohr $this->checkField($doc, 'schema2', 'athird', 'foobar'); 215850ad33eSAndreas Gohr $this->checkField($doc, 'schema2', 'afourth', '42'); 2168fed17f3SAndreas Gohr } 2178fed17f3SAndreas Gohr 2188fed17f3SAndreas Gohr public function test_fail_saving_empty_page() 2198fed17f3SAndreas Gohr { 2208fed17f3SAndreas Gohr $page = 'test_fail_saving_empty_page'; 2218fed17f3SAndreas Gohr $assignment = Assignments::getInstance(); 2228fed17f3SAndreas Gohr $schema = 'schema2'; 2238fed17f3SAndreas Gohr $assignment->addPattern($page, $schema); 2248fed17f3SAndreas Gohr 2258fed17f3SAndreas Gohr $request = new \TestRequest(); 2268fed17f3SAndreas Gohr $structData = [ 2278fed17f3SAndreas Gohr $schema => [ 2288fed17f3SAndreas Gohr 'afirst' => 'foo', 2298fed17f3SAndreas Gohr 'asecond' => 'bar, baz', 2308fed17f3SAndreas Gohr 'athird' => 'foobar', 2318fed17f3SAndreas Gohr 'afourth' => '42' 2328fed17f3SAndreas Gohr ] 2338fed17f3SAndreas Gohr ]; 2348fed17f3SAndreas Gohr $request->setPost('struct_schema_data', $structData); 2358fed17f3SAndreas Gohr $request->setPost('summary', 'only struct data saved'); 2368fed17f3SAndreas Gohr $response = $request->post(['id' => $page, 'do' => 'save'], '/doku.php'); 2378fed17f3SAndreas Gohr $expected_errormsg = $this->getLang('emptypage'); 2388fed17f3SAndreas Gohr $actual_errormsg = $response->queryHTML('.error')->html(); 239*6a819106SAndreas Gohr $pagelog = new PageChangelog($page); 2408fed17f3SAndreas Gohr $revisions = $pagelog->getRevisions(-1, 200); 2418fed17f3SAndreas Gohr 2428fed17f3SAndreas Gohr $this->assertCount(0, $revisions); 2438fed17f3SAndreas Gohr $this->assertEquals($expected_errormsg, $actual_errormsg, "An empty page should not be saved."); 2448fed17f3SAndreas Gohr } 2458fed17f3SAndreas Gohr 2468fed17f3SAndreas Gohr public function test_fail_saveing_page_with_invaliddata() 2478fed17f3SAndreas Gohr { 2488fed17f3SAndreas Gohr $page = 'test_fail_saveing_page_with_invaliddata'; 2498fed17f3SAndreas Gohr $assignment = Assignments::getInstance(); 2508fed17f3SAndreas Gohr $schema = 'schema2'; 2518fed17f3SAndreas Gohr $assignment->addPattern($page, $schema); 2528fed17f3SAndreas Gohr 2538fed17f3SAndreas Gohr $wikitext = 'teststring'; 2548fed17f3SAndreas Gohr $request = new \TestRequest(); 2558fed17f3SAndreas Gohr $structData = [ 2568fed17f3SAndreas Gohr $schema => [ 2578fed17f3SAndreas Gohr 'afirst' => 'foo', 2588fed17f3SAndreas Gohr 'asecond' => 'bar, baz', 2598fed17f3SAndreas Gohr 'athird' => 'foobar', 2608fed17f3SAndreas Gohr 'afourth' => 'Eve' 2618fed17f3SAndreas Gohr ] 2628fed17f3SAndreas Gohr ]; 2638fed17f3SAndreas Gohr $request->setPost('struct_schema_data', $structData); 2648fed17f3SAndreas Gohr $request->setPost('wikitext', $wikitext); 2658fed17f3SAndreas Gohr $request->setPost('summary', 'content and struct data saved'); 266*6a819106SAndreas Gohr $response = $request->post(['id' => $page, 'do' => 'save']); 2678fed17f3SAndreas Gohr $actual_wikitext = trim($response->queryHTML('#wiki__text')->html()); 2688fed17f3SAndreas Gohr $expected_wikitext = $wikitext; 2698fed17f3SAndreas Gohr 2708fed17f3SAndreas Gohr $actual_errormsg = $response->queryHTML('.error')->html(); 2718fed17f3SAndreas Gohr $expected_errormsg = sprintf($this->getLang('validation_prefix') . $this->getLang('Validation Exception Decimal needed'), 'afourth'); 2728fed17f3SAndreas Gohr 2738fed17f3SAndreas Gohr $test_html = trim($response->queryHTML('.struct_entry_form')->html()); 2748fed17f3SAndreas Gohr 275*6a819106SAndreas Gohr $pagelog = new PageChangelog($page); 2768fed17f3SAndreas Gohr $revisions = $pagelog->getRevisions(-1, 200); 2778fed17f3SAndreas Gohr 2788fed17f3SAndreas Gohr // assert 2798fed17f3SAndreas Gohr $this->assertCount(0, $revisions); 2808fed17f3SAndreas Gohr $this->assertEquals($expected_errormsg, $actual_errormsg, 'If there is invalid data, then there should be an error message.'); 2818fed17f3SAndreas Gohr $this->assertEquals($expected_wikitext, $actual_wikitext); 2828fed17f3SAndreas Gohr 283850ad33eSAndreas Gohr $doc = new Document(); 28476e537bfSAndreas Gohr $doc->html($test_html); 285850ad33eSAndreas Gohr $this->assertEquals('schema2', $doc->find('legend')->text()); 286850ad33eSAndreas Gohr $this->checkField($doc, 'schema2', 'afirst', 'foo'); 287850ad33eSAndreas Gohr $this->checkField($doc, 'schema2', 'asecond', 'bar, baz'); 288850ad33eSAndreas Gohr $this->checkField($doc, 'schema2', 'athird', 'foobar'); 289850ad33eSAndreas Gohr $this->checkField($doc, 'schema2', 'afourth', 'Eve'); 2908fed17f3SAndreas Gohr 2918fed17f3SAndreas Gohr // todo: assert that no struct data has been saved 2928fed17f3SAndreas Gohr } 2938fed17f3SAndreas Gohr 2948fed17f3SAndreas Gohr public function test_save_page() 2958fed17f3SAndreas Gohr { 2968fed17f3SAndreas Gohr $page = 'test_save_page'; 2978fed17f3SAndreas Gohr $assignment = Assignments::getInstance(); 2988fed17f3SAndreas Gohr $schema = 'schema2'; 2998fed17f3SAndreas Gohr $assignment->addPattern($page, $schema); 3008fed17f3SAndreas Gohr 3018fed17f3SAndreas Gohr $request = new \TestRequest(); 3028fed17f3SAndreas Gohr $structData = [ 3038fed17f3SAndreas Gohr $schema => [ 3048fed17f3SAndreas Gohr 'afirst' => 'foo', 3058fed17f3SAndreas Gohr 'asecond' => 'bar, baz', 3068fed17f3SAndreas Gohr 'athird' => 'foobar', 3078fed17f3SAndreas Gohr 'afourth' => '42' 3088fed17f3SAndreas Gohr ] 3098fed17f3SAndreas Gohr ]; 3108fed17f3SAndreas Gohr $request->setPost('struct_schema_data', $structData); 3118fed17f3SAndreas Gohr $request->setPost('wikitext', 'teststring'); 3128fed17f3SAndreas Gohr $request->setPost('summary', 'content and struct data saved'); 313*6a819106SAndreas Gohr $request->post(['id' => $page, 'do' => 'save']); 3148fed17f3SAndreas Gohr 315*6a819106SAndreas Gohr $pagelog = new PageChangelog($page); 3168fed17f3SAndreas Gohr $revisions = $pagelog->getRevisions(-1, 200); 3178fed17f3SAndreas Gohr $revinfo = $pagelog->getRevisionInfo($revisions[0]); 3188fed17f3SAndreas Gohr $schemaData = meta\AccessTable::getPageAccess($schema, $page, $revisions[0]); 3198fed17f3SAndreas Gohr $actual_struct_data = $schemaData->getDataArray(); 3208fed17f3SAndreas Gohr $expected_struct_data = [ 3218fed17f3SAndreas Gohr 'afirst' => 'foo', 3228fed17f3SAndreas Gohr 'asecond' => ['bar', 'baz'], 3238fed17f3SAndreas Gohr 'athird' => 'foobar', 3248fed17f3SAndreas Gohr 'afourth' => 42 3258fed17f3SAndreas Gohr ]; 3268fed17f3SAndreas Gohr 3278fed17f3SAndreas Gohr $this->assertCount(1, $revisions); 3288fed17f3SAndreas Gohr $this->assertEquals('content and struct data saved', $revinfo['sum']); 3298fed17f3SAndreas Gohr $this->assertEquals(DOKU_CHANGE_TYPE_CREATE, $revinfo['type']); 3308fed17f3SAndreas Gohr $this->assertEquals($expected_struct_data, $actual_struct_data); 3318fed17f3SAndreas Gohr // todo: assert that pagerevision and struct data have the same timestamp 3328fed17f3SAndreas Gohr } 3338fed17f3SAndreas Gohr 3348fed17f3SAndreas Gohr /** 3358fed17f3SAndreas Gohr * @group slow 3368fed17f3SAndreas Gohr */ 3378fed17f3SAndreas Gohr public function test_save_page_without_new_text() 3388fed17f3SAndreas Gohr { 3398fed17f3SAndreas Gohr $page = 'test_save_page_without_new_text'; 3408fed17f3SAndreas Gohr $assignment = Assignments::getInstance(); 3418fed17f3SAndreas Gohr $schema = 'schema2'; 3428fed17f3SAndreas Gohr $assignment->addPattern($page, $schema); 3438fed17f3SAndreas Gohr $wikitext = 'teststring'; 3448fed17f3SAndreas Gohr 3458fed17f3SAndreas Gohr // first save; 3468fed17f3SAndreas Gohr $request = new \TestRequest(); 3478fed17f3SAndreas Gohr $structData = [ 3488fed17f3SAndreas Gohr $schema => [ 3498fed17f3SAndreas Gohr 'afirst' => 'foo', 3508fed17f3SAndreas Gohr 'asecond' => 'bar, baz', 3518fed17f3SAndreas Gohr 'athird' => 'foobar', 3528fed17f3SAndreas Gohr 'afourth' => '42' 3538fed17f3SAndreas Gohr ] 3548fed17f3SAndreas Gohr ]; 3558fed17f3SAndreas Gohr $request->setPost('struct_schema_data', $structData); 3568fed17f3SAndreas Gohr $request->setPost('wikitext', $wikitext); 3578fed17f3SAndreas Gohr $request->setPost('summary', 'content and struct data saved'); 358*6a819106SAndreas Gohr $request->post(['id' => $page, 'do' => 'save']); 3598fed17f3SAndreas Gohr 3608fed17f3SAndreas Gohr $this->waitForTick(true); 3618fed17f3SAndreas Gohr 3628fed17f3SAndreas Gohr // second save - only struct data 3638fed17f3SAndreas Gohr $request = new \TestRequest(); 3648fed17f3SAndreas Gohr $structData = [ 3658fed17f3SAndreas Gohr $schema => [ 3668fed17f3SAndreas Gohr 'afirst' => 'foo2', 3678fed17f3SAndreas Gohr 'asecond' => 'bar2, baz2', 3688fed17f3SAndreas Gohr 'athird' => 'foobar2', 3698fed17f3SAndreas Gohr 'afourth' => '43' 3708fed17f3SAndreas Gohr ] 3718fed17f3SAndreas Gohr ]; 3728fed17f3SAndreas Gohr $request->setPost('struct_schema_data', $structData); 3738fed17f3SAndreas Gohr $request->setPost('wikitext', $wikitext); 3748fed17f3SAndreas Gohr $request->setPost('summary', '2nd revision'); 375*6a819106SAndreas Gohr $request->post(['id' => $page, 'do' => 'save']); 3768fed17f3SAndreas Gohr 3778fed17f3SAndreas Gohr // assert 378*6a819106SAndreas Gohr $pagelog = new PageChangelog($page); 3798fed17f3SAndreas Gohr $revisions = $pagelog->getRevisions(-1, 200); 3808fed17f3SAndreas Gohr $revinfo = $pagelog->getRevisionInfo($revisions[0]); 3818fed17f3SAndreas Gohr $schemaData = meta\AccessTable::getPageAccess($schema, $page, $revisions[0]); 3828fed17f3SAndreas Gohr $actual_struct_data = $schemaData->getDataArray(); 3838fed17f3SAndreas Gohr $expected_struct_data = [ 3848fed17f3SAndreas Gohr 'afirst' => 'foo2', 3858fed17f3SAndreas Gohr 'asecond' => ['bar2', 'baz2'], 3868fed17f3SAndreas Gohr 'athird' => 'foobar2', 3878fed17f3SAndreas Gohr 'afourth' => 43 3888fed17f3SAndreas Gohr ]; 3898fed17f3SAndreas Gohr 3908fed17f3SAndreas Gohr $this->assertCount(2, $revisions, 'there should be 2 (two) revisions'); 3918fed17f3SAndreas Gohr $this->assertEquals('2nd revision', $revinfo['sum']); 3928fed17f3SAndreas Gohr $this->assertEquals(DOKU_CHANGE_TYPE_EDIT, $revinfo['type']); 3938fed17f3SAndreas Gohr $this->assertEquals($expected_struct_data, $actual_struct_data); 3948fed17f3SAndreas Gohr // todo: assert that pagerevisions and struct entries have the same timestamps 3958fed17f3SAndreas Gohr } 3968fed17f3SAndreas Gohr 3978fed17f3SAndreas Gohr /** 3988fed17f3SAndreas Gohr * @group slow 3998fed17f3SAndreas Gohr */ 4008fed17f3SAndreas Gohr public function test_delete_page() 4018fed17f3SAndreas Gohr { 4028fed17f3SAndreas Gohr $page = 'test_delete_page'; 4038fed17f3SAndreas Gohr $assignment = Assignments::getInstance(); 4048fed17f3SAndreas Gohr $schema = 'schema2'; 4058fed17f3SAndreas Gohr $assignment->addPattern($page, $schema); 4068fed17f3SAndreas Gohr $wikitext = 'teststring'; 4078fed17f3SAndreas Gohr 4088fed17f3SAndreas Gohr // first save; 4098fed17f3SAndreas Gohr $request = new \TestRequest(); 4108fed17f3SAndreas Gohr $structData = [ 4118fed17f3SAndreas Gohr $schema => [ 4128fed17f3SAndreas Gohr 'afirst' => 'foo', 4138fed17f3SAndreas Gohr 'asecond' => 'bar, baz', 4148fed17f3SAndreas Gohr 'athird' => 'foobar', 4158fed17f3SAndreas Gohr 'afourth' => '42' 4168fed17f3SAndreas Gohr ] 4178fed17f3SAndreas Gohr ]; 4188fed17f3SAndreas Gohr $request->setPost('struct_schema_data', $structData); 4198fed17f3SAndreas Gohr $request->setPost('wikitext', $wikitext); 4208fed17f3SAndreas Gohr $request->setPost('summary', 'content and struct data saved'); 421*6a819106SAndreas Gohr $request->post(['id' => $page, 'do' => 'save']); 4228fed17f3SAndreas Gohr 4238fed17f3SAndreas Gohr $this->waitForTick(true); 4248fed17f3SAndreas Gohr 4258fed17f3SAndreas Gohr // delete 4268fed17f3SAndreas Gohr $request = new \TestRequest(); 4278fed17f3SAndreas Gohr $structData = [ 4288fed17f3SAndreas Gohr $schema => [ 4298fed17f3SAndreas Gohr 'afirst' => 'foo2', 4308fed17f3SAndreas Gohr 'asecond' => 'bar2, baz2', 4318fed17f3SAndreas Gohr 'athird' => 'foobar2', 4328fed17f3SAndreas Gohr 'afourth' => '43' 4338fed17f3SAndreas Gohr ] 4348fed17f3SAndreas Gohr ]; 4358fed17f3SAndreas Gohr $request->setPost('struct_schema_data', $structData); 4368fed17f3SAndreas Gohr $request->setPost('wikitext', ''); 4378fed17f3SAndreas Gohr $request->setPost('summary', 'delete page'); 438*6a819106SAndreas Gohr $request->post(['id' => $page, 'do' => 'save']); 4398fed17f3SAndreas Gohr 4408fed17f3SAndreas Gohr // assert 441*6a819106SAndreas Gohr $pagelog = new PageChangelog($page); 4428fed17f3SAndreas Gohr $revisions = $pagelog->getRevisions(-1, 200); 4438fed17f3SAndreas Gohr $revinfo = $pagelog->getRevisionInfo($revisions[0]); 4448fed17f3SAndreas Gohr $schemaData = meta\AccessTable::getPageAccess($schema, $page, $revisions[0]); 4458fed17f3SAndreas Gohr $actual_struct_data = $schemaData->getDataArray(); 4468fed17f3SAndreas Gohr $expected_struct_data = [ 4478fed17f3SAndreas Gohr 'afirst' => '', 4488fed17f3SAndreas Gohr 'asecond' => [], 4498fed17f3SAndreas Gohr 'athird' => '', 4508fed17f3SAndreas Gohr 'afourth' => '' 4518fed17f3SAndreas Gohr ]; 4528fed17f3SAndreas Gohr 4538fed17f3SAndreas Gohr $this->assertCount(2, $revisions, 'there should be 2 (two) revisions'); 4548fed17f3SAndreas Gohr $this->assertEquals('delete page', $revinfo['sum']); 4558fed17f3SAndreas Gohr $this->assertEquals(DOKU_CHANGE_TYPE_DELETE, $revinfo['type']); 4568fed17f3SAndreas Gohr $this->assertEquals($expected_struct_data, $actual_struct_data); 4578fed17f3SAndreas Gohr // todo: timestamps? 4588fed17f3SAndreas Gohr } 4598fed17f3SAndreas Gohr 4608fed17f3SAndreas Gohr /** 4618fed17f3SAndreas Gohr * @group slow 4628fed17f3SAndreas Gohr */ 4638fed17f3SAndreas Gohr public function test_revert_page() 4648fed17f3SAndreas Gohr { 4658fed17f3SAndreas Gohr $page = 'test_revert_page'; 4668fed17f3SAndreas Gohr $assignment = Assignments::getInstance(); 4678fed17f3SAndreas Gohr $schema = 'schema2'; 4688fed17f3SAndreas Gohr $assignment->addPattern($page, $schema); 4698fed17f3SAndreas Gohr $wikitext = 'teststring'; 4708fed17f3SAndreas Gohr 4718fed17f3SAndreas Gohr global $conf; 4728fed17f3SAndreas Gohr $conf['useacl'] = 1; 4738fed17f3SAndreas Gohr $conf['superuser'] = 'admin'; 4748fed17f3SAndreas Gohr $_SERVER['REMOTE_USER'] = 'admin'; //now it's testing as admin 4758fed17f3SAndreas Gohr global $default_server_vars; 4768fed17f3SAndreas Gohr $default_server_vars['REMOTE_USER'] = 'admin'; //Hack until Issue #1099 is fixed 4778fed17f3SAndreas Gohr global $USERINFO; 4788fed17f3SAndreas Gohr $USERINFO['name'] = 'admin'; 4798fed17f3SAndreas Gohr $USERINFO['mail'] = 'admin@example.com'; 4808fed17f3SAndreas Gohr $USERINFO['grps'] = ['admin', 'user']; 4818fed17f3SAndreas Gohr 4828fed17f3SAndreas Gohr // first save; 4838fed17f3SAndreas Gohr $request = new \TestRequest(); 4848fed17f3SAndreas Gohr $structData = [ 4858fed17f3SAndreas Gohr $schema => [ 4868fed17f3SAndreas Gohr 'afirst' => 'foo', 4878fed17f3SAndreas Gohr 'asecond' => 'bar, baz', 4888fed17f3SAndreas Gohr 'athird' => 'foobar', 4898fed17f3SAndreas Gohr 'afourth' => '42' 4908fed17f3SAndreas Gohr ] 4918fed17f3SAndreas Gohr ]; 4928fed17f3SAndreas Gohr $request->setPost('struct_schema_data', $structData); 4938fed17f3SAndreas Gohr $request->setPost('wikitext', $wikitext); 4948fed17f3SAndreas Gohr $request->setPost('summary', 'content and struct data saved'); 495*6a819106SAndreas Gohr $request->post(['id' => $page, 'do' => 'save', 'sectok' => getSecurityToken()]); 4968fed17f3SAndreas Gohr 4978fed17f3SAndreas Gohr $this->waitForTick(true); 4988fed17f3SAndreas Gohr 4998fed17f3SAndreas Gohr // second save 5008fed17f3SAndreas Gohr $request = new \TestRequest(); 5018fed17f3SAndreas Gohr $structData = [ 5028fed17f3SAndreas Gohr $schema => [ 5038fed17f3SAndreas Gohr 'afirst' => 'foo2', 5048fed17f3SAndreas Gohr 'asecond' => 'bar2, baz2', 5058fed17f3SAndreas Gohr 'athird' => 'foobar2', 5068fed17f3SAndreas Gohr 'afourth' => '43' 5078fed17f3SAndreas Gohr ] 5088fed17f3SAndreas Gohr ]; 5098fed17f3SAndreas Gohr $request->setPost('struct_schema_data', $structData); 5108fed17f3SAndreas Gohr $request->setPost('wikitext', $wikitext . $wikitext); 5118fed17f3SAndreas Gohr $request->setPost('summary', 'delete page'); 512*6a819106SAndreas Gohr $request->post(['id' => $page, 'do' => 'save', 'sectok' => getSecurityToken()]); 5138fed17f3SAndreas Gohr 5148fed17f3SAndreas Gohr $this->waitForTick(true); 5158fed17f3SAndreas Gohr 5168fed17f3SAndreas Gohr // revert to first save 517*6a819106SAndreas Gohr $actpagelog = new PageChangelog($page); 5188fed17f3SAndreas Gohr $actrevisions = $actpagelog->getRevisions(0, 200); 5198fed17f3SAndreas Gohr 5208fed17f3SAndreas Gohr $actrevinfo = $actpagelog->getRevisionInfo($actrevisions[0]); 5218fed17f3SAndreas Gohr $request = new \TestRequest(); 5228fed17f3SAndreas Gohr $request->setPost('summary', 'revert page'); 523*6a819106SAndreas Gohr $request->post(['id' => $page, 'do' => 'revert', 'rev' => $actrevinfo['date'], 'sectok' => getSecurityToken()]); 5248fed17f3SAndreas Gohr 5258fed17f3SAndreas Gohr // assert 526*6a819106SAndreas Gohr $pagelog = new PageChangelog($page); 5278fed17f3SAndreas Gohr $revisions = $pagelog->getRevisions(-1, 200); 5288fed17f3SAndreas Gohr $revinfo = $pagelog->getRevisionInfo($revisions[0]); 5298fed17f3SAndreas Gohr $schemaData = meta\AccessTable::getPageAccess($schema, $page, $revisions[0]); 5308fed17f3SAndreas Gohr $actual_struct_data = $schemaData->getDataArray(); 5318fed17f3SAndreas Gohr $expected_struct_data = [ 5328fed17f3SAndreas Gohr 'afirst' => 'foo', 5338fed17f3SAndreas Gohr 'asecond' => ['bar', 'baz'], 5348fed17f3SAndreas Gohr 'athird' => 'foobar', 5358fed17f3SAndreas Gohr 'afourth' => '42' 5368fed17f3SAndreas Gohr ]; 5378fed17f3SAndreas Gohr 5388fed17f3SAndreas Gohr $this->assertCount(3, $revisions, 'there should be 3 (three) revisions'); 5398fed17f3SAndreas Gohr $this->assertStringContainsString('restored', $revinfo['sum']); 5408fed17f3SAndreas Gohr $this->assertEquals(DOKU_CHANGE_TYPE_REVERT, $revinfo['type']); 5418fed17f3SAndreas Gohr $this->assertEquals($expected_struct_data, $actual_struct_data); 5428fed17f3SAndreas Gohr // todo: timestamps? 5438fed17f3SAndreas Gohr } 5448fed17f3SAndreas Gohr 5458fed17f3SAndreas Gohr} 546