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