ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
PageCompareTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use PHPUnit\Framework\TestCase;
25
30{
31 protected function getElementChange(string $pcid, array $changes): string
32 {
33 return $changes[str_pad($pcid, 32, "0", STR_PAD_LEFT)]["change"] ?? "";
34 }
35 public function testCompareEqual(): void
36 {
37 $compare = new PageCompare();
38
39 $l_page = $this->getEmptyPageWithDom();
40 $this->insertParagraphAt($l_page, "pg");
41 $l_page->insertPCIds();
42
43 $this->setPCIdCnt(1); // reset PCID counter to get same PCID
44
45 $r_page = $this->getEmptyPageWithDom();
46 $this->insertParagraphAt($r_page, "pg");
47 $r_page->insertPCIds();
48
49 $res = $compare->compare($l_page, $l_page, $r_page);
50
51 $this->assertEquals(
52 "",
53 $this->getElementChange("1", $res["l_changes"])
54 );
55
56 $this->assertEquals(
57 "",
58 $this->getElementChange("1", $res["r_changes"])
59 );
60 }
61
62 public function testCompareNewDeleted(): void
63 {
64 $compare = new PageCompare();
65
66 $l_page = $this->getEmptyPageWithDom();
67 $this->insertParagraphAt($l_page, "pg");
68 $l_page->insertPCIds();
69
70 // Note, since we do not reset the PCID counter
71 // the second will get a pc id of 2
72
73 $r_page = $this->getEmptyPageWithDom();
74 $this->insertParagraphAt($r_page, "pg");
75 $r_page->insertPCIds();
76
77 $res = $compare->compare($l_page, $l_page, $r_page);
78
79 $this->assertEquals(
80 "Deleted",
81 $this->getElementChange("1", $res["l_changes"])
82 );
83
84 $this->assertEquals(
85 "New",
86 $this->getElementChange("2", $res["r_changes"])
87 );
88 }
89
90 public function testCompareChanged(): void
91 {
92 $compare = new PageCompare();
93
94 $l_page = $this->getEmptyPageWithDom();
95 $this->insertParagraphAt($l_page, "pg", "Hello World!");
96 $l_page->insertPCIds();
97
98 $this->setPCIdCnt(1); // reset PCID counter to get same PCID
99
100 $r_page = $this->getEmptyPageWithDom();
101 $this->insertParagraphAt($r_page, "pg", "Hello little World!");
102 $r_page->insertPCIds();
103
104 $res = $compare->compare($l_page, $l_page, $r_page);
105
106 $this->assertEquals(
107 "Modified",
108 $this->getElementChange("1", $res["l_changes"])
109 );
110
111 $this->assertEquals(
112 "Modified",
113 $this->getElementChange("1", $res["r_changes"])
114 );
115 }
116
117 public function testCompareTextChanges(): void
118 {
119 $compare = new PageCompare();
120
121 $l_page = $this->getEmptyPageWithDom();
122 $this->insertParagraphAt($l_page, "pg", "Hello World!");
123 $l_page->insertPCIds();
124
125 $this->setPCIdCnt(1); // reset PCID counter to get same PCID
126
127 $r_page = $this->getEmptyPageWithDom();
128 $this->insertParagraphAt($r_page, "pg", "Hello little World!");
129 $r_page->insertPCIds();
130
131 $res = $compare->compare($l_page, $l_page, $r_page);
132
133 $expected = <<<EOT
134<PageObject HierId="pg"><PageContent HierId="1" PCID="00000000000000000000000000000001">Hello [ilDiffInsStart]little [ilDiffInsEnd]World!</PageContent><DivClass HierId="1" Class="ilEditModified"/></PageObject>
135EOT;
136
137 $this->assertXmlEquals(
138 $expected,
139 $r_page->getXMLFromDom()
140 );
141 }
142}
insertParagraphAt(\ilPageObject $page, string $hier_id, string $text="")
assertXmlEquals(string $expected_xml_as_string, string $html_xml_string)
setPCIdCnt(int $cnt)
getElementChange(string $pcid, array $changes)
$res
Definition: ltiservices.php:69