/** * @dataProvider dataMatchers * @covers ::getType * @covers ::getMatchers */ public function testMatchers($selector, $expectedCount, $expected) { $index = new Crawler('index.html'); $query = new Label($selector, new Filters()); $result = $index->query($query->getXPath()); $this->assertMatchesSelector($expected, $result->item(0), sprintf('Label "%s" should match "%s"', $selector, $expected)); }
public function testSimple() { $index = new Crawler('index.html'); $session = new CrawlerSession($index); $a = $session->get('.subnav li a:visible(true):text("Subpage 2")'); $this->assertEquals('Subpage Title 2', $a->getAttribute('title')); $session->get('#form')->with(function ($form) use($index) { $this->assertEquals('form', $form->getAttribute('id')); $form->getField('Enter Email:value("*****@*****.**")')->with(function ($email) { $this->assertEquals('*****@*****.**', $email->getValue()); }); $form->setField('Enter Name', 'Other thing'); $name = $form->getField('Enter Name'); $this->assertMatchesSelector('input[value="Other thing"]', $index->getElement($name->getId()), 'Should set a text input value'); $form->setFieldFile('Logo', '/var/usr/example.jpg'); $file = $form->getField('file'); $this->assertMatchesSelector('input[value="/var/usr/example.jpg"]', $index->getElement($file->getId()), 'Should set a file input value'); $label = $form->getLabel('Gender Male'); $this->assertMatchesSelector('label[for="gender-1"]', $index->getElement($label->getId()), 'Should find the correct label by text content'); }); }