@@ -56,8 +56,44 @@ public function testUnmatchedElements(): void
5656 }
5757 }
5858
59+ /**
60+ * Test bookmark element.
61+ */
62+ public function testBookmarkElement (): void
63+ {
64+ $ phpWord = new PhpWord ();
65+ $ section = $ phpWord ->addSection ();
66+ $ section ->addBookmark ('test_bookmark ' );
67+
68+ $ doc = TestHelperDOCX::getDocument ($ phpWord , 'ODText ' );
69+
70+ $ path = '/office:document-content/office:body/office:text/text:section/text:p/text:bookmark ' ;
71+ self ::assertTrue ($ doc ->elementExists ($ path ));
72+ self ::assertEquals ('test_bookmark ' , $ doc ->getElementAttribute ($ path , 'text:name ' ));
73+ }
74+
75+ /**
76+ * Test multiple bookmarks and bookmarks in text runs.
77+ */
78+ public function testMultipleBookmarksAndNestedBookmarkElement (): void
79+ {
80+ $ phpWord = new PhpWord ();
81+ $ section = $ phpWord ->addSection ();
82+ $ section ->addBookmark ('first_bookmark ' );
83+ $ section ->addBookmark ('bookmark_with_& ' );
84+ $ textRun = $ section ->addTextRun ();
85+ $ textRun ->addBookmark ('nested_bookmark ' );
86+
87+ $ doc = TestHelperDOCX::getDocument ($ phpWord , 'ODText ' );
88+
89+ $ path = '/office:document-content/office:body/office:text/text:section//text:bookmark ' ;
90+ self ::assertTrue ($ doc ->elementExists ("( $ path)[3] " ));
91+ self ::assertEquals ('first_bookmark ' , $ doc ->getElementAttribute ("( $ path)[1] " , 'text:name ' ));
92+ self ::assertEquals ('bookmark_with_& ' , $ doc ->getElementAttribute ("( $ path)[2] " , 'text:name ' ));
93+ self ::assertEquals ('nested_bookmark ' , $ doc ->getElementAttribute ("( $ path)[3] " , 'text:name ' ));
94+ }
95+
5996 // ODT Line Element not yet implemented
60- // ODT Bookmark not yet implemented
6197 // ODT Table with style name not yet implemented (Word test defective)
6298 // ODT Shape Elements not yet implemented
6399 // ODT Chart Elements not yet implemented
0 commit comments