File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -72,10 +72,11 @@ function add(
7272 /**
7373 * @return GlHtmlNode
7474 */
75- public function getParent () {
75+ public function getParent ()
76+ {
7677 return new GlHtmlNode ($ this ->node ->parentNode );
7778 }
78-
79+
7980 /**
8081 * @param string $html
8182 */
@@ -114,6 +115,24 @@ public function getName()
114115 return strtolower ($ this ->node ->nodeName );
115116 }
116117
118+ /**
119+ * @param array $hasAttributesList
120+ *
121+ * @return bool
122+ */
123+ public function hasAttributes (array $ hasAttributesList )
124+ {
125+ $ attributes = $ this ->node ->attributes ;
126+
127+ foreach ($ attributes as $ name => $ attrNode ) {
128+ if (in_array ($ name , $ hasAttributesList )) {
129+ return true ;
130+ }
131+ }
132+
133+ return false ;
134+ }
135+
117136 /**
118137 * @param string $name
119138 *
Original file line number Diff line number Diff line change @@ -183,6 +183,21 @@ public function testRemplaceMeParent()
183183 $ this ->assertEquals ($ htmlresult , $ result );
184184 }
185185
186+ public function testhasAttributes ()
187+ {
188+ $ html = '<!DOCTYPE html><html><head></head><body><div><span data-original="test"><div class="tortue" nolazyload></div></span></div></body></html> ' ;
189+
190+ $ dom = new GlHtml ($ html );
191+ $ node = $ dom ->get ("span " )[0 ];
192+
193+ $ this ->assertEquals ($ node ->hasAttributes (['data-original ' ,'nolazyload ' ]), true );
194+
195+ $ node = $ dom ->get (".tortue " )[0 ];
196+
197+ $ this ->assertEquals ($ node ->hasAttributes (['nolazyload ' ]), true );
198+ $ this ->assertEquals ($ node ->hasAttributes (['nolazload ' ]), false );
199+ }
200+
186201 public function testsetAttributes ()
187202 {
188203 $ html = "<!DOCTYPE html><html><head></head><body><div><span><div></div></span></div></body></html> " ;
You can’t perform that action at this time.
0 commit comments