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,83 @@
<?php
namespace Behat\Mink\Tests\Driver;
use Behat\Mink\Driver\DriverInterface;
abstract class AbstractConfig
{
/**
* Creates driver instance.
*
* @return DriverInterface
*/
abstract public function createDriver();
/**
* Map remote file path.
*
* @param string $file File path.
*
* @return string
*/
public function mapRemoteFilePath($file)
{
if (!isset($_SERVER['TEST_MACHINE_BASE_PATH']) || !isset($_SERVER['DRIVER_MACHINE_BASE_PATH'])) {
return $file;
}
$pattern = '/^'.preg_quote($_SERVER['TEST_MACHINE_BASE_PATH'], '/').'/';
$basePath = $_SERVER['DRIVER_MACHINE_BASE_PATH'];
return preg_replace($pattern, $basePath, $file, 1);
}
/**
* Gets the base url to the fixture folder.
*
* @return string
*/
public function getWebFixturesUrl()
{
return $_SERVER['WEB_FIXTURES_HOST'];
}
/**
* @param string $testCase The name of the TestCase class
* @param string $test The name of the test method
*
* @return string|null A message explaining why the test should be skipped, or null to run the test.
*/
public function skipMessage($testCase, $test)
{
if (!$this->supportsCss() && 0 === strpos($testCase, 'Behat\Mink\Tests\Driver\Css\\')) {
return 'This driver does not support CSS.';
}
if (!$this->supportsJs() && 0 === strpos($testCase, 'Behat\Mink\Tests\Driver\Js\\')) {
return 'This driver does not support JavaScript.';
}
return null;
}
/**
* Whether the JS tests should run or no.
*
* @return bool
*/
protected function supportsJs()
{
return true;
}
/**
* Whether the CSS tests should run or no.
*
* @return bool
*/
protected function supportsCss()
{
return false;
}
}

View file

@ -0,0 +1,64 @@
<?php
namespace Behat\Mink\Tests\Driver\Basic;
use Behat\Mink\Tests\Driver\TestCase;
class BasicAuthTest extends TestCase
{
/**
* @dataProvider setBasicAuthDataProvider
*/
public function testSetBasicAuth($user, $pass, $pageText)
{
$session = $this->getSession();
$session->setBasicAuth($user, $pass);
$session->visit($this->pathTo('/basic_auth.php'));
$this->assertContains($pageText, $session->getPage()->getContent());
}
public function setBasicAuthDataProvider()
{
return array(
array('mink-user', 'mink-password', 'is authenticated'),
array('', '', 'is not authenticated'),
);
}
public function testResetBasicAuth()
{
$session = $this->getSession();
$session->setBasicAuth('mink-user', 'mink-password');
$session->visit($this->pathTo('/basic_auth.php'));
$this->assertContains('is authenticated', $session->getPage()->getContent());
$session->setBasicAuth(false);
$session->visit($this->pathTo('/headers.php'));
$this->assertNotContains('PHP_AUTH_USER', $session->getPage()->getContent());
}
public function testResetWithBasicAuth()
{
$session = $this->getSession();
$session->setBasicAuth('mink-user', 'mink-password');
$session->visit($this->pathTo('/basic_auth.php'));
$this->assertContains('is authenticated', $session->getPage()->getContent());
$session->reset();
$session->visit($this->pathTo('/headers.php'));
$this->assertNotContains('PHP_AUTH_USER', $session->getPage()->getContent());
}
}

View file

@ -0,0 +1,84 @@
<?php
namespace Behat\Mink\Tests\Driver\Basic;
use Behat\Mink\Tests\Driver\TestCase;
/**
* This testcase ensures that the driver implementation follows recommended practices for drivers.
*/
class BestPracticesTest extends TestCase
{
public function testExtendsCoreDriver()
{
$driver = $this->createDriver();
$this->assertInstanceOf('Behat\Mink\Driver\CoreDriver', $driver);
return $driver;
}
/**
* @depends testExtendsCoreDriver
*/
public function testImplementFindXpath()
{
$driver = $this->createDriver();
$this->assertNotImplementMethod('find', $driver, 'The driver should overwrite `findElementXpaths` rather than `find` for forward compatibility with Mink 2.');
$this->assertImplementMethod('findElementXpaths', $driver, 'The driver must be able to find elements.');
$this->assertNotImplementMethod('setSession', $driver, 'The driver should not deal with the Session directly for forward compatibility with Mink 2.');
}
/**
* @dataProvider provideRequiredMethods
*/
public function testImplementBasicApi($method)
{
$driver = $this->createDriver();
$this->assertImplementMethod($method, $driver, 'The driver is unusable when this method is not implemented.');
}
public function provideRequiredMethods()
{
return array(
array('start'),
array('isStarted'),
array('stop'),
array('reset'),
array('visit'),
array('getCurrentUrl'),
array('getContent'),
array('click'),
);
}
private function assertImplementMethod($method, $object, $reason = '')
{
$ref = new \ReflectionClass(get_class($object));
$refMethod = $ref->getMethod($method);
$message = sprintf('The driver should implement the `%s` method.', $method);
if ('' !== $reason) {
$message .= ' '.$reason;
}
$this->assertSame($ref->name, $refMethod->getDeclaringClass()->name, $message);
}
private function assertNotImplementMethod($method, $object, $reason = '')
{
$ref = new \ReflectionClass(get_class($object));
$refMethod = $ref->getMethod($method);
$message = sprintf('The driver should not implement the `%s` method.', $method);
if ('' !== $reason) {
$message .= ' '.$reason;
}
$this->assertNotSame($ref->name, $refMethod->getDeclaringClass()->name, $message);
}
}

View file

@ -0,0 +1,86 @@
<?php
namespace Behat\Mink\Tests\Driver\Basic;
use Behat\Mink\Tests\Driver\TestCase;
class ContentTest extends TestCase
{
public function testOuterHtml()
{
$this->getSession()->visit($this->pathTo('/index.html'));
$element = $this->getAssertSession()->elementExists('css', '.travers');
$this->assertEquals(
"<div class=\"travers\">\n <div class=\"sub\">el1</div>\n".
" <div class=\"sub\">el2</div>\n <div class=\"sub\">\n".
" <a href=\"some_url\">some <strong>deep</strong> url</a>\n".
" </div>\n </div>",
$element->getOuterHtml()
);
}
public function testDumpingEmptyElements()
{
$this->getSession()->visit($this->pathTo('/index.html'));
$element = $this->getAssertSession()->elementExists('css', '#empty');
$this->assertEquals(
'An empty <em></em> tag should be rendered with both open and close tags.',
trim($element->getHtml())
);
}
/**
* @dataProvider getAttributeDataProvider
*/
public function testGetAttribute($attributeName, $attributeValue)
{
$this->getSession()->visit($this->pathTo('/index.html'));
$element = $this->getSession()->getPage()->findById('attr-elem['.$attributeName.']');
$this->assertNotNull($element);
$this->assertSame($attributeValue, $element->getAttribute($attributeName));
}
public function getAttributeDataProvider()
{
return array(
array('with-value', 'some-value'),
array('without-value', ''),
array('with-empty-value', ''),
array('with-missing', null),
);
}
public function testJson()
{
$this->getSession()->visit($this->pathTo('/json.php'));
$this->assertContains(
'{"key1":"val1","key2":234,"key3":[1,2,3]}',
$this->getSession()->getPage()->getContent()
);
}
public function testHtmlDecodingNotPerformed()
{
$session = $this->getSession();
$webAssert = $this->getAssertSession();
$session->visit($this->pathTo('/html_decoding.html'));
$page = $session->getPage();
$span = $webAssert->elementExists('css', 'span');
$input = $webAssert->elementExists('css', 'input');
$expectedHtml = '<span custom-attr="&amp;">some text</span>';
$this->assertContains($expectedHtml, $page->getHtml(), '.innerHTML is returned as-is');
$this->assertContains($expectedHtml, $page->getContent(), '.outerHTML is returned as-is');
$this->assertEquals('&', $span->getAttribute('custom-attr'), '.getAttribute value is decoded');
$this->assertEquals('&', $input->getAttribute('value'), '.getAttribute value is decoded');
$this->assertEquals('&', $input->getValue(), 'node value is decoded');
}
}

View file

@ -0,0 +1,168 @@
<?php
namespace Behat\Mink\Tests\Driver\Basic;
use Behat\Mink\Tests\Driver\TestCase;
class CookieTest extends TestCase
{
/**
* test cookie decoding.
*
* @group issue140
*/
public function testIssue140()
{
$this->getSession()->visit($this->pathTo('/issue140.php'));
$this->getSession()->getPage()->fillField('cookie_value', 'some:value;');
$this->getSession()->getPage()->pressButton('Set cookie');
$this->getSession()->visit($this->pathTo('/issue140.php?show_value'));
$this->assertEquals('some:value;', $this->getSession()->getCookie('tc'));
$this->assertEquals('some:value;', $this->getSession()->getPage()->getText());
}
public function testCookie()
{
$this->getSession()->visit($this->pathTo('/cookie_page2.php'));
$this->assertContains('Previous cookie: NO', $this->getSession()->getPage()->getText());
$this->assertNull($this->getSession()->getCookie('srvr_cookie'));
$this->getSession()->setCookie('srvr_cookie', 'client cookie set');
$this->getSession()->reload();
$this->assertContains('Previous cookie: client cookie set', $this->getSession()->getPage()->getText());
$this->assertEquals('client cookie set', $this->getSession()->getCookie('srvr_cookie'));
$this->getSession()->setCookie('srvr_cookie', null);
$this->getSession()->reload();
$this->assertContains('Previous cookie: NO', $this->getSession()->getPage()->getText());
$this->getSession()->visit($this->pathTo('/cookie_page1.php'));
$this->getSession()->visit($this->pathTo('/cookie_page2.php'));
$this->assertContains('Previous cookie: srv_var_is_set', $this->getSession()->getPage()->getText());
$this->getSession()->setCookie('srvr_cookie', null);
$this->getSession()->reload();
$this->assertContains('Previous cookie: NO', $this->getSession()->getPage()->getText());
}
/**
* @dataProvider cookieWithPathsDataProvider
*/
public function testCookieWithPaths($cookieRemovalMode)
{
// start clean
$session = $this->getSession();
$session->visit($this->pathTo('/sub-folder/cookie_page2.php'));
$this->assertContains('Previous cookie: NO', $session->getPage()->getText());
// cookie from root path is accessible in sub-folder
$session->visit($this->pathTo('/cookie_page1.php'));
$session->visit($this->pathTo('/sub-folder/cookie_page2.php'));
$this->assertContains('Previous cookie: srv_var_is_set', $session->getPage()->getText());
// cookie from sub-folder overrides cookie from root path
$session->visit($this->pathTo('/sub-folder/cookie_page1.php'));
$session->visit($this->pathTo('/sub-folder/cookie_page2.php'));
$this->assertContains('Previous cookie: srv_var_is_set_sub_folder', $session->getPage()->getText());
if ($cookieRemovalMode == 'session_reset') {
$session->reset();
} elseif ($cookieRemovalMode == 'cookie_delete') {
$session->setCookie('srvr_cookie', null);
}
// cookie is removed from all paths
$session->visit($this->pathTo('/sub-folder/cookie_page2.php'));
$this->assertContains('Previous cookie: NO', $session->getPage()->getText());
}
public function cookieWithPathsDataProvider()
{
return array(
array('session_reset'),
array('cookie_delete'),
);
}
public function testReset()
{
$this->getSession()->visit($this->pathTo('/cookie_page1.php'));
$this->getSession()->visit($this->pathTo('/cookie_page2.php'));
$this->assertContains('Previous cookie: srv_var_is_set', $this->getSession()->getPage()->getText());
$this->getSession()->reset();
$this->getSession()->visit($this->pathTo('/cookie_page2.php'));
$this->assertContains('Previous cookie: NO', $this->getSession()->getPage()->getText());
$this->getSession()->setCookie('srvr_cookie', 'test_cookie');
$this->getSession()->visit($this->pathTo('/cookie_page2.php'));
$this->assertContains('Previous cookie: test_cookie', $this->getSession()->getPage()->getText());
$this->getSession()->reset();
$this->getSession()->visit($this->pathTo('/cookie_page2.php'));
$this->assertContains('Previous cookie: NO', $this->getSession()->getPage()->getText());
$this->getSession()->setCookie('client_cookie1', 'some_val');
$this->getSession()->setCookie('client_cookie2', 123);
$this->getSession()->visit($this->pathTo('/session_test.php'));
$this->getSession()->visit($this->pathTo('/cookie_page1.php'));
$this->getSession()->visit($this->pathTo('/print_cookies.php'));
$this->assertContains(
"'client_cookie1' = 'some_val'",
$this->getSession()->getPage()->getText()
);
$this->assertContains(
"'client_cookie2' = '123'",
$this->getSession()->getPage()->getText()
);
$this->assertContains(
"_SESS' = ",
$this->getSession()->getPage()->getText()
);
$this->assertContains(
" 'srvr_cookie' = 'srv_var_is_set'",
$this->getSession()->getPage()->getText()
);
$this->getSession()->reset();
$this->getSession()->visit($this->pathTo('/print_cookies.php'));
$this->assertContains('array ( )', $this->getSession()->getPage()->getText());
}
public function testHttpOnlyCookieIsDeleted()
{
$this->getSession()->restart();
$this->getSession()->visit($this->pathTo('/cookie_page3.php'));
$this->assertEquals('Has Cookie: false', $this->findById('cookie-status')->getText());
$this->getSession()->reload();
$this->assertEquals('Has Cookie: true', $this->findById('cookie-status')->getText());
$this->getSession()->restart();
$this->getSession()->visit($this->pathTo('/cookie_page3.php'));
$this->assertEquals('Has Cookie: false', $this->findById('cookie-status')->getText());
}
public function testSessionPersistsBetweenRequests()
{
$this->getSession()->visit($this->pathTo('/session_test.php'));
$webAssert = $this->getAssertSession();
$node = $webAssert->elementExists('css', '#session-id');
$sessionId = $node->getText();
$this->getSession()->visit($this->pathTo('/session_test.php'));
$node = $webAssert->elementExists('css', '#session-id');
$this->assertEquals($sessionId, $node->getText());
$this->getSession()->visit($this->pathTo('/session_test.php?login'));
$node = $webAssert->elementExists('css', '#session-id');
$this->assertNotEquals($sessionId, $newSessionId = $node->getText());
$this->getSession()->visit($this->pathTo('/session_test.php'));
$node = $webAssert->elementExists('css', '#session-id');
$this->assertEquals($newSessionId, $node->getText());
}
}

View file

@ -0,0 +1,265 @@
<?php
namespace Behat\Mink\Tests\Driver\Basic;
use Behat\Mink\Tests\Driver\TestCase;
/**
* @group slow
*/
class ErrorHandlingTest extends TestCase
{
const NOT_FOUND_XPATH = '//html/./invalid';
const NOT_FOUND_EXCEPTION = 'Exception';
const INVALID_EXCEPTION = 'Exception';
public function testVisitErrorPage()
{
$this->getSession()->visit($this->pathTo('/500.php'));
$this->assertContains(
'Sorry, a server error happened',
$this->getSession()->getPage()->getContent(),
'Drivers allow loading pages with a 500 status code'
);
}
public function testCheckInvalidElement()
{
$this->getSession()->visit($this->pathTo('/index.html'));
$element = $this->findById('user-name');
$this->setExpectedException(self::INVALID_EXCEPTION);
$this->getSession()->getDriver()->check($element->getXpath());
}
public function testCheckNotFoundElement()
{
$this->getSession()->visit($this->pathTo('/index.html'));
$this->setExpectedException(self::NOT_FOUND_EXCEPTION);
$this->getSession()->getDriver()->check(self::NOT_FOUND_XPATH);
}
public function testUncheckInvalidElement()
{
$this->getSession()->visit($this->pathTo('/index.html'));
$element = $this->findById('user-name');
$this->setExpectedException(self::INVALID_EXCEPTION);
$this->getSession()->getDriver()->uncheck($element->getXpath());
}
public function testUncheckNotFoundElement()
{
$this->getSession()->visit($this->pathTo('/index.html'));
$this->setExpectedException(self::NOT_FOUND_EXCEPTION);
$this->getSession()->getDriver()->uncheck(self::NOT_FOUND_XPATH);
}
public function testSelectOptionInvalidElement()
{
$this->getSession()->visit($this->pathTo('/index.html'));
$element = $this->findById('user-name');
$this->setExpectedException(self::INVALID_EXCEPTION);
$this->getSession()->getDriver()->selectOption($element->getXpath(), 'test');
}
public function testSelectOptionNotFoundElement()
{
$this->getSession()->visit($this->pathTo('/index.html'));
$this->setExpectedException(self::NOT_FOUND_EXCEPTION);
$this->getSession()->getDriver()->selectOption(self::NOT_FOUND_XPATH, 'test');
}
public function testAttachFileInvalidElement()
{
$this->getSession()->visit($this->pathTo('/index.html'));
$element = $this->findById('user-name');
$this->setExpectedException(self::INVALID_EXCEPTION);
$this->getSession()->getDriver()->attachFile($element->getXpath(), __FILE__);
}
public function testAttachFileNotFoundElement()
{
$this->getSession()->visit($this->pathTo('/index.html'));
$this->setExpectedException(self::NOT_FOUND_EXCEPTION);
$this->getSession()->getDriver()->attachFile(self::NOT_FOUND_XPATH, __FILE__);
}
public function testSubmitFormInvalidElement()
{
$this->getSession()->visit($this->pathTo('/index.html'));
$element = $this->findById('core');
$this->setExpectedException(self::INVALID_EXCEPTION);
$this->getSession()->getDriver()->submitForm($element->getXpath());
}
public function testSubmitFormNotFoundElement()
{
$this->getSession()->visit($this->pathTo('/index.html'));
$this->setExpectedException(self::NOT_FOUND_EXCEPTION);
$this->getSession()->getDriver()->submitForm(self::NOT_FOUND_XPATH);
}
public function testGetTagNameNotFoundElement()
{
$this->getSession()->visit($this->pathTo('/index.html'));
$this->setExpectedException(self::NOT_FOUND_EXCEPTION);
$this->getSession()->getDriver()->getTagName(self::NOT_FOUND_XPATH);
}
public function testGetTextNotFoundElement()
{
$this->getSession()->visit($this->pathTo('/index.html'));
$this->setExpectedException(self::NOT_FOUND_EXCEPTION);
$this->getSession()->getDriver()->getText(self::NOT_FOUND_XPATH);
}
public function testGetHtmlNotFoundElement()
{
$this->getSession()->visit($this->pathTo('/index.html'));
$this->setExpectedException(self::NOT_FOUND_EXCEPTION);
$this->getSession()->getDriver()->getHtml(self::NOT_FOUND_XPATH);
}
public function testGetOuterHtmlNotFoundElement()
{
$this->getSession()->visit($this->pathTo('/index.html'));
$this->setExpectedException(self::NOT_FOUND_EXCEPTION);
$this->getSession()->getDriver()->getOuterHtml(self::NOT_FOUND_XPATH);
}
public function testGetValueNotFoundElement()
{
$this->getSession()->visit($this->pathTo('/index.html'));
$this->setExpectedException(self::NOT_FOUND_EXCEPTION);
$this->getSession()->getDriver()->getValue(self::NOT_FOUND_XPATH);
}
public function testSetValueNotFoundElement()
{
$this->getSession()->visit($this->pathTo('/index.html'));
$this->setExpectedException(self::NOT_FOUND_EXCEPTION);
$this->getSession()->getDriver()->setValue(self::NOT_FOUND_XPATH, 'test');
}
public function testIsSelectedNotFoundElement()
{
$this->getSession()->visit($this->pathTo('/index.html'));
$this->setExpectedException(self::NOT_FOUND_EXCEPTION);
$this->getSession()->getDriver()->isSelected(self::NOT_FOUND_XPATH);
}
public function testIsCheckedNotFoundElement()
{
$this->getSession()->visit($this->pathTo('/index.html'));
$this->setExpectedException(self::NOT_FOUND_EXCEPTION);
$this->getSession()->getDriver()->isChecked(self::NOT_FOUND_XPATH);
}
public function testIsVisibleNotFoundElement()
{
$this->getSession()->visit($this->pathTo('/index.html'));
$this->setExpectedException(self::NOT_FOUND_EXCEPTION);
$this->getSession()->getDriver()->isVisible(self::NOT_FOUND_XPATH);
}
public function testClickNotFoundElement()
{
$this->getSession()->visit($this->pathTo('/index.html'));
$this->setExpectedException(self::NOT_FOUND_EXCEPTION);
$this->getSession()->getDriver()->click(self::NOT_FOUND_XPATH);
}
public function testDoubleClickNotFoundElement()
{
$this->getSession()->visit($this->pathTo('/index.html'));
$this->setExpectedException(self::NOT_FOUND_EXCEPTION);
$this->getSession()->getDriver()->doubleClick(self::NOT_FOUND_XPATH);
}
public function testRightClickNotFoundElement()
{
$this->getSession()->visit($this->pathTo('/index.html'));
$this->setExpectedException(self::NOT_FOUND_EXCEPTION);
$this->getSession()->getDriver()->rightClick(self::NOT_FOUND_XPATH);
}
public function testGetAttributeNotFoundElement()
{
$this->getSession()->visit($this->pathTo('/index.html'));
$this->setExpectedException(self::NOT_FOUND_EXCEPTION);
$this->getSession()->getDriver()->getAttribute(self::NOT_FOUND_XPATH, 'id');
}
public function testMouseOverNotFoundElement()
{
$this->getSession()->visit($this->pathTo('/index.html'));
$this->setExpectedException(self::NOT_FOUND_EXCEPTION);
$this->getSession()->getDriver()->mouseOver(self::NOT_FOUND_XPATH);
}
public function testFocusNotFoundElement()
{
$this->getSession()->visit($this->pathTo('/index.html'));
$this->setExpectedException(self::NOT_FOUND_EXCEPTION);
$this->getSession()->getDriver()->focus(self::NOT_FOUND_XPATH);
}
public function testBlurNotFoundElement()
{
$this->getSession()->visit($this->pathTo('/index.html'));
$this->setExpectedException(self::NOT_FOUND_EXCEPTION);
$this->getSession()->getDriver()->blur(self::NOT_FOUND_XPATH);
}
public function testKeyPressNotFoundElement()
{
$this->getSession()->visit($this->pathTo('/index.html'));
$this->setExpectedException(self::NOT_FOUND_EXCEPTION);
$this->getSession()->getDriver()->keyPress(self::NOT_FOUND_XPATH, 'a');
}
public function testKeyDownNotFoundElement()
{
$this->getSession()->visit($this->pathTo('/index.html'));
$this->setExpectedException(self::NOT_FOUND_EXCEPTION);
$this->getSession()->getDriver()->keyDown(self::NOT_FOUND_XPATH, 'a');
}
public function testKeyUpNotFoundElement()
{
$this->getSession()->visit($this->pathTo('/index.html'));
$this->setExpectedException(self::NOT_FOUND_EXCEPTION);
$this->getSession()->getDriver()->keyUp(self::NOT_FOUND_XPATH, 'a');
}
}

View file

@ -0,0 +1,78 @@
<?php
namespace Behat\Mink\Tests\Driver\Basic;
use Behat\Mink\Tests\Driver\TestCase;
class HeaderTest extends TestCase
{
/**
* test referrer.
*
* @group issue130
*/
public function testIssue130()
{
$this->getSession()->visit($this->pathTo('/issue130.php?p=1'));
$page = $this->getSession()->getPage();
$page->clickLink('Go to 2');
$this->assertEquals($this->pathTo('/issue130.php?p=1'), $page->getText());
}
public function testHeaders()
{
$this->getSession()->setRequestHeader('Accept-Language', 'fr');
$this->getSession()->visit($this->pathTo('/headers.php'));
$this->assertContains('[HTTP_ACCEPT_LANGUAGE] => fr', $this->getSession()->getPage()->getContent());
}
public function testSetUserAgent()
{
$session = $this->getSession();
$session->setRequestHeader('user-agent', 'foo bar');
$session->visit($this->pathTo('/headers.php'));
$this->assertContains('[HTTP_USER_AGENT] => foo bar', $session->getPage()->getContent());
}
public function testResetHeaders()
{
$session = $this->getSession();
$session->setRequestHeader('X-Mink-Test', 'test');
$session->visit($this->pathTo('/headers.php'));
$this->assertContains(
'[HTTP_X_MINK_TEST] => test',
$session->getPage()->getContent(),
'The custom header should be sent',
true
);
$session->reset();
$session->visit($this->pathTo('/headers.php'));
$this->assertNotContains(
'[HTTP_X_MINK_TEST] => test',
$session->getPage()->getContent(),
'The custom header should not be sent after resetting',
true
);
}
public function testResponseHeaders()
{
$this->getSession()->visit($this->pathTo('/response_headers.php'));
$headers = $this->getSession()->getResponseHeaders();
$lowercasedHeaders = array();
foreach ($headers as $name => $value) {
$lowercasedHeaders[str_replace('_', '-', strtolower($name))] = $value;
}
$this->assertArrayHasKey('x-mink-test', $lowercasedHeaders);
}
}

View file

@ -0,0 +1,27 @@
<?php
namespace Behat\Mink\Tests\Driver\Basic;
use Behat\Mink\Tests\Driver\TestCase;
class IFrameTest extends TestCase
{
public function testIFrame()
{
$this->getSession()->visit($this->pathTo('/iframe.html'));
$webAssert = $this->getAssertSession();
$el = $webAssert->elementExists('css', '#text');
$this->assertSame('Main window div text', $el->getText());
$this->getSession()->switchToIFrame('subframe');
$el = $webAssert->elementExists('css', '#text');
$this->assertSame('iFrame div text', $el->getText());
$this->getSession()->switchToIFrame();
$el = $webAssert->elementExists('css', '#text');
$this->assertSame('Main window div text', $el->getText());
}
}

View file

@ -0,0 +1,69 @@
<?php
namespace Behat\Mink\Tests\Driver\Basic;
use Behat\Mink\Tests\Driver\TestCase;
class NavigationTest extends TestCase
{
public function testRedirect()
{
$this->getSession()->visit($this->pathTo('/redirector.php'));
$this->assertEquals($this->pathTo('/redirect_destination.html'), $this->getSession()->getCurrentUrl());
}
public function testPageControls()
{
$this->getSession()->visit($this->pathTo('/randomizer.php'));
$number1 = $this->getAssertSession()->elementExists('css', '#number')->getText();
$this->getSession()->reload();
$number2 = $this->getAssertSession()->elementExists('css', '#number')->getText();
$this->assertNotEquals($number1, $number2);
$this->getSession()->visit($this->pathTo('/links.html'));
$this->getSession()->getPage()->clickLink('Random number page');
$this->assertEquals($this->pathTo('/randomizer.php'), $this->getSession()->getCurrentUrl());
$this->getSession()->back();
$this->assertEquals($this->pathTo('/links.html'), $this->getSession()->getCurrentUrl());
$this->getSession()->forward();
$this->assertEquals($this->pathTo('/randomizer.php'), $this->getSession()->getCurrentUrl());
}
public function testLinks()
{
$this->getSession()->visit($this->pathTo('/links.html'));
$page = $this->getSession()->getPage();
$link = $page->findLink('Redirect me to');
$this->assertNotNull($link);
$this->assertRegExp('/redirector\.php$/', $link->getAttribute('href'));
$link->click();
$this->assertEquals($this->pathTo('/redirect_destination.html'), $this->getSession()->getCurrentUrl());
$this->getSession()->visit($this->pathTo('/links.html'));
$page = $this->getSession()->getPage();
$link = $page->findLink('basic form image');
$this->assertNotNull($link);
$this->assertRegExp('/basic_form\.html$/', $link->getAttribute('href'));
$link->click();
$this->assertEquals($this->pathTo('/basic_form.html'), $this->getSession()->getCurrentUrl());
$this->getSession()->visit($this->pathTo('/links.html'));
$page = $this->getSession()->getPage();
$link = $page->findLink('Link with a ');
$this->assertNotNull($link);
$this->assertRegExp('/links\.html\?quoted$/', $link->getAttribute('href'));
$link->click();
$this->assertEquals($this->pathTo('/links.html?quoted'), $this->getSession()->getCurrentUrl());
}
}

View file

@ -0,0 +1,30 @@
<?php
namespace Behat\Mink\Tests\Driver\Basic;
use Behat\Mink\Tests\Driver\TestCase;
class ScreenshotTest extends TestCase
{
public function testScreenshot()
{
if (!extension_loaded('gd')) {
$this->markTestSkipped('Testing screenshots requires the GD extension');
}
$this->getSession()->visit($this->pathTo('/index.html'));
$screenShot = $this->getSession()->getScreenshot();
$this->assertInternalType('string', $screenShot);
$this->assertFalse(base64_decode($screenShot, true), 'The returned screenshot should not be base64-encoded');
$img = imagecreatefromstring($screenShot);
if (false === $img) {
$this->fail('The screenshot should be a valid image');
}
imagedestroy($img);
}
}

View file

@ -0,0 +1,22 @@
<?php
namespace Behat\Mink\Tests\Driver\Basic;
use Behat\Mink\Tests\Driver\TestCase;
class StatusCodeTest extends TestCase
{
public function testStatuses()
{
$this->getSession()->visit($this->pathTo('/index.html'));
$this->assertEquals(200, $this->getSession()->getStatusCode());
$this->assertEquals($this->pathTo('/index.html'), $this->getSession()->getCurrentUrl());
$this->getSession()->visit($this->pathTo('/404.php'));
$this->assertEquals($this->pathTo('/404.php'), $this->getSession()->getCurrentUrl());
$this->assertEquals(404, $this->getSession()->getStatusCode());
$this->assertEquals('Sorry, page not found', $this->getSession()->getPage()->getContent());
}
}

View file

@ -0,0 +1,143 @@
<?php
namespace Behat\Mink\Tests\Driver\Basic;
use Behat\Mink\Tests\Driver\TestCase;
class TraversingTest extends TestCase
{
/**
* find by label.
*
* @group issue211
*/
public function testIssue211()
{
$this->getSession()->visit($this->pathTo('/issue211.html'));
$field = $this->getSession()->getPage()->findField('Téléphone');
$this->assertNotNull($field);
}
public function testElementsTraversing()
{
$this->getSession()->visit($this->pathTo('/index.html'));
$page = $this->getSession()->getPage();
$title = $page->find('css', 'h1');
$this->assertNotNull($title);
$this->assertEquals('Extremely useless page', $title->getText());
$this->assertEquals('h1', $title->getTagName());
$strong = $page->find('xpath', '//div/strong[3]');
$this->assertNotNull($strong);
$this->assertEquals('pariatur', $strong->getText());
$this->assertEquals('super-duper', $strong->getAttribute('class'));
$this->assertTrue($strong->hasAttribute('class'));
$strong2 = $page->find('xpath', '//div/strong[2]');
$this->assertNotNull($strong2);
$this->assertEquals('veniam', $strong2->getText());
$this->assertEquals('strong', $strong2->getTagName());
$this->assertNull($strong2->getAttribute('class'));
$this->assertFalse($strong2->hasAttribute('class'));
$strongs = $page->findAll('css', 'div#core > strong');
$this->assertCount(3, $strongs);
$this->assertEquals('Lorem', $strongs[0]->getText());
$this->assertEquals('pariatur', $strongs[2]->getText());
$element = $page->find('css', '#some-element');
$this->assertNotNull($element);
$this->assertEquals('some very interesting text', $element->getText());
$this->assertEquals(
"\n some <div>very\n </div>\n".
"<em>interesting</em> text\n ",
$element->getHtml()
);
$this->assertTrue($element->hasAttribute('data-href'));
$this->assertFalse($element->hasAttribute('data-url'));
$this->assertEquals('http://mink.behat.org', $element->getAttribute('data-href'));
$this->assertNull($element->getAttribute('data-url'));
$this->assertEquals('div', $element->getTagName());
}
public function testVeryDeepElementsTraversing()
{
$this->getSession()->visit($this->pathTo('/index.html'));
$page = $this->getSession()->getPage();
$footer = $page->find('css', 'footer');
$this->assertNotNull($footer);
$searchForm = $footer->find('css', 'form#search-form');
$this->assertNotNull($searchForm);
$this->assertEquals('search-form', $searchForm->getAttribute('id'));
$searchInput = $searchForm->findField('Search site...');
$this->assertNotNull($searchInput);
$this->assertEquals('text', $searchInput->getAttribute('type'));
$searchInput = $searchForm->findField('Search site...');
$this->assertNotNull($searchInput);
$this->assertEquals('text', $searchInput->getAttribute('type'));
$profileForm = $footer->find('css', '#profile');
$this->assertNotNull($profileForm);
$profileFormDiv = $profileForm->find('css', 'div');
$this->assertNotNull($profileFormDiv);
$profileFormDivLabel = $profileFormDiv->find('css', 'label');
$this->assertNotNull($profileFormDivLabel);
$profileFormDivParent = $profileFormDivLabel->getParent();
$this->assertNotNull($profileFormDivParent);
$profileFormDivParent = $profileFormDivLabel->getParent();
$this->assertEquals('something', $profileFormDivParent->getAttribute('data-custom'));
$profileFormInput = $profileFormDivLabel->findField('user-name');
$this->assertNotNull($profileFormInput);
$this->assertEquals('username', $profileFormInput->getAttribute('name'));
}
public function testDeepTraversing()
{
$this->getSession()->visit($this->pathTo('/index.html'));
$traversDivs = $this->getSession()->getPage()->findAll('css', 'div.travers');
$this->assertCount(1, $traversDivs);
$subDivs = $traversDivs[0]->findAll('css', 'div.sub');
$this->assertCount(3, $subDivs);
$this->assertTrue($subDivs[2]->hasLink('some deep url'));
$this->assertFalse($subDivs[2]->hasLink('come deep url'));
$subUrl = $subDivs[2]->findLink('some deep url');
$this->assertNotNull($subUrl);
$this->assertRegExp('/some_url$/', $subUrl->getAttribute('href'));
$this->assertEquals('some deep url', $subUrl->getText());
$this->assertEquals('some <strong>deep</strong> url', $subUrl->getHtml());
$this->assertTrue($subUrl->has('css', 'strong'));
$this->assertFalse($subUrl->has('css', 'em'));
$this->assertEquals('deep', $subUrl->find('css', 'strong')->getText());
}
public function testFindingChild()
{
$this->getSession()->visit($this->pathTo('/index.html'));
$form = $this->getSession()->getPage()->find('css', 'footer form');
$this->assertNotNull($form);
$this->assertCount(1, $form->findAll('css', 'input'), 'Elements are searched only in the element, not in all previous matches');
}
}

View file

@ -0,0 +1,20 @@
<?php
namespace Behat\Mink\Tests\Driver\Basic;
use Behat\Mink\Tests\Driver\TestCase;
class VisibilityTest extends TestCase
{
public function testVisibility()
{
$this->getSession()->visit($this->pathTo('/js_test.html'));
$webAssert = $this->getAssertSession();
$clicker = $webAssert->elementExists('css', '.elements div#clicker');
$invisible = $webAssert->elementExists('css', '#invisible');
$this->assertFalse($invisible->isVisible());
$this->assertTrue($clicker->isVisible());
}
}

View file

@ -0,0 +1,76 @@
<?php
namespace Behat\Mink\Tests\Driver\Css;
use Behat\Mink\Tests\Driver\TestCase;
class HoverTest extends TestCase
{
/**
* @group mouse-events
*/
public function testMouseOverHover()
{
$this->getSession()->visit($this->pathTo('/css_mouse_events.html'));
$this->findById('reset-square')->mouseOver();
$this->assertActionSquareHeight(100);
$this->findById('action-square')->mouseOver();
$this->assertActionSquareHeight(200);
}
/**
* @group mouse-events
* @depends testMouseOverHover
*/
public function testClickHover()
{
$this->getSession()->visit($this->pathTo('/css_mouse_events.html'));
$this->findById('reset-square')->mouseOver();
$this->assertActionSquareHeight(100);
$this->findById('action-square')->click();
$this->assertActionSquareHeight(200);
}
/**
* @group mouse-events
* @depends testMouseOverHover
*/
public function testDoubleClickHover()
{
$this->getSession()->visit($this->pathTo('/css_mouse_events.html'));
$this->findById('reset-square')->mouseOver();
$this->assertActionSquareHeight(100);
$this->findById('action-square')->doubleClick();
$this->assertActionSquareHeight(200);
}
/**
* @group mouse-events
* @depends testMouseOverHover
*/
public function testRightClickHover()
{
$this->getSession()->visit($this->pathTo('/css_mouse_events.html'));
$this->findById('reset-square')->mouseOver();
$this->assertActionSquareHeight(100);
$this->findById('action-square')->rightClick();
$this->assertActionSquareHeight(200);
}
private function assertActionSquareHeight($expected)
{
$this->assertEquals(
$expected,
$this->getSession()->evaluateScript("return window.$('#action-square').height();"),
'Mouse is located over the object when mouse-related action is performed'
);
}
}

View file

@ -0,0 +1,73 @@
<?php
namespace Behat\Mink\Tests\Driver\Form;
use Behat\Mink\Tests\Driver\TestCase;
class CheckboxTest extends TestCase
{
public function testManipulate()
{
$this->getSession()->visit($this->pathTo('advanced_form.html'));
$checkbox = $this->getAssertSession()->fieldExists('agreement');
$this->assertNull($checkbox->getValue());
$this->assertFalse($checkbox->isChecked());
$checkbox->check();
$this->assertEquals('yes', $checkbox->getValue());
$this->assertTrue($checkbox->isChecked());
$checkbox->uncheck();
$this->assertNull($checkbox->getValue());
$this->assertFalse($checkbox->isChecked());
}
public function testSetValue()
{
$this->getSession()->visit($this->pathTo('advanced_form.html'));
$checkbox = $this->getAssertSession()->fieldExists('agreement');
$this->assertNull($checkbox->getValue());
$this->assertFalse($checkbox->isChecked());
$checkbox->setValue(true);
$this->assertEquals('yes', $checkbox->getValue());
$this->assertTrue($checkbox->isChecked());
$checkbox->setValue(false);
$this->assertNull($checkbox->getValue());
$this->assertFalse($checkbox->isChecked());
}
public function testCheckboxMultiple()
{
$this->getSession()->visit($this->pathTo('/multicheckbox_form.html'));
$webAssert = $this->getAssertSession();
$this->assertEquals('Multicheckbox Test', $webAssert->elementExists('css', 'h1')->getText());
$updateMail = $webAssert->elementExists('css', '[name="mail_types[]"][value="update"]');
$spamMail = $webAssert->elementExists('css', '[name="mail_types[]"][value="spam"]');
$this->assertEquals('update', $updateMail->getValue());
$this->assertNull($spamMail->getValue());
$this->assertTrue($updateMail->isChecked());
$this->assertFalse($spamMail->isChecked());
$updateMail->uncheck();
$this->assertFalse($updateMail->isChecked());
$this->assertFalse($spamMail->isChecked());
$spamMail->check();
$this->assertFalse($updateMail->isChecked());
$this->assertTrue($spamMail->isChecked());
}
}

View file

@ -0,0 +1,312 @@
<?php
namespace Behat\Mink\Tests\Driver\Form;
use Behat\Mink\Tests\Driver\TestCase;
class GeneralTest extends TestCase
{
// test multiple submit buttons
public function testIssue212()
{
$session = $this->getSession();
$session->visit($this->pathTo('/issue212.html'));
$field = $this->findById('poney-button');
$this->assertEquals('poney', $field->getValue());
}
public function testBasicForm()
{
$this->getSession()->visit($this->pathTo('/basic_form.html'));
$webAssert = $this->getAssertSession();
$page = $this->getSession()->getPage();
$this->assertEquals('Basic Form Page', $webAssert->elementExists('css', 'h1')->getText());
$firstname = $webAssert->fieldExists('first_name');
$lastname = $webAssert->fieldExists('lastn');
$this->assertEquals('Firstname', $firstname->getValue());
$this->assertEquals('Lastname', $lastname->getValue());
$firstname->setValue('Konstantin');
$page->fillField('last_name', 'Kudryashov');
$this->assertEquals('Konstantin', $firstname->getValue());
$this->assertEquals('Kudryashov', $lastname->getValue());
$page->findButton('Reset')->click();
$this->assertEquals('Firstname', $firstname->getValue());
$this->assertEquals('Lastname', $lastname->getValue());
$firstname->setValue('Konstantin');
$page->fillField('last_name', 'Kudryashov');
$page->findButton('Save')->click();
if ($this->safePageWait(5000, 'document.getElementById("first") !== null')) {
$this->assertEquals('Anket for Konstantin', $webAssert->elementExists('css', 'h1')->getText());
$this->assertEquals('Firstname: Konstantin', $webAssert->elementExists('css', '#first')->getText());
$this->assertEquals('Lastname: Kudryashov', $webAssert->elementExists('css', '#last')->getText());
}
}
/**
* @dataProvider formSubmitWaysDataProvider
*/
public function testFormSubmitWays($submitVia)
{
$session = $this->getSession();
$session->visit($this->pathTo('/basic_form.html'));
$page = $session->getPage();
$webAssert = $this->getAssertSession();
$firstname = $webAssert->fieldExists('first_name');
$firstname->setValue('Konstantin');
$page->findButton($submitVia)->click();
if ($this->safePageWait(5000, 'document.getElementById("first") !== null')) {
$this->assertEquals('Firstname: Konstantin', $webAssert->elementExists('css', '#first')->getText());
} else {
$this->fail('Form was never submitted');
}
}
public function formSubmitWaysDataProvider()
{
return array(
array('Save'),
array('input-type-image'),
array('button-without-type'),
array('button-type-submit'),
);
}
public function testFormSubmit()
{
$session = $this->getSession();
$session->visit($this->pathTo('/basic_form.html'));
$webAssert = $this->getAssertSession();
$webAssert->fieldExists('first_name')->setValue('Konstantin');
$webAssert->elementExists('xpath', 'descendant-or-self::form[1]')->submit();
if ($this->safePageWait(5000, 'document.getElementById("first") !== null')) {
$this->assertEquals('Firstname: Konstantin', $webAssert->elementExists('css', '#first')->getText());
};
}
public function testFormSubmitWithoutButton()
{
$session = $this->getSession();
$session->visit($this->pathTo('/form_without_button.html'));
$webAssert = $this->getAssertSession();
$webAssert->fieldExists('first_name')->setValue('Konstantin');
$webAssert->elementExists('xpath', 'descendant-or-self::form[1]')->submit();
if ($this->safePageWait(5000, 'document.getElementById("first") !== null')) {
$this->assertEquals('Firstname: Konstantin', $webAssert->elementExists('css', '#first')->getText());
};
}
public function testBasicGetForm()
{
$this->getSession()->visit($this->pathTo('/basic_get_form.php'));
$webAssert = $this->getAssertSession();
$page = $this->getSession()->getPage();
$this->assertEquals('Basic Get Form Page', $webAssert->elementExists('css', 'h1')->getText());
$search = $webAssert->fieldExists('q');
$search->setValue('some#query');
$page->pressButton('Find');
$div = $webAssert->elementExists('css', 'div');
$this->assertEquals('some#query', $div->getText());
}
public function testAdvancedForm()
{
$this->getSession()->visit($this->pathTo('/advanced_form.html'));
$page = $this->getSession()->getPage();
$page->fillField('first_name', 'ever');
$page->fillField('last_name', 'zet');
$page->pressButton('Register');
$this->assertContains('no file', $page->getContent());
$this->getSession()->visit($this->pathTo('/advanced_form.html'));
$webAssert = $this->getAssertSession();
$page = $this->getSession()->getPage();
$this->assertEquals('ADvanced Form Page', $webAssert->elementExists('css', 'h1')->getText());
$firstname = $webAssert->fieldExists('first_name');
$lastname = $webAssert->fieldExists('lastn');
$email = $webAssert->fieldExists('Your email:');
$select = $webAssert->fieldExists('select_number');
$sex = $webAssert->fieldExists('sex');
$maillist = $webAssert->fieldExists('mail_list');
$agreement = $webAssert->fieldExists('agreement');
$notes = $webAssert->fieldExists('notes');
$about = $webAssert->fieldExists('about');
$this->assertEquals('Firstname', $firstname->getValue());
$this->assertEquals('Lastname', $lastname->getValue());
$this->assertEquals('your@email.com', $email->getValue());
$this->assertEquals('20', $select->getValue());
$this->assertEquals('w', $sex->getValue());
$this->assertEquals('original notes', $notes->getValue());
$this->assertEquals('on', $maillist->getValue());
$this->assertNull($agreement->getValue());
$this->assertTrue($maillist->isChecked());
$this->assertFalse($agreement->isChecked());
$agreement->check();
$this->assertTrue($agreement->isChecked());
$maillist->uncheck();
$this->assertFalse($maillist->isChecked());
$select->selectOption('thirty');
$this->assertEquals('30', $select->getValue());
$sex->selectOption('m');
$this->assertEquals('m', $sex->getValue());
$notes->setValue('new notes');
$this->assertEquals('new notes', $notes->getValue());
$about->attachFile($this->mapRemoteFilePath(__DIR__.'/../../web-fixtures/some_file.txt'));
$button = $page->findButton('Register');
$this->assertNotNull($button);
$page->fillField('first_name', 'Foo "item"');
$page->fillField('last_name', 'Bar');
$page->fillField('Your email:', 'ever.zet@gmail.com');
$this->assertEquals('Foo "item"', $firstname->getValue());
$this->assertEquals('Bar', $lastname->getValue());
$button->press();
if ($this->safePageWait(5000, 'document.getElementsByTagName("title") !== null')) {
$out = <<<OUT
array (
'agreement' = 'on',
'email' = 'ever.zet@gmail.com',
'first_name' = 'Foo "item"',
'last_name' = 'Bar',
'notes' = 'new notes',
'select_number' = '30',
'sex' = 'm',
'submit' = 'Register',
)
some_file.txt
1 uploaded file
OUT;
$this->assertContains($out, $page->getContent());
}
}
public function testMultiInput()
{
$this->getSession()->visit($this->pathTo('/multi_input_form.html'));
$page = $this->getSession()->getPage();
$webAssert = $this->getAssertSession();
$this->assertEquals('Multi input Test', $webAssert->elementExists('css', 'h1')->getText());
$first = $webAssert->fieldExists('First');
$second = $webAssert->fieldExists('Second');
$third = $webAssert->fieldExists('Third');
$this->assertEquals('tag1', $first->getValue());
$this->assertSame('tag2', $second->getValue());
$this->assertEquals('tag1', $third->getValue());
$first->setValue('tag2');
$this->assertEquals('tag2', $first->getValue());
$this->assertSame('tag2', $second->getValue());
$this->assertEquals('tag1', $third->getValue());
$second->setValue('one');
$this->assertEquals('tag2', $first->getValue());
$this->assertSame('one', $second->getValue());
$third->setValue('tag3');
$this->assertEquals('tag2', $first->getValue());
$this->assertSame('one', $second->getValue());
$this->assertEquals('tag3', $third->getValue());
$button = $page->findButton('Register');
$this->assertNotNull($button);
$button->press();
$space = ' ';
$out = <<<OUT
'tags' =$space
array (
0 = 'tag2',
1 = 'one',
2 = 'tag3',
),
OUT;
$this->assertContains($out, $page->getContent());
}
public function testAdvancedFormSecondSubmit()
{
$this->getSession()->visit($this->pathTo('/advanced_form.html'));
$page = $this->getSession()->getPage();
$button = $page->findButton('Login');
$this->assertNotNull($button);
$button->press();
$toSearch = array(
"'agreement' = 'off',",
"'submit' = 'Login',",
'no file',
);
$pageContent = $page->getContent();
foreach ($toSearch as $searchString) {
$this->assertContains($searchString, $pageContent);
}
}
public function testSubmitEmptyTextarea()
{
$this->getSession()->visit($this->pathTo('/empty_textarea.html'));
$page = $this->getSession()->getPage();
$page->pressButton('Save');
$toSearch = array(
"'textarea' = '',",
"'submit' = 'Save',",
'no file',
);
$pageContent = $page->getContent();
foreach ($toSearch as $searchString) {
$this->assertContains($searchString, $pageContent);
}
}
}

View file

@ -0,0 +1,128 @@
<?php
namespace Behat\Mink\Tests\Driver\Form;
use Behat\Mink\Tests\Driver\TestCase;
class Html5Test extends TestCase
{
public function testHtml5FormInputAttribute()
{
$this->getSession()->visit($this->pathTo('/html5_form.html'));
$page = $this->getSession()->getPage();
$webAssert = $this->getAssertSession();
$firstName = $webAssert->fieldExists('first_name');
$lastName = $webAssert->fieldExists('last_name');
$this->assertEquals('not set', $lastName->getValue());
$firstName->setValue('John');
$lastName->setValue('Doe');
$this->assertEquals('Doe', $lastName->getValue());
$page->pressButton('Submit in form');
if ($this->safePageWait(5000, 'document.getElementsByTagName("title") !== null')) {
$out = <<<OUT
'first_name' = 'John',
'last_name' = 'Doe',
OUT;
$this->assertContains($out, $page->getContent());
$this->assertNotContains('other_field', $page->getContent());
}
}
public function testHtml5FormRadioAttribute()
{
$this->getSession()->visit($this->pathTo('html5_radio.html'));
$page = $this->getSession()->getPage();
$radio = $this->findById('sex_f');
$otherRadio = $this->findById('sex_invalid');
$this->assertEquals('f', $radio->getValue());
$this->assertEquals('invalid', $otherRadio->getValue());
$radio->selectOption('m');
$this->assertEquals('m', $radio->getValue());
$this->assertEquals('invalid', $otherRadio->getValue());
$page->pressButton('Submit in form');
$out = <<<OUT
'sex' = 'm',
OUT;
$this->assertContains($out, $page->getContent());
}
public function testHtml5FormButtonAttribute()
{
$this->getSession()->visit($this->pathTo('/html5_form.html'));
$page = $this->getSession()->getPage();
$webAssert = $this->getAssertSession();
$firstName = $webAssert->fieldExists('first_name');
$lastName = $webAssert->fieldExists('last_name');
$firstName->setValue('John');
$lastName->setValue('Doe');
$page->pressButton('Submit outside form');
if ($this->safePageWait(5000, 'document.getElementsByTagName("title") !== null')) {
$out = <<<OUT
'first_name' = 'John',
'last_name' = 'Doe',
'submit_button' = 'test',
OUT;
$this->assertContains($out, $page->getContent());
}
}
public function testHtml5FormOutside()
{
$this->getSession()->visit($this->pathTo('/html5_form.html'));
$page = $this->getSession()->getPage();
$page->fillField('other_field', 'hello');
$page->pressButton('Submit separate form');
if ($this->safePageWait(5000, 'document.getElementsByTagName("title") !== null')) {
$out = <<<OUT
'other_field' = 'hello',
OUT;
$this->assertContains($out, $page->getContent());
$this->assertNotContains('first_name', $page->getContent());
}
}
public function testHtml5Types()
{
$this->getSession()->visit($this->pathTo('html5_types.html'));
$page = $this->getSession()->getPage();
$page->fillField('url', 'http://mink.behat.org/');
$page->fillField('email', 'mink@example.org');
$page->fillField('number', '6');
$page->fillField('search', 'mink');
$page->fillField('date', '2014-05-19');
$page->fillField('color', '#ff00aa');
$page->pressButton('Submit');
$out = <<<OUT
'color' = '#ff00aa',
'date' = '2014-05-19',
'email' = 'mink@example.org',
'number' = '6',
'search' = 'mink',
'submit_button' = 'Submit',
'url' = 'http://mink.behat.org/',
OUT;
$this->assertContains($out, $page->getContent());
}
}

View file

@ -0,0 +1,84 @@
<?php
namespace Behat\Mink\Tests\Driver\Form;
use Behat\Mink\Tests\Driver\TestCase;
class RadioTest extends TestCase
{
protected function setUp()
{
$this->getSession()->visit($this->pathTo('radio.html'));
}
public function testIsChecked()
{
$option = $this->findById('first');
$option2 = $this->findById('second');
$this->assertTrue($option->isChecked());
$this->assertFalse($option2->isChecked());
$option2->selectOption('updated');
$this->assertFalse($option->isChecked());
$this->assertTrue($option2->isChecked());
}
public function testSelectOption()
{
$option = $this->findById('first');
$this->assertEquals('set', $option->getValue());
$option->selectOption('updated');
$this->assertEquals('updated', $option->getValue());
$option->selectOption('set');
$this->assertEquals('set', $option->getValue());
}
public function testSetValue()
{
$option = $this->findById('first');
$this->assertEquals('set', $option->getValue());
$option->setValue('updated');
$this->assertEquals('updated', $option->getValue());
$this->assertFalse($option->isChecked());
}
public function testSameNameInMultipleForms()
{
$option1 = $this->findById('reused_form1');
$option2 = $this->findById('reused_form2');
$this->assertEquals('test2', $option1->getValue());
$this->assertEquals('test3', $option2->getValue());
$option1->selectOption('test');
$this->assertEquals('test', $option1->getValue());
$this->assertEquals('test3', $option2->getValue());
}
/**
* @see https://github.com/Behat/MinkSahiDriver/issues/32
*/
public function testSetValueXPathEscaping()
{
$session = $this->getSession();
$session->visit($this->pathTo('/advanced_form.html'));
$page = $session->getPage();
$sex = $page->find('xpath', '//*[@name = "sex"]'."\n|\n".'//*[@id = "sex"]');
$this->assertNotNull($sex, 'xpath with line ending works');
$sex->setValue('m');
$this->assertEquals('m', $sex->getValue(), 'no double xpath escaping during radio button value change');
}
}

View file

@ -0,0 +1,134 @@
<?php
namespace Behat\Mink\Tests\Driver\Form;
use Behat\Mink\Tests\Driver\TestCase;
class SelectTest extends TestCase
{
public function testMultiselect()
{
$this->getSession()->visit($this->pathTo('/multiselect_form.html'));
$webAssert = $this->getAssertSession();
$page = $this->getSession()->getPage();
$this->assertEquals('Multiselect Test', $webAssert->elementExists('css', 'h1')->getText());
$select = $webAssert->fieldExists('select_number');
$multiSelect = $webAssert->fieldExists('select_multiple_numbers[]');
$secondMultiSelect = $webAssert->fieldExists('select_multiple_values[]');
$this->assertEquals('20', $select->getValue());
$this->assertSame(array(), $multiSelect->getValue());
$this->assertSame(array('2', '3'), $secondMultiSelect->getValue());
$select->selectOption('thirty');
$this->assertEquals('30', $select->getValue());
$multiSelect->selectOption('one', true);
$this->assertSame(array('1'), $multiSelect->getValue());
$multiSelect->selectOption('three', true);
$this->assertEquals(array('1', '3'), $multiSelect->getValue());
$secondMultiSelect->selectOption('two');
$this->assertSame(array('2'), $secondMultiSelect->getValue());
$button = $page->findButton('Register');
$this->assertNotNull($button);
$button->press();
$space = ' ';
$out = <<<OUT
'agreement' = 'off',
'select_multiple_numbers' =$space
array (
0 = '1',
1 = '3',
),
'select_multiple_values' =$space
array (
0 = '2',
),
'select_number' = '30',
OUT;
$this->assertContains($out, $page->getContent());
}
/**
* @dataProvider testElementSelectedStateCheckDataProvider
*/
public function testElementSelectedStateCheck($selectName, $optionValue, $optionText)
{
$session = $this->getSession();
$webAssert = $this->getAssertSession();
$session->visit($this->pathTo('/multiselect_form.html'));
$select = $webAssert->fieldExists($selectName);
$option = $webAssert->elementExists('named', array('option', $optionValue));
$this->assertFalse($option->isSelected());
$select->selectOption($optionText);
$this->assertTrue($option->isSelected());
}
public function testElementSelectedStateCheckDataProvider()
{
return array(
array('select_number', '30', 'thirty'),
array('select_multiple_numbers[]', '2', 'two'),
);
}
public function testSetValueSingleSelect()
{
$session = $this->getSession();
$session->visit($this->pathTo('/multiselect_form.html'));
$select = $this->getAssertSession()->fieldExists('select_number');
$select->setValue('10');
$this->assertEquals('10', $select->getValue());
}
public function testSetValueMultiSelect()
{
$session = $this->getSession();
$session->visit($this->pathTo('/multiselect_form.html'));
$select = $this->getAssertSession()->fieldExists('select_multiple_values[]');
$select->setValue(array('1', '2'));
$this->assertEquals(array('1', '2'), $select->getValue());
}
/**
* @see https://github.com/Behat/Mink/issues/193
*/
public function testOptionWithoutValue()
{
$session = $this->getSession();
$session->visit($this->pathTo('/issue193.html'));
$session->getPage()->selectFieldOption('options-without-values', 'Two');
$this->assertEquals('Two', $this->findById('options-without-values')->getValue());
$this->assertTrue($this->findById('two')->isSelected());
$this->assertFalse($this->findById('one')->isSelected());
$session->getPage()->selectFieldOption('options-with-values', 'two');
$this->assertEquals('two', $this->findById('options-with-values')->getValue());
}
/**
* @see https://github.com/Behat/Mink/issues/131
*/
public function testAccentuatedOption()
{
$this->getSession()->visit($this->pathTo('/issue131.html'));
$page = $this->getSession()->getPage();
$page->selectFieldOption('foobar', 'Gimme some accentués characters');
$this->assertEquals('1', $page->findField('foobar')->getValue());
}
}

View file

@ -0,0 +1,155 @@
<?php
namespace Behat\Mink\Tests\Driver\Js;
use Behat\Mink\Tests\Driver\TestCase;
/**
* @group slow
*/
class ChangeEventTest extends TestCase
{
/**
* 'change' event should be fired after selecting an <option> in a <select>.
*
* TODO check whether this test is redundant with other change event tests.
*/
public function testIssue255()
{
$session = $this->getSession();
$session->visit($this->pathTo('/issue255.html'));
$session->getPage()->selectFieldOption('foo_select', 'Option 3');
$session->wait(2000, '$("#output_foo_select").text() != ""');
$this->assertEquals('onChangeSelect', $this->getAssertSession()->elementExists('css', '#output_foo_select')->getText());
}
public function testIssue178()
{
$session = $this->getSession();
$session->visit($this->pathTo('/issue178.html'));
$this->findById('source')->setValue('foo');
$this->assertEquals('foo', $this->findById('target')->getText());
}
/**
* @dataProvider setValueChangeEventDataProvider
* @group change-event-detector
*/
public function testSetValueChangeEvent($elementId, $valueForEmpty, $valueForFilled = '')
{
$this->getSession()->visit($this->pathTo('/element_change_detector.html'));
$page = $this->getSession()->getPage();
$input = $this->findById($elementId);
$this->assertNull($page->findById($elementId.'-result'));
// Verify setting value, when control is initially empty.
$input->setValue($valueForEmpty);
$this->assertElementChangeCount($elementId, 'initial value setting triggers change event');
if ($valueForFilled) {
// Verify setting value, when control already has a value.
$this->findById('results')->click();
$input->setValue($valueForFilled);
$this->assertElementChangeCount($elementId, 'value change triggers change event');
}
}
public function setValueChangeEventDataProvider()
{
return array(
'input default' => array('the-input-default', 'from empty', 'from existing'),
'input text' => array('the-input-text', 'from empty', 'from existing'),
'input email' => array('the-email', 'from empty', 'from existing'),
'textarea' => array('the-textarea', 'from empty', 'from existing'),
'file' => array('the-file', 'from empty', 'from existing'),
'select' => array('the-select', '30'),
'radio' => array('the-radio-m', 'm'),
);
}
/**
* @dataProvider selectOptionChangeEventDataProvider
* @group change-event-detector
*/
public function testSelectOptionChangeEvent($elementId, $elementValue)
{
$this->getSession()->visit($this->pathTo('/element_change_detector.html'));
$page = $this->getSession()->getPage();
$input = $this->findById($elementId);
$this->assertNull($page->findById($elementId.'-result'));
$input->selectOption($elementValue);
$this->assertElementChangeCount($elementId);
}
public function selectOptionChangeEventDataProvider()
{
return array(
'select' => array('the-select', '30'),
'radio' => array('the-radio-m', 'm'),
);
}
/**
* @dataProvider checkboxTestWayDataProvider
* @group change-event-detector
*/
public function testCheckChangeEvent($useSetValue)
{
$this->getSession()->visit($this->pathTo('/element_change_detector.html'));
$page = $this->getSession()->getPage();
$checkbox = $this->findById('the-unchecked-checkbox');
$this->assertNull($page->findById('the-unchecked-checkbox-result'));
if ($useSetValue) {
$checkbox->setValue(true);
} else {
$checkbox->check();
}
$this->assertElementChangeCount('the-unchecked-checkbox');
}
/**
* @dataProvider checkboxTestWayDataProvider
* @group change-event-detector
*/
public function testUncheckChangeEvent($useSetValue)
{
$this->getSession()->visit($this->pathTo('/element_change_detector.html'));
$page = $this->getSession()->getPage();
$checkbox = $this->findById('the-checked-checkbox');
$this->assertNull($page->findById('the-checked-checkbox-result'));
if ($useSetValue) {
$checkbox->setValue(false);
} else {
$checkbox->uncheck();
}
$this->assertElementChangeCount('the-checked-checkbox');
}
public function checkboxTestWayDataProvider()
{
return array(
array(true),
array(false),
);
}
private function assertElementChangeCount($elementId, $message = '')
{
$counterElement = $this->getSession()->getPage()->findById($elementId.'-result');
$actualCount = null === $counterElement ? 0 : $counterElement->getText();
$this->assertEquals('1', $actualCount, $message);
}
}

View file

@ -0,0 +1,122 @@
<?php
namespace Behat\Mink\Tests\Driver\Js;
use Behat\Mink\Tests\Driver\TestCase;
class EventsTest extends TestCase
{
/**
* @group mouse-events
*/
public function testClick()
{
$this->getSession()->visit($this->pathTo('/js_test.html'));
$clicker = $this->getAssertSession()->elementExists('css', '.elements div#clicker');
$this->assertEquals('not clicked', $clicker->getText());
$clicker->click();
$this->assertEquals('single clicked', $clicker->getText());
}
/**
* @group mouse-events
*/
public function testDoubleClick()
{
$this->getSession()->visit($this->pathTo('/js_test.html'));
$clicker = $this->getAssertSession()->elementExists('css', '.elements div#clicker');
$this->assertEquals('not clicked', $clicker->getText());
$clicker->doubleClick();
$this->assertEquals('double clicked', $clicker->getText());
}
/**
* @group mouse-events
*/
public function testRightClick()
{
$this->getSession()->visit($this->pathTo('/js_test.html'));
$clicker = $this->getAssertSession()->elementExists('css', '.elements div#clicker');
$this->assertEquals('not clicked', $clicker->getText());
$clicker->rightClick();
$this->assertEquals('right clicked', $clicker->getText());
}
/**
* @group mouse-events
*/
public function testFocus()
{
$this->getSession()->visit($this->pathTo('/js_test.html'));
$focusBlurDetector = $this->getAssertSession()->elementExists('css', '.elements input#focus-blur-detector');
$this->assertEquals('no action detected', $focusBlurDetector->getValue());
$focusBlurDetector->focus();
$this->assertEquals('focused', $focusBlurDetector->getValue());
}
/**
* @group mouse-events
* @depends testFocus
*/
public function testBlur()
{
$this->getSession()->visit($this->pathTo('/js_test.html'));
$focusBlurDetector = $this->getAssertSession()->elementExists('css', '.elements input#focus-blur-detector');
$this->assertEquals('no action detected', $focusBlurDetector->getValue());
$focusBlurDetector->blur();
$this->assertEquals('blured', $focusBlurDetector->getValue());
}
/**
* @group mouse-events
*/
public function testMouseOver()
{
$this->getSession()->visit($this->pathTo('/js_test.html'));
$mouseOverDetector = $this->getAssertSession()->elementExists('css', '.elements div#mouseover-detector');
$this->assertEquals('no mouse action detected', $mouseOverDetector->getText());
$mouseOverDetector->mouseOver();
$this->assertEquals('mouse overed', $mouseOverDetector->getText());
}
/**
* @dataProvider provideKeyboardEventsModifiers
*/
public function testKeyboardEvents($modifier, $eventProperties)
{
$this->getSession()->visit($this->pathTo('/js_test.html'));
$webAssert = $this->getAssertSession();
$input1 = $webAssert->elementExists('css', '.elements input.input.first');
$input2 = $webAssert->elementExists('css', '.elements input.input.second');
$input3 = $webAssert->elementExists('css', '.elements input.input.third');
$event = $webAssert->elementExists('css', '.elements .text-event');
$input1->keyDown('u', $modifier);
$this->assertEquals('key downed:'.$eventProperties, $event->getText());
$input2->keyPress('r', $modifier);
$this->assertEquals('key pressed:114 / '.$eventProperties, $event->getText());
$input3->keyUp(78, $modifier);
$this->assertEquals('key upped:78 / '.$eventProperties, $event->getText());
}
public function provideKeyboardEventsModifiers()
{
return array(
'none' => array(null, '0 / 0 / 0 / 0'),
'alt' => array('alt', '1 / 0 / 0 / 0'),
// jQuery considers ctrl as being a metaKey in the normalized event
'ctrl' => array('ctrl', '0 / 1 / 0 / 1'),
'shift' => array('shift', '0 / 0 / 1 / 0'),
'meta' => array('meta', '0 / 0 / 0 / 1'),
);
}
}

View file

@ -0,0 +1,85 @@
<?php
namespace Behat\Mink\Tests\Driver\Js;
use Behat\Mink\Tests\Driver\TestCase;
class JavascriptEvaluationTest extends TestCase
{
/**
* Tests, that `wait` method returns check result after exit.
*/
public function testWaitReturnValue()
{
$this->getSession()->visit($this->pathTo('/js_test.html'));
$found = $this->getSession()->wait(5000, '$("#draggable").length == 1');
$this->assertTrue($found);
}
public function testWait()
{
$this->getSession()->visit($this->pathTo('/js_test.html'));
$waitable = $this->findById('waitable');
$waitable->click();
$this->getSession()->wait(3000, '$("#waitable").has("div").length > 0');
$this->assertEquals('arrived', $this->getAssertSession()->elementExists('css', '#waitable > div')->getText());
$waitable->click();
$this->getSession()->wait(3000, 'false');
$this->assertEquals('timeout', $this->getAssertSession()->elementExists('css', '#waitable > div')->getText());
}
/**
* @dataProvider provideExecutedScript
*/
public function testExecuteScript($script)
{
$this->getSession()->visit($this->pathTo('/index.html'));
$this->getSession()->executeScript($script);
sleep(1);
$heading = $this->getAssertSession()->elementExists('css', 'h1');
$this->assertEquals('Hello world', $heading->getText());
}
public function provideExecutedScript()
{
return array(
array('document.querySelector("h1").textContent = "Hello world"'),
array('document.querySelector("h1").textContent = "Hello world";'),
array('function () {document.querySelector("h1").textContent = "Hello world";}()'),
array('function () {document.querySelector("h1").textContent = "Hello world";}();'),
array('(function () {document.querySelector("h1").textContent = "Hello world";})()'),
array('(function () {document.querySelector("h1").textContent = "Hello world";})();'),
);
}
/**
* @dataProvider provideEvaluatedScript
*/
public function testEvaluateJavascript($script)
{
$this->getSession()->visit($this->pathTo('/index.html'));
$this->assertSame(2, $this->getSession()->evaluateScript($script));
}
public function provideEvaluatedScript()
{
return array(
array('1 + 1'),
array('1 + 1;'),
array('return 1 + 1'),
array('return 1 + 1;'),
array('function () {return 1+1;}()'),
array('(function () {return 1+1;})()'),
array('return function () { return 1+1;}()'),
array('return (function () {return 1+1;})()'),
);
}
}

View file

@ -0,0 +1,42 @@
<?php
namespace Behat\Mink\Tests\Driver\Js;
use Behat\Mink\Tests\Driver\TestCase;
class JavascriptTest extends TestCase
{
public function testAriaRoles()
{
$this->getSession()->visit($this->pathTo('/aria_roles.html'));
$this->getSession()->wait(5000, '$("#hidden-element").is(":visible") === false');
$this->getSession()->getPage()->pressButton('Toggle');
$this->getSession()->wait(5000, '$("#hidden-element").is(":visible") === true');
$this->getSession()->getPage()->clickLink('Go to Index');
$this->assertEquals($this->pathTo('/index.html'), $this->getSession()->getCurrentUrl());
}
public function testDragDrop()
{
$this->getSession()->visit($this->pathTo('/js_test.html'));
$webAssert = $this->getAssertSession();
$draggable = $webAssert->elementExists('css', '#draggable');
$droppable = $webAssert->elementExists('css', '#droppable');
$draggable->dragTo($droppable);
$this->assertEquals('Dropped!', $this->getAssertSession()->elementExists('css', 'p', $droppable)->getText());
}
// test accentuated char in button
public function testIssue225()
{
$this->getSession()->visit($this->pathTo('/issue225.html'));
$this->getSession()->getPage()->pressButton('Créer un compte');
$this->getSession()->wait(5000, '$("#panel").text() != ""');
$this->assertContains('OH AIH!', $this->getSession()->getPage()->getText());
}
}

View file

@ -0,0 +1,83 @@
<?php
namespace Behat\Mink\Tests\Driver\Js;
use Behat\Mink\Tests\Driver\TestCase;
class WindowTest extends TestCase
{
public function testWindow()
{
$this->getSession()->visit($this->pathTo('/window.html'));
$session = $this->getSession();
$page = $session->getPage();
$webAssert = $this->getAssertSession();
$page->clickLink('Popup #1');
$session->switchToWindow(null);
$page->clickLink('Popup #2');
$session->switchToWindow(null);
$el = $webAssert->elementExists('css', '#text');
$this->assertSame('Main window div text', $el->getText());
$session->switchToWindow('popup_1');
$el = $webAssert->elementExists('css', '#text');
$this->assertSame('Popup#1 div text', $el->getText());
$session->switchToWindow('popup_2');
$el = $webAssert->elementExists('css', '#text');
$this->assertSame('Popup#2 div text', $el->getText());
$session->switchToWindow(null);
$el = $webAssert->elementExists('css', '#text');
$this->assertSame('Main window div text', $el->getText());
}
public function testGetWindowNames()
{
$this->getSession()->visit($this->pathTo('/window.html'));
$session = $this->getSession();
$page = $session->getPage();
$windowName = $this->getSession()->getWindowName();
$this->assertNotNull($windowName);
$page->clickLink('Popup #1');
$page->clickLink('Popup #2');
$windowNames = $this->getSession()->getWindowNames();
$this->assertNotNull($windowNames[0]);
$this->assertNotNull($windowNames[1]);
$this->assertNotNull($windowNames[2]);
}
public function testResizeWindow()
{
$this->getSession()->visit($this->pathTo('/index.html'));
$session = $this->getSession();
$session->resizeWindow(400, 300);
$session->wait(1000, 'false');
$script = 'return Math.abs(window.outerHeight - 300) <= 100 && Math.abs(window.outerWidth - 400) <= 100;';
$this->assertTrue($session->evaluateScript($script));
}
public function testWindowMaximize()
{
$this->getSession()->visit($this->pathTo('/index.html'));
$session = $this->getSession();
$session->maximizeWindow();
$session->wait(1000, 'false');
$script = 'return Math.abs(screen.availHeight - window.outerHeight) <= 100;';
$this->assertTrue($session->evaluateScript($script));
}
}

View file

@ -0,0 +1,167 @@
<?php
namespace Behat\Mink\Tests\Driver;
use Behat\Mink\Exception\UnsupportedDriverActionException;
use Behat\Mink\Mink;
use Behat\Mink\Session;
use Behat\Mink\WebAssert;
abstract class TestCase extends \PHPUnit_Framework_TestCase
{
/**
* Mink session manager.
*
* @var Mink
*/
private static $mink;
/**
* @var AbstractConfig
*/
private static $config;
/**
* Initializes the test case.
*/
public static function setUpBeforeClass()
{
if (null === self::$mink) {
$session = new Session(self::getConfig()->createDriver());
self::$mink = new Mink(array('sess' => $session));
}
}
/**
* @return AbstractConfig
*
* @throws \UnexpectedValueException if the global driver_config_factory returns an invalid object
*/
private static function getConfig()
{
if (null === self::$config) {
self::$config = call_user_func($GLOBALS['driver_config_factory']);
if (!self::$config instanceof AbstractConfig) {
throw new \UnexpectedValueException('The "driver_config_factory" global variable must return a \Behat\Mink\Tests\Driver\AbstractConfig.');
}
}
return self::$config;
}
protected function checkRequirements()
{
if (null !== $message = self::getConfig()->skipMessage(get_class($this), $this->getName(false))) {
$this->markTestSkipped($message);
}
parent::checkRequirements();
}
protected function tearDown()
{
if (null !== self::$mink) {
self::$mink->resetSessions();
}
}
protected function onNotSuccessfulTest(\Exception $e)
{
if ($e instanceof UnsupportedDriverActionException) {
$this->markTestSkipped($e->getMessage());
}
parent::onNotSuccessfulTest($e);
}
/**
* Returns session.
*
* @return Session
*/
protected function getSession()
{
return self::$mink->getSession('sess');
}
/**
* Returns assert session.
*
* @return WebAssert
*/
protected function getAssertSession()
{
return self::$mink->assertSession('sess');
}
/**
* @param string $id
*
* @return \Behat\Mink\Element\NodeElement
*/
protected function findById($id)
{
return $this->getAssertSession()->elementExists('named', array('id', $id));
}
/**
* Creates a new driver instance.
*
* This driver is not associated to a session. It is meant to be used for tests on the driver
* implementation itself rather than test using the Mink API.
*
* @return \Behat\Mink\Driver\DriverInterface
*/
protected function createDriver()
{
return self::getConfig()->createDriver();
}
/**
* Map remote file path.
*
* @param string $file File path.
*
* @return string
*/
protected function mapRemoteFilePath($file)
{
$realPath = realpath($file);
if (false !== $realPath) {
$file = $realPath;
}
return self::getConfig()->mapRemoteFilePath($file);
}
/**
* @param string $path
*
* @return string
*/
protected function pathTo($path)
{
return rtrim(self::getConfig()->getWebFixturesUrl(), '/').'/'.ltrim($path, '/');
}
/**
* Waits for a condition to be true, considering than it is successful for drivers not supporting wait().
*
* @param int $time
* @param string $condition A JS condition to evaluate
*
* @return bool
*
* @see \Behat\Mink\Session::wait()
*/
protected function safePageWait($time, $condition)
{
try {
return $this->getSession()->wait($time, $condition);
} catch (UnsupportedDriverActionException $e) {
return true;
}
}
}