@@ -98,7 +98,7 @@ public function testXmlLang($css, array $elementsId)
9898 $ elements = $ document ->xpath ($ translator ->cssToXPath ($ css ));
9999 $ this ->assertCount (\count ($ elementsId ), $ elements );
100100 foreach ($ elements as $ element ) {
101- $ this ->assertTrue ( \in_array ( $ element ->attributes ()->id , $ elementsId) );
101+ $ this ->assertContains (( string ) $ element ->attributes ()->id , $ elementsId );
102102 }
103103 }
104104
@@ -116,7 +116,7 @@ public function testHtmlIds($css, array $elementsId)
116116 $ this ->assertCount (\count ($ elementsId ), $ elementsId );
117117 foreach ($ elements as $ element ) {
118118 if (null !== $ element ->attributes ()->id ) {
119- $ this ->assertTrue ( \in_array ( $ element ->attributes ()->id , $ elementsId) );
119+ $ this ->assertContains (( string ) $ element ->attributes ()->id , $ elementsId );
120120 }
121121 }
122122 libxml_clear_errors ();
@@ -137,6 +137,33 @@ public function testHtmlShakespear($css, $count)
137137 $ this ->assertCount ($ count , $ elements );
138138 }
139139
140+ public function testOnlyOfTypeFindsSingleChildrenOfGivenType ()
141+ {
142+ $ translator = new Translator ();
143+ $ translator ->registerExtension (new HtmlExtension ($ translator ));
144+ $ document = new \DOMDocument ();
145+ $ document ->loadHTML (<<<'HTML'
146+ <html>
147+ <body>
148+ <p>
149+ <span>A</span>
150+ </p>
151+ <p>
152+ <span>B</span>
153+ <span>C</span>
154+ </p>
155+ </body>
156+ </html>
157+ HTML
158+ );
159+
160+ $ xpath = new \DOMXPath ($ document );
161+ $ nodeList = $ xpath ->query ($ translator ->cssToXPath ('span:only-of-type ' ));
162+
163+ $ this ->assertSame (1 , $ nodeList ->length );
164+ $ this ->assertSame ('A ' , $ nodeList ->item (0 )->textContent );
165+ }
166+
140167 public function getXpathLiteralTestData ()
141168 {
142169 return [
@@ -175,7 +202,7 @@ public function getCssToXPathTestData()
175202 ['e:first-of-type ' , '*/e[position() = 1] ' ],
176203 ['e:last-of-type ' , '*/e[position() = last()] ' ],
177204 ['e:only-child ' , "*/*[(name() = 'e') and (last() = 1)] " ],
178- ['e:only-of-type ' , 'e[last() = 1 ] ' ],
205+ ['e:only-of-type ' , 'e[count(preceding-sibling::e)=0 and count(following-sibling::e)=0 ] ' ],
179206 ['e:empty ' , 'e[not(*) and not(string-length())] ' ],
180207 ['e:EmPTY ' , 'e[not(*) and not(string-length())] ' ],
181208 ['e:root ' , 'e[not(parent::*)] ' ],
0 commit comments