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