Best Phpunit code snippet using Count.matches
QueryPathEventHandlerTest.php
Source:QueryPathEventHandlerTest.php
...43 </ul>44 </body>45 </html>46 ';47 private function firstMatch($matches) {48 $matches->rewind();49 return $matches->current();50 }51 private function nthMatch($matches, $n = 0) {52 foreach ($matches as $m) {53 if ($matches->key() == $n) return $m;54 }55 }56 public function testGetMatches() {57 // Test root element:58 $xml = '<?xml version="1.0" ?><test><inside/>Text<inside/></test>';59 $doc = new \DomDocument();60 $doc->loadXML($xml);61 // Test handing it a DOM Document62 $handler = new QueryPathEventHandler($doc);63 $matches = $handler->getMatches();64 $this->assertTrue($matches->count() == 1);65 $match = $this->firstMatch($matches);66 $this->assertEquals('test', $match->tagName);67 // Test handling single element68 $root = $doc->documentElement;69 $handler = new QueryPathEventHandler($root);70 $matches = $handler->getMatches();71 $this->assertEquals(1, $matches->count());72 $match = $this->firstMatch($matches);73 $this->assertEquals('test', $match->tagName);74 // Test handling a node list75 $eles = $doc->getElementsByTagName('inside');76 $handler = new QueryPathEventHandler($eles);77 $matches = $handler->getMatches();78 $this->assertEquals(2, $matches->count());79 $match = $this->firstMatch($matches);80 $this->assertEquals('inside', $match->tagName);81 // Test handling an array of elements82 $eles = $doc->getElementsByTagName('inside');83 $array = array();84 foreach ($eles as $ele) $array[] = $ele;85 $handler = new QueryPathEventHandler($array);86 $matches = $handler->getMatches();87 $this->assertEquals(2, $matches->count());88 $match = $this->firstMatch($matches);89 $this->assertEquals('inside', $match->tagName);90 }91 /**92 * @expectedException \QueryPath\CSS\ParseException93 */94 public function testEmptySelector() {95 $xml = '<?xml version="1.0" ?><t:test xmlns:t="urn:foo/bar"><t:inside id="first"/>Text<t:inside/><inside/></t:test>';96 $doc = new \DomDocument();97 $doc->loadXML($xml);98 // Basic test99 $handler = new QueryPathEventHandler($doc);100 $handler->find('');101 $matches = $handler->getMatches();102 $this->assertEquals(0, $matches->count());103 }104 public function testElementNS() {105 $xml = '<?xml version="1.0" ?><t:test xmlns:t="urn:foo/bar"><t:inside id="first"/>Text<t:inside/><inside/></t:test>';106 $doc = new \DomDocument();107 $doc->loadXML($xml);108 // Basic test109 $handler = new QueryPathEventHandler($doc);110 $handler->find('t|inside');111 $matches = $handler->getMatches();112 $this->assertEquals(2, $matches->count());113 $match = $this->firstMatch($matches);114 $this->assertEquals('t:inside', $match->tagName);115 // Basic test116 $handler = new QueryPathEventHandler($doc);117 $handler->find('t|test');118 $matches = $handler->getMatches();119 $this->assertEquals(1, $matches->count());120 $match = $this->firstMatch($matches);121 $this->assertEquals('t:test', $match->tagName);122 }123 /**124 * @expectedException \QueryPath\CSS\ParseException125 */126 public function testFailedElementNS() {127 $xml = '<?xml version="1.0" ?><t:test xmlns:t="urn:foo/bar"><t:inside id="first"/>Text<t:inside/><inside/></t:test>';128 $doc = new \DomDocument();129 $doc->loadXML($xml);130 $handler = new QueryPathEventHandler($doc);131 $handler->find('myns\:mytest');132 }133 public function testElement() {134 $xml = '<?xml version="1.0" ?><test><inside id="first"/>Text<inside/></test>';135 $doc = new \DomDocument();136 $doc->loadXML($xml);137 // Basic test138 $handler = new QueryPathEventHandler($doc);139 $handler->find('inside');140 $matches = $handler->getMatches();141 $this->assertEquals(2, $matches->count());142 $match = $this->firstMatch($matches);143 $this->assertEquals('inside', $match->tagName);144 $doc = new \DomDocument();145 $doc->loadXML($this->xml);146 // Test getting nested147 $handler = new QueryPathEventHandler($doc);148 $handler->find('div');149 $matches = $handler->getMatches();150 $this->assertEquals(3, $matches->count());151 $match = $this->firstMatch($matches);152 $this->assertEquals('div', $match->tagName);153 $this->assertEquals('one', $match->getAttribute('id'));154 // Test getting a list155 $handler = new QueryPathEventHandler($doc);156 $handler->find('li');157 $matches = $handler->getMatches();158 $this->assertEquals(10, $matches->count());159 $match = $this->firstMatch($matches);160 //$this->assertEquals('div', $match->tagName);161 $this->assertEquals('li-one', $match->getAttribute('id'));162 // Test getting the root element163 $handler = new QueryPathEventHandler($doc);164 $handler->find('html');165 $matches = $handler->getMatches();166 $this->assertEquals(1, $matches->count());167 $match = $this->firstMatch($matches);168 $this->assertEquals('html', $match->tagName);169 }170 public function testElementId() {171 // Test root element:172 $xml = '<?xml version="1.0" ?><test><inside id="first"/>Text<inside/></test>';173 $doc = new \DomDocument();174 $doc->loadXML($xml);175 $handler = new QueryPathEventHandler($doc);176 $handler->find('#first');177 $matches = $handler->getMatches();178 $this->assertEquals(1, $matches->count());179 $match = $this->firstMatch($matches);180 $this->assertEquals('inside', $match->tagName);181 // Test a search with restricted scope:182 $handler = new QueryPathEventHandler($doc);183 $handler->find('inside#first');184 $matches = $handler->getMatches();185 $this->assertEquals(1, $matches->count());186 $match = $this->firstMatch($matches);187 $this->assertEquals('inside', $match->tagName);188 }189 public function testAnyElementInNS() {190 $xml = '<?xml version="1.0" ?><ns1:test xmlns:ns1="urn:foo/bar"><ns1:inside/>Text<ns1:inside/></ns1:test>';191 $doc = new \DomDocument();192 $doc->loadXML($xml);193 // Test handing it a DOM Document194 $handler = new QueryPathEventHandler($doc);195 $handler->find('ns1|*');196 $matches = $handler->getMatches();197 $this->assertEquals(3, $matches->count());198 $match = $this->firstMatch($matches);199 $this->assertEquals('ns1:test', $match->tagName);200 // Test Issue #30:201 $xml = '<?xml version="1.0" ?>202 <ns1:test xmlns:ns1="urn:foo/bar">203 <ns1:inside>204 <ns1:insideInside>Test</ns1:insideInside>205 </ns1:inside>206 </ns1:test>';207 $doc = new \DomDocument();208 $doc->loadXML($xml);209 $handler = new QueryPathEventHandler($doc);210 $handler->find('ns1|test>*');211 $matches = $handler->getMatches();212 $this->assertEquals(1, $matches->count());213 $match = $this->firstMatch($matches);214 $this->assertEquals('ns1:inside', $match->tagName);215 }216 public function testAnyElement() {217 $xml = '<?xml version="1.0" ?><test><inside/>Text<inside/></test>';218 $doc = new \DomDocument();219 $doc->loadXML($xml);220 // Test handing it a DOM Document221 $handler = new QueryPathEventHandler($doc);222 $handler->find('*');223 $matches = $handler->getMatches();224 $this->assertEquals(3, $matches->count());225 $match = $this->firstMatch($matches);226 $this->assertEquals('test', $match->tagName);227 $doc = new \DomDocument();228 $doc->loadXML($this->xml);229 // Test handing it a DOM Document230 $handler = new QueryPathEventHandler($doc);231 $handler->find('#two *');232 $matches = $handler->getMatches();233 $this->assertEquals(1, $matches->count());234 $match = $this->firstMatch($matches);235 $this->assertEquals('three', $match->getAttribute('id'));236 // Regression for issue #30237 $handler = new QueryPathEventHandler($doc);238 $handler->find('#one>*');239 $matches = $handler->getMatches();240 $this->assertEquals(1, $matches->count(), 'Should match just top div.');241 $match = $this->firstMatch($matches);242 $this->assertEquals('two', $match->getAttribute('id'), 'Should match ID #two');243 }244 public function testElementClass() {245 $xml = '<?xml version="1.0" ?><test><inside class="foo" id="one"/>Text<inside/></test>';246 $doc = new \DomDocument();247 $doc->loadXML($xml);248 // Test basic class249 $handler = new QueryPathEventHandler($doc);250 $handler->find('.foo');251 $matches = $handler->getMatches();252 $this->assertEquals(1, $matches->count());253 $match = $this->firstMatch($matches);254 $this->assertEquals('one', $match->getAttribute('id'));255 // Test class in element256 $doc = new \DomDocument();257 $doc->loadXML($this->xml);258 $handler = new QueryPathEventHandler($doc);259 $handler->find('li.Odd');260 $matches = $handler->getMatches();261 $this->assertEquals(5, $matches->count());262 $match = $this->nthMatch($matches, 4);263 $this->assertEquals('li-nine', $match->getAttribute('id'));264 // Test ID/class combo265 $handler = new QueryPathEventHandler($doc);266 $handler->find('.Odd#li-nine');267 $matches = $handler->getMatches();268 $this->assertEquals(1, $matches->count());269 $match = $this->firstMatch($matches);270 $this->assertEquals('li-nine', $match->getAttribute('id'));271 }272 public function testDirectDescendant() {273 $xml = '<?xml version="1.0" ?>274 <test>275 <inside class="foo" id="one"/>276 Text277 <inside id="two">278 <inside id="inner-one"/>279 </inside>280 </test>';281 $doc = new \DomDocument();282 $doc->loadXML($xml);283 // Test direct descendent284 $handler = new QueryPathEventHandler($doc);285 $handler->find('test > inside');286 $matches = $handler->getMatches();287 $this->assertEquals(2, $matches->count());288 $match = $this->nthMatch($matches, 1);289 $this->assertEquals('two', $match->getAttribute('id'));290 }291 public function testAttribute() {292 $xml = '<?xml version="1.0" ?><test><inside id="one" name="antidisestablishmentarianism"/>Text<inside/></test>';293 $doc = new \DomDocument();294 $doc->loadXML($xml);295 // Test match on attr name296 $handler = new QueryPathEventHandler($doc);297 $handler->find('inside[name]');298 $matches = $handler->getMatches();299 $this->assertEquals(1, $matches->count());300 $match = $this->firstMatch($matches);301 $this->assertEquals('one', $match->getAttribute('id'));302 // Test broken form303 $handler = new QueryPathEventHandler($doc);304 $handler->find('inside[@name]');305 $matches = $handler->getMatches();306 $this->assertEquals(1, $matches->count());307 $match = $this->firstMatch($matches);308 $this->assertEquals('one', $match->getAttribute('id'));309 // Test match on attr name and equals value310 $handler = new QueryPathEventHandler($doc);311 $handler->find('inside[name="antidisestablishmentarianism"]');312 $matches = $handler->getMatches();313 $this->assertEquals(1, $matches->count());314 $match = $this->firstMatch($matches);315 $this->assertEquals('one', $match->getAttribute('id'));316 // Test match on containsInString317 $handler = new QueryPathEventHandler($doc);318 $handler->find('inside[name*="disestablish"]');319 $matches = $handler->getMatches();320 $this->assertEquals(1, $matches->count());321 $match = $this->firstMatch($matches);322 $this->assertEquals('one', $match->getAttribute('id'));323 // Test match on beginsWith324 $handler = new QueryPathEventHandler($doc);325 $handler->find('inside[name^="anti"]');326 $matches = $handler->getMatches();327 $this->assertEquals(1, $matches->count());328 $match = $this->firstMatch($matches);329 $this->assertEquals('one', $match->getAttribute('id'));330 // Test match on endsWith331 $handler = new QueryPathEventHandler($doc);332 $handler->find('inside[name$="ism"]');333 $matches = $handler->getMatches();334 $this->assertEquals(1, $matches->count());335 $match = $this->firstMatch($matches);336 $this->assertEquals('one', $match->getAttribute('id'));337 // Test containsWithSpace338 $xml = '<?xml version="1.0" ?><test><inside id="one" name="anti dis establishment arian ism"/>Text<inside/></test>';339 $doc = new \DomDocument();340 $doc->loadXML($xml);341 $handler = new QueryPathEventHandler($doc);342 $handler->find('inside[name~="dis"]');343 $matches = $handler->getMatches();344 $this->assertEquals(1, $matches->count());345 $match = $this->firstMatch($matches);346 $this->assertEquals('one', $match->getAttribute('id'));347 // Test containsWithHyphen348 $xml = '<?xml version="1.0" ?><test><inside id="one" name="en-us"/>Text<inside/></test>';349 $doc = new \DomDocument();350 $doc->loadXML($xml);351 $handler = new QueryPathEventHandler($doc);352 $handler->find('inside[name|="us"]');353 $matches = $handler->getMatches();354 $this->assertEquals(1, $matches->count());355 $match = $this->firstMatch($matches);356 $this->assertEquals('one', $match->getAttribute('id'));357 }358 public function testPseudoClassLang() {359 $xml = '<?xml version="1.0" ?><test><inside lang="en-us" id="one"/>Text<inside/></test>';360 $doc = new \DomDocument();361 $doc->loadXML($xml);362 $handler = new QueryPathEventHandler($doc);363 $handler->find(':lang(en-us)');364 $matches = $handler->getMatches();365 $this->assertEquals(1, $matches->count());366 $match = $this->firstMatch($matches);367 $this->assertEquals('one', $match->getAttribute('id'));368 $handler = new QueryPathEventHandler($doc);369 $handler->find('inside:lang(en)');370 $matches = $handler->getMatches();371 $this->assertEquals(1, $matches->count());372 $match = $this->firstMatch($matches);373 $this->assertEquals('one', $match->getAttribute('id'));374 $handler = new QueryPathEventHandler($doc);375 $handler->find('inside:lang(us)');376 $matches = $handler->getMatches();377 $this->assertEquals(1, $matches->count());378 $match = $this->firstMatch($matches);379 $this->assertEquals('one', $match->getAttribute('id'));380 $xml = '<?xml version="1.0" ?><test><inside lang="en-us" id="one"/>Text<inside lang="us" id="two"/></test>';381 $doc = new \DomDocument();382 $doc->loadXML($xml);383 $handler = new QueryPathEventHandler($doc);384 $handler->find(':lang(us)');385 $matches = $handler->getMatches();386 $this->assertEquals(2, $matches->count());387 $match = $this->nthMatch($matches, 1);388 $this->assertEquals('two', $match->getAttribute('id'));389 $xml = '<?xml version="1.0" ?>390 <test xmlns="http://aleph-null.tv/xml" xmlns:xml="http://www.w3.org/XML/1998/namespace">391 <inside lang="en-us" id="one"/>Text392 <inside xml:lang="en-us" id="two"/>393 </test>';394 $doc = new \DomDocument();395 $doc->loadXML($xml);396 $handler = new QueryPathEventHandler($doc);397 $handler->find(':lang(us)');398 $matches = $handler->getMatches();399 $this->assertEquals(2, $matches->count());400 $match = $this->nthMatch($matches, 1);401 $this->assertEquals('two', $match->getAttribute('id'));402 }403 public function testPseudoClassEnabledDisabledChecked() {404 $xml = '<?xml version="1.0" ?>405 <test>406 <inside enabled="enabled" id="one"/>Text407 <inside disabled="disabled" id="two"/>408 <inside checked="FOOOOO" id="three"/>409 </test>';410 $doc = new \DomDocument();411 $doc->loadXML($xml);412 $handler = new QueryPathEventHandler($doc);413 $handler->find(':enabled');414 $matches = $handler->getMatches();415 $this->assertEquals(1, $matches->count());416 $match = $this->firstMatch($matches);417 $this->assertEquals('one', $match->getAttribute('id'));418 $handler = new QueryPathEventHandler($doc);419 $handler->find(':disabled');420 $matches = $handler->getMatches();421 $this->assertEquals(1, $matches->count());422 $match = $this->firstMatch($matches);423 $this->assertEquals('two', $match->getAttribute('id'));424 $handler = new QueryPathEventHandler($doc);425 $handler->find(':checked()');426 $matches = $handler->getMatches();427 $this->assertEquals(1, $matches->count());428 $match = $this->firstMatch($matches);429 $this->assertEquals('three', $match->getAttribute('id'));430 }431 public function testPseudoClassLink() {432 $xml = '<?xml version="1.0"?><a><b href="foo"/><c href="foo"/></a>';433 $qp = qp($xml, ':link');434 $this->assertEquals(2, $qp->size());435 }436 public function testPseudoClassXReset() {437 $xml = '<?xml version="1.0" ?>438 <test>439 <inside enabled="enabled" id="one"/>Text440 <inside disabled="disabled" id="two"/>441 <inside checked="FOOOOO" id="three"/>442 </test>';443 $doc = new \DomDocument();444 $doc->loadXML($xml);445 $handler = new QueryPathEventHandler($doc);446 $handler->find('inside');447 $matches = $handler->getMatches();448 $this->assertEquals(3, $matches->count());449 $handler->find(':x-reset');450 $matches = $handler->getMatches();451 $this->assertEquals(1, $matches->count());452 $this->assertEquals('test', $this->firstMatch($matches)->tagName);453 }454 public function testPseudoClassRoot() {455 $xml = '<?xml version="1.0" ?>456 <test>457 <inside enabled="enabled" id="one"/>Text458 <inside disabled="disabled" id="two"/>459 <inside checked="FOOOOO" id="three"/>460 </test>';461 $doc = new \DomDocument();462 $doc->loadXML($xml);463 $start = $doc->getElementsByTagName('inside');464 // Start "deep in the doc" and traverse backward.465 $handler = new QueryPathEventHandler($start);466 $handler->find(':root');467 $matches = $handler->getMatches();468 $this->assertEquals(1, $matches->count());469 $this->assertEquals('test', $this->firstMatch($matches)->tagName);470 }471 // Test removed so I can re-declare472 // listPeerElements as private.473 public function xtestListPeerElements() {474 $xml = '<?xml version="1.0" ?>475 <test>476 <i class="odd" id="one"/>477 <i class="even" id="two"/>478 <i class="odd" id="three"/>479 <i class="even" id="four"/>480 <i class="odd" id="five"/>481 <e class="even" id="six"/>482 </test>';483 $doc = new \DomDocument();484 $doc->loadXML($xml);485 // Test full list486 $handler = new QueryPathEventHandler($doc);487 $handler->find('#one');488 $matches = $handler->getMatches();489 $peers = $handler->listPeerElements($this->firstMatch($matches));490 $this->assertEquals(6, count($peers));491 }492 /*493 public function testChildAtIndex() {494 $xml = '<?xml version="1.0" ?>495 <test>496 <i class="odd" id="one"/>497 <i class="even" id="two"/>498 <i class="odd" id="three"/>499 <i class="even" id="four"/>500 <i class="odd" id="five"/>501 <e class="even" id="six"/>502 </test>';503 $doc = new \DomDocument();504 $doc->loadXML($xml);505 // Test full list506 $handler = new QueryPathEventHandler($doc);507 $handler->find('test:child-at-index(1)');508 $matches = $handler->getMatches();509 $this->assertEquals(1, $matches->count());510 $this->assertEquals('one', $this->nthMatch($matches, 1)->getAttribute('id'));511 }*/512 public function testPseudoClassNthChild() {513 $xml = '<?xml version="1.0" ?>514 <test>515 <i class="odd" id="one"/>516 <i class="even" id="two"/>517 <i class="odd" id="three"/>518 <i class="even" id="four"/>519 <i class="odd" id="five"/>520 <e class="even" id="six"/>521 </test>';522 $doc = new \DomDocument();523 $doc->loadXML($xml);524 // Test full list525 $handler = new QueryPathEventHandler($doc);526 $handler->find(':root :even');527 $matches = $handler->getMatches();528 $this->assertEquals(3, $matches->count());529 $this->assertEquals('four', $this->nthMatch($matches, 1)->getAttribute('id'));530 // Test restricted to specific element531 $handler = new QueryPathEventHandler($doc);532 $handler->find('i:even');533 $matches = $handler->getMatches();534 $this->assertEquals(2, $matches->count());535 $this->assertEquals('four', $this->nthMatch($matches, 1)->getAttribute('id'));536 // Test restricted to specific element, odd this time537 $handler = new QueryPathEventHandler($doc);538 $handler->find('i:odd');539 $matches = $handler->getMatches();540 $this->assertEquals(3, $matches->count());541 $this->assertEquals('three', $this->nthMatch($matches, 1)->getAttribute('id'));542 // Test nth-child(odd)543 $handler = new QueryPathEventHandler($doc);544 $handler->find('i:nth-child(odd)');545 $matches = $handler->getMatches();546 $this->assertEquals(3, $matches->count());547 $this->assertEquals('three', $this->nthMatch($matches, 1)->getAttribute('id'));548 // Test nth-child(2n+1)549 $handler = new QueryPathEventHandler($doc);550 $handler->find('i:nth-child(2n+1)');551 $matches = $handler->getMatches();552 $this->assertEquals(3, $matches->count());553 $this->assertEquals('three', $this->nthMatch($matches, 1)->getAttribute('id'));554 // Test nth-child(2n) (even)555 $handler = new QueryPathEventHandler($doc);556 $handler->find('i:nth-child(2n)');557 $matches = $handler->getMatches();558 $this->assertEquals(2, $matches->count());559 $this->assertEquals('four', $this->nthMatch($matches, 1)->getAttribute('id'));560 // Not totally sure what should be returned here561 // Test nth-child(-2n)562 // $handler = new QueryPathEventHandler($doc);563 // $handler->find('i:nth-child(-2n)');564 // $matches = $handler->getMatches();565 // $this->assertEquals(2, $matches->count());566 // $this->assertEquals('four', $this->nthMatch($matches, 1)->getAttribute('id'));567 // Test nth-child(2n-1) (odd, equiv to 2n + 1)568 $handler = new QueryPathEventHandler($doc);569 $handler->find('i:nth-child(2n-1)');570 $matches = $handler->getMatches();571 $this->assertEquals(3, $matches->count());572 $this->assertEquals('three', $this->nthMatch($matches, 1)->getAttribute('id'));573 // Test nth-child(4n) (every fourth row)574 $handler = new QueryPathEventHandler($doc);575 $handler->find('i:nth-child(4n)');576 $matches = $handler->getMatches();577 $this->assertEquals(1, $matches->count());578 $this->assertEquals('four', $this->nthMatch($matches, 0)->getAttribute('id'));579 // Test nth-child(4n+1) (first of every four rows)580 $handler = new QueryPathEventHandler($doc);581 $handler->find('i:nth-child(4n+1)');582 $matches = $handler->getMatches();583 // Should match rows one and five584 $this->assertEquals(2, $matches->count());585 $this->assertEquals('five', $this->nthMatch($matches, 1)->getAttribute('id'));586 // Test nth-child(1) (First row)587 $handler = new QueryPathEventHandler($doc);588 $handler->find('i:nth-child(1)');589 $matches = $handler->getMatches();590 $this->assertEquals(1, $matches->count());591 $this->assertEquals('one', $this->firstMatch($matches)->getAttribute('id'));592 // Test nth-child(0n-0) (Empty list)593 $handler = new QueryPathEventHandler($doc);594 $handler->find('i:nth-child(0n-0)');595 $matches = $handler->getMatches();596 $this->assertEquals(0, $matches->count());597 // Test nth-child(-n+3) (First three lines)598 // $handler = new QueryPathEventHandler($doc);599 // $handler->find('i:nth-child(-n+3)');600 // $matches = $handler->getMatches();601 // $this->assertEquals(3, $matches->count());602 $xml = '<?xml version="1.0" ?>603 <test>604 <i class="odd" id="one"/>605 <i class="even" id="two"/>606 <i class="odd" id="three">607 <i class="odd" id="inner-one"/>608 <i class="even" id="inner-two"/>609 </i>610 <i class="even" id="four"/>611 <i class="odd" id="five"/>612 <e class="even" id="six"/>613 </test>';614 $doc = new \DomDocument();615 $doc->loadXML($xml);616 // Test nested items.617 $handler = new QueryPathEventHandler($doc);618 $handler->find('i:nth-child(odd)');619 $matches = $handler->getMatches();620 $this->assertEquals(4, $matches->count());621 $matchIDs = array();622 foreach ($matches as $m) {623 $matchIDs[] = $m->getAttribute('id');624 }625// $matchIDs = sort($matchIDs);626 $this->assertEquals(array('one', 'three', 'inner-one', 'five'), $matchIDs);627 //$this->assertEquals('inner-one', $matches[3]->getAttribute('id'));628 }629 public function testPseudoClassOnlyChild() {630 $xml = '<?xml version="1.0" ?>631 <test>632 <i class="odd" id="one"/>633 </test>';634 $doc = new \DomDocument();635 $doc->loadXML($xml);636 // Test single last child.637 $handler = new QueryPathEventHandler($doc);638 $handler->find('i:only-child');639 $matches = $handler->getMatches();640 $this->assertEquals(1, $matches->count());641 $this->assertEquals('one', $this->firstMatch($matches)->getAttribute('id'));642 $xml = '<?xml version="1.0" ?>643 <test>644 <i class="odd" id="one"/>645 <i class="odd" id="two"/>646 </test>';647 $doc = new \DomDocument();648 $doc->loadXML($xml);649 // Test single last child.650 $handler = new QueryPathEventHandler($doc);651 $handler->find('i:only-child');652 $matches = $handler->getMatches();653 $this->assertEquals(0, $matches->count());654 //$this->assertEquals('one', $this->firstMatch($matches)->getAttribute('id'));655 }656 public function testPseudoClassOnlyOfType() {657 // TODO: Added this late (it was missing in original test),658 // and I'm not sure if the assumed behavior is correct.659 $xml = '<?xml version="1.0" ?>660 <test>661 <i class="odd" id="one"/>662 </test>';663 $doc = new \DomDocument();664 $doc->loadXML($xml);665 // Test single last child.666 $handler = new QueryPathEventHandler($doc);667 $handler->find('i:only-of-type');668 $matches = $handler->getMatches();669 $this->assertEquals(1, $matches->count());670 $this->assertEquals('one', $this->firstMatch($matches)->getAttribute('id'));671 $xml = '<?xml version="1.0" ?>672 <test>673 <i class="odd" id="one"/>674 <i class="odd" id="two"/>675 </test>';676 $doc = new \DomDocument();677 $doc->loadXML($xml);678 // Test single last child.679 $handler = new QueryPathEventHandler($doc);680 $handler->find('i:only-of-type');681 $matches = $handler->getMatches();682 $this->assertEquals(0, $matches->count());683 }684 public function testPseudoClassFirstChild() {685 $xml = '<?xml version="1.0" ?>686 <test>687 <i class="odd" id="one"/>688 <i class="even" id="two"/>689 <i class="odd" id="three"/>690 <i class="even" id="four">691 <i class="odd" id="inner-one"/>692 <i class="even" id="inner-two"/>693 <i class="odd" id="inner-three"/>694 <i class="even" id="inner-four"/>695 </i>696 <i class="odd" id="five"/>697 <e class="even" id="six"/>698 </test>';699 $doc = new \DomDocument();700 $doc->loadXML($xml);701 // Test single last child.702 $handler = new QueryPathEventHandler($doc);703 $handler->find('#four > i:first-child');704 $matches = $handler->getMatches();705 $this->assertEquals(1, $matches->count());706 $this->assertEquals('inner-one', $this->firstMatch($matches)->getAttribute('id'));707 // Test for two last children708 $handler = new QueryPathEventHandler($doc);709 $handler->find('i:first-child');710 $matches = $handler->getMatches();711 $this->assertEquals(2, $matches->count());712 $this->assertEquals('inner-one', $this->nthMatch($matches, 1)->getAttribute('id'));713 }714 public function testPseudoClassLastChild() {715 //print '----' . PHP_EOL;716 $xml = '<?xml version="1.0" ?>717 <test>718 <i class="odd" id="one"/>719 <i class="even" id="two"/>720 <i class="odd" id="three"/>721 <i class="even" id="four">722 <i class="odd" id="inner-one"/>723 <i class="even" id="inner-two"/>724 <i class="odd" id="inner-three"/>725 <i class="even" id="inner-four"/>726 </i>727 <i class="odd" id="five"/>728 <e class="even" id="six"/>729 </test>';730 $doc = new \DomDocument();731 $doc->loadXML($xml);732 // Test single last child.733 $handler = new QueryPathEventHandler($doc);734 $handler->find('#four > i:last-child');735 $matches = $handler->getMatches();736 $this->assertEquals(1, $matches->count());737 $this->assertEquals('inner-four', $this->nthMatch($matches, 0)->getAttribute('id'));738 // Test for two last children739 $handler = new QueryPathEventHandler($doc);740 $handler->find('i:last-child');741 $matches = $handler->getMatches();742 $this->assertEquals(2, $matches->count());743 $this->assertEquals('inner-four', $this->nthMatch($matches, 0)->getAttribute('id'));744 $this->assertEquals('five', $this->nthMatch($matches, 1)->getAttribute('id'));745 }746 public function testPseudoClassNthLastChild() {747 $xml = '<?xml version="1.0" ?>748 <test>749 <i class="odd" id="one"/>750 <i class="even" id="two"/>751 <i class="odd" id="three"/>752 <i class="even" id="four">753 <i class="odd" id="inner-one"/>754 <i class="even" id="inner-two"/>755 <i class="odd" id="inner-three"/>756 <i class="even" id="inner-four"/>757 </i>758 <i class="odd" id="five"/>759 <e class="even" id="six"/>760 </test>';761 $doc = new \DomDocument();762 $doc->loadXML($xml);763 // Test alternate rows from the end.764 $handler = new QueryPathEventHandler($doc);765 $handler->find('#four > i:nth-last-child(odd)');766 $matches = $handler->getMatches();767 $this->assertEquals(2, $matches->count());768 $this->assertEquals('inner-two', $this->nthMatch($matches, 0)->getAttribute('id'));769 $this->assertEquals('inner-four', $this->nthMatch($matches, 1)->getAttribute('id'));770 // According to spec, this should be last two elements.771 $handler = new QueryPathEventHandler($doc);772 $handler->find('#four > i:nth-last-child(-1n+2)');773 $matches = $handler->getMatches();774 //print $this->firstMatch($matches)->getAttribute('id');775 $this->assertEquals(2, $matches->count());776 $this->assertEquals('inner-three', $this->nthMatch($matches, 0)->getAttribute('id'));777 $this->assertEquals('inner-four', $this->nthMatch($matches, 1)->getAttribute('id'));778 }779 public function testPseudoClassFirstOfType() {780 $xml = '<?xml version="1.0" ?>781 <test>782 <n class="odd" id="one"/>783 <i class="even" id="two"/>784 <i class="odd" id="three"/>785 </test>';786 $doc = new \DomDocument();787 $doc->loadXML($xml);788 // Test alternate rows from the end.789 $handler = new QueryPathEventHandler($doc);790 $handler->find('i:first-of-type(odd)');791 $matches = $handler->getMatches();792 $this->assertEquals(1, $matches->count());793 $this->assertEquals('two', $this->firstMatch($matches)->getAttribute('id'));794 }795 public function testPseudoClassNthFirstOfType() {796 $xml = '<?xml version="1.0" ?>797 <test>798 <n class="odd" id="one"/>799 <i class="even" id="two"/>800 <i class="odd" id="three"/>801 </test>';802 $doc = new \DomDocument();803 $doc->loadXML($xml);804 // Test alternate rows from the end.805 $handler = new QueryPathEventHandler($doc);806 $handler->find('i:first-of-type(1)');807 $matches = $handler->getMatches();808 $this->assertEquals(1, $matches->count());809 $this->assertEquals('two', $this->firstMatch($matches)->getAttribute('id'));810 }811 public function testPseudoClassLastOfType() {812 $xml = '<?xml version="1.0" ?>813 <test>814 <n class="odd" id="one"/>815 <i class="even" id="two"/>816 <i class="odd" id="three"/>817 </test>';818 $doc = new \DomDocument();819 $doc->loadXML($xml);820 // Test alternate rows from the end.821 $handler = new QueryPathEventHandler($doc);822 $handler->find('i:last-of-type(odd)');823 $matches = $handler->getMatches();824 $this->assertEquals(1, $matches->count());825 $this->assertEquals('three', $this->firstMatch($matches)->getAttribute('id'));826 }827 public function testPseudoNthClassLastOfType() {828 $xml = '<?xml version="1.0" ?>829 <test>830 <n class="odd" id="one"/>831 <i class="even" id="two"/>832 <i class="odd" id="three"/>833 </test>';834 $doc = new \DomDocument();835 $doc->loadXML($xml);836 // Test alternate rows from the end.837 $handler = new QueryPathEventHandler($doc);838 $handler->find('i:nth-last-of-type(1)');839 $matches = $handler->getMatches();840 $this->assertEquals(1, $matches->count());841 $this->assertEquals('three', $this->firstMatch($matches)->getAttribute('id'));842 // Issue #56: an+b not working.843 $xml = '<?xml version="1.0"?>844 <root>845 <div>I am the first div.</div>846 <div>I am the second div.</div>847 <div>I am the third div.</div>848 <div>I am the fourth div.</div>849 <div id="five">I am the fifth div.</div>850 <div id="six">I am the sixth div.</div>851 <div id="seven">I am the seventh div.</div>852 </root>';853 $doc = new \DomDocument();854 $doc->loadXML($xml);855 $handler = new QueryPathEventHandler($doc);856 $handler->find('div:nth-last-of-type(-n+3)');857 $matches = $handler->getMatches();858 $this->assertEquals(3, $matches->count());859 $this->assertEquals('five', $this->firstMatch($matches)->getAttribute('id'));860 }861 public function testPseudoClassEmpty() {862 $xml = '<?xml version="1.0" ?>863 <test>864 <n class="odd" id="one"/>865 <i class="even" id="two"></i>866 </test>';867 $doc = new \DomDocument();868 $doc->loadXML($xml);869 $handler = new QueryPathEventHandler($doc);870 $handler->find('n:empty');871 $matches = $handler->getMatches();872 $this->assertEquals(1, $matches->count());873 $this->assertEquals('one', $this->firstMatch($matches)->getAttribute('id'));874 $handler = new QueryPathEventHandler($doc);875 $handler->find('i:empty');876 $matches = $handler->getMatches();877 $this->assertEquals(1, $matches->count());878 $this->assertEquals('two', $this->firstMatch($matches)->getAttribute('id'));879 }880 public function testPseudoClassFirst() {881 $xml = '<?xml version="1.0" ?>882 <test>883 <i class="odd" id="one"/>884 <i class="even" id="two"/>885 <i class="odd" id="three"/>886 </test>';887 $doc = new \DomDocument();888 $doc->loadXML($xml);889 // Test alternate rows from the end.890 $handler = new QueryPathEventHandler($doc);891 $handler->find('i:first');892 $matches = $handler->getMatches();893 $this->assertEquals(1, $matches->count());894 $this->assertEquals('one', $this->firstMatch($matches)->getAttribute('id'));895 }896 public function testPseudoClassLast() {897 $xml = '<?xml version="1.0" ?>898 <test>899 <i class="odd" id="one"/>900 <i class="even" id="two"/>901 <i class="odd" id="three"/>902 </test>';903 $doc = new \DomDocument();904 $doc->loadXML($xml);905 // Test alternate rows from the end.906 $handler = new QueryPathEventHandler($doc);907 $handler->find('i:last');908 $matches = $handler->getMatches();909 $this->assertEquals(1, $matches->count());910 $this->assertEquals('three', $this->firstMatch($matches)->getAttribute('id'));911 }912 public function testPseudoClassGT() {913 $xml = '<?xml version="1.0" ?>914 <test>915 <i class="odd" id="one"/>916 <i class="even" id="two"/>917 <i class="odd" id="three"/>918 </test>';919 $doc = new \DomDocument();920 $doc->loadXML($xml);921 // Test alternate rows from the end.922 $handler = new QueryPathEventHandler($doc);923 $handler->find('i:gt(1)');924 $matches = $handler->getMatches();925 $this->assertEquals(2, $matches->count());926 $this->assertEquals('two', $this->firstMatch($matches)->getAttribute('id'));927 }928 public function testPseudoClassLT() {929 $xml = '<?xml version="1.0" ?>930 <test>931 <i class="odd" id="one"/>932 <i class="even" id="two"/>933 <i class="odd" id="three"/>934 </test>';935 $doc = new \DomDocument();936 $doc->loadXML($xml);937 // Test alternate rows from the end.938 $handler = new QueryPathEventHandler($doc);939 $handler->find('i:lt(3)');940 $matches = $handler->getMatches();941 $this->assertEquals(2, $matches->count());942 $this->assertEquals('one', $this->nthMatch($matches,0)->getAttribute('id'));943 $this->assertEquals('two', $this->nthMatch($matches,1)->getAttribute('id'));944 }945 public function testPseudoClassNTH() {946 $xml = '<?xml version="1.0" ?>947 <test>948 <i class="odd" id="one"/>949 <i class="even" id="two"/>950 <i class="odd" id="three"/>951 </test>';952 $doc = new \DomDocument();953 $doc->loadXML($xml);954 $handler = new QueryPathEventHandler($doc);955 $handler->find('i:nth(2)');956 $matches = $handler->getMatches();957 $this->assertEquals(1, $matches->count());958 $this->assertEquals('two', $this->firstMatch($matches)->getAttribute('id'));959 $handler = new QueryPathEventHandler($doc);960 $handler->find('i:eq(2)');961 $matches = $handler->getMatches();962 $this->assertEquals(1, $matches->count());963 $this->assertEquals('two', $this->firstMatch($matches)->getAttribute('id'));964 }965 public function testPseudoClassNthOfType() {966 $xml = '<?xml version="1.0" ?>967 <test>968 <i class="odd" id="one"/>969 <i class="even" id="two"/>970 <i class="odd" id="three"/>971 </test>';972 $doc = new \DomDocument();973 $doc->loadXML($xml);974 $handler = new QueryPathEventHandler($doc);975 $handler->find('i:nth-of-type(2)');976 $matches = $handler->getMatches();977 $this->assertEquals(1, $matches->count());978 $this->assertEquals('two', $this->firstMatch($matches)->getAttribute('id'));979 }980 public function testPseudoClassFormElements() {981 $form = array('text', 'radio', 'checkbox', 'button', 'password');982 $xml = '<?xml version="1.0" ?>983 <test>984 <input type="%s" class="odd" id="one"/>985 </test>';986 foreach ($form as $item) {987 $doc = new \DomDocument();988 $doc->loadXML(sprintf($xml, $item));989 $handler = new QueryPathEventHandler($doc);990 $handler->find(':' . $item);991 $matches = $handler->getMatches();992 $this->assertEquals(1, $matches->count());993 $this->assertEquals('one', $this->firstMatch($matches)->getAttribute('id'));994 }995 }996 public function testPseudoClassHeader() {997 $xml = '<?xml version="1.0" ?>998 <test>999 <h1 class="odd" id="one"/>1000 <h2 class="even" id="two"/>1001 <h6 class="odd" id="three"/>1002 </test>';1003 $doc = new \DomDocument();1004 $doc->loadXML($xml);1005 $handler = new QueryPathEventHandler($doc);1006 $handler->find('test :header');1007 $matches = $handler->getMatches();1008 $this->assertEquals(3, $matches->count());1009 $this->assertEquals('three', $this->nthMatch($matches, 2)->getAttribute('id'));1010 }1011 public function testPseudoClassContains() {1012 $xml = '<?xml version="1.0" ?>1013 <test>1014 <p id="one">This is text.</p>1015 <p id="two"><i>More text</i></p>1016 </test>';1017 $doc = new \DomDocument();1018 $doc->loadXML($xml);1019 $handler = new QueryPathEventHandler($doc);1020 $handler->find('p:contains(This is text.)');1021 $matches = $handler->getMatches();1022 $this->assertEquals(1, $matches->count());1023 $this->assertEquals('one', $this->firstMatch($matches)->getAttribute('id'));1024 $handler = new QueryPathEventHandler($doc);1025 $handler->find('* :contains(More text)');1026 $matches = $handler->getMatches();1027 $this->assertEquals(2, $matches->count(), 'Matches two instance of same text?');1028 $this->assertEquals('two', $this->firstMatch($matches)->getAttribute('id'));1029 $handler = new QueryPathEventHandler($doc);1030 $handler->find('p:contains("This is text.")');1031 $matches = $handler->getMatches();1032 $this->assertEquals(1, $matches->count(), 'Quoted text matches unquoted pcdata');1033 $this->assertEquals('one', $this->firstMatch($matches)->getAttribute('id'));1034 $handler = new QueryPathEventHandler($doc);1035 $handler->find('p:contains(\\\'This is text.\\\')');1036 $matches = $handler->getMatches();1037 $this->assertEquals(1, $matches->count(), 'One match for quoted string.');1038 $this->assertEquals('one', $this->firstMatch($matches)->getAttribute('id'));1039 // Test for issue #321040 $handler = new QueryPathEventHandler($doc);1041 $handler->find('p:contains(text)');1042 $matches = $handler->getMatches();1043 $this->assertEquals(2, $matches->count(), 'Two matches for fragment of string.');1044 $this->assertEquals('one', $this->firstMatch($matches)->getAttribute('id'));1045 }1046 public function testPseudoClassContainsExactly() {1047 $xml = '<?xml version="1.0" ?>1048 <test>1049 <p id="one">This is text.</p>1050 <p id="two"><i>More text</i></p>1051 </test>';1052 $doc = new \DomDocument();1053 $doc->loadXML($xml);1054 $handler = new QueryPathEventHandler($doc);1055 $handler->find('p:contains(This is text.)');1056 $matches = $handler->getMatches();1057 $this->assertEquals(1, $matches->count());1058 $this->assertEquals('one', $this->firstMatch($matches)->getAttribute('id'));1059 $handler = new QueryPathEventHandler($doc);1060 $handler->find('* :contains(More text)');1061 $matches = $handler->getMatches();1062 $this->assertEquals(2, $matches->count(), 'Matches two instance of same text.');1063 $this->assertEquals('two', $this->firstMatch($matches)->getAttribute('id'));1064 $handler = new QueryPathEventHandler($doc);1065 $handler->find('p:contains("This is text.")');1066 $matches = $handler->getMatches();1067 $this->assertEquals(1, $matches->count(), 'Quoted text matches unquoted pcdata');1068 $this->assertEquals('one', $this->firstMatch($matches)->getAttribute('id'));1069 $handler = new QueryPathEventHandler($doc);1070 $handler->find('p:contains(\\\'This is text.\\\')');1071 $matches = $handler->getMatches();1072 $this->assertEquals(1, $matches->count(), 'One match for quoted string.');1073 $this->assertEquals('one', $this->firstMatch($matches)->getAttribute('id'));1074 }1075 public function testPseudoClassHas() {1076 $xml = '<?xml version="1.0" ?>1077 <test>1078 <outer id="one">1079 <inner/>1080 </outer>1081 <outer id="two"/>1082 </test>';1083 $doc = new \DomDocument();1084 $doc->loadXML($xml);1085 $handler = new QueryPathEventHandler($doc);1086 $handler->find('outer:has(inner)');1087 $matches = $handler->getMatches();1088 $this->assertEquals(1, $matches->count());1089 $this->assertEquals('one', $this->firstMatch($matches)->getAttribute('id'));1090 }1091 public function testPseudoClassNot() {1092 $xml = '<?xml version="1.0" ?>1093 <test>1094 <outer id="one">1095 <inner/>1096 </outer>1097 <outer id="two" class="notMe"/>1098 </test>';1099 $doc = new \DomDocument();1100 $doc->loadXML($xml);1101 $handler = new QueryPathEventHandler($doc);1102 $handler->find('outer:not(#one)');1103 $matches = $handler->getMatches();1104 $this->assertEquals(1, $matches->count());1105 $this->assertEquals('two', $this->firstMatch($matches)->getAttribute('id'));1106 $handler = new QueryPathEventHandler($doc);1107 $handler->find('outer:not(inner)');1108 $matches = $handler->getMatches();1109 $this->assertEquals(1, $matches->count());1110 $this->assertEquals('two', $this->firstMatch($matches)->getAttribute('id'));1111 $handler = new QueryPathEventHandler($doc);1112 $handler->find('outer:not(.notMe)');1113 $matches = $handler->getMatches();1114 $this->assertEquals(1, $matches->count());1115 $this->assertEquals('one', $this->firstMatch($matches)->getAttribute('id'));1116 }1117 public function testPseudoElement() {1118 $xml = '<?xml version="1.0" ?>1119 <test>1120 <outer id="one">Texts1121 More text</outer>1122 <outer id="two" class="notMe"/>1123 </test>';1124 $doc = new \DomDocument();1125 $doc->loadXML($xml);1126 $handler = new QueryPathEventHandler($doc);1127 $handler->find('outer::first-letter');1128 $matches = $handler->getMatches();1129 $this->assertEquals(1, $matches->count());1130 $this->assertEquals('T', $this->firstMatch($matches)->textContent);1131 $handler = new QueryPathEventHandler($doc);1132 $handler->find('outer::first-line');1133 $matches = $handler->getMatches();1134 $this->assertEquals(1, $matches->count());1135 $this->assertEquals('Texts', $this->firstMatch($matches)->textContent);1136 }1137 public function testAdjacent() {1138 $xml = '<?xml version="1.0" ?>1139 <test>1140 <li id="one"/><li id="two"/><li id="three">1141 <li id="inner-one">1142 <li id="inner-inner-one"/>1143 <li id="inner-inner-one"/>1144 </li>1145 <li id="inner-two"/>1146 </li>1147 <li id="four"/>1148 <li id="five"/>1149 </test>';1150 $doc = new \DomDocument();1151 $doc->loadXML($xml);1152 $handler = new QueryPathEventHandler($doc);1153 $handler->find('#one + li');1154 $matches = $handler->getMatches();1155 $this->assertEquals(1, $matches->count());1156 $this->assertEquals('two', $this->firstMatch($matches)->getAttribute('id'));1157 // Tell it to ignore whitespace nodes.1158 $doc->loadXML($xml, LIBXML_NOBLANKS);1159 // Test with whitespace sensitivity weakened.1160 $handler = new QueryPathEventHandler($doc);1161 $handler->find('#four + li');1162 $matches = $handler->getMatches();1163 $this->assertEquals(1, $matches->count());1164 $this->assertEquals('five', $this->firstMatch($matches)->getAttribute('id'));1165 }1166 public function testAnotherSelector() {1167 $xml = '<?xml version="1.0" ?>1168 <test>1169 <li id="one"/><li id="two"/><li id="three">1170 <li id="inner-one">1171 <li id="inner-inner-one"/>1172 <li id="inner-inner-one"/>1173 </li>1174 <li id="inner-two"/>1175 </li>1176 <li id="four"/>1177 <li id="five"/>1178 </test>';1179 $doc = new \DomDocument();1180 $doc->loadXML($xml);1181 $handler = new QueryPathEventHandler($doc);1182 $handler->find('#one, #two');1183 $matches = $handler->getMatches();1184 //print $this->firstMatch($matches)->getAttribute('id') . PHP_EOL;1185 $this->assertEquals(2, $matches->count());1186 $this->assertEquals('two', $this->nthMatch($matches, 1)->getAttribute('id'));1187 }1188 public function testSibling() {1189 $xml = '<?xml version="1.0" ?>1190 <test>1191 <li id="one"/><li id="two"/><li id="three">1192 <li id="inner-one">1193 <li id="inner-inner-one"/>1194 <il id="inner-inner-two"/>1195 <li id="dont-match-me"/>1196 </li>1197 <li id="inner-two"/>1198 </li>1199 <li id="four"/>1200 <li id="five"/>1201 </test>';1202 $doc = new \DomDocument();1203 $doc->loadXML($xml);1204 $handler = new QueryPathEventHandler($doc);1205 $handler->find('#one ~ li');1206 $matches = $handler->getMatches();1207 //print $this->firstMatch($matches)->getAttribute('id') . PHP_EOL;1208 $this->assertEquals(4, $matches->count());1209 $this->assertEquals('three', $this->nthMatch($matches, 1)->getAttribute('id'));1210 $handler = new QueryPathEventHandler($doc);1211 $handler->find('#two ~ li');1212 $matches = $handler->getMatches();1213 //print $this->firstMatch($matches)->getAttribute('id') . PHP_EOL;1214 $this->assertEquals(3, $matches->count());1215 //$this->assertEquals('three', $this->nthMatch($matches, 1)->getAttribute('id'));1216 $handler = new QueryPathEventHandler($doc);1217 $handler->find('#inner-one > li ~ il');1218 $matches = $handler->getMatches();1219 //print $this->firstMatch($matches)->getAttribute('id') . PHP_EOL;1220 $this->assertEquals(1, $matches->count());1221 $this->assertEquals('inner-inner-two', $this->firstMatch($matches)->getAttribute('id'));1222 }1223 public function testAnyDescendant() {1224 $xml = '<?xml version="1.0" ?>1225 <test>1226 <li id="one"/><li id="two"/><li id="three">1227 <li id="inner-one" class="foo">1228 <li id="inner-inner-one" class="foo"/>1229 <il id="inner-inner-two"/>1230 <li id="dont-match-me"/>1231 </li>1232 <li id="inner-two"/>1233 </li>1234 <li id="four"/>1235 <li id="five"/>1236 </test>';1237 $doc = new \DomDocument();1238 $doc->loadXML($xml);1239 $handler = new QueryPathEventHandler($doc);1240 $handler->find('*');1241 $matches = $handler->getMatches();1242 $this->assertEquals(11, $matches->count());1243 $handler = new QueryPathEventHandler($doc);1244 $handler->find('*.foo');1245 $matches = $handler->getMatches();1246 $this->assertEquals(2, $matches->count());1247 $this->assertEquals('inner-inner-one', $this->nthMatch($matches, 1)->getAttribute('id'));1248 $handler = new QueryPathEventHandler($doc);1249 $handler->find('test > li *.foo');1250 $matches = $handler->getMatches();1251 $this->assertEquals(2, $matches->count());1252 $this->assertEquals('inner-inner-one', $this->nthMatch($matches, 1)->getAttribute('id'));1253 }1254}...
class-wp-text-diff-renderer-table.php
Source:class-wp-text-diff-renderer-table.php
...223 */224 public function _changed( $orig, $final ) {225 $r = '';226 // Does the aforementioned additional processing227 // *_matches tell what rows are "the same" in orig and final. Those pairs will be diffed to get word changes228 // match is numeric: an index in other column229 // match is 'X': no match. It is a new row230 // *_rows are column vectors for the orig column and the final column.231 // row >= 0: an indix of the $orig or $final array232 // row < 0: a blank row for that column233 list($orig_matches, $final_matches, $orig_rows, $final_rows) = $this->interleave_changed_lines( $orig, $final );234 // These will hold the word changes as determined by an inline diff235 $orig_diffs = array();236 $final_diffs = array();237 // Compute word diffs for each matched pair using the inline diff238 foreach ( $orig_matches as $o => $f ) {239 if ( is_numeric( $o ) && is_numeric( $f ) ) {240 $text_diff = new Text_Diff( 'auto', array( array( $orig[ $o ] ), array( $final[ $f ] ) ) );241 $renderer = new $this->inline_diff_renderer;242 $diff = $renderer->render( $text_diff );243 // If they're too different, don't include any <ins> or <dels>244 if ( preg_match_all( '!(<ins>.*?</ins>|<del>.*?</del>)!', $diff, $diff_matches ) ) {245 // length of all text between <ins> or <del>246 $stripped_matches = strlen( strip_tags( join( ' ', $diff_matches[0] ) ) );247 // since we count lengith of text between <ins> or <del> (instead of picking just one),248 // we double the length of chars not in those tags.249 $stripped_diff = strlen( strip_tags( $diff ) ) * 2 - $stripped_matches;250 $diff_ratio = $stripped_matches / $stripped_diff;251 if ( $diff_ratio > $this->_diff_threshold ) {252 continue; // Too different. Don't save diffs.253 }254 }255 // Un-inline the diffs by removing del or ins256 $orig_diffs[ $o ] = preg_replace( '|<ins>.*?</ins>|', '', $diff );257 $final_diffs[ $f ] = preg_replace( '|<del>.*?</del>|', '', $diff );258 }259 }260 foreach ( array_keys( $orig_rows ) as $row ) {261 // Both columns have blanks. Ignore them.262 if ( $orig_rows[ $row ] < 0 && $final_rows[ $row ] < 0 ) {263 continue;264 }265 // If we have a word based diff, use it. Otherwise, use the normal line.266 if ( isset( $orig_diffs[ $orig_rows[ $row ] ] ) ) {267 $orig_line = $orig_diffs[ $orig_rows[ $row ] ];268 } elseif ( isset( $orig[ $orig_rows[ $row ] ] ) ) {269 $orig_line = htmlspecialchars( $orig[ $orig_rows[ $row ] ] );270 } else {271 $orig_line = '';272 }273 if ( isset( $final_diffs[ $final_rows[ $row ] ] ) ) {274 $final_line = $final_diffs[ $final_rows[ $row ] ];275 } elseif ( isset( $final[ $final_rows[ $row ] ] ) ) {276 $final_line = htmlspecialchars( $final[ $final_rows[ $row ] ] );277 } else {278 $final_line = '';279 }280 if ( $orig_rows[ $row ] < 0 ) { // Orig is blank. This is really an added row.281 $r .= $this->_added( array( $final_line ), false );282 } elseif ( $final_rows[ $row ] < 0 ) { // Final is blank. This is really a deleted row.283 $r .= $this->_deleted( array( $orig_line ), false );284 } else { // A true changed row.285 if ( $this->_show_split_view ) {286 $r .= '<tr>' . $this->deletedLine( $orig_line ) . $this->emptyLine() . $this->addedLine( $final_line ) . "</tr>\n";287 } else {288 $r .= '<tr>' . $this->deletedLine( $orig_line ) . '</tr><tr>' . $this->addedLine( $final_line ) . "</tr>\n";289 }290 }291 }292 return $r;293 }294 /**295 * Takes changed blocks and matches which rows in orig turned into which rows in final.296 *297 * @since 2.6.0298 *299 * @param array $orig Lines of the original version of the text.300 * @param array $final Lines of the final version of the text.301 * @return array {302 * Array containing results of comparing the original text to the final text.303 *304 * @type array $orig_matches Associative array of original matches. Index == row305 * number of `$orig`, value == corresponding row number306 * of that same line in `$final` or 'x' if there is no307 * corresponding row (indicating it is a deleted line).308 * @type array $final_matches Associative array of final matches. Index == row309 * number of `$final`, value == corresponding row number310 * of that same line in `$orig` or 'x' if there is no311 * corresponding row (indicating it is a new line).312 * @type array $orig_rows Associative array of interleaved rows of `$orig` with313 * blanks to keep matches aligned with side-by-side diff314 * of `$final`. A value >= 0 corresponds to index of `$orig`.315 * Value < 0 indicates a blank row.316 * @type array $final_rows Associative array of interleaved rows of `$final` with317 * blanks to keep matches aligned with side-by-side diff318 * of `$orig`. A value >= 0 corresponds to index of `$final`.319 * Value < 0 indicates a blank row.320 * }321 */322 public function interleave_changed_lines( $orig, $final ) {323 // Contains all pairwise string comparisons. Keys are such that this need only be a one dimensional array.324 $matches = array();325 foreach ( array_keys( $orig ) as $o ) {326 foreach ( array_keys( $final ) as $f ) {327 $matches[ "$o,$f" ] = $this->compute_string_distance( $orig[ $o ], $final[ $f ] );328 }329 }330 asort( $matches ); // Order by string distance.331 $orig_matches = array();332 $final_matches = array();333 foreach ( $matches as $keys => $difference ) {334 list($o, $f) = explode( ',', $keys );335 $o = (int) $o;336 $f = (int) $f;337 // Already have better matches for these guys338 if ( isset( $orig_matches[ $o ] ) && isset( $final_matches[ $f ] ) ) {339 continue;340 }341 // First match for these guys. Must be best match342 if ( ! isset( $orig_matches[ $o ] ) && ! isset( $final_matches[ $f ] ) ) {343 $orig_matches[ $o ] = $f;344 $final_matches[ $f ] = $o;345 continue;346 }347 // Best match of this final is already taken? Must mean this final is a new row.348 if ( isset( $orig_matches[ $o ] ) ) {349 $final_matches[ $f ] = 'x';350 } elseif ( isset( $final_matches[ $f ] ) ) {351 // Best match of this orig is already taken? Must mean this orig is a deleted row.352 $orig_matches[ $o ] = 'x';353 }354 }355 // We read the text in this order356 ksort( $orig_matches );357 ksort( $final_matches );358 // Stores rows and blanks for each column.359 $orig_rows = $orig_rows_copy = array_keys( $orig_matches );360 $final_rows = array_keys( $final_matches );361 // Interleaves rows with blanks to keep matches aligned.362 // We may end up with some extraneous blank rows, but we'll just ignore them later.363 foreach ( $orig_rows_copy as $orig_row ) {364 $final_pos = array_search( $orig_matches[ $orig_row ], $final_rows, true );365 $orig_pos = (int) array_search( $orig_row, $orig_rows, true );366 if ( false === $final_pos ) { // This orig is paired with a blank final.367 array_splice( $final_rows, $orig_pos, 0, -1 );368 } elseif ( $final_pos < $orig_pos ) { // This orig's match is up a ways. Pad final with blank rows.369 $diff_array = range( -1, $final_pos - $orig_pos );370 array_splice( $final_rows, $orig_pos, 0, $diff_array );371 } elseif ( $final_pos > $orig_pos ) { // This orig's match is down a ways. Pad orig with blank rows.372 $diff_array = range( -1, $orig_pos - $final_pos );373 array_splice( $orig_rows, $orig_pos, 0, $diff_array );374 }375 }376 // Pad the ends with blank rows if the columns aren't the same length377 $diff_count = count( $orig_rows ) - count( $final_rows );378 if ( $diff_count < 0 ) {379 while ( $diff_count < 0 ) {380 array_push( $orig_rows, $diff_count++ );381 }382 } elseif ( $diff_count > 0 ) {383 $diff_count = -1 * $diff_count;384 while ( $diff_count < 0 ) {385 array_push( $final_rows, $diff_count++ );386 }387 }388 return array( $orig_matches, $final_matches, $orig_rows, $final_rows );389 }390 /**391 * Computes a number that is intended to reflect the "distance" between two strings.392 *393 * @since 2.6.0394 *395 * @param string $string1396 * @param string $string2397 * @return int398 */399 public function compute_string_distance( $string1, $string2 ) {400 // Use an md5 hash of the strings for a count cache, as it's fast to generate, and collisions aren't a concern.401 $count_key1 = md5( $string1 );402 $count_key2 = md5( $string2 );...
StringMatchesFormatDescriptionTest.php
Source:StringMatchesFormatDescriptionTest.php
...19 $constraint = new StringMatchesFormatDescription('*%e*');20 $this->assertFalse($constraint->evaluate('**', '', true));21 $this->assertFalse($constraint->evaluate('*a*', '', true));22 $this->assertTrue($constraint->evaluate('*' . \DIRECTORY_SEPARATOR . '*', '', true));23 $this->assertEquals('matches PCRE pattern "/^\*\\' . \DIRECTORY_SEPARATOR . '\*$/s"', $constraint->toString());24 $this->assertCount(1, $constraint);25 }26 public function testConstraintStringMatchesString(): void27 {28 $constraint = new StringMatchesFormatDescription('*%s*');29 $this->assertFalse($constraint->evaluate('**', '', true));30 $this->assertFalse($constraint->evaluate("*\n*", '', true));31 $this->assertTrue($constraint->evaluate('***', '', true));32 $this->assertTrue($constraint->evaluate('*foo 123 bar*', '', true));33 $this->assertEquals('matches PCRE pattern "/^\*[^\r\n]+\*$/s"', $constraint->toString());34 $this->assertCount(1, $constraint);35 }36 public function testConstraintStringMatchesOptionalString(): void37 {38 $constraint = new StringMatchesFormatDescription('*%S*');39 $this->assertFalse($constraint->evaluate('*', '', true));40 $this->assertFalse($constraint->evaluate("*\n*", '', true));41 $this->assertTrue($constraint->evaluate('***', '', true));42 $this->assertTrue($constraint->evaluate('*foo 123 bar*', '', true));43 $this->assertTrue($constraint->evaluate('**', '', true));44 $this->assertEquals('matches PCRE pattern "/^\*[^\r\n]*\*$/s"', $constraint->toString());45 $this->assertCount(1, $constraint);46 }47 public function testConstraintStringMatchesAnything(): void48 {49 $constraint = new StringMatchesFormatDescription('*%a*');50 $this->assertFalse($constraint->evaluate('**', '', true));51 $this->assertTrue($constraint->evaluate('***', '', true));52 $this->assertTrue($constraint->evaluate('*foo 123 bar*', '', true));53 $this->assertTrue($constraint->evaluate("*\n*", '', true));54 $this->assertEquals('matches PCRE pattern "/^\*.+\*$/s"', $constraint->toString());55 $this->assertCount(1, $constraint);56 }57 public function testConstraintStringMatchesOptionalAnything(): void58 {59 $constraint = new StringMatchesFormatDescription('*%A*');60 $this->assertFalse($constraint->evaluate('*', '', true));61 $this->assertTrue($constraint->evaluate('***', '', true));62 $this->assertTrue($constraint->evaluate('*foo 123 bar*', '', true));63 $this->assertTrue($constraint->evaluate("*\n*", '', true));64 $this->assertTrue($constraint->evaluate('**', '', true));65 $this->assertEquals('matches PCRE pattern "/^\*.*\*$/s"', $constraint->toString());66 $this->assertCount(1, $constraint);67 }68 public function testConstraintStringMatchesWhitespace(): void69 {70 $constraint = new StringMatchesFormatDescription('*%w*');71 $this->assertFalse($constraint->evaluate('*', '', true));72 $this->assertFalse($constraint->evaluate('*a*', '', true));73 $this->assertTrue($constraint->evaluate('* *', '', true));74 $this->assertTrue($constraint->evaluate("*\t\n*", '', true));75 $this->assertTrue($constraint->evaluate('**', '', true));76 $this->assertEquals('matches PCRE pattern "/^\*\s*\*$/s"', $constraint->toString());77 $this->assertCount(1, $constraint);78 }79 public function testConstraintStringMatchesInteger(): void80 {81 $constraint = new StringMatchesFormatDescription('*%i*');82 $this->assertFalse($constraint->evaluate('**', '', true));83 $this->assertFalse($constraint->evaluate('*a*', '', true));84 $this->assertFalse($constraint->evaluate('*1.0*', '', true));85 $this->assertTrue($constraint->evaluate('*0*', '', true));86 $this->assertTrue($constraint->evaluate('*12*', '', true));87 $this->assertTrue($constraint->evaluate('*-1*', '', true));88 $this->assertTrue($constraint->evaluate('*+2*', '', true));89 $this->assertEquals('matches PCRE pattern "/^\*[+-]?\d+\*$/s"', $constraint->toString());90 $this->assertCount(1, $constraint);91 }92 public function testConstraintStringMatchesUnsignedInt(): void93 {94 $constraint = new StringMatchesFormatDescription('*%d*');95 $this->assertFalse($constraint->evaluate('**', '', true));96 $this->assertFalse($constraint->evaluate('*a*', '', true));97 $this->assertFalse($constraint->evaluate('*1.0*', '', true));98 $this->assertFalse($constraint->evaluate('*-1*', '', true));99 $this->assertFalse($constraint->evaluate('*+2*', '', true));100 $this->assertTrue($constraint->evaluate('*0*', '', true));101 $this->assertTrue($constraint->evaluate('*12*', '', true));102 $this->assertEquals('matches PCRE pattern "/^\*\d+\*$/s"', $constraint->toString());103 $this->assertCount(1, $constraint);104 }105 public function testConstraintStringMatchesHexadecimal(): void106 {107 $constraint = new StringMatchesFormatDescription('*%x*');108 $this->assertFalse($constraint->evaluate('**', '', true));109 $this->assertFalse($constraint->evaluate('***', '', true));110 $this->assertFalse($constraint->evaluate('*g*', '', true));111 $this->assertFalse($constraint->evaluate('*1.0*', '', true));112 $this->assertFalse($constraint->evaluate('*-1*', '', true));113 $this->assertFalse($constraint->evaluate('*+2*', '', true));114 $this->assertTrue($constraint->evaluate('*0f0f0f*', '', true));115 $this->assertTrue($constraint->evaluate('*0*', '', true));116 $this->assertTrue($constraint->evaluate('*12*', '', true));117 $this->assertTrue($constraint->evaluate('*a*', '', true));118 $this->assertEquals('matches PCRE pattern "/^\*[0-9a-fA-F]+\*$/s"', $constraint->toString());119 $this->assertCount(1, $constraint);120 }121 public function testConstraintStringMatchesFloat(): void122 {123 $constraint = new StringMatchesFormatDescription('*%f*');124 $this->assertFalse($constraint->evaluate('**', '', true));125 $this->assertFalse($constraint->evaluate('***', '', true));126 $this->assertFalse($constraint->evaluate('*a*', '', true));127 $this->assertTrue($constraint->evaluate('*1.0*', '', true));128 $this->assertTrue($constraint->evaluate('*0*', '', true));129 $this->assertTrue($constraint->evaluate('*12*', '', true));130 $this->assertTrue($constraint->evaluate('*.1*', '', true));131 $this->assertTrue($constraint->evaluate('*1.*', '', true));132 $this->assertTrue($constraint->evaluate('*2e3*', '', true));133 $this->assertTrue($constraint->evaluate('*-2.34e-56*', '', true));134 $this->assertTrue($constraint->evaluate('*+2.34e+56*', '', true));135 $this->assertEquals('matches PCRE pattern "/^\*[+-]?\.?\d+\.?\d*(?:[Ee][+-]?\d+)?\*$/s"', $constraint->toString());136 $this->assertCount(1, $constraint);137 }138 public function testConstraintStringMatchesCharacter(): void139 {140 $constraint = new StringMatchesFormatDescription('*%c*');141 $this->assertFalse($constraint->evaluate('**', '', true));142 $this->assertFalse($constraint->evaluate('*ab*', '', true));143 $this->assertTrue($constraint->evaluate('***', '', true));144 $this->assertTrue($constraint->evaluate('*a*', '', true));145 $this->assertTrue($constraint->evaluate('*g*', '', true));146 $this->assertTrue($constraint->evaluate('*0*', '', true));147 $this->assertTrue($constraint->evaluate('*2*', '', true));148 $this->assertTrue($constraint->evaluate('* *', '', true));149 $this->assertTrue($constraint->evaluate("*\n*", '', true));150 $this->assertEquals('matches PCRE pattern "/^\*.\*$/s"', $constraint->toString());151 $this->assertCount(1, $constraint);152 }153 public function testConstraintStringMatchesEscapedPercent(): void154 {155 $constraint = new StringMatchesFormatDescription('%%,%%e,%%s,%%S,%%a,%%A,%%w,%%i,%%d,%%x,%%f,%%c,%%Z,%%%%,%%');156 $this->assertFalse($constraint->evaluate('%%,%' . \DIRECTORY_SEPARATOR . ',%*,%*,%*,%*,% ,%0,%0,%0f0f0f,%1.0,%*,%%Z,%%%%,%%', '', true));157 $this->assertTrue($constraint->evaluate('%,%e,%s,%S,%a,%A,%w,%i,%d,%x,%f,%c,%Z,%%,%', '', true));158 $this->assertEquals('matches PCRE pattern "/^%,%e,%s,%S,%a,%A,%w,%i,%d,%x,%f,%c,%Z,%%,%$/s"', $constraint->toString());159 $this->assertCount(1, $constraint);160 }161 public function testConstraintStringMatchesEscapedPercentThenPlaceholder(): void162 {163 $constraint = new StringMatchesFormatDescription('%%%e,%%%s,%%%S,%%%a,%%%A,%%%w,%%%i,%%%d,%%%x,%%%f,%%%c');164 $this->assertFalse($constraint->evaluate('%%e,%%s,%%S,%%a,%%A,%%w,%%i,%%d,%%x,%%f,%%c', '', true));165 $this->assertTrue($constraint->evaluate('%' . \DIRECTORY_SEPARATOR . ',%*,%*,%*,%*,% ,%0,%0,%0f0f0f,%1.0,%*', '', true));166 $this->assertEquals('matches PCRE pattern "/^%\\' . \DIRECTORY_SEPARATOR . ',%[^\r\n]+,%[^\r\n]*,%.+,%.*,%\s*,%[+-]?\d+,%\d+,%[0-9a-fA-F]+,%[+-]?\.?\d+\.?\d*(?:[Ee][+-]?\d+)?,%.$/s"', $constraint->toString());167 $this->assertCount(1, $constraint);168 }169 public function testConstraintStringMatchesSlash(): void170 {171 $constraint = new StringMatchesFormatDescription('/');172 $this->assertFalse($constraint->evaluate('\\/', '', true));173 $this->assertTrue($constraint->evaluate('/', '', true));174 $this->assertEquals('matches PCRE pattern "/^\\/$/s"', $constraint->toString());175 $this->assertCount(1, $constraint);176 }177 public function testConstraintStringMatchesBackslash(): void178 {179 $constraint = new StringMatchesFormatDescription('\\');180 $this->assertFalse($constraint->evaluate('\\\\', '', true));181 $this->assertTrue($constraint->evaluate('\\', '', true));182 $this->assertEquals('matches PCRE pattern "/^\\\\$/s"', $constraint->toString());183 $this->assertCount(1, $constraint);184 }185 public function testConstraintStringMatchesBackslashSlash(): void186 {187 $constraint = new StringMatchesFormatDescription('\\/');188 $this->assertFalse($constraint->evaluate('/', '', true));189 $this->assertTrue($constraint->evaluate('\\/', '', true));190 $this->assertEquals('matches PCRE pattern "/^\\\\\\/$/s"', $constraint->toString());191 $this->assertCount(1, $constraint);192 }193 public function testConstraintStringMatchesNewline(): void194 {195 $constraint = new StringMatchesFormatDescription("\r\n");196 $this->assertFalse($constraint->evaluate("*\r\n", '', true));197 $this->assertTrue($constraint->evaluate("\r\n", '', true));198 $this->assertEquals("matches PCRE pattern \"/^\n$/s\"", $constraint->toString());199 $this->assertCount(1, $constraint);200 }201 public function testFailureMessageWithNewlines(): void202 {203 $constraint = new StringMatchesFormatDescription("%c\nfoo\n%c");204 try {205 $constraint->evaluate("*\nbar\n*");206 $this->fail('Expected ExpectationFailedException, but it was not thrown.');207 } catch (ExpectationFailedException $e) {208 $expected = <<<EOD209Failed asserting that string matches format description.210--- Expected211+++ Actual212@@ @@213 *214-foo215+bar216 *217EOD;218 $this->assertEquals($expected, $e->getMessage());219 }220 }221}...
DOMTraverserTest.php
Source:DOMTraverserTest.php
...36 $traverser = new DOMTraverser($splos);37 return $traverser;38 }39 protected function find($selector) {40 return $this->traverser()->find($selector)->matches();41 }42 public function testFind() {43 $res = $this->traverser()->find('root');44 // Ensure that return contract is not violated.45 $this->assertInstanceOf('\QueryPath\CSS\Traverser', $res);46 }47 public function testMatches() {48 $res = $this->traverser()->matches();49 $this->assertEquals(1, count($res));50 }51 public function testMatchElement() {52 // Canary: If element does not exist, must return FALSE.53 $matches = $this->find('NO_SUCH_ELEMENT');54 $this->assertEquals(0, count($matches));55 // Test without namespace56 $matches = $this->find('root');57 $this->assertEquals(1, count($matches));58 $matches = $this->find('crowded');59 $this->assertEquals(1, count($matches));60 $matches = $this->find('outside');61 $this->assertEquals(3, count($matches));62 // Check nested elements.63 $matches = $this->find('a');64 $this->assertEquals(3, count($matches));65 // Test wildcard.66 $traverser = $this->traverser();67 $matches = $traverser->find('*')->matches();68 $actual= $traverser->getDocument()->getElementsByTagName('*');69 $this->assertEquals($actual->length, count($matches));70 // Test with namespace71 //$this->markTestIncomplete();72 $matches = $this->find('ns_test');73 $this->assertEquals(3, count($matches));74 $matches = $this->find('test|ns_test');75 $this->assertEquals(1, count($matches));76 $matches = $this->find('test|ns_test>ns_attr');77 $this->assertEquals(1, count($matches));78 $matches = $this->find('*|ns_test');79 $this->assertEquals(3, count($matches));80 $matches = $this->find('test|*');81 $this->assertEquals(1, count($matches));82 // Test where namespace is declared on the element.83 $matches = $this->find('newns|my_element');84 $this->assertEquals(1, count($matches));85 $matches = $this->find('test|ns_test>newns|my_element');86 $this->assertEquals(1, count($matches));87 $matches = $this->find('test|*>newns|my_element');88 $this->assertEquals(1, count($matches));89 $matches = $this->find('*|ns_test>newns|my_element');90 $this->assertEquals(1, count($matches));91 $matches = $this->find('*|*>newns|my_element');92 $this->assertEquals(1, count($matches));93 $matches = $this->find('*>newns|my_element');94 $this->assertEquals(1, count($matches));95 }96 public function testMatchAttributes() {97 $matches = $this->find('crowded[attr1]');98 $this->assertEquals(1, count($matches));99 $matches = $this->find('crowded[attr1=one]');100 $this->assertEquals(1, count($matches));101 $matches = $this->find('crowded[attr2^=tw]');102 $this->assertEquals(1, count($matches));103 $matches = $this->find('classtest[class~=two]');104 $this->assertEquals(1, count($matches));105 $matches = $this->find('classtest[class~=one]');106 $this->assertEquals(1, count($matches));107 $matches = $this->find('classtest[class~=seven]');108 $this->assertEquals(1, count($matches));109 $matches = $this->find('crowded[attr0]');110 $this->assertEquals(0, count($matches));111 $matches = $this->find('[level=1]');112 $this->assertEquals(3, count($matches));113 $matches = $this->find('[attr1]');114 $this->assertEquals(1, count($matches));115 $matches = $this->find('[test|myattr]');116 $this->assertEquals(1, count($matches));117 $matches = $this->find('[test|myattr=foo]');118 $this->assertEquals(1, count($matches));119 $matches = $this->find('[*|myattr=foo]');120 $this->assertEquals(1, count($matches));121 $matches = $this->find('[|myattr=foo]');122 $this->assertEquals(0, count($matches));123 $matches = $this->find('[|level=1]');124 $this->assertEquals(3, count($matches));125 $matches = $this->find('[*|level=1]');126 $this->assertEquals(4, count($matches));127 // Test namespace on attr where namespace128 // is declared on that element129 $matches = $this->find('[nuther|ping]');130 $this->assertEquals(1, count($matches));131 // Test multiple namespaces on an element.132 $matches = $this->find('[*|ping=3]');133 $this->assertEquals(1, count($matches));134 // Test multiple namespaces on an element.135 $matches = $this->find('[*|ping]');136 $this->assertEquals(1, count($matches));137 }138 public function testMatchId() {139 $matches = $this->find('idtest#idtest-one');140 $this->assertEquals(1, count($matches));141 $matches = $this->find('#idtest-one');142 $this->assertEquals(1, count($matches));143 $matches = $this->find('outter#fake');144 $this->assertEquals(0, count($matches));145 $matches = $this->find('#fake');146 $this->assertEquals(0, count($matches));147 }148 public function testMatchClasses() {149 // Basic test.150 $matches = $this->find('a.a1');151 $this->assertEquals(1, count($matches));152 // Count multiple.153 $matches = $this->find('.first');154 $this->assertEquals(2, count($matches));155 // Grab one in the middle of a list.156 $matches = $this->find('.four');157 $this->assertEquals(1, count($matches));158 // One element with two classes.159 $matches = $this->find('.three.four');160 $this->assertEquals(1, count($matches));161 }162 public function testMatchPseudoClasses() {163 $matches = $this->find('ul>li:first');164 $this->assertEquals(1, count($matches));165 $matches = $this->find('ul>li:not(.first)');166 $this->assertEquals(5, count($matches));167 }168 public function testMatchPseudoElements() {169 $matches = $this->find('p::first-line');170 $this->assertEquals(1, count($matches));171 $matches = $this->find('p::first-letter');172 $this->assertEquals(1, count($matches));173 $matches = $this->find('p::before');174 $this->assertEquals(1, count($matches));175 $matches = $this->find('p::after');176 $this->assertEquals(1, count($matches));177 $matches = $this->find('bottom::after');178 $this->assertEquals(0, count($matches));179 }180 public function testCombineAdjacent() {181 // Simple test182 $matches = $this->find('idtest + p');183 $this->assertEquals(1, count($matches));184 foreach ($matches as $m) {185 $this->assertEquals('p', $m->tagName);186 }187 // Test ignoring PCDATA188 $matches = $this->find('p + one');189 $this->assertEquals(1, count($matches));190 foreach ($matches as $m) {191 $this->assertEquals('one', $m->tagName);192 }193 // Test that non-adjacent elements don't match.194 $matches = $this->find('idtest + one');195 foreach ($matches as $m) {196 $this->assertEquals('one', $m->tagName);197 }198 $this->assertEquals(0, count($matches), 'Non-adjacents should not match.');199 // Test that elements BEFORE don't match200 $matches = $this->find('one + p');201 foreach ($matches as $m) {202 $this->assertEquals('one', $m->tagName);203 }204 $this->assertEquals(0, count($matches), 'Match only if b is after a');205 }206 public function testCombineSibling() {207 // Canary:208 $matches = $this->find('one ~ two');209 $this->assertEquals(0, count($matches));210 // Canary 2:211 $matches = $this->find('NO_SUCH_ELEMENT ~ two');212 $this->assertEquals(0, count($matches));213 // Simple test214 $matches = $this->find('idtest ~ p');215 $this->assertEquals(1, count($matches));216 foreach ($matches as $m) {217 $this->assertEquals('p', $m->tagName);218 }219 // Simple test220 $matches = $this->find('outside ~ p');221 $this->assertEquals(1, count($matches));222 foreach ($matches as $m) {223 $this->assertEquals('p', $m->tagName);224 }225 // Matches only go left, not right.226 $matches = $this->find('p ~ outside');227 $this->assertEquals(0, count($matches));228 }229 public function testCombineDirectDescendant() {230 // Canary:231 $matches = $this->find('one > four');232 $this->assertEquals(0, count($matches));233 $matches = $this->find('two>three');234 $this->assertEquals(1, count($matches));235 foreach ($matches as $m) {236 $this->assertEquals('three', $m->tagName);237 }238 $matches = $this->find('one > two > three');239 $this->assertEquals(1, count($matches));240 foreach ($matches as $m) {241 $this->assertEquals('three', $m->tagName);242 }243 $matches = $this->find('a>a>a');244 $this->assertEquals(1, count($matches));245 $matches = $this->find('a>a');246 $this->assertEquals(2, count($matches));247 }248 public function testCombineAnyDescendant() {249 // Canary250 $matches = $this->find('four one');251 $this->assertEquals(0, count($matches));252 $matches = $this->find('one two');253 $this->assertEquals(1, count($matches));254 foreach ($matches as $m) {255 $this->assertEquals('two', $m->tagName);256 }257 $matches = $this->find('one four');258 $this->assertEquals(1, count($matches));259 $matches = $this->find('a a');260 $this->assertEquals(2, count($matches));261 $matches = $this->find('root two four');262 $this->assertEquals(1, count($matches));263 }264 public function testMultipleSelectors() {265 // fprintf(STDOUT, "=========TEST=========\n\n");266 $matches = $this->find('one, two');267 $this->assertEquals(2, count($matches));268 }269}...
results.php
Source:results.php
...35 # Player Numbers36 $player_numbers = [$player_ball1, $player_ball2, $player_ball3, $player_ball4, $player_ball5];37 38 # Array of the player numbers that matched the drawn balls39 $player_matches = [];40 $powerball_match;41 # Text to accompany output42 $matches_found;43 # Checks to see if there a match for powerball44 # if not, powerball_match is nothing45 $powerball_match = ($powerball === $player_powerball) ? $powerball : null;46 47 # These are all separate statements to see if any of the players numbers match any balls number drawn48 # If they do, they are pushed to the array49 if (in_array($player_ball1, $winning_numbers)) {50 $player_matches[] = $player_ball1;51 }52 if (in_array($player_ball2, $winning_numbers)) {53 $player_matches[] = $player_ball2;54 }55 if (in_array($player_ball3, $winning_numbers)) {56 $player_matches[] = $player_ball3;57 }58 if (in_array($player_ball4, $winning_numbers)) {59 $player_matches[] = $player_ball4;60 }61 if (in_array($player_ball5, $winning_numbers)) {62 $player_matches[] = $player_ball5;63 }64 $cost = 2;65 # Prizes66 $total = number_format(450000000);67 # Match 5 + PB68 $jackpot= number_format(306000000);69 # Match 570 $second_prize = number_format(1000000);71 # Match 4 + PB72 $third_prize = number_format(50000);73 74 # Match 475 $fourth_prize = 100;76 # Match 3 + PB77 $fifth_prize = 100;78 # Match 379 $sixth_prize = 7;80 # Match 2 + PB81 $seventh_prize = 7;82 # Match 1 + PB83 $eighth_prize = 4;84 # Match 0 + PB85 $ninth_prize = 4;86 # Figuring out Matches and Prize won87 # First filter to see if Powerball matches, then if numbers match88 # This will count the length of the array $player_matches.89 # The length of the array determines the number of matches.90 if ($powerball === $player_powerball) {91 $correct = true;92 if (count($player_matches) == 0) {93 $matches_found = "No Match + Powerball";94 $winnings = "$" . $ninth_prize;95 } elseif (count($player_matches) == 1) {96 $matches_found = "One Match + Powerball";97 $winnings = "$" . $eighth_prize;98 } elseif (count($player_matches) == 2) {99 $matches_found = "Two Matches + Powerball";100 $winnings = "$" . $seventh_prize;101 } elseif (count($player_matches) == 3) {102 $matches_found = "Three Matches + Powerball";103 $winnings = "$" . $fifth_prize;104 } elseif (count($player_matches) == 4) {105 $matches_found = "Four Matches + Powerball";106 $winnings = "$" . $third_prize;107 } elseif (count($player_matches) == 5) {108 $matches_found = 'jackpot';109 $winnings = "JACKPOT $" . $jackpot;110 }111 } elseif (count($player_matches) == 0) {112 $matches_found = "No Match";113 $winnings = "None";114 } elseif (count($player_matches) == 1) {115 $matches_found = "One Match";116 $winnings = "None";117 } elseif (count($player_matches) == 2) {118 $matches_found = "Two Matches";119 $winnings = "None";120 } elseif (count($player_matches) == 3) {121 $matches_found = "Three Matches";122 $winnings = "$" . $sixth_prize;123 } elseif (count($player_matches) == 4) {124 $matches_found = "Four Matches";125 $winnings = "$" . $fourth_prize;126 } elseif (count($player_matches) == 5) {127 $matches_found = "Five Matches";128 $winnings = "$" . $second_prize;129 } else {130 $matches_found = "No Match";131 $winnings = "None";132 }133 134 $_SESSION['results'] = [135 'matches-found' => $matches_found,136 'winnings' => $winnings,137 'cost' => $cost,138 'error' => $error139];140}141 require 'results-view.php';...
index.php
Source:index.php
...42// Array of the player numbers that matched the drawn balls43$playerMatches = [];44$powerballMatch;45//Text to accompany output46$matches;47// Checks to see if there a match for powerball48if ($powerball === $player_powerball) {49 $powerballMatch = "<span class='powerball-match'>" . $powerball . "</span>";50}else{51 //if not, powerballMatch is nothing52 $powerballMatch = null;53}54// These are all separate statements to see if any of the players numbers match any balls number drawn 55// If they do, they are pushed to the array56if (in_array($player_ball1, $drawing)) {57 $playerMatches[] = $player_ball1;58}if (in_array($player_ball2, $drawing)) {59 $playerMatches[] = $player_ball2;60}if (in_array($player_ball3, $drawing)) {61 $playerMatches[] = $player_ball3;62}if (in_array($player_ball4, $drawing)) {63 $playerMatches[] = $player_ball4;64}if (in_array($player_ball5, $drawing)) {65 $playerMatches[] = $player_ball5;66}67// Not sure if we're allowed to use functions, 68// but I couldn't figure out how to output this unless I used echo.69// Numbers that were matched Output70function thisFunction($playerMatches) {71 $arrlength = count($playerMatches);72 for($x = 0; $x < $arrlength; $x++) {73 echo "<span class='ball-match'>" . $playerMatches[$x] . "</span>";74 }75 }76// Figuring out Matches and Prize won77// First filter to see if Powerball matches, then if numbers match78// This will count the length of the array $playerMatches. 79// The length of the array determines the number of matches.80if($powerball === $player_powerball) {81 if(count($playerMatches) == 0) {82 $matches = "No Match + Powerball";83 $winnings = "$" . $ninthPrize;84 }elseif(count($playerMatches) == 1) {85 $matches = "One Match + Powerball";86 $winnings = "$" . $eighthPrize;87 }elseif(count($playerMatches) == 2) {88 $matches = "Two Matches + Powerball";89 $winnings = "$" . $seventhPrize;90 }elseif(count($playerMatches) == 3) {91 $matches = "Three Matches + Powerball";92 $winnings = "$" . $fifthPrize;93 }elseif(count($playerMatches) == 4) {94 $matches = "Four Matches + Powerball";95 $winnings = "$" . $thirdPrize;96 }elseif(count($playerMatches) == 5) {97 $matches = "Five Matches + Powerball <br> <br> <span class='jackpot'> YOU HAVE WON THE JACKPOT!</span>";98 $winnings = "JACKPOT $" . $jackpot;99 }100}elseif(count($playerMatches) == 0) {101 $matches = "No Match";102 $winnings = "None";103}elseif(count($playerMatches) == 1) {104 $matches = "One Match";105 $winnings = "None";106}elseif(count($playerMatches) == 2) {107 $matches = "Two Matches";108 $winnings = "None";109}elseif(count($playerMatches) == 3) {110 $matches = "Three Matches";111 $winnings = "$" . $sixthPrize;112}elseif(count($playerMatches) == 4) {113 $matches = "Four Matches";114 $winnings = "$" . $fourthPrize;115}elseif(count($playerMatches) == 5) {116 $matches = "Five Matches";117 $winnings = "$" . $secondPrize;118}else{119 $matches = "No Match";120 $winnings = "None";121} 122require 'index-view.php';123?>...
EmailForwardParser.php
Source:EmailForwardParser.php
...17 if (preg_match(self::REPLY_REGEX, $line)) {18 $line = preg_replace(self::REPLY_REGEX, '', $line);19 $line = trim($line);20 if (0 === stripos($line, 'from:')) {21 preg_match(self::FROM_REGEX, $line, $matches);22 if (($count = count($matches)) > 1) {23 if (2 == $count) {24 $email->setFrom(array(25 'name' => '',26 'email' => $matches[1],27 ));28 continue;29 }30 $email->setFrom(array(31 'name' => $matches[1],32 'email' => $matches[2],33 ));34 continue;35 }36 }37 if (0 === stripos($line, 'to:')) {38 preg_match(self::TO_REGEX, $line, $matches);39 if (($count = count($matches)) > 1) {40 if (2 == $count) {41 $email->setTo(array(42 'name' => '',43 'email' => $matches[1],44 ));45 continue;46 }47 $email->setTo(array(48 'name' => $matches[1],49 'email' => $matches[2],50 ));51 continue;52 }53 }54 if (0 === stripos($line, 'cc:')) {55 preg_match(self::CC_REGEX, $line, $matches);56 if (($count = count($matches)) > 1) {57 if (2 == $count) {58 $email->setCc(array(59 'name' => '',60 'email' => $matches[1],61 ));62 continue;63 }64 $email->setCc(array(65 'name' => $matches[1],66 'email' => $matches[2],67 ));68 continue;69 }70 }71 if (0 === stripos($line, 'subject:')) {72 preg_match(self::SUBJECT_REGEX, $line, $matches);73 if (count($matches) > 1) {74 $email->setSubject($matches[1]);75 continue;76 }77 }78 if (0 === stripos($line, 'date:')) {79 preg_match(self::DATE_REGEX, $line, $matches);80 if (count($matches) > 1) {81 $date = new \DateTime();82 $date->setTimestamp(strtotime($matches[1]));83 $email->setDate($date);84 continue;85 }86 }87 $body .= $line . "\n";88 }89 }90 $email->setBody(trim($body));91 return $email;92 }93}...
GoogleCloudContactcenterinsightsV1CalculateStatsResponse.php
Source:GoogleCloudContactcenterinsightsV1CalculateStatsResponse.php
1<?php2/*3 * Copyright 2014 Google Inc.4 *5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not6 * use this file except in compliance with the License. You may obtain a copy of7 * the License at8 *9 * http://www.apache.org/licenses/LICENSE-2.010 *11 * Unless required by applicable law or agreed to in writing, software12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the14 * License for the specific language governing permissions and limitations under15 * the License.16 */17namespace Google\Service\Contactcenterinsights;18class GoogleCloudContactcenterinsightsV1CalculateStatsResponse extends \Google\Model19{20 public $averageDuration;21 public $averageTurnCount;22 public $conversationCount;23 protected $conversationCountTimeSeriesType = GoogleCloudContactcenterinsightsV1CalculateStatsResponseTimeSeries::class;24 protected $conversationCountTimeSeriesDataType = '';25 public $customHighlighterMatches;26 public $issueMatches;27 protected $issueMatchesStatsType = GoogleCloudContactcenterinsightsV1IssueModelLabelStatsIssueStats::class;28 protected $issueMatchesStatsDataType = 'map';29 public $smartHighlighterMatches;30 public function setAverageDuration($averageDuration)31 {32 $this->averageDuration = $averageDuration;33 }34 public function getAverageDuration()35 {36 return $this->averageDuration;37 }38 public function setAverageTurnCount($averageTurnCount)39 {40 $this->averageTurnCount = $averageTurnCount;41 }42 public function getAverageTurnCount()43 {44 return $this->averageTurnCount;45 }46 public function setConversationCount($conversationCount)47 {48 $this->conversationCount = $conversationCount;49 }50 public function getConversationCount()51 {52 return $this->conversationCount;53 }54 /**55 * @param GoogleCloudContactcenterinsightsV1CalculateStatsResponseTimeSeries56 */57 public function setConversationCountTimeSeries(GoogleCloudContactcenterinsightsV1CalculateStatsResponseTimeSeries $conversationCountTimeSeries)58 {59 $this->conversationCountTimeSeries = $conversationCountTimeSeries;60 }61 /**62 * @return GoogleCloudContactcenterinsightsV1CalculateStatsResponseTimeSeries63 */64 public function getConversationCountTimeSeries()65 {66 return $this->conversationCountTimeSeries;67 }68 public function setCustomHighlighterMatches($customHighlighterMatches)69 {70 $this->customHighlighterMatches = $customHighlighterMatches;71 }72 public function getCustomHighlighterMatches()73 {74 return $this->customHighlighterMatches;75 }76 public function setIssueMatches($issueMatches)77 {78 $this->issueMatches = $issueMatches;79 }80 public function getIssueMatches()81 {82 return $this->issueMatches;83 }84 /**85 * @param GoogleCloudContactcenterinsightsV1IssueModelLabelStatsIssueStats[]86 */87 public function setIssueMatchesStats($issueMatchesStats)88 {89 $this->issueMatchesStats = $issueMatchesStats;90 }91 /**92 * @return GoogleCloudContactcenterinsightsV1IssueModelLabelStatsIssueStats[]93 */94 public function getIssueMatchesStats()95 {96 return $this->issueMatchesStats;97 }98 public function setSmartHighlighterMatches($smartHighlighterMatches)99 {100 $this->smartHighlighterMatches = $smartHighlighterMatches;101 }102 public function getSmartHighlighterMatches()103 {104 return $this->smartHighlighterMatches;105 }106}107// Adding a class alias for backwards compatibility with the previous class name.108class_alias(GoogleCloudContactcenterinsightsV1CalculateStatsResponse::class, 'Google_Service_Contactcenterinsights_GoogleCloudContactcenterinsightsV1CalculateStatsResponse');...
matches
Using AI Code Generation
1$counter = new Count;2$counter->matches("1.php");3$counter = new Count;4$counter->matches("2.php");5$counter = new Count;6$counter->matches("3.php");7$counter = new Count;8$counter->matches("4.php");9$counter = new Count;10$counter->matches("5.php");11$counter = new Count;12$counter->matches("6.php");13$counter = new Count;14$counter->matches("7.php");15$counter = new Count;16$counter->matches("8.php");17$counter = new Count;18$counter->matches("9.php");19$counter = new Count;20$counter->matches("10.php");21$counter = new Count;22$counter->matches("11.php");23$counter = new Count;24$counter->matches("12.php");25$counter = new Count;26$counter->matches("13.php");27$counter = new Count;28$counter->matches("14.php");29$counter = new Count;30$counter->matches("15.php");31$counter = new Count;32$counter->matches("16.php");
matches
Using AI Code Generation
1$mycount = new Count();2$mycount->matches(1,2,3,4,5,6,7,8,9,10);3$mycount = new Count();4$mycount->matches(1,2,3,4,5,6,7,8,9,10);5$mycount = new Count();6$mycount->matches(1,2,3,4,5,6,7,8,9,10);7$mycount = new Count();8$mycount->matches(1,2,3,4,5,6,7,8,9,10);9$mycount = new Count();10$mycount->matches(1,2,3,4,5,6,7,8,9,10);11$mycount = new Count();12$mycount->matches(1,2,3,4,5,6,7,8,9,10);13$mycount = new Count();14$mycount->matches(1,2,3,4,5,6,7,8,9,10);15$mycount = new Count();16$mycount->matches(1,2,3,4,5,6,7,8,9,10);17$mycount = new Count();18$mycount->matches(1,2,3,4,5,6,7,8,9,10);19$mycount = new Count();20$mycount->matches(1,2,3,4,5,6,7,8,9,10);
matches
Using AI Code Generation
1$pattern = '1';2$subject = '1';3$count = new Count($pattern, $subject);4echo $count->matches();5$pattern = '1';6$subject = '1';7$count = new Count($pattern, $subject);8echo $count->matches();9$pattern = '1';10$subject = '1';11$count = new Count($pattern, $subject);12echo $count->matches();13$pattern = '1';14$subject = '1';15$count = new Count($pattern, $subject);16echo $count->matches();17$pattern = '1';18$subject = '1';19$count = new Count($pattern, $subject);20echo $count->matches();21$pattern = '1';22$subject = '1';23$count = new Count($pattern, $subject);24echo $count->matches();25$pattern = '1';26$subject = '1';27$count = new Count($pattern, $subject);28echo $count->matches();29$pattern = '1';30$subject = '1';31$count = new Count($pattern, $subject);32echo $count->matches();33$pattern = '1';34$subject = '1';35$count = new Count($pattern, $subject);36echo $count->matches();37$pattern = '1';38$subject = '1';39$count = new Count($pattern, $subject);40echo $count->matches();41$pattern = '1';42$subject = '1';43$count = new Count($pattern, $subject);44echo $count->matches();
matches
Using AI Code Generation
1$myCount = new Count();2$myCount->matches(3, 3);3$myCount->matches(3, 2);4$myCount->matches(3, 4);5$myCount->matches(3, 3);6$myCount = new Count();7$myCount->matches(3, 3);8$myCount->matches(3, 2);9$myCount->matches(3, 4);10$myCount->matches(3, 3);11$myCount = new Count();12$myCount->matches(3, 3);13$myCount->matches(3, 2);14$myCount->matches(3, 4);15$myCount->matches(3, 3);16$myCount = new Count();17$myCount->matches(3, 3);18$myCount->matches(3, 2);19$myCount->matches(3, 4);20$myCount->matches(3, 3);21$myCount = new Count();22$myCount->matches(3, 3);23$myCount->matches(3, 2);24$myCount->matches(3, 4);25$myCount->matches(3, 3);26$myCount = new Count();27$myCount->matches(3, 3);28$myCount->matches(3, 2);29$myCount->matches(3, 4);30$myCount->matches(3, 3);
matches
Using AI Code Generation
1$count = new Count();2$count->matches($string, $pattern);3$count->matches($string, $pattern, $matches);4$count->matches($string, $pattern, $matches, $flags);5$count->matches($string, $pattern, $matches, $flags, $offset);6$count = new Count();7$count->countMatches($string, $pattern);8$count->countMatches($string, $pattern, $flags);9$count->countMatches($string, $pattern, $flags, $offset);10$count = new Count();11$count->split($string, $pattern);12$count->split($string, $pattern, $limit);13$count->split($string, $pattern, $limit, $flags);14$count = new Count();15$count->replace($string, $pattern, $replacement);16$count->replace($string, $pattern, $replacement, $limit);17$count->replace($string, $pattern, $replacement, $limit, $count);18$count = new Count();19$count->replaceMatches($string, $pattern, $replacement);20$count->replaceMatches($string, $pattern, $replacement, $limit);21$count->replaceMatches($string, $pattern, $replacement, $limit, $count);22$count = new Count();23$count->replaceCallback($string, $pattern, $callback);24$count->replaceCallback($string, $pattern, $callback, $limit);25$count->replaceCallback($string, $pattern, $callback, $limit, $count);26$count = new Count();27$count->replaceCallbackMatches($string, $pattern, $callback);28$count->replaceCallbackMatches($string, $pattern, $callback, $limit);29$count->replaceCallbackMatches($string, $pattern, $callback, $limit, $count);30$count = new Count();31$count->filter($string, $pattern);32$count->filter($string, $pattern, $flags);33$count->filter($string, $pattern, $flags, $offset);34$count = new Count();35$count->filterMatches($string, $pattern);
matches
Using AI Code Generation
1$myCount = new Count();2$myCount->setCount(10);3$myCount = new Count();4$myCount->setCount(10);5$myCount = new Count();6$myCount->setCount(10);7$myCount = new Count();8$myCount->setCount(10);9$myCount = new Count();10$myCount->setCount(10);11$myCount = new Count();12$myCount->setCount(10);13$myCount = new Count();14$myCount->setCount(10);15$myCount = new Count();16$myCount->setCount(10);17$myCount = new Count();18$myCount->setCount(10);19$myCount = new Count();20$myCount->setCount(10);21$myCount = new Count();22$myCount->setCount(10);
matches
Using AI Code Generation
1$pattern = "/^([a-z]+) ([0-9]+)$/";2$subject = "This is 123";3$count = new Count($pattern, $subject);4echo $count->matches();5$pattern = "/^([a-z]+) ([0-9]+)$/";6$subject = "This is 123";7$count = new Count($pattern, $subject);8echo $count->matches();9$pattern = "/^([a-z]+) ([0-9]+)$/";10$subject = "This is 123";11$count = new Count($pattern, $subject);12echo $count->matches();13$pattern = "/^([a-z]+) ([0-9]+)$/";14$subject = "This is 123";15$count = new Count($pattern, $subject);16echo $count->matches();17$pattern = "/^([a-z]+) ([0-9]+)$/";18$subject = "This is 123";19$count = new Count($pattern, $subject);20echo $count->matches();21$pattern = "/^([a-z]+) ([0-9]+)$/";22$subject = "This is 123";23$count = new Count($pattern, $subject);24echo $count->matches();25$pattern = "/^([a-z]+) ([0-9]+)$/";26$subject = "This is 123";27$count = new Count($pattern, $subject);28echo $count->matches();29$pattern = "/^([a-z]+) ([0-9]+)$/";30$subject = "This is 123";31$count = new Count($pattern, $subject);32echo $count->matches();33$pattern = "/^([a-z]+) ([0-9]+)$/";34$subject = "This is 123";
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with matches on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!