1<?php 2 3namespace dokuwiki\plugin\struct\test\action; 4 5use dokuwiki\plugin\struct\test\mock\Assignments; 6use dokuwiki\plugin\struct\test\StructTest; 7 8/** 9 * Tests for the diff-view of the struct plugin 10 * 11 * @group plugin_struct 12 * @group plugins 13 * 14 * @covers action_plugin_struct_diff 15 * 16 * 17 */ 18class DiffTest extends StructTest 19{ 20 21 public function setUp(): void 22 { 23 parent::setUp(); 24 25 $this->loadSchemaJSON('schema1'); 26 } 27 28 public function test_diff() 29 { 30 $page = 'test_save_page_without_new_text'; 31 $assignment = Assignments::getInstance(); 32 $schema = 'schema1'; 33 $assignment->addPattern($page, $schema); 34 $wikitext = 'teststring'; 35 36 // first save; 37 $request = new \TestRequest(); 38 $structData = [ 39 $schema => [ 40 'first' => 'foo', 41 'second' => 'bar, baz', 42 'third' => 'foobar', 43 'fourth' => '42' 44 ] 45 ]; 46 $request->setPost('struct_schema_data', $structData); 47 $request->setPost('wikitext', $wikitext); 48 $request->setPost('summary', 'content and struct data saved'); 49 $request->post(['id' => $page, 'do' => 'save'], '/doku.php'); 50 51 $this->waitForTick(true); 52 53 // second save - only struct data 54 $request = new \TestRequest(); 55 $structData = [ 56 $schema => [ 57 'first' => 'foo', 58 'second' => 'bar2, baz2', 59 'third' => 'foobar2', 60 'fourth' => '42' 61 ] 62 ]; 63 $request->setPost('struct_schema_data', $structData); 64 $request->setPost('wikitext', $wikitext); 65 $request->setPost('summary', '2nd revision'); 66 $request->post(array('id' => $page, 'do' => 'save'), '/doku.php'); 67 68 // diff 69 $request = new \TestRequest(); 70 $response = $request->post(['id' => $page, 'do' => 'diff'], '/doku.php'); 71 72 $pq = $response->queryHTML('table.diff_sidebyside'); 73 $this->assertEquals(1, $pq->count()); 74 75 $added = $pq->find('td.diff-addedline'); 76 $deleted = $pq->find('td.diff-deletedline'); 77 78 $this->assertEquals(2, $added->count()); 79 $this->assertEquals(2, $deleted->count()); 80 81 $this->assertStringContainsString('bar', $deleted->eq(0)->getHTML()); 82 $this->assertStringContainsString('baz', $deleted->eq(0)->getHtml()); 83 $this->assertStringContainsString('bar2', $added->eq(0)->getHtml()); 84 $this->assertStringContainsString('baz2', $added->eq(0)->getHtml()); 85 86 $this->assertStringContainsString('foobar', $deleted->eq(1)->getHtml()); 87 $this->assertStringContainsString('foobar2', $added->eq(1)->getHtml()); 88 } 89 90} 91