Update to drupal 8.0.0-rc1. For more information, see https://www.drupal.org/node/2582663

This commit is contained in:
Greg Anderson 2015-10-08 11:40:12 -07:00
parent eb34d130a8
commit f32e58e4b1
8476 changed files with 211648 additions and 170042 deletions

View file

@ -0,0 +1,110 @@
<?php
namespace Behat\Mink\Tests\Driver;
use Behat\Mink\Element\NodeElement;
class CoreDriverTest extends \PHPUnit_Framework_TestCase
{
public function testNoExtraMethods()
{
$interfaceRef = new \ReflectionClass('Behat\Mink\Driver\DriverInterface');
$coreDriverRef = new \ReflectionClass('Behat\Mink\Driver\CoreDriver');
foreach ($coreDriverRef->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
$this->assertTrue(
$interfaceRef->hasMethod($method->getName()),
sprintf('CoreDriver should not implement methods which are not part of the DriverInterface but %s found', $method->getName())
);
}
}
public function testCreateNodeElements()
{
$driver = $this->getMockBuilder('Behat\Mink\Driver\CoreDriver')
->setMethods(array('findElementXpaths'))
->getMockForAbstractClass();
$session = $this->getMockBuilder('Behat\Mink\Session')
->disableOriginalConstructor()
->getMock();
$driver->setSession($session);
$driver->expects($this->once())
->method('findElementXpaths')
->with('xpath')
->willReturn(array('xpath1', 'xpath2'));
/** @var NodeElement[] $elements */
$elements = $driver->find('xpath');
$this->assertInternalType('array', $elements);
$this->assertCount(2, $elements);
$this->assertContainsOnlyInstancesOf('Behat\Mink\Element\NodeElement', $elements);
$this->assertSame('xpath1', $elements[0]->getXpath());
$this->assertSame('xpath2', $elements[1]->getXpath());
}
/**
* @dataProvider getDriverInterfaceMethods
*/
public function testInterfaceMethods(\ReflectionMethod $method)
{
$refl = new \ReflectionClass('Behat\Mink\Driver\CoreDriver');
$this->assertFalse(
$refl->getMethod($method->getName())->isAbstract(),
sprintf('CoreDriver should implement a dummy %s method', $method->getName())
);
if ('setSession' === $method->getName()) {
return; // setSession is actually implemented, so we don't expect an exception here.
}
$driver = $this->getMockForAbstractClass('Behat\Mink\Driver\CoreDriver');
$this->setExpectedException('Behat\Mink\Exception\UnsupportedDriverActionException');
call_user_func_array(array($driver, $method->getName()), $this->getArguments($method));
}
public function getDriverInterfaceMethods()
{
$ref = new \ReflectionClass('Behat\Mink\Driver\DriverInterface');
return array_map(function ($method) {
return array($method);
}, $ref->getMethods());
}
private function getArguments(\ReflectionMethod $method)
{
$arguments = array();
foreach ($method->getParameters() as $parameter) {
$arguments[] = $this->getArgument($parameter);
}
return $arguments;
}
private function getArgument(\ReflectionParameter $argument)
{
if ($argument->isOptional()) {
return $argument->getDefaultValue();
}
if ($argument->allowsNull()) {
return null;
}
if ($argument->getClass()) {
return $this->getMockBuilder($argument->getClass()->getName())
->disableOriginalConstructor()
->getMock();
}
return null;
}
}

View file

@ -0,0 +1,449 @@
<?php
namespace Behat\Mink\Tests\Element;
use Behat\Mink\Element\DocumentElement;
class DocumentElementTest extends ElementTest
{
/**
* Page.
*
* @var DocumentElement
*/
private $document;
protected function setUp()
{
parent::setUp();
$this->document = new DocumentElement($this->session);
}
/**
* @group legacy
*/
public function testGetSession()
{
$this->assertEquals($this->session, $this->document->getSession());
}
public function testFindAll()
{
$xpath = 'h3[a]';
$css = 'h3 > a';
$this->driver
->expects($this->exactly(2))
->method('find')
->will($this->returnValueMap(array(
array('//html/'.$xpath, array(2, 3, 4)),
array('//html/'.$css, array(1, 2)),
)));
$this->selectors
->expects($this->exactly(2))
->method('selectorToXpath')
->will($this->returnValueMap(array(
array('xpath', $xpath, $xpath),
array('css', $css, $css),
)));
$this->assertEquals(3, count($this->document->findAll('xpath', $xpath)));
$this->assertEquals(2, count($this->document->findAll('css', $css)));
}
public function testFind()
{
$this->driver
->expects($this->exactly(3))
->method('find')
->with('//html/h3[a]')
->will($this->onConsecutiveCalls(array(2, 3, 4), array(1, 2), array()));
$xpath = 'h3[a]';
$css = 'h3 > a';
$this->selectors
->expects($this->exactly(3))
->method('selectorToXpath')
->will($this->returnValueMap(array(
array('xpath', $xpath, $xpath),
array('xpath', $xpath, $xpath),
array('css', $css, $xpath),
)));
$this->assertEquals(2, $this->document->find('xpath', $xpath));
$this->assertEquals(1, $this->document->find('css', $css));
$this->assertNull($this->document->find('xpath', $xpath));
}
public function testFindField()
{
$this->mockNamedFinder(
'//field',
array('field1', 'field2', 'field3'),
array('field', 'some field')
);
$this->assertEquals('field1', $this->document->findField('some field'));
$this->assertEquals(null, $this->document->findField('some field'));
}
public function testFindLink()
{
$this->mockNamedFinder(
'//link',
array('link1', 'link2', 'link3'),
array('link', 'some link')
);
$this->assertEquals('link1', $this->document->findLink('some link'));
$this->assertEquals(null, $this->document->findLink('some link'));
}
public function testFindButton()
{
$this->mockNamedFinder(
'//button',
array('button1', 'button2', 'button3'),
array('button', 'some button')
);
$this->assertEquals('button1', $this->document->findButton('some button'));
$this->assertEquals(null, $this->document->findButton('some button'));
}
public function testFindById()
{
$xpath = '//*[@id=some-item-2]';
$this->mockNamedFinder($xpath, array(array('id2', 'id3'), array()), array('id', 'some-item-2'));
$this->assertEquals('id2', $this->document->findById('some-item-2'));
$this->assertEquals(null, $this->document->findById('some-item-2'));
}
public function testHasSelector()
{
$this->driver
->expects($this->exactly(2))
->method('find')
->with('//html/some xpath')
->will($this->onConsecutiveCalls(array('id2', 'id3'), array()));
$this->selectors
->expects($this->exactly(2))
->method('selectorToXpath')
->with('xpath', 'some xpath')
->will($this->returnValue('some xpath'));
$this->assertTrue($this->document->has('xpath', 'some xpath'));
$this->assertFalse($this->document->has('xpath', 'some xpath'));
}
public function testHasContent()
{
$this->mockNamedFinder(
'//some content',
array('item1', 'item2'),
array('content', 'some content')
);
$this->assertTrue($this->document->hasContent('some content'));
$this->assertFalse($this->document->hasContent('some content'));
}
public function testHasLink()
{
$this->mockNamedFinder(
'//link',
array('link1', 'link2', 'link3'),
array('link', 'some link')
);
$this->assertTrue($this->document->hasLink('some link'));
$this->assertFalse($this->document->hasLink('some link'));
}
public function testHasButton()
{
$this->mockNamedFinder(
'//button',
array('button1', 'button2', 'button3'),
array('button', 'some button')
);
$this->assertTrue($this->document->hasButton('some button'));
$this->assertFalse($this->document->hasButton('some button'));
}
public function testHasField()
{
$this->mockNamedFinder(
'//field',
array('field1', 'field2', 'field3'),
array('field', 'some field')
);
$this->assertTrue($this->document->hasField('some field'));
$this->assertFalse($this->document->hasField('some field'));
}
public function testHasCheckedField()
{
$checkbox = $this->getMockBuilder('Behat\Mink\Element\NodeElement')
->disableOriginalConstructor()
->getMock();
$checkbox
->expects($this->exactly(2))
->method('isChecked')
->will($this->onConsecutiveCalls(true, false));
$this->mockNamedFinder(
'//field',
array(array($checkbox), array(), array($checkbox)),
array('field', 'some checkbox'),
3
);
$this->assertTrue($this->document->hasCheckedField('some checkbox'));
$this->assertFalse($this->document->hasCheckedField('some checkbox'));
$this->assertFalse($this->document->hasCheckedField('some checkbox'));
}
public function testHasUncheckedField()
{
$checkbox = $this->getMockBuilder('Behat\Mink\Element\NodeElement')
->disableOriginalConstructor()
->getMock();
$checkbox
->expects($this->exactly(2))
->method('isChecked')
->will($this->onConsecutiveCalls(true, false));
$this->mockNamedFinder(
'//field',
array(array($checkbox), array(), array($checkbox)),
array('field', 'some checkbox'),
3
);
$this->assertFalse($this->document->hasUncheckedField('some checkbox'));
$this->assertFalse($this->document->hasUncheckedField('some checkbox'));
$this->assertTrue($this->document->hasUncheckedField('some checkbox'));
}
public function testHasSelect()
{
$this->mockNamedFinder(
'//select',
array('select'),
array('select', 'some select field')
);
$this->assertTrue($this->document->hasSelect('some select field'));
$this->assertFalse($this->document->hasSelect('some select field'));
}
public function testHasTable()
{
$this->mockNamedFinder(
'//table',
array('table'),
array('table', 'some table')
);
$this->assertTrue($this->document->hasTable('some table'));
$this->assertFalse($this->document->hasTable('some table'));
}
public function testClickLink()
{
$node = $this->getMockBuilder('Behat\Mink\Element\NodeElement')
->disableOriginalConstructor()
->getMock();
$node
->expects($this->once())
->method('click');
$this->mockNamedFinder(
'//link',
array($node),
array('link', 'some link')
);
$this->document->clickLink('some link');
$this->setExpectedException('Behat\Mink\Exception\ElementNotFoundException');
$this->document->clickLink('some link');
}
public function testClickButton()
{
$node = $this->getMockBuilder('Behat\Mink\Element\NodeElement')
->disableOriginalConstructor()
->getMock();
$node
->expects($this->once())
->method('press');
$this->mockNamedFinder(
'//button',
array($node),
array('button', 'some button')
);
$this->document->pressButton('some button');
$this->setExpectedException('Behat\Mink\Exception\ElementNotFoundException');
$this->document->pressButton('some button');
}
public function testFillField()
{
$node = $this->getMockBuilder('Behat\Mink\Element\NodeElement')
->disableOriginalConstructor()
->getMock();
$node
->expects($this->once())
->method('setValue')
->with('some val');
$this->mockNamedFinder(
'//field',
array($node),
array('field', 'some field')
);
$this->document->fillField('some field', 'some val');
$this->setExpectedException('Behat\Mink\Exception\ElementNotFoundException');
$this->document->fillField('some field', 'some val');
}
public function testCheckField()
{
$node = $this->getMockBuilder('Behat\Mink\Element\NodeElement')
->disableOriginalConstructor()
->getMock();
$node
->expects($this->once())
->method('check');
$this->mockNamedFinder(
'//field',
array($node),
array('field', 'some field')
);
$this->document->checkField('some field');
$this->setExpectedException('Behat\Mink\Exception\ElementNotFoundException');
$this->document->checkField('some field');
}
public function testUncheckField()
{
$node = $this->getMockBuilder('Behat\Mink\Element\NodeElement')
->disableOriginalConstructor()
->getMock();
$node
->expects($this->once())
->method('uncheck');
$this->mockNamedFinder(
'//field',
array($node),
array('field', 'some field')
);
$this->document->uncheckField('some field');
$this->setExpectedException('Behat\Mink\Exception\ElementNotFoundException');
$this->document->uncheckField('some field');
}
public function testSelectField()
{
$node = $this->getMockBuilder('Behat\Mink\Element\NodeElement')
->disableOriginalConstructor()
->getMock();
$node
->expects($this->once())
->method('selectOption')
->with('option2');
$this->mockNamedFinder(
'//field',
array($node),
array('field', 'some field')
);
$this->document->selectFieldOption('some field', 'option2');
$this->setExpectedException('Behat\Mink\Exception\ElementNotFoundException');
$this->document->selectFieldOption('some field', 'option2');
}
public function testAttachFileToField()
{
$node = $this->getMockBuilder('Behat\Mink\Element\NodeElement')
->disableOriginalConstructor()
->getMock();
$node
->expects($this->once())
->method('attachFile')
->with('/path/to/file');
$this->mockNamedFinder(
'//field',
array($node),
array('field', 'some field')
);
$this->document->attachFileToField('some field', '/path/to/file');
$this->setExpectedException('Behat\Mink\Exception\ElementNotFoundException');
$this->document->attachFileToField('some field', '/path/to/file');
}
public function testGetContent()
{
$expects = 'page content';
$this->driver
->expects($this->once())
->method('getContent')
->will($this->returnValue($expects));
$this->assertEquals($expects, $this->document->getContent());
}
public function testGetText()
{
$expects = 'val1';
$this->driver
->expects($this->once())
->method('getText')
->with('//html')
->will($this->returnValue($expects));
$this->assertEquals($expects, $this->document->getText());
}
public function testGetHtml()
{
$expects = 'val1';
$this->driver
->expects($this->once())
->method('getHtml')
->with('//html')
->will($this->returnValue($expects));
$this->assertEquals($expects, $this->document->getHtml());
}
public function testGetOuterHtml()
{
$expects = 'val1';
$this->driver
->expects($this->once())
->method('getOuterHtml')
->with('//html')
->will($this->returnValue($expects));
$this->assertEquals($expects, $this->document->getOuterHtml());
}
}

View file

@ -0,0 +1,71 @@
<?php
namespace Behat\Mink\Tests\Element;
use Behat\Mink\Driver\DriverInterface;
use Behat\Mink\Session;
use Behat\Mink\Selector\SelectorsHandler;
abstract class ElementTest extends \PHPUnit_Framework_TestCase
{
/**
* Session.
*
* @var Session
*/
protected $session;
/**
* @var DriverInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $driver;
/**
* Selectors.
*
* @var SelectorsHandler|\PHPUnit_Framework_MockObject_MockObject
*/
protected $selectors;
protected function setUp()
{
$this->driver = $this->getMockBuilder('Behat\Mink\Driver\DriverInterface')->getMock();
$this->driver
->expects($this->once())
->method('setSession');
$this->selectors = $this->getMockBuilder('Behat\Mink\Selector\SelectorsHandler')->getMock();
$this->session = new Session($this->driver, $this->selectors);
}
protected function mockNamedFinder($xpath, array $results, $locator, $times = 2)
{
if (!is_array($results[0])) {
$results = array($results, array());
}
// In case of empty results, a second call will be done using the partial selector
$processedResults = array();
foreach ($results as $result) {
$processedResults[] = $result;
if (empty($result)) {
$processedResults[] = $result;
++$times;
}
}
$returnValue = call_user_func_array(array($this, 'onConsecutiveCalls'), $processedResults);
$this->driver
->expects($this->exactly($times))
->method('find')
->with('//html'.$xpath)
->will($returnValue);
$this->selectors
->expects($this->exactly($times))
->method('selectorToXpath')
->with($this->logicalOr('named_exact', 'named_partial'), $locator)
->will($this->returnValue($xpath));
}
}

View file

@ -0,0 +1,598 @@
<?php
namespace Behat\Mink\Tests\Element;
use Behat\Mink\Element\NodeElement;
class NodeElementTest extends ElementTest
{
public function testGetXpath()
{
$node = new NodeElement('some custom xpath', $this->session);
$this->assertEquals('some custom xpath', $node->getXpath());
$this->assertNotEquals('not some custom xpath', $node->getXpath());
}
public function testGetText()
{
$expected = 'val1';
$node = new NodeElement('text_tag', $this->session);
$this->driver
->expects($this->once())
->method('getText')
->with('text_tag')
->will($this->returnValue($expected));
$this->assertEquals($expected, $node->getText());
}
public function testGetOuterHtml()
{
$expected = 'val1';
$node = new NodeElement('text_tag', $this->session);
$this->driver
->expects($this->once())
->method('getOuterHtml')
->with('text_tag')
->will($this->returnValue($expected));
$this->assertEquals($expected, $node->getOuterHtml());
}
public function testElementIsValid()
{
$elementXpath = 'some xpath';
$node = new NodeElement($elementXpath, $this->session);
$this->driver
->expects($this->once())
->method('find')
->with($elementXpath)
->will($this->returnValue(array($elementXpath)));
$this->assertTrue($node->isValid());
}
public function testElementIsNotValid()
{
$node = new NodeElement('some xpath', $this->session);
$this->driver
->expects($this->exactly(2))
->method('find')
->with('some xpath')
->will($this->onConsecutiveCalls(array(), array('xpath1', 'xpath2')));
$this->assertFalse($node->isValid(), 'no elements found is invalid element');
$this->assertFalse($node->isValid(), 'more then 1 element found is invalid element');
}
public function testWaitForSuccess()
{
$callCounter = 0;
$node = new NodeElement('some xpath', $this->session);
$result = $node->waitFor(5, function ($givenNode) use (&$callCounter) {
++$callCounter;
if (1 === $callCounter) {
return null;
} elseif (2 === $callCounter) {
return false;
} elseif (3 === $callCounter) {
return array();
}
return $givenNode;
});
$this->assertEquals(4, $callCounter, '->waitFor() tries to locate element several times before failing');
$this->assertSame($node, $result, '->waitFor() returns node found in callback');
}
/**
* @medium
*/
public function testWaitForTimeout()
{
$node = new NodeElement('some xpath', $this->session);
$expectedTimeout = 2;
$startTime = microtime(true);
$result = $node->waitFor($expectedTimeout, function () {
return null;
});
$endTime = microtime(true);
$this->assertNull($result, '->waitFor() returns whatever callback gives');
$this->assertEquals($expectedTimeout, round($endTime - $startTime));
}
/**
* @expectedException \InvalidArgumentException
*/
public function testWaitForFailure()
{
$node = new NodeElement('some xpath', $this->session);
$node->waitFor(5, 'not a callable');
}
public function testHasAttribute()
{
$node = new NodeElement('input_tag', $this->session);
$this->driver
->expects($this->exactly(2))
->method('getAttribute')
->with('input_tag', 'href')
->will($this->onConsecutiveCalls(null, 'http://...'));
$this->assertFalse($node->hasAttribute('href'));
$this->assertTrue($node->hasAttribute('href'));
}
public function testGetAttribute()
{
$expected = 'http://...';
$node = new NodeElement('input_tag', $this->session);
$this->driver
->expects($this->once())
->method('getAttribute')
->with('input_tag', 'href')
->will($this->returnValue($expected));
$this->assertEquals($expected, $node->getAttribute('href'));
}
public function testHasClass()
{
$node = new NodeElement('input_tag', $this->session);
$this->driver
->expects($this->exactly(6))
->method('getAttribute')
->with('input_tag', 'class')
->will($this->returnValue('
class1 class2
'));
$this->assertTrue($node->hasClass('class1'), 'The "class1" was found');
$this->assertTrue($node->hasClass('class2'), 'The "class2" was found');
$this->assertFalse($node->hasClass('class3'), 'The "class3" was not found');
}
public function testHasClassWithoutArgument()
{
$node = new NodeElement('input_tag', $this->session);
$this->driver
->expects($this->once())
->method('getAttribute')
->with('input_tag', 'class')
->will($this->returnValue(null));
$this->assertFalse($node->hasClass('class3'));
}
public function testGetValue()
{
$expected = 'val1';
$node = new NodeElement('input_tag', $this->session);
$this->driver
->expects($this->once())
->method('getValue')
->with('input_tag')
->will($this->returnValue($expected));
$this->assertEquals($expected, $node->getValue());
}
public function testSetValue()
{
$expected = 'new_val';
$node = new NodeElement('input_tag', $this->session);
$this->driver
->expects($this->once())
->method('setValue')
->with('input_tag', $expected);
$node->setValue($expected);
}
public function testClick()
{
$node = new NodeElement('link_or_button', $this->session);
$this->driver
->expects($this->once())
->method('click')
->with('link_or_button');
$node->click();
}
public function testPress()
{
$node = new NodeElement('link_or_button', $this->session);
$this->driver
->expects($this->once())
->method('click')
->with('link_or_button');
$node->press();
}
public function testRightClick()
{
$node = new NodeElement('elem', $this->session);
$this->driver
->expects($this->once())
->method('rightClick')
->with('elem');
$node->rightClick();
}
public function testDoubleClick()
{
$node = new NodeElement('elem', $this->session);
$this->driver
->expects($this->once())
->method('doubleClick')
->with('elem');
$node->doubleClick();
}
public function testCheck()
{
$node = new NodeElement('checkbox_or_radio', $this->session);
$this->driver
->expects($this->once())
->method('check')
->with('checkbox_or_radio');
$node->check();
}
public function testUncheck()
{
$node = new NodeElement('checkbox_or_radio', $this->session);
$this->driver
->expects($this->once())
->method('uncheck')
->with('checkbox_or_radio');
$node->uncheck();
}
public function testSelectOption()
{
$node = new NodeElement('select', $this->session);
$option = $this->getMockBuilder('Behat\Mink\Element\NodeElement')
->disableOriginalConstructor()
->getMock();
$option
->expects($this->once())
->method('getValue')
->will($this->returnValue('item1'));
$this->driver
->expects($this->once())
->method('getTagName')
->with('select')
->will($this->returnValue('select'));
$this->driver
->expects($this->once())
->method('find')
->with('select/option')
->will($this->returnValue(array($option)));
$this->selectors
->expects($this->once())
->method('selectorToXpath')
->with('named_exact', array('option', 'item1'))
->will($this->returnValue('option'));
$this->driver
->expects($this->once())
->method('selectOption')
->with('select', 'item1', false);
$node->selectOption('item1');
}
/**
* @expectedException \Behat\Mink\Exception\ElementNotFoundException
*/
public function testSelectOptionNotFound()
{
$node = new NodeElement('select', $this->session);
$this->driver
->expects($this->once())
->method('getTagName')
->with('select')
->will($this->returnValue('select'));
$this->driver
->expects($this->exactly(2))
->method('find')
->with('select/option')
->will($this->returnValue(array()));
$this->selectors
->expects($this->exactly(2))
->method('selectorToXpath')
->with($this->logicalOr('named_exact', 'named_partial'), array('option', 'item1'))
->will($this->returnValue('option'));
$node->selectOption('item1');
}
public function testSelectOptionOtherTag()
{
$node = new NodeElement('div', $this->session);
$this->driver
->expects($this->once())
->method('getTagName')
->with('div')
->will($this->returnValue('div'));
$this->driver
->expects($this->once())
->method('selectOption')
->with('div', 'item1', false);
$node->selectOption('item1');
}
public function testGetTagName()
{
$node = new NodeElement('html//h3', $this->session);
$this->driver
->expects($this->once())
->method('getTagName')
->with('html//h3')
->will($this->returnValue('h3'));
$this->assertEquals('h3', $node->getTagName());
}
public function testGetParent()
{
$node = new NodeElement('elem', $this->session);
$parent = $this->getMockBuilder('Behat\Mink\Element\NodeElement')
->disableOriginalConstructor()
->getMock();
$this->driver
->expects($this->once())
->method('find')
->with('elem/..')
->will($this->returnValue(array($parent)));
$this->selectors
->expects($this->once())
->method('selectorToXpath')
->with('xpath', '..')
->will($this->returnValue('..'));
$this->assertSame($parent, $node->getParent());
}
public function testAttachFile()
{
$node = new NodeElement('elem', $this->session);
$this->driver
->expects($this->once())
->method('attachFile')
->with('elem', 'path');
$node->attachFile('path');
}
public function testIsVisible()
{
$node = new NodeElement('some_xpath', $this->session);
$this->driver
->expects($this->exactly(2))
->method('isVisible')
->with('some_xpath')
->will($this->onConsecutiveCalls(true, false));
$this->assertTrue($node->isVisible());
$this->assertFalse($node->isVisible());
}
public function testIsChecked()
{
$node = new NodeElement('some_xpath', $this->session);
$this->driver
->expects($this->exactly(2))
->method('isChecked')
->with('some_xpath')
->will($this->onConsecutiveCalls(true, false));
$this->assertTrue($node->isChecked());
$this->assertFalse($node->isChecked());
}
public function testIsSelected()
{
$node = new NodeElement('some_xpath', $this->session);
$this->driver
->expects($this->exactly(2))
->method('isSelected')
->with('some_xpath')
->will($this->onConsecutiveCalls(true, false));
$this->assertTrue($node->isSelected());
$this->assertFalse($node->isSelected());
}
public function testFocus()
{
$node = new NodeElement('some-element', $this->session);
$this->driver
->expects($this->once())
->method('focus')
->with('some-element');
$node->focus();
}
public function testBlur()
{
$node = new NodeElement('some-element', $this->session);
$this->driver
->expects($this->once())
->method('blur')
->with('some-element');
$node->blur();
}
public function testMouseOver()
{
$node = new NodeElement('some-element', $this->session);
$this->driver
->expects($this->once())
->method('mouseOver')
->with('some-element');
$node->mouseOver();
}
public function testDragTo()
{
$node = new NodeElement('some_tag1', $this->session);
$target = $this->getMock('Behat\Mink\Element\ElementInterface');
$target->expects($this->any())
->method('getXPath')
->will($this->returnValue('some_tag2'));
$this->driver
->expects($this->once())
->method('dragTo')
->with('some_tag1', 'some_tag2');
$node->dragTo($target);
}
public function testKeyPress()
{
$node = new NodeElement('elem', $this->session);
$this->driver
->expects($this->once())
->method('keyPress')
->with('elem', 'key');
$node->keyPress('key');
}
public function testKeyDown()
{
$node = new NodeElement('elem', $this->session);
$this->driver
->expects($this->once())
->method('keyDown')
->with('elem', 'key');
$node->keyDown('key');
}
public function testKeyUp()
{
$node = new NodeElement('elem', $this->session);
$this->driver
->expects($this->once())
->method('keyUp')
->with('elem', 'key');
$node->keyUp('key');
}
public function testSubmitForm()
{
$node = new NodeElement('some_xpath', $this->session);
$this->driver
->expects($this->once())
->method('submitForm')
->with('some_xpath');
$node->submit();
}
public function testFindAllUnion()
{
$node = new NodeElement('some_xpath', $this->session);
$xpath = "some_tag1 | some_tag2[@foo =\n 'bar|'']\n | some_tag3[foo | bar]";
$expected = "some_xpath/some_tag1 | some_xpath/some_tag2[@foo =\n 'bar|''] | some_xpath/some_tag3[foo | bar]";
$this->driver
->expects($this->exactly(1))
->method('find')
->will($this->returnValueMap(array(
array($expected, array(2, 3, 4)),
)));
$this->selectors
->expects($this->exactly(1))
->method('selectorToXpath')
->will($this->returnValueMap(array(
array('xpath', $xpath, $xpath),
)));
$this->assertEquals(3, count($node->findAll('xpath', $xpath)));
}
public function testFindAllParentUnion()
{
$node = new NodeElement('some_xpath | another_xpath', $this->session);
$xpath = 'some_tag1 | some_tag2';
$expectedPrefixed = '(some_xpath | another_xpath)/some_tag1 | (some_xpath | another_xpath)/some_tag2';
$this->driver
->expects($this->exactly(1))
->method('find')
->will($this->returnValueMap(array(
array($expectedPrefixed, array(2, 3, 4)),
)));
$this->selectors
->expects($this->exactly(1))
->method('selectorToXpath')
->will($this->returnValueMap(array(
array('xpath', $xpath, $xpath),
)));
$this->assertEquals(3, count($node->findAll('xpath', $xpath)));
}
}

View file

@ -0,0 +1,42 @@
<?php
namespace Behat\Mink\Tests\Exception;
use Behat\Mink\Exception\ElementException;
/**
* @group legacy
*/
class ElementExceptionTest extends \PHPUnit_Framework_TestCase
{
public function testMessage()
{
$exception = new ElementException($this->getElementMock(), new \Exception('Something went wrong'));
$expectedMessage = "Exception thrown by element XPath\nSomething went wrong";
$this->assertEquals($expectedMessage, $exception->getMessage());
$this->assertEquals($expectedMessage, (string) $exception);
}
public function testElement()
{
$element = $this->getElementMock();
$exception = new ElementException($element, new \Exception('Something went wrong'));
$this->assertSame($element, $exception->getElement());
}
private function getElementMock()
{
$mock = $this->getMockBuilder('Behat\Mink\Element\Element')
->disableOriginalConstructor()
->getMock();
$mock->expects($this->any())
->method('getXPath')
->will($this->returnValue('element XPath'));
return $mock;
}
}

View file

@ -0,0 +1,50 @@
<?php
namespace Behat\Mink\Tests\Exception;
use Behat\Mink\Exception\ElementHtmlException;
class ElementHtmlExceptionTest extends \PHPUnit_Framework_TestCase
{
public function testExceptionToString()
{
$driver = $this->getMock('Behat\Mink\Driver\DriverInterface');
$element = $this->getElementMock();
$driver->expects($this->any())
->method('getStatusCode')
->will($this->returnValue(200));
$driver->expects($this->any())
->method('getCurrentUrl')
->will($this->returnValue('http://localhost/test'));
$element->expects($this->any())
->method('getOuterHtml')
->will($this->returnValue("<div>\n <h1>Hello world</h1>\n <p>Test</p>\n</div>"));
$expected = <<<'TXT'
Html error
+--[ HTTP/1.1 200 | http://localhost/test | %s ]
|
| <div>
| <h1>Hello world</h1>
| <p>Test</p>
| </div>
|
TXT;
$expected = sprintf($expected.' ', get_class($driver));
$exception = new ElementHtmlException('Html error', $driver, $element);
$this->assertEquals($expected, $exception->__toString());
}
private function getElementMock()
{
return $this->getMockBuilder('Behat\Mink\Element\NodeElement')
->disableOriginalConstructor()
->getMock();
}
}

View file

@ -0,0 +1,50 @@
<?php
namespace Behat\Mink\Tests\Exception;
use Behat\Mink\Exception\ElementNotFoundException;
class ElementNotFoundExceptionTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider provideExceptionMessage
*/
public function testBuildMessage($message, $type, $selector = null, $locator = null)
{
$driver = $this->getMock('Behat\Mink\Driver\DriverInterface');
$exception = new ElementNotFoundException($driver, $type, $selector, $locator);
$this->assertEquals($message, $exception->getMessage());
}
public function provideExceptionMessage()
{
return array(
array('Tag not found.', null),
array('Field not found.', 'field'),
array('Tag matching locator "foobar" not found.', null, null, 'foobar'),
array('Tag matching css "foobar" not found.', null, 'css', 'foobar'),
array('Field matching xpath "foobar" not found.', 'Field', 'xpath', 'foobar'),
array('Tag with name "foobar" not found.', null, 'name', 'foobar'),
);
}
/**
* @group legacy
*/
public function testConstructWithSession()
{
$driver = $this->getMock('Behat\Mink\Driver\DriverInterface');
$session = $this->getMockBuilder('Behat\Mink\Session')
->disableOriginalConstructor()
->getMock();
$session->expects($this->any())
->method('getDriver')
->will($this->returnValue($driver));
$exception = new ElementNotFoundException($session);
$this->assertEquals('Tag not found.', $exception->getMessage());
}
}

View file

@ -0,0 +1,48 @@
<?php
namespace Behat\Mink\Tests\Exception;
use Behat\Mink\Exception\ElementTextException;
class ElementTextExceptionTest extends \PHPUnit_Framework_TestCase
{
public function testExceptionToString()
{
$driver = $this->getMock('Behat\Mink\Driver\DriverInterface');
$element = $this->getElementMock();
$driver->expects($this->any())
->method('getStatusCode')
->will($this->returnValue(200));
$driver->expects($this->any())
->method('getCurrentUrl')
->will($this->returnValue('http://localhost/test'));
$element->expects($this->any())
->method('getText')
->will($this->returnValue("Hello world\nTest\n"));
$expected = <<<'TXT'
Text error
+--[ HTTP/1.1 200 | http://localhost/test | %s ]
|
| Hello world
| Test
|
TXT;
$expected = sprintf($expected.' ', get_class($driver));
$exception = new ElementTextException('Text error', $driver, $element);
$this->assertEquals($expected, $exception->__toString());
}
private function getElementMock()
{
return $this->getMockBuilder('Behat\Mink\Element\NodeElement')
->disableOriginalConstructor()
->getMock();
}
}

View file

@ -0,0 +1,114 @@
<?php
namespace Behat\Mink\Tests\Exception;
use Behat\Mink\Exception\ExpectationException;
class ExpectationExceptionTest extends \PHPUnit_Framework_TestCase
{
public function testEmptyMessageAndPreviousException()
{
$exception = new ExpectationException('', $this->getMock('Behat\Mink\Driver\DriverInterface'), new \Exception('Something failed'));
$this->assertEquals('Something failed', $exception->getMessage());
}
public function testExceptionToString()
{
$driver = $this->getMock('Behat\Mink\Driver\DriverInterface');
$driver->expects($this->any())
->method('getStatusCode')
->will($this->returnValue(200));
$driver->expects($this->any())
->method('getCurrentUrl')
->will($this->returnValue('http://localhost/test'));
$html = "<html><head><title>Hello</title></head>\n<body>\n<h1>Hello world</h1>\n<p>Test</p>\n</body></html>";
$driver->expects($this->any())
->method('getContent')
->will($this->returnValue($html));
$expected = <<<'TXT'
Expectation failure
+--[ HTTP/1.1 200 | http://localhost/test | %s ]
|
| <body>
| <h1>Hello world</h1>
| <p>Test</p>
| </body>
|
TXT;
$expected = sprintf($expected.' ', get_class($driver));
$exception = new ExpectationException('Expectation failure', $driver);
$this->assertEquals($expected, $exception->__toString());
}
public function testBigContent()
{
$driver = $this->getMock('Behat\Mink\Driver\DriverInterface');
$driver->expects($this->any())
->method('getStatusCode')
->will($this->returnValue(200));
$driver->expects($this->any())
->method('getCurrentUrl')
->will($this->returnValue('http://localhost/test'));
$body = str_repeat('a', 1001 - strlen('<body></body>'));
$html = sprintf("<html><head><title>Hello</title></head>\n<body>%s</body></html>", $body);
$driver->expects($this->any())
->method('getContent')
->will($this->returnValue($html));
$expected = <<<'TXT'
Expectation failure
+--[ HTTP/1.1 200 | http://localhost/test | %s ]
|
| <body>%s</b...
|
TXT;
$expected = sprintf($expected.' ', get_class($driver), $body);
$exception = new ExpectationException('Expectation failure', $driver);
$this->assertEquals($expected, $exception->__toString());
}
public function testExceptionWhileRenderingString()
{
$driver = $this->getMock('Behat\Mink\Driver\DriverInterface');
$driver->expects($this->any())
->method('getContent')
->will($this->throwException(new \Exception('Broken page')));
$exception = new ExpectationException('Expectation failure', $driver);
$this->assertEquals('Expectation failure', $exception->__toString());
}
/**
* @group legacy
*/
public function testConstructWithSession()
{
$driver = $this->getMock('Behat\Mink\Driver\DriverInterface');
$session = $this->getMockBuilder('Behat\Mink\Session')
->disableOriginalConstructor()
->getMock();
$session->expects($this->any())
->method('getDriver')
->will($this->returnValue($driver));
$exception = new ExpectationException('', $session, new \Exception('Something failed'));
$this->assertEquals('Something failed', $exception->getMessage());
}
}

View file

@ -0,0 +1,40 @@
<?php
namespace Behat\Mink\Tests\Exception;
use Behat\Mink\Exception\ResponseTextException;
class ResponseTextExceptionTest extends \PHPUnit_Framework_TestCase
{
public function testExceptionToString()
{
$driver = $this->getMock('Behat\Mink\Driver\DriverInterface');
$driver->expects($this->any())
->method('getStatusCode')
->will($this->returnValue(200));
$driver->expects($this->any())
->method('getCurrentUrl')
->will($this->returnValue('http://localhost/test'));
$driver->expects($this->any())
->method('getText')
->with('//html')
->will($this->returnValue("Hello world\nTest\n"));
$expected = <<<'TXT'
Text error
+--[ HTTP/1.1 200 | http://localhost/test | %s ]
|
| Hello world
| Test
|
TXT;
$expected = sprintf($expected.' ', get_class($driver));
$exception = new ResponseTextException('Text error', $driver);
$this->assertEquals($expected, $exception->__toString());
}
}

246
vendor/behat/mink/tests/MinkTest.php vendored Normal file
View file

@ -0,0 +1,246 @@
<?php
namespace Behat\Mink\Tests;
use Behat\Mink\Mink;
class MinkTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Mink
*/
private $mink;
protected function setUp()
{
$this->mink = new Mink();
}
public function testRegisterSession()
{
$session = $this->getSessionMock();
$this->assertFalse($this->mink->hasSession('not_registered'));
$this->assertFalse($this->mink->hasSession('js'));
$this->assertFalse($this->mink->hasSession('my'));
$this->mink->registerSession('my', $session);
$this->assertTrue($this->mink->hasSession('my'));
$this->assertFalse($this->mink->hasSession('not_registered'));
$this->assertFalse($this->mink->hasSession('js'));
}
public function testRegisterSessionThroughConstructor()
{
$mink = new Mink(array('my' => $this->getSessionMock()));
$this->assertTrue($mink->hasSession('my'));
}
public function testSessionAutostop()
{
$session1 = $this->getSessionMock();
$session2 = $this->getSessionMock();
$this->mink->registerSession('my1', $session1);
$this->mink->registerSession('my2', $session2);
$session1
->expects($this->once())
->method('isStarted')
->will($this->returnValue(true));
$session1
->expects($this->once())
->method('stop');
$session2
->expects($this->once())
->method('isStarted')
->will($this->returnValue(false));
$session2
->expects($this->never())
->method('stop');
unset($this->mink);
}
public function testNotStartedSession()
{
$session = $this->getSessionMock();
$session
->expects($this->once())
->method('isStarted')
->will($this->returnValue(false));
$session
->expects($this->once())
->method('start');
$this->mink->registerSession('mock_session', $session);
$this->assertSame($session, $this->mink->getSession('mock_session'));
$this->setExpectedException('InvalidArgumentException');
$this->mink->getSession('not_registered');
}
public function testGetAlreadyStartedSession()
{
$session = $this->getSessionMock();
$session
->expects($this->once())
->method('isStarted')
->will($this->returnValue(true));
$session
->expects($this->never())
->method('start');
$this->mink->registerSession('mock_session', $session);
$this->assertSame($session, $this->mink->getSession('mock_session'));
}
public function testSetDefaultSessionName()
{
$this->assertNull($this->mink->getDefaultSessionName());
$session = $this->getSessionMock();
$this->mink->registerSession('session_name', $session);
$this->mink->setDefaultSessionName('session_name');
$this->assertEquals('session_name', $this->mink->getDefaultSessionName());
$this->setExpectedException('InvalidArgumentException');
$this->mink->setDefaultSessionName('not_registered');
}
public function testGetDefaultSession()
{
$session1 = $this->getSessionMock();
$session2 = $this->getSessionMock();
$this->assertNotSame($session1, $session2);
$this->mink->registerSession('session_1', $session1);
$this->mink->registerSession('session_2', $session2);
$this->mink->setDefaultSessionName('session_2');
$this->assertSame($session1, $this->mink->getSession('session_1'));
$this->assertSame($session2, $this->mink->getSession('session_2'));
$this->assertSame($session2, $this->mink->getSession());
$this->mink->setDefaultSessionName('session_1');
$this->assertSame($session1, $this->mink->getSession());
}
public function testGetNoDefaultSession()
{
$session1 = $this->getSessionMock();
$this->mink->registerSession('session_1', $session1);
$this->setExpectedException('InvalidArgumentException');
$this->mink->getSession();
}
public function testIsSessionStarted()
{
$session_1 = $this->getSessionMock();
$session_2 = $this->getSessionMock();
$session_1
->expects($this->any())
->method('isStarted')
->will($this->returnValue(false));
$session_1
->expects($this->never())
->method('start');
$session_2
->expects($this->any())
->method('isStarted')
->will($this->returnValue(true));
$session_2
->expects($this->never())
->method('start');
$this->mink->registerSession('not_started', $session_1);
$this->assertFalse($this->mink->isSessionStarted('not_started'));
$this->mink->registerSession('started', $session_2);
$this->assertTrue($this->mink->isSessionStarted('started'));
$this->setExpectedException('InvalidArgumentException');
$this->mink->getSession('not_registered');
}
public function testAssertSession()
{
$session = $this->getSessionMock();
$this->mink->registerSession('my', $session);
$this->assertInstanceOf('Behat\Mink\WebAssert', $this->mink->assertSession('my'));
}
public function testAssertSessionNotRegistered()
{
$session = $this->getSessionMock();
$this->assertInstanceOf('Behat\Mink\WebAssert', $this->mink->assertSession($session));
}
public function testResetSessions()
{
$session1 = $this->getSessionMock();
$session1->expects($this->once())
->method('isStarted')
->will($this->returnValue(false));
$session1->expects($this->never())
->method('reset');
$session2 = $this->getSessionMock();
$session2->expects($this->once())
->method('isStarted')
->will($this->returnValue(true));
$session2->expects($this->once())
->method('reset');
$this->mink->registerSession('not started', $session1);
$this->mink->registerSession('started', $session2);
$this->mink->resetSessions();
}
public function testRestartSessions()
{
$session1 = $this->getSessionMock();
$session1->expects($this->once())
->method('isStarted')
->will($this->returnValue(false));
$session1->expects($this->never())
->method('restart');
$session2 = $this->getSessionMock();
$session2->expects($this->once())
->method('isStarted')
->will($this->returnValue(true));
$session2->expects($this->once())
->method('restart');
$this->mink->registerSession('not started', $session1);
$this->mink->registerSession('started', $session2);
$this->mink->restartSessions();
}
private function getSessionMock()
{
return $this->getMockBuilder('Behat\Mink\Session')
->disableOriginalConstructor()
->getMock();
}
}

View file

@ -0,0 +1,41 @@
<?php
namespace Behat\Mink\Tests\Selector;
use Behat\Mink\Selector\CssSelector;
class CssSelectorTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
if (!class_exists('Symfony\Component\CssSelector\CssSelector')) {
$this->markTestSkipped('Symfony2 CssSelector component not installed');
}
}
public function testSelector()
{
$selector = new CssSelector();
$this->assertEquals('descendant-or-self::h3', $selector->translateToXPath('h3'));
$this->assertEquals('descendant-or-self::h3/span', $selector->translateToXPath('h3 > span'));
if (interface_exists('Symfony\Component\CssSelector\XPath\TranslatorInterface')) {
// The rewritten component of Symfony 2.3 checks for attribute existence first for the class.
$expectation = "descendant-or-self::h3/*[@class and contains(concat(' ', normalize-space(@class), ' '), ' my_div ')]";
} else {
$expectation = "descendant-or-self::h3/*[contains(concat(' ', normalize-space(@class), ' '), ' my_div ')]";
}
$this->assertEquals($expectation, $selector->translateToXPath('h3 > .my_div'));
}
/**
* @expectedException \InvalidArgumentException
*/
public function testThrowsForArrayLocator()
{
$selector = new CssSelector();
$selector->translateToXPath(array('h3'));
}
}

View file

@ -0,0 +1,18 @@
<?php
namespace Behat\Mink\Tests\Selector;
use Behat\Mink\Selector\ExactNamedSelector;
class ExactNamedSelectorTest extends NamedSelectorTest
{
protected function getSelector()
{
return new ExactNamedSelector();
}
protected function allowPartialMatch()
{
return false;
}
}

View file

@ -0,0 +1,168 @@
<?php
namespace Behat\Mink\Tests\Selector;
use Behat\Mink\Selector\NamedSelector;
use Behat\Mink\Selector\Xpath\Escaper;
abstract class NamedSelectorTest extends \PHPUnit_Framework_TestCase
{
public function testRegisterXpath()
{
$selector = $this->getSelector();
$selector->registerNamedXpath('some', 'my_xpath');
$this->assertEquals('my_xpath', $selector->translateToXPath('some'));
$this->setExpectedException('InvalidArgumentException');
$selector->translateToXPath('custom');
}
/**
* @expectedException \InvalidArgumentException
*/
public function testInvalidLocator()
{
$namedSelector = $this->getSelector();
$namedSelector->translateToXPath(array('foo', 'bar', 'baz'));
}
/**
* @dataProvider getSelectorTests
*/
public function testSelectors($fixtureFile, $selector, $locator, $expectedExactCount, $expectedPartialCount = null)
{
$expectedCount = $this->allowPartialMatch() && null !== $expectedPartialCount
? $expectedPartialCount
: $expectedExactCount;
// Don't use "loadHTMLFile" due HHVM 3.3.0 issue.
$dom = new \DOMDocument('1.0', 'UTF-8');
$dom->loadHTML(file_get_contents(__DIR__.'/fixtures/'.$fixtureFile));
$namedSelector = $this->getSelector();
$xpath = $namedSelector->translateToXPath(array($selector, $locator));
$domXpath = new \DOMXPath($dom);
$nodeList = $domXpath->query($xpath);
$this->assertEquals($expectedCount, $nodeList->length);
}
/**
* @dataProvider getSelectorTests
* @group legacy
*/
public function testEscapedSelectors($fixtureFile, $selector, $locator, $expectedExactCount, $expectedPartialCount = null)
{
// Escape the locator as Mink 1.x expects the caller of the NamedSelector to handle it
$escaper = new Escaper();
$locator = $escaper->escapeLiteral($locator);
$this->testSelectors($fixtureFile, $selector, $locator, $expectedExactCount, $expectedPartialCount);
}
public function getSelectorTests()
{
$fieldCount = 8; // fields without `type` attribute
$fieldCount += 4; // fields with `type=checkbox` attribute
$fieldCount += 4; // fields with `type=radio` attribute
$fieldCount += 4; // fields with `type=file` attribute
// Fixture file, selector name, locator, expected number of exact matched elements, expected number of partial matched elements if different
return array(
'fieldset' => array('test.html', 'fieldset', 'fieldset-text', 2, 3),
'field (name/placeholder/label)' => array('test.html', 'field', 'the-field', $fieldCount),
'field (input, with-id)' => array('test.html', 'field', 'the-field-input', 1),
'field (textarea, with-id)' => array('test.html', 'field', 'the-field-textarea', 1),
'field (select, with-id)' => array('test.html', 'field', 'the-field-select', 1),
'field (input type=submit, with-id) ignored' => array('test.html', 'field', 'the-field-submit-button', 0),
'field (input type=image, with-id) ignored' => array('test.html', 'field', 'the-field-image-button', 0),
'field (input type=button, with-id) ignored' => array('test.html', 'field', 'the-field-button-button', 0),
'field (input type=reset, with-id) ignored' => array('test.html', 'field', 'the-field-reset-button', 0),
'field (input type=hidden, with-id) ignored' => array('test.html', 'field', 'the-field-hidden', 0),
'link (with-href)' => array('test.html', 'link', 'link-text', 5, 9),
'link (without-href) ignored' => array('test.html', 'link', 'bad-link-text', 0),
'link* (role=link)' => array('test.html', 'link', 'link-role-text', 4, 7),
'button (input, name/value/title)' => array('test.html', 'button', 'button-text', 25, 42),
'button (type=image, with-alt)' => array('test.html', 'button', 'button-alt-text', 1, 2),
'button (input type=submit, with-id)' => array('test.html', 'button', 'input-submit-button', 1),
'button (input type=image, with-id)' => array('test.html', 'button', 'input-image-button', 1),
'button (input type=button, with-id)' => array('test.html', 'button', 'input-button-button', 1),
'button (input type=reset, with-id)' => array('test.html', 'button', 'input-reset-button', 1),
'button (button type=submit, with-id)' => array('test.html', 'button', 'button-submit-button', 1),
'button (button type=image, with-id)' => array('test.html', 'button', 'button-image-button', 1),
'button (button type=button, with-id)' => array('test.html', 'button', 'button-button-button', 1),
'button (button type=reset, with-id)' => array('test.html', 'button', 'button-reset-button', 1),
'button* (role=button, name/value/title)' => array('test.html', 'button', 'button-role-text', 12, 20),
'button* (role=button type=submit, with-id)' => array('test.html', 'button', 'role-button-submit-button', 1),
'button* (role=button type=image, with-id)' => array('test.html', 'button', 'role-button-image-button', 1),
'button* (role=button type=button, with-id)' => array('test.html', 'button', 'role-button-button-button', 1),
'button* (role=button type=reset, with-id)' => array('test.html', 'button', 'role-button-reset-button', 1),
'link_or_button (with-href)' => array('test.html', 'link_or_button', 'link-text', 5, 9),
'link_or_button (without-href) ignored' => array('test.html', 'link_or_button', 'bad-link-text', 0),
'link_or_button* (role=link)' => array('test.html', 'link_or_button', 'link-role-text', 4, 7),
// bug in selector: 17 instead of 25 and 34 instead of 42, because 8 buttons with `name` attribute were not matched
'link_or_button (input, name/value/title)' => array('test.html', 'link_or_button', 'button-text', 17, 34),
'link_or_button (type=image, with-alt)' => array('test.html', 'link_or_button', 'button-alt-text', 1, 2),
'link_or_button (input type=submit, with-id)' => array('test.html', 'link_or_button', 'input-submit-button', 1),
'link_or_button (input type=image, with-id)' => array('test.html', 'link_or_button', 'input-image-button', 1),
'link_or_button (input type=button, with-id)' => array('test.html', 'link_or_button', 'input-button-button', 1),
'link_or_button (input type=reset, with-id)' => array('test.html', 'link_or_button', 'input-reset-button', 1),
'link_or_button (button type=submit, with-id)' => array('test.html', 'link_or_button', 'button-submit-button', 1),
'link_or_button (button type=image, with-id)' => array('test.html', 'link_or_button', 'button-image-button', 1),
'link_or_button (button type=button, with-id)' => array('test.html', 'link_or_button', 'button-button-button', 1),
'link_or_button (button type=reset, with-id)' => array('test.html', 'link_or_button', 'button-reset-button', 1),
// bug in selector: 8 instead of 12 and 16 instead of 20, because 4 buttons with `name` attribute were not matched
'link_or_button* (role=button, name/value/title)' => array('test.html', 'link_or_button', 'button-role-text', 8, 16),
'link_or_button* (role=button type=submit, with-id)' => array('test.html', 'link_or_button', 'role-button-submit-button', 1),
'link_or_button* (role=button type=image, with-id)' => array('test.html', 'link_or_button', 'role-button-image-button', 1),
'link_or_button* (role=button type=button, with-id)' => array('test.html', 'link_or_button', 'role-button-button-button', 1),
'link_or_button* (role=button type=reset, with-id)' => array('test.html', 'link_or_button', 'role-button-reset-button', 1),
// 3 matches, because matches every HTML node in path: html > body > div
'content' => array('test.html', 'content', 'content-text', 1, 4),
'content with quotes' => array('test.html', 'content', 'some "quoted" content', 1, 3),
'select (name/label)' => array('test.html', 'select', 'the-field', 3),
'select (with-id)' => array('test.html', 'select', 'the-field-select', 1),
'checkbox (name/label)' => array('test.html', 'checkbox', 'the-field', 3),
'checkbox (with-id)' => array('test.html', 'checkbox', 'the-field-checkbox', 1),
'radio (name/label)' => array('test.html', 'radio', 'the-field', 3),
'radio (with-id)' => array('test.html', 'radio', 'the-field-radio', 1),
'file (name/label)' => array('test.html', 'file', 'the-field', 3),
'file (with-id)' => array('test.html', 'file', 'the-field-file', 1),
'optgroup' => array('test.html', 'optgroup', 'group-label', 1, 2),
'option' => array('test.html', 'option', 'option-value', 2, 3),
'table' => array('test.html', 'table', 'the-table', 2, 3),
'id' => array('test.html', 'id', 'bad-link-text', 1),
'id or name' => array('test.html', 'id_or_name', 'the-table', 2),
);
}
/**
* @return NamedSelector
*/
abstract protected function getSelector();
/**
* @return bool
*/
abstract protected function allowPartialMatch();
}

View file

@ -0,0 +1,18 @@
<?php
namespace Behat\Mink\Tests\Selector;
use Behat\Mink\Selector\PartialNamedSelector;
class PartialNamedSelectorTest extends NamedSelectorTest
{
protected function getSelector()
{
return new PartialNamedSelector();
}
protected function allowPartialMatch()
{
return true;
}
}

View file

@ -0,0 +1,96 @@
<?php
namespace Behat\Mink\Tests\Selector;
use Behat\Mink\Selector\SelectorsHandler;
class SelectorsHandlerTest extends \PHPUnit_Framework_TestCase
{
public function testRegisterSelector()
{
$selector = $this->getMockBuilder('Behat\Mink\Selector\SelectorInterface')->getMock();
$handler = new SelectorsHandler();
$this->assertFalse($handler->isSelectorRegistered('custom'));
$handler->registerSelector('custom', $selector);
$this->assertTrue($handler->isSelectorRegistered('custom'));
$this->assertSame($selector, $handler->getSelector('custom'));
}
public function testRegisterSelectorThroughConstructor()
{
$selector = $this->getMockBuilder('Behat\Mink\Selector\SelectorInterface')->getMock();
$handler = new SelectorsHandler(array('custom' => $selector));
$this->assertTrue($handler->isSelectorRegistered('custom'));
$this->assertSame($selector, $handler->getSelector('custom'));
}
public function testRegisterDefaultSelectors()
{
$handler = new SelectorsHandler();
$this->assertTrue($handler->isSelectorRegistered('css'));
$this->assertTrue($handler->isSelectorRegistered('named_exact'));
$this->assertTrue($handler->isSelectorRegistered('named_partial'));
}
/**
* @expectedException \InvalidArgumentException
*/
public function testXpathSelectorThrowsExceptionForArrayLocator()
{
$handler = new SelectorsHandler();
$handler->selectorToXpath('xpath', array('some_xpath'));
}
public function testXpathSelectorIsReturnedAsIs()
{
$handler = new SelectorsHandler();
$this->assertEquals('some_xpath', $handler->selectorToXpath('xpath', 'some_xpath'));
}
public function testSelectorToXpath()
{
$selector = $this->getMockBuilder('Behat\Mink\Selector\SelectorInterface')->getMock();
$handler = new SelectorsHandler();
$handler->registerSelector('custom_selector', $selector);
$selector
->expects($this->once())
->method('translateToXPath')
->with($locator = 'some[locator]')
->will($this->returnValue($ret = '[]some[]locator'));
$this->assertEquals($ret, $handler->selectorToXpath('custom_selector', $locator));
$this->setExpectedException('InvalidArgumentException');
$handler->selectorToXpath('undefined', 'asd');
}
/**
* @group legacy
*/
public function testXpathLiteral()
{
$handler = new SelectorsHandler();
$this->assertEquals("'some simple string'", $handler->xpathLiteral('some simple string'));
}
/**
* @group legacy
*/
public function testBcLayer()
{
$selector = $this->getMockBuilder('Behat\Mink\Selector\SelectorInterface')->getMock();
$handler = new SelectorsHandler();
$handler->registerSelector('named_partial', $selector);
$this->assertSame($selector, $handler->getSelector('named'));
}
}

View file

@ -0,0 +1,31 @@
<?php
namespace Behat\Mink\Tests\Selector\Xpath;
use Behat\Mink\Selector\Xpath\Escaper;
class EscaperTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider getXpathLiterals
*/
public function testXpathLiteral($string, $expected)
{
$escaper = new Escaper();
$this->assertEquals($expected, $escaper->escapeLiteral($string));
}
public function getXpathLiterals()
{
return array(
array('some simple string', "'some simple string'"),
array('some "d-brackets" string', "'some \"d-brackets\" string'"),
array('some \'s-brackets\' string', "\"some 's-brackets' string\""),
array(
'some \'s-brackets\' and "d-brackets" string',
'concat(\'some \',"\'",\'s-brackets\',"\'",\' and "d-brackets" string\')',
),
);
}
}

View file

@ -0,0 +1,64 @@
<?php
namespace Behat\Mink\Tests\Selector\Xpath;
use Behat\Mink\Selector\Xpath\Manipulator;
class ManipulatorTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider getPrependedXpath
*/
public function testPrepend($prefix, $xpath, $expectedXpath)
{
$manipulator = new Manipulator();
$this->assertEquals($expectedXpath, $manipulator->prepend($xpath, $prefix));
}
public function getPrependedXpath()
{
return array(
'simple' => array(
'some_xpath',
'some_tag1',
'some_xpath/some_tag1',
),
'with slash' => array(
'some_xpath',
'/some_tag1',
'some_xpath/some_tag1',
),
'union' => array(
'some_xpath',
'some_tag1 | some_tag2',
'some_xpath/some_tag1 | some_xpath/some_tag2',
),
'wrapped union' => array(
'some_xpath',
'(some_tag1 | some_tag2)/some_child',
'(some_xpath/some_tag1 | some_xpath/some_tag2)/some_child',
),
'multiple wrapped union' => array(
'some_xpath',
'( ( some_tag1 | some_tag2)/some_child | some_tag3)/leaf',
'( ( some_xpath/some_tag1 | some_xpath/some_tag2)/some_child | some_xpath/some_tag3)/leaf',
),
'parent union' => array(
'some_xpath | another_xpath',
'some_tag1 | some_tag2',
'(some_xpath | another_xpath)/some_tag1 | (some_xpath | another_xpath)/some_tag2',
),
'complex condition' => array(
'some_xpath',
'some_tag1 | some_tag2[@foo = "bar|"] | some_tag3[foo | bar]',
'some_xpath/some_tag1 | some_xpath/some_tag2[@foo = "bar|"] | some_xpath/some_tag3[foo | bar]',
),
'multiline' => array(
'some_xpath',
"some_tag1 | some_tag2[@foo =\n 'bar|'']\n | some_tag3[foo | bar]",
"some_xpath/some_tag1 | some_xpath/some_tag2[@foo =\n 'bar|''] | some_xpath/some_tag3[foo | bar]",
),
);
}
}

View file

@ -0,0 +1,312 @@
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div id="test-for-link-selector">
<!-- match links with `href` attribute -->
<a href="#" id="link-text"></a>
<a href="#">link-text</a>
<a href="#" title="link-text"></a>
<a href="#" rel="link-text"></a>
<a href="#">
<img src="#" alt="link-text"/>
</a>
<!-- partial match -->
<a href="#">some link-text</a>
<a href="#" title="some link-text"></a>
<a href="#" rel="some link-text"></a>
<a href="#">
<img src="#" alt="some link-text"/>
</a>
<!-- don't match links without `href` attribute -->
<a id="bad-link-text"></a>
<a>bad-link-text</a>
<a title="bad-link-text"></a>
<a rel="bad-link-text"></a>
<a>
<img src="#" alt="bad-link-text"/>
</a>
<!-- match links with `role=link` attribute -->
<span role="Link" id="link-role-text"></span>
<span role="lInk" value="link-role-text"></span>
<span role="liNk" title="link-role-text"></span>
<span role="linK">link-role-text</span>
<!-- partial match -->
<span role="link" value="some link-role-text"></span>
<span role="link" title="some link-role-text"></span>
<span role="link">some link-role-text</span>
</div>
<div id="test-for-fieldset-selector">
<!-- match fieldsets -->
<fieldset id="fieldset-text"></fieldset>
<fieldset>
<legend>fieldset-text</legend>
</fieldset>
<!-- partial match -->
<fieldset>
<legend>fieldset-text sample</legend>
</fieldset>
<!-- don't match fieldsets -->
<fieldset>fieldset-text</fieldset>
<fieldset></fieldset>
</div>
<div id="test-for-content-selector">
content-text
</div>
<!-- partial match -->
<div id="test-for-partial-content-selector">
some content-text
</div>
<div>some "quoted" content</div>
<form>
<div id="test-for-field-selector">
<!-- match fields by `id` attribute -->
<input id="the-field-input"/>
<textarea id="the-field-textarea"></textarea>
<select id="the-field-select"></select>
<!-- match fields by `name` attribute -->
<input name="the-field"/>
<textarea name="the-field"></textarea>
<select name="the-field"></select>
<!-- match fields by `placeholder` attribute -->
<input placeholder="the-field"/>
<textarea placeholder="the-field"></textarea>
<select placeholder="the-field"></select>
<!-- match fields by associated label -->
<label for="label-for-input">the-field</label><input id="label-for-input"/>
<label for="label-for-textarea">the-field</label><textarea id="label-for-textarea"></textarea>
<label for="label-for-select">the-field</label><select id="label-for-select"></select>
<!-- match fields, surrounded by matching label -->
<label>the-field<input/></label>
<label>the-field<textarea></textarea></label>
<label>the-field<select></select></label>
<!-- don't match fields by `id` attribute -->
<input type="Submit" id="the-field-submit-button"/>
<input type="iMage" id="the-field-image-button"/>
<input type="butTon" id="the-field-button-button"/>
<input type="resEt" id="the-field-reset-button"/>
<input type="hidDen" id="the-field-hidden"/>
<!-- don't match fields by `name` attribute -->
<input type="submit" name="the-field"/>
<input type="image" name="the-field"/>
<input type="button" name="the-field"/>
<input type="reset" name="the-field"/>
<input type="hidden" name="the-field"/>
<!-- don't match fields by `placeholder` attribute -->
<input type="submit" placeholder="the-field"/>
<input type="image" placeholder="the-field"/>
<input type="button" placeholder="the-field"/>
<input type="reset" placeholder="the-field"/>
<input type="hidden" placeholder="the-field"/>
<!-- don't match fields by associated label -->
<label for="label-for-the-field-submit-button">the-field</label><input type="submit" id="label-for-the-field-submit-button"/>
<label for="label-for-the-field-image-button">the-field</label><input type="image" id="label-for-the-field-image-button"/>
<label for="label-for-the-field-button-button">the-field</label><input type="button" id="label-for-the-field-button-button"/>
<label for="label-for-the-field-reset-button">the-field</label><input type="reset" id="label-for-the-field-reset-button"/>
<label for="label-for-the-field-hidden">the-field</label><input type="hidden" id="label-for-the-field-hidden"/>
<!-- don't match fields, surrounded by matching label -->
<label>the-field<input type="submit"/></label>
<label>the-field<input type="image"/></label>
<label>the-field<input type="button"/></label>
<label>the-field<input type="reset"/></label>
<label>the-field<input type="hidden"/></label>
</div>
<div id="test-for-button-selector">
<!-- match buttons by `id` attribute -->
<input type="Submit" id="input-submit-button"/>
<input type="iMage" id="input-image-button"/>
<input type="butTon" id="input-button-button"/>
<input type="resEt" id="input-reset-button"/>
<button type="submit" id="button-submit-button"></button>
<button type="image" id="button-image-button"></button>
<button type="button" id="button-button-button"></button>
<button type="reset" id="button-reset-button"></button>
<!-- match buttons by `name` attribute -->
<input type="submit" name="button-text"/>
<input type="image" name="button-text"/>
<input type="button" name="button-text"/>
<input type="reset" name="button-text"/>
<button type="submit" name="button-text"></button>
<button type="image" name="button-text"></button>
<button type="button" name="button-text"></button>
<button type="reset" name="button-text"></button>
<!-- match buttons by `value` attribute -->
<input type="submit" value="button-text"/>
<input type="image" value="button-text"/>
<input type="button" value="button-text"/>
<input type="reset" value="button-text"/>
<button type="submit" value="button-text"></button>
<button type="image" value="button-text"></button>
<button type="button" value="button-text"></button>
<button type="reset" value="button-text"></button>
<!-- Partial match -->
<input type="submit" value="some button-text"/>
<input type="image" value="some button-text"/>
<input type="button" value="some button-text"/>
<input type="reset" value="some button-text"/>
<button type="submit" value="some button-text"></button>
<button type="image" value="some button-text"></button>
<button type="button" value="some button-text"></button>
<button type="reset" value="some button-text"></button>
<!-- match buttons by `title` attribute -->
<input type="submit" title="button-text"/>
<input type="image" title="button-text"/>
<input type="button" title="button-text"/>
<input type="reset" title="button-text"/>
<button type="submit" title="button-text"></button>
<button type="image" title="button-text"></button>
<button type="button" title="button-text"></button>
<button type="reset" title="button-text"></button>
<!-- partial match -->
<input type="submit" title="some button-text"/>
<input type="image" title="some button-text"/>
<input type="button" title="some button-text"/>
<input type="reset" title="some button-text"/>
<button type="submit" title="some button-text"></button>
<button type="image" title="some button-text"></button>
<button type="button" title="some button-text"></button>
<button type="reset" title="some button-text"></button>
<!-- match some buttons by `alt` attribute -->
<input type="submit" alt="button-alt-text"/>
<input type="imaGe" alt="button-alt-text"/>
<input type="button" alt="button-alt-text"/>
<input type="reset" alt="button-alt-text"/>
<!-- partial match -->
<input type="submit" alt="some button-alt-text"/>
<input type="image" alt="some button-alt-text"/>
<input type="button" alt="some button-alt-text"/>
<input type="reset" alt="some button-alt-text"/>
<!-- match by `button` text -->
<button>button-text</button>
<!-- partial match -->
<button>some button-text</button>
<!-- match buttons with `role=button` & `id` attribute -->
<span role="Button" type="submit" id="role-button-submit-button"></span>
<span role="bUtton" type="image" id="role-button-image-button"></span>
<span role="buTton" type="button" id="role-button-button-button"></span>
<span role="butTon" type="reset" id="role-button-reset-button"></span>
<!-- match buttons with `role=button` & `name` attribute -->
<span role="buttOn" type="submit" name="button-role-text"></span>
<span role="buttoN" type="image" name="button-role-text"></span>
<span role="button" type="button" name="button-role-text"></span>
<span role="button" type="reset" name="button-role-text"></span>
<!-- match buttons with `role=button` & `value` attribute -->
<span role="button" type="submit" value="button-role-text"></span>
<span role="button" type="image" value="button-role-text"></span>
<span role="button" type="button" value="button-role-text"></span>
<span role="button" type="reset" value="button-role-text"></span>
<!-- partial match -->
<span role="button" type="submit" value="some button-role-text"></span>
<span role="button" type="image" value="some button-role-text"></span>
<span role="button" type="button" value="some button-role-text"></span>
<span role="button" type="reset" value="some button-role-text"></span>
<!-- match buttons with `role=button` & `title` attribute -->
<span role="button" type="submit" title="button-role-text"></span>
<span role="button" type="image" title="button-role-text"></span>
<span role="button" type="button" title="button-role-text"></span>
<span role="button" type="reset" title="button-role-text"></span>
<!-- partial match -->
<span role="button" type="submit" title="some button-role-text"></span>
<span role="button" type="image" title="some button-role-text"></span>
<span role="button" type="button" title="some button-role-text"></span>
<span role="button" type="reset" title="some button-role-text"></span>
</div>
<div id="test-for-checkbox-selector">
<input type="Checkbox" id="the-field-checkbox"/>
<input type="checkBox" name="the-field"/>
<input type="cheCkbox" placeholder="the-field"/>
<label for="label-for-checkbox">the-field</label><input type="checkboX" id="label-for-checkbox"/>
<label>the-field<input type="chEckbox"/></label>
</div>
<div id="test-for-radio-selector">
<input type="Radio" id="the-field-radio"/>
<input type="raDio" name="the-field"/>
<input type="radIo" placeholder="the-field"/>
<label for="label-for-radio">the-field</label><input type="radiO" id="label-for-radio"/>
<label>the-field<input type="radIo"/></label>
</div>
<div id="test-for-file-selector">
<input type="File" id="the-field-file"/>
<input type="fIle" name="the-field"/>
<input type="fiLe" placeholder="the-field"/>
<label for="label-for-file">the-field</label><input type="filE" id="label-for-file"/>
<label>the-field<input type="fiLe"/></label>
</div>
<div id="test-for-select-related-stuff">
<!-- match select stuff -->
<select name="the-select-stuff-test">
<optgroup label="group-label">
<option value="option-value"></option>
</optgroup>
<option value="">option-value</option>
<!-- partial match -->
<optgroup label="some group-label">
<option value="">some option-value</option>
</optgroup>
</select>
<!-- don't match select stuff -->
<select name="the-select-stuff-test">
<optgroup label="">some group-label</optgroup>
<option value="some option-value"></option>
</select>
</div>
</form>
<div id="test-for-table-selector">
<!-- match tables -->
<table id="the-table"></table>
<table>
<caption>the-table</caption>
</table>
<!-- partial match -->
<table>
<caption>some the-table</caption>
</table>
<!-- don't match tables -->
<table>
<tr>
<th>the-table</th>
<td>the-table</td>
</tr>
</table>
</div>
<input name="the-table"/>
</body>
</html>

312
vendor/behat/mink/tests/SessionTest.php vendored Normal file
View file

@ -0,0 +1,312 @@
<?php
namespace Behat\Mink\Tests;
use Behat\Mink\Session;
class SessionTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $driver;
private $selectorsHandler;
/**
* Session.
*
* @var Session
*/
private $session;
protected function setUp()
{
$this->driver = $this->getMockBuilder('Behat\Mink\Driver\DriverInterface')->getMock();
$this->selectorsHandler = $this->getMockBuilder('Behat\Mink\Selector\SelectorsHandler')->getMock();
$this->session = new Session($this->driver, $this->selectorsHandler);
}
public function testGetDriver()
{
$this->assertSame($this->driver, $this->session->getDriver());
}
public function testGetPage()
{
$this->assertInstanceOf('Behat\Mink\Element\DocumentElement', $this->session->getPage());
}
public function testGetSelectorsHandler()
{
$this->assertSame($this->selectorsHandler, $this->session->getSelectorsHandler());
}
public function testInstantiateWithoutOptionalDeps()
{
$session = new Session($this->driver);
$this->assertInstanceOf('Behat\Mink\Selector\SelectorsHandler', $session->getSelectorsHandler());
}
public function testIsStarted()
{
$this->driver->expects($this->once())
->method('isStarted')
->will($this->returnValue(true));
$this->assertTrue($this->session->isStarted());
}
public function testStart()
{
$this->driver->expects($this->once())
->method('start');
$this->session->start();
}
public function testStop()
{
$this->driver->expects($this->once())
->method('stop');
$this->session->stop();
}
public function testRestart()
{
$this->driver->expects($this->at(0))
->method('stop');
$this->driver->expects($this->at(1))
->method('start');
$this->session->restart();
}
public function testVisit()
{
$this->driver
->expects($this->once())
->method('visit')
->with($url = 'some_url');
$this->session->visit($url);
}
public function testReset()
{
$this->driver
->expects($this->once())
->method('reset');
$this->session->reset();
}
public function testSetBasicAuth()
{
$this->driver->expects($this->once())
->method('setBasicAuth')
->with('user', 'pass');
$this->session->setBasicAuth('user', 'pass');
}
public function testSetRequestHeader()
{
$this->driver->expects($this->once())
->method('setRequestHeader')
->with('name', 'value');
$this->session->setRequestHeader('name', 'value');
}
public function testGetResponseHeaders()
{
$this->driver
->expects($this->once())
->method('getResponseHeaders')
->will($this->returnValue($ret = array(2, 3, 4)));
$this->assertEquals($ret, $this->session->getResponseHeaders());
}
/**
* @dataProvider provideResponseHeader
*/
public function testGetResponseHeader($expected, $name, array $headers)
{
$this->driver->expects($this->once())
->method('getResponseHeaders')
->willReturn($headers);
$this->assertSame($expected, $this->session->getResponseHeader($name));
}
public function provideResponseHeader()
{
return array(
array('test', 'Mink', array('Mink' => 'test')),
array('test', 'mink', array('Mink' => 'test')),
array('test', 'Mink', array('mink' => 'test')),
array('test', 'Mink', array('Mink' => array('test', 'test2'))),
array(null, 'other', array('Mink' => 'test')),
);
}
public function testSetCookie()
{
$this->driver->expects($this->once())
->method('setCookie')
->with('name', 'value');
$this->session->setCookie('name', 'value');
}
public function testGetCookie()
{
$this->driver->expects($this->once())
->method('getCookie')
->with('name')
->will($this->returnValue('value'));
$this->assertEquals('value', $this->session->getCookie('name'));
}
public function testGetStatusCode()
{
$this->driver
->expects($this->once())
->method('getStatusCode')
->will($this->returnValue($ret = 404));
$this->assertEquals($ret, $this->session->getStatusCode());
}
public function testGetCurrentUrl()
{
$this->driver
->expects($this->once())
->method('getCurrentUrl')
->will($this->returnValue($ret = 'http://some.url'));
$this->assertEquals($ret, $this->session->getCurrentUrl());
}
public function testGetScreenshot()
{
$this->driver->expects($this->once())
->method('getScreenshot')
->will($this->returnValue('screenshot'));
$this->assertEquals('screenshot', $this->session->getScreenshot());
}
public function testGetWindowNames()
{
$this->driver->expects($this->once())
->method('getWindowNames')
->will($this->returnValue($names = array('window 1', 'window 2')));
$this->assertEquals($names, $this->session->getWindowNames());
}
public function testGetWindowName()
{
$this->driver->expects($this->once())
->method('getWindowName')
->will($this->returnValue('name'));
$this->assertEquals('name', $this->session->getWindowName());
}
public function testReload()
{
$this->driver->expects($this->once())
->method('reload');
$this->session->reload();
}
public function testBack()
{
$this->driver->expects($this->once())
->method('back');
$this->session->back();
}
public function testForward()
{
$this->driver->expects($this->once())
->method('forward');
$this->session->forward();
}
public function testSwitchToWindow()
{
$this->driver->expects($this->once())
->method('switchToWindow')
->with('test');
$this->session->switchToWindow('test');
}
public function testSwitchToIFrame()
{
$this->driver->expects($this->once())
->method('switchToIFrame')
->with('test');
$this->session->switchToIFrame('test');
}
public function testExecuteScript()
{
$this->driver
->expects($this->once())
->method('executeScript')
->with($arg = 'JS');
$this->session->executeScript($arg);
}
public function testEvaluateScript()
{
$this->driver
->expects($this->once())
->method('evaluateScript')
->with($arg = 'JS func')
->will($this->returnValue($ret = '23'));
$this->assertEquals($ret, $this->session->evaluateScript($arg));
}
public function testWait()
{
$this->driver
->expects($this->once())
->method('wait')
->with(1000, 'function () {}');
$this->session->wait(1000, 'function () {}');
}
public function testResizeWindow()
{
$this->driver->expects($this->once())
->method('resizeWindow')
->with(800, 600, 'test');
$this->session->resizeWindow(800, 600, 'test');
}
public function testMaximizeWindow()
{
$this->driver->expects($this->once())
->method('maximizeWindow')
->with('test');
$this->session->maximizeWindow('test');
}
}

1297
vendor/behat/mink/tests/WebAssertTest.php vendored Normal file

File diff suppressed because it is too large Load diff