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,3 @@
vendor
composer.lock
/phpunit.xml

View file

@ -0,0 +1,27 @@
language: php
sudo: false
php: [5.3, 5.4, 5.5, 5.6, hhvm]
matrix:
include:
- php: 5.5
env: SYMFONY_VERSION='2.3.*'
- php: 5.5
env: SYMFONY_VERSION='2.5.*@dev'
cache:
directories:
- $HOME/.composer/cache/files
before_install:
- sh -c 'if [ "$SYMFONY_VERSION" != "" ]; then composer require -n --no-update symfony/symfony=$SYMFONY_VERSION; fi;'
install:
- composer install -n
script: phpunit -v --coverage-clover=coverage.clover
after_script:
- wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover coverage.clover

View file

@ -0,0 +1,54 @@
1.3.0 / 2015-09-21
==================
BC break:
* Dropped support for Symfony 2.2 and older
* Bumped required PHP version to 5.3.6
New features:
* Updated the driver to use findElementsXpaths for Mink 1.7 and forward compatibility with Mink 2
Bug fixes:
* Improved the exception message when clicking on an invalid element
* Use `saveHTML` to get correct HTML code back
Misc:
* Updated the repository structure to PSR-4
1.2.0 / 2014-09-26
==================
BC break:
* Changed the behavior of `getValue` for checkboxes according to the BC break in Mink 1.6
New features:
* Implemented `getOuterHtml`
* Added the support of manipulating forms without submit buttons
* Added support of any request headers instead of supporting only a few hardcoded ones
* Added support of any BrowserKit client using `filterResponse` when using BrowserKit 2.3+
* Added the support of reset buttons
* Implemented `submitForm`
* Implemented `isSelected`
Bug fixes:
* Fixed the support of options without value attribute in `isSelected` and `getValue`
* Added the support of radio buttons in `isChecked`
* Fixed the submission of empty textarea fields
* Refactored the handling of request headers to ensure they are reset when resetting the driver
* Fixed the handling of buttons to submit only for submit buttons rather than all buttons
* Fixed the code to throw exceptions rather than triggering a fatal error for invalid usages of the driver
* Fixed the removal of cookies
* Fixed the submission of form fields with same name and without id
* Fixed `getAttribute` to return `null` for missing attributes rather than an empty string
Testing:
* Updated the testsuite to use the new Mink 1.6 driver testsuite
* Added testing on HHVM

View file

@ -0,0 +1,22 @@
Copyright (c) 2012-2013 Konstantin Kudryashov <ever.zet@gmail.com>
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

54
vendor/behat/mink-browserkit-driver/README.md vendored Executable file
View file

@ -0,0 +1,54 @@
Mink BrowserKit Driver
======================
[![Latest Stable Version](https://poser.pugx.org/behat/mink-browserkit-driver/v/stable.png)](https://packagist.org/packages/behat/mink-browserkit-driver)
[![Latest Unstable Version](https://poser.pugx.org/behat/mink-browserkit-driver/v/unstable.svg)](https://packagist.org/packages/behat/mink-browserkit-driver)
[![Total Downloads](https://poser.pugx.org/behat/mink-browserkit-driver/downloads.png)](https://packagist.org/packages/behat/mink-browserkit-driver)
[![Build Status](https://travis-ci.org/minkphp/MinkBrowserKitDriver.svg?branch=master)](https://travis-ci.org/minkphp/MinkBrowserKitDriver)
[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/minkphp/MinkBrowserKitDriver/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/minkphp/MinkBrowserKitDriver/)
[![Code Coverage](https://scrutinizer-ci.com/g/minkphp/MinkBrowserKitDriver/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/minkphp/MinkBrowserKitDriver/)
[![License](https://poser.pugx.org/behat/mink-browserkit-driver/license.svg)](https://packagist.org/packages/behat/mink-browserkit-driver)
Usage Example
-------------
``` php
<?php
use Behat\Mink\Mink,
Behat\Mink\Session,
Behat\Mink\Driver\BrowserKitDriver;
use Symfony\Component\HttpKernel\Client;
$app = require_once(__DIR__.'/app.php'); // Silex app
$mink = new Mink(array(
'silex' => new Session(new BrowserKitDriver(new Client($app))),
));
$mink->getSession('silex')->getPage()->findLink('Chat')->click();
```
Installation
------------
``` json
{
"require": {
"behat/mink": "~1.5",
"behat/mink-browserkit-driver": "~1.1"
}
}
```
``` bash
$> curl -sS https://getcomposer.org/installer | php
$> php composer.phar install
```
Maintainers
-----------
* Christophe Coevoet [stof](https://github.com/stof)
* Other [awesome developers](https://github.com/minkphp/MinkBrowserKitDriver/graphs/contributors)

View file

@ -0,0 +1,46 @@
{
"name": "behat/mink-browserkit-driver",
"description": "Symfony2 BrowserKit driver for Mink framework",
"keywords": ["Symfony2", "Mink", "testing", "browser"],
"homepage": "http://mink.behat.org/",
"type": "mink-driver",
"license": "MIT",
"authors": [
{
"name": "Konstantin Kudryashov",
"email": "ever.zet@gmail.com",
"homepage": "http://everzet.com"
}
],
"require": {
"php": ">=5.3.6",
"behat/mink": "~1.7@dev",
"symfony/browser-kit": "~2.3",
"symfony/dom-crawler": "~2.3"
},
"require-dev": {
"symfony/phpunit-bridge": "~2.7",
"silex/silex": "~1.2"
},
"autoload": {
"psr-4": {
"Behat\\Mink\\Driver\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Behat\\Mink\\Tests\\Driver\\": "tests"
}
},
"extra": {
"branch-alias": {
"dev-master": "1.3.x-dev"
}
}
}

View file

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true" bootstrap="vendor/behat/mink/driver-testsuite/bootstrap.php">
<php>
<var name="driver_config_factory" value="Behat\Mink\Tests\Driver\BrowserKitConfig::getInstance" />
</php>
<testsuites>
<testsuite name="Driver test suite">
<directory>tests</directory>
<directory>vendor/behat/mink/driver-testsuite/tests/Basic</directory>
<directory>vendor/behat/mink/driver-testsuite/tests/Form</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src</directory>
</whitelist>
</filter>
</phpunit>

View file

@ -0,0 +1,855 @@
<?php
/*
* This file is part of the Behat\Mink.
* (c) Konstantin Kudryashov <ever.zet@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Behat\Mink\Driver;
use Behat\Mink\Exception\DriverException;
use Behat\Mink\Exception\UnsupportedDriverActionException;
use Symfony\Component\BrowserKit\Client;
use Symfony\Component\BrowserKit\Cookie;
use Symfony\Component\BrowserKit\Response;
use Symfony\Component\DomCrawler\Crawler;
use Symfony\Component\DomCrawler\Field\ChoiceFormField;
use Symfony\Component\DomCrawler\Field\FileFormField;
use Symfony\Component\DomCrawler\Field\FormField;
use Symfony\Component\DomCrawler\Field\InputFormField;
use Symfony\Component\DomCrawler\Field\TextareaFormField;
use Symfony\Component\DomCrawler\Form;
use Symfony\Component\HttpKernel\Client as HttpKernelClient;
/**
* Symfony2 BrowserKit driver.
*
* @author Konstantin Kudryashov <ever.zet@gmail.com>
*/
class BrowserKitDriver extends CoreDriver
{
private $client;
/**
* @var Form[]
*/
private $forms = array();
private $serverParameters = array();
private $started = false;
private $removeScriptFromUrl = false;
private $removeHostFromUrl = false;
/**
* Initializes BrowserKit driver.
*
* @param Client $client BrowserKit client instance
* @param string|null $baseUrl Base URL for HttpKernel clients
*/
public function __construct(Client $client, $baseUrl = null)
{
$this->client = $client;
$this->client->followRedirects(true);
if ($baseUrl !== null && $client instanceof HttpKernelClient) {
$client->setServerParameter('SCRIPT_FILENAME', parse_url($baseUrl, PHP_URL_PATH));
}
}
/**
* Returns BrowserKit HTTP client instance.
*
* @return Client
*/
public function getClient()
{
return $this->client;
}
/**
* Tells driver to remove hostname from URL.
*
* @param Boolean $remove
*
* @deprecated Deprecated as of 1.2, to be removed in 2.0. Pass the base url in the constructor instead.
*/
public function setRemoveHostFromUrl($remove = true)
{
trigger_error(
'setRemoveHostFromUrl() is deprecated as of 1.2 and will be removed in 2.0. Pass the base url in the constructor instead.',
E_USER_DEPRECATED
);
$this->removeHostFromUrl = (bool) $remove;
}
/**
* Tells driver to remove script name from URL.
*
* @param Boolean $remove
*
* @deprecated Deprecated as of 1.2, to be removed in 2.0. Pass the base url in the constructor instead.
*/
public function setRemoveScriptFromUrl($remove = true)
{
trigger_error(
'setRemoveScriptFromUrl() is deprecated as of 1.2 and will be removed in 2.0. Pass the base url in the constructor instead.',
E_USER_DEPRECATED
);
$this->removeScriptFromUrl = (bool) $remove;
}
/**
* {@inheritdoc}
*/
public function start()
{
$this->started = true;
}
/**
* {@inheritdoc}
*/
public function isStarted()
{
return $this->started;
}
/**
* {@inheritdoc}
*/
public function stop()
{
$this->reset();
$this->started = false;
}
/**
* {@inheritdoc}
*/
public function reset()
{
// Restarting the client resets the cookies and the history
$this->client->restart();
$this->forms = array();
$this->serverParameters = array();
}
/**
* {@inheritdoc}
*/
public function visit($url)
{
$this->client->request('GET', $this->prepareUrl($url), array(), array(), $this->serverParameters);
$this->forms = array();
}
/**
* {@inheritdoc}
*/
public function getCurrentUrl()
{
$request = $this->client->getInternalRequest();
if ($request === null) {
throw new DriverException('Unable to access the request before visiting a page');
}
return $request->getUri();
}
/**
* {@inheritdoc}
*/
public function reload()
{
$this->client->reload();
$this->forms = array();
}
/**
* {@inheritdoc}
*/
public function forward()
{
$this->client->forward();
$this->forms = array();
}
/**
* {@inheritdoc}
*/
public function back()
{
$this->client->back();
$this->forms = array();
}
/**
* {@inheritdoc}
*/
public function setBasicAuth($user, $password)
{
if (false === $user) {
unset($this->serverParameters['PHP_AUTH_USER'], $this->serverParameters['PHP_AUTH_PW']);
return;
}
$this->serverParameters['PHP_AUTH_USER'] = $user;
$this->serverParameters['PHP_AUTH_PW'] = $password;
}
/**
* {@inheritdoc}
*/
public function setRequestHeader($name, $value)
{
$contentHeaders = array('CONTENT_LENGTH' => true, 'CONTENT_MD5' => true, 'CONTENT_TYPE' => true);
$name = str_replace('-', '_', strtoupper($name));
// CONTENT_* are not prefixed with HTTP_ in PHP when building $_SERVER
if (!isset($contentHeaders[$name])) {
$name = 'HTTP_' . $name;
}
$this->serverParameters[$name] = $value;
}
/**
* {@inheritdoc}
*/
public function getResponseHeaders()
{
return $this->getResponse()->getHeaders();
}
/**
* {@inheritdoc}
*/
public function setCookie($name, $value = null)
{
if (null === $value) {
$this->deleteCookie($name);
return;
}
$jar = $this->client->getCookieJar();
$jar->set(new Cookie($name, $value));
}
/**
* Deletes a cookie by name.
*
* @param string $name Cookie name.
*/
private function deleteCookie($name)
{
$path = $this->getCookiePath();
$jar = $this->client->getCookieJar();
do {
if (null !== $jar->get($name, $path)) {
$jar->expire($name, $path);
}
$path = preg_replace('/.$/', '', $path);
} while ($path);
}
/**
* Returns current cookie path.
*
* @return string
*/
private function getCookiePath()
{
$path = dirname(parse_url($this->getCurrentUrl(), PHP_URL_PATH));
if ('\\' === DIRECTORY_SEPARATOR) {
$path = str_replace('\\', '/', $path);
}
return $path;
}
/**
* {@inheritdoc}
*/
public function getCookie($name)
{
// Note that the following doesn't work well because
// Symfony\Component\BrowserKit\CookieJar stores cookies by name,
// path, AND domain and if you don't fill them all in correctly then
// you won't get the value that you're expecting.
//
// $jar = $this->client->getCookieJar();
//
// if (null !== $cookie = $jar->get($name)) {
// return $cookie->getValue();
// }
$allValues = $this->client->getCookieJar()->allValues($this->getCurrentUrl());
if (isset($allValues[$name])) {
return $allValues[$name];
}
return null;
}
/**
* {@inheritdoc}
*/
public function getStatusCode()
{
return $this->getResponse()->getStatus();
}
/**
* {@inheritdoc}
*/
public function getContent()
{
return $this->getResponse()->getContent();
}
/**
* {@inheritdoc}
*/
public function findElementXpaths($xpath)
{
$nodes = $this->getCrawler()->filterXPath($xpath);
$elements = array();
foreach ($nodes as $i => $node) {
$elements[] = sprintf('(%s)[%d]', $xpath, $i + 1);
}
return $elements;
}
/**
* {@inheritdoc}
*/
public function getTagName($xpath)
{
return $this->getCrawlerNode($this->getFilteredCrawler($xpath))->nodeName;
}
/**
* {@inheritdoc}
*/
public function getText($xpath)
{
$text = $this->getFilteredCrawler($xpath)->text();
$text = str_replace("\n", ' ', $text);
$text = preg_replace('/ {2,}/', ' ', $text);
return trim($text);
}
/**
* {@inheritdoc}
*/
public function getHtml($xpath)
{
// cut the tag itself (making innerHTML out of outerHTML)
return preg_replace('/^\<[^\>]+\>|\<[^\>]+\>$/', '', $this->getOuterHtml($xpath));
}
/**
* {@inheritdoc}
*/
public function getOuterHtml($xpath)
{
$node = $this->getCrawlerNode($this->getFilteredCrawler($xpath));
return $node->ownerDocument->saveHTML($node);
}
/**
* {@inheritdoc}
*/
public function getAttribute($xpath, $name)
{
$node = $this->getFilteredCrawler($xpath);
if ($this->getCrawlerNode($node)->hasAttribute($name)) {
return $node->attr($name);
}
return null;
}
/**
* {@inheritdoc}
*/
public function getValue($xpath)
{
if (in_array($this->getAttribute($xpath, 'type'), array('submit', 'image', 'button'), true)) {
return $this->getAttribute($xpath, 'value');
}
$node = $this->getCrawlerNode($this->getFilteredCrawler($xpath));
if ('option' === $node->tagName) {
return $this->getOptionValue($node);
}
try {
$field = $this->getFormField($xpath);
} catch (\InvalidArgumentException $e) {
return $this->getAttribute($xpath, 'value');
}
return $field->getValue();
}
/**
* {@inheritdoc}
*/
public function setValue($xpath, $value)
{
$this->getFormField($xpath)->setValue($value);
}
/**
* {@inheritdoc}
*/
public function check($xpath)
{
$this->getCheckboxField($xpath)->tick();
}
/**
* {@inheritdoc}
*/
public function uncheck($xpath)
{
$this->getCheckboxField($xpath)->untick();
}
/**
* {@inheritdoc}
*/
public function selectOption($xpath, $value, $multiple = false)
{
$field = $this->getFormField($xpath);
if (!$field instanceof ChoiceFormField) {
throw new DriverException(sprintf('Impossible to select an option on the element with XPath "%s" as it is not a select or radio input', $xpath));
}
if ($multiple) {
$oldValue = (array) $field->getValue();
$oldValue[] = $value;
$value = $oldValue;
}
$field->select($value);
}
/**
* {@inheritdoc}
*/
public function isSelected($xpath)
{
$optionValue = $this->getOptionValue($this->getCrawlerNode($this->getFilteredCrawler($xpath)));
$selectField = $this->getFormField('(' . $xpath . ')/ancestor-or-self::*[local-name()="select"]');
$selectValue = $selectField->getValue();
return is_array($selectValue) ? in_array($optionValue, $selectValue, true) : $optionValue === $selectValue;
}
/**
* {@inheritdoc}
*/
public function click($xpath)
{
$crawler = $this->getFilteredCrawler($xpath);
$node = $this->getCrawlerNode($crawler);
$tagName = $node->nodeName;
if ('a' === $tagName) {
$this->client->click($crawler->link());
$this->forms = array();
} elseif ($this->canSubmitForm($node)) {
$this->submit($crawler->form());
} elseif ($this->canResetForm($node)) {
$this->resetForm($node);
} else {
$message = sprintf('%%s supports clicking on links and submit or reset buttons only. But "%s" provided', $tagName);
throw new UnsupportedDriverActionException($message, $this);
}
}
/**
* {@inheritdoc}
*/
public function isChecked($xpath)
{
$field = $this->getFormField($xpath);
if (!$field instanceof ChoiceFormField || 'select' === $field->getType()) {
throw new DriverException(sprintf('Impossible to get the checked state of the element with XPath "%s" as it is not a checkbox or radio input', $xpath));
}
if ('checkbox' === $field->getType()) {
return $field->hasValue();
}
$radio = $this->getCrawlerNode($this->getFilteredCrawler($xpath));
return $radio->getAttribute('value') === $field->getValue();
}
/**
* {@inheritdoc}
*/
public function attachFile($xpath, $path)
{
$field = $this->getFormField($xpath);
if (!$field instanceof FileFormField) {
throw new DriverException(sprintf('Impossible to attach a file on the element with XPath "%s" as it is not a file input', $xpath));
}
$field->upload($path);
}
/**
* {@inheritdoc}
*/
public function submitForm($xpath)
{
$crawler = $this->getFilteredCrawler($xpath);
$this->submit($crawler->form());
}
/**
* @return Response
*
* @throws DriverException If there is not response yet
*/
protected function getResponse()
{
$response = $this->client->getInternalResponse();
if (null === $response) {
throw new DriverException('Unable to access the response before visiting a page');
}
return $response;
}
/**
* Prepares URL for visiting.
* Removes "*.php/" from urls and then passes it to BrowserKitDriver::visit().
*
* @param string $url
*
* @return string
*/
protected function prepareUrl($url)
{
$replacement = ($this->removeHostFromUrl ? '' : '$1') . ($this->removeScriptFromUrl ? '' : '$2');
return preg_replace('#(https?\://[^/]+)(/[^/\.]+\.php)?#', $replacement, $url);
}
/**
* Returns form field from XPath query.
*
* @param string $xpath
*
* @return FormField
*
* @throws DriverException
*/
protected function getFormField($xpath)
{
$fieldNode = $this->getCrawlerNode($this->getFilteredCrawler($xpath));
$fieldName = str_replace('[]', '', $fieldNode->getAttribute('name'));
$formNode = $this->getFormNode($fieldNode);
$formId = $this->getFormNodeId($formNode);
if (!isset($this->forms[$formId])) {
$this->forms[$formId] = new Form($formNode, $this->getCurrentUrl());
}
if (is_array($this->forms[$formId][$fieldName])) {
return $this->forms[$formId][$fieldName][$this->getFieldPosition($fieldNode)];
}
return $this->forms[$formId][$fieldName];
}
/**
* Returns the checkbox field from xpath query, ensuring it is valid.
*
* @param string $xpath
*
* @return ChoiceFormField
*
* @throws DriverException when the field is not a checkbox
*/
private function getCheckboxField($xpath)
{
$field = $this->getFormField($xpath);
if (!$field instanceof ChoiceFormField) {
throw new DriverException(sprintf('Impossible to check the element with XPath "%s" as it is not a checkbox', $xpath));
}
return $field;
}
/**
* @param \DOMElement $element
*
* @return \DOMElement
*
* @throws DriverException if the form node cannot be found
*/
private function getFormNode(\DOMElement $element)
{
if ($element->hasAttribute('form')) {
$formId = $element->getAttribute('form');
$formNode = $element->ownerDocument->getElementById($formId);
if (null === $formNode || 'form' !== $formNode->nodeName) {
throw new DriverException(sprintf('The selected node has an invalid form attribute (%s).', $formId));
}
return $formNode;
}
$formNode = $element;
do {
// use the ancestor form element
if (null === $formNode = $formNode->parentNode) {
throw new DriverException('The selected node does not have a form ancestor.');
}
} while ('form' !== $formNode->nodeName);
return $formNode;
}
/**
* Gets the position of the field node among elements with the same name
*
* BrowserKit uses the field name as index to find the field in its Form object.
* When multiple fields have the same name (checkboxes for instance), it will return
* an array of elements in the order they appear in the DOM.
*
* @param \DOMElement $fieldNode
*
* @return integer
*/
private function getFieldPosition(\DOMElement $fieldNode)
{
$elements = $this->getCrawler()->filterXPath('//*[@name=\''.$fieldNode->getAttribute('name').'\']');
if (count($elements) > 1) {
// more than one element contains this name !
// so we need to find the position of $fieldNode
foreach ($elements as $key => $element) {
/** @var \DOMElement $element */
if ($element->getNodePath() === $fieldNode->getNodePath()) {
return $key;
}
}
}
return 0;
}
private function submit(Form $form)
{
$formId = $this->getFormNodeId($form->getFormNode());
if (isset($this->forms[$formId])) {
$this->mergeForms($form, $this->forms[$formId]);
}
// remove empty file fields from request
foreach ($form->getFiles() as $name => $field) {
if (empty($field['name']) && empty($field['tmp_name'])) {
$form->remove($name);
}
}
foreach ($form->all() as $field) {
// Add a fix for https://github.com/symfony/symfony/pull/10733 to support Symfony versions which are not fixed
if ($field instanceof TextareaFormField && null === $field->getValue()) {
$field->setValue('');
}
}
$this->client->submit($form);
$this->forms = array();
}
private function resetForm(\DOMElement $fieldNode)
{
$formNode = $this->getFormNode($fieldNode);
$formId = $this->getFormNodeId($formNode);
unset($this->forms[$formId]);
}
/**
* Determines if a node can submit a form.
*
* @param \DOMElement $node Node.
*
* @return boolean
*/
private function canSubmitForm(\DOMElement $node)
{
$type = $node->hasAttribute('type') ? $node->getAttribute('type') : null;
if ('input' === $node->nodeName && in_array($type, array('submit', 'image'), true)) {
return true;
}
return 'button' === $node->nodeName && (null === $type || 'submit' === $type);
}
/**
* Determines if a node can reset a form.
*
* @param \DOMElement $node Node.
*
* @return boolean
*/
private function canResetForm(\DOMElement $node)
{
$type = $node->hasAttribute('type') ? $node->getAttribute('type') : null;
return in_array($node->nodeName, array('input', 'button'), true) && 'reset' === $type;
}
/**
* Returns form node unique identifier.
*
* @param \DOMElement $form
*
* @return string
*/
private function getFormNodeId(\DOMElement $form)
{
return md5($form->getLineNo() . $form->getNodePath() . $form->nodeValue);
}
/**
* Gets the value of an option element
*
* @param \DOMElement $option
*
* @return string
*
* @see \Symfony\Component\DomCrawler\Field\ChoiceFormField::buildOptionValue
*/
private function getOptionValue(\DOMElement $option)
{
if ($option->hasAttribute('value')) {
return $option->getAttribute('value');
}
if (!empty($option->nodeValue)) {
return $option->nodeValue;
}
return '1'; // DomCrawler uses 1 by default if there is no text in the option
}
/**
* Merges second form values into first one.
*
* @param Form $to merging target
* @param Form $from merging source
*/
private function mergeForms(Form $to, Form $from)
{
foreach ($from->all() as $name => $field) {
$fieldReflection = new \ReflectionObject($field);
$nodeReflection = $fieldReflection->getProperty('node');
$valueReflection = $fieldReflection->getProperty('value');
$nodeReflection->setAccessible(true);
$valueReflection->setAccessible(true);
$isIgnoredField = $field instanceof InputFormField &&
in_array($nodeReflection->getValue($field)->getAttribute('type'), array('submit', 'button', 'image'), true);
if (!$isIgnoredField) {
$valueReflection->setValue($to[$name], $valueReflection->getValue($field));
}
}
}
/**
* Returns DOMElement from crawler instance.
*
* @param Crawler $crawler
*
* @return \DOMElement
*
* @throws DriverException when the node does not exist
*/
private function getCrawlerNode(Crawler $crawler)
{
$crawler->rewind();
$node = $crawler->current();
if (null !== $node) {
return $node;
}
throw new DriverException('The element does not exist');
}
/**
* Returns a crawler filtered for the given XPath, requiring at least 1 result.
*
* @param string $xpath
*
* @return Crawler
*
* @throws DriverException when no matching elements are found
*/
private function getFilteredCrawler($xpath)
{
if (!count($crawler = $this->getCrawler()->filterXPath($xpath))) {
throw new DriverException(sprintf('There is no element matching XPath "%s"', $xpath));
}
return $crawler;
}
/**
* Returns crawler instance (got from client).
*
* @return Crawler
*
* @throws DriverException
*/
private function getCrawler()
{
$crawler = $this->client->getCrawler();
if (null === $crawler) {
throw new DriverException('Unable to access the response content before visiting a page');
}
return $crawler;
}
}

View file

@ -0,0 +1,37 @@
<?php
namespace Behat\Mink\Tests\Driver;
use Behat\Mink\Driver\BrowserKitDriver;
use Symfony\Component\HttpKernel\Client;
class BrowserKitConfig extends AbstractConfig
{
public static function getInstance()
{
return new self();
}
/**
* {@inheritdoc}
*/
public function createDriver()
{
$client = new Client(require(__DIR__.'/app.php'));
return new BrowserKitDriver($client);
}
/**
* {@inheritdoc}
*/
public function getWebFixturesUrl()
{
return 'http://localhost';
}
protected function supportsJs()
{
return false;
}
}

View file

@ -0,0 +1,24 @@
<?php
namespace Behat\Mink\Tests\Driver\Custom;
use Behat\Mink\Driver\BrowserKitDriver;
use Behat\Mink\Session;
use Symfony\Component\HttpKernel\Client;
/**
* @group functional
*/
class BaseUrlTest extends \PHPUnit_Framework_TestCase
{
public function testBaseUrl()
{
$client = new Client(require(__DIR__.'/../app.php'));
$driver = new BrowserKitDriver($client, 'http://localhost/foo/');
$session = new Session($driver);
$session->visit('http://localhost/foo/index.html');
$this->assertEquals(200, $session->getStatusCode());
$this->assertEquals('http://localhost/foo/index.html', $session->getCurrentUrl());
}
}

View file

@ -0,0 +1,181 @@
<?php
namespace Behat\Mink\Tests\Driver\Custom;
use Behat\Mink\Driver\BrowserKitDriver;
use Symfony\Component\BrowserKit\Client;
use Symfony\Component\BrowserKit\Response;
class ErrorHandlingTest extends \PHPUnit_Framework_TestCase
{
/**
* @var TestClient
*/
private $client;
protected function setUp()
{
$this->client = new TestClient();
}
public function testGetClient()
{
$this->assertSame($this->client, $this->getDriver()->getClient());
}
/**
* @expectedException \Behat\Mink\Exception\DriverException
* @expectedExceptionMessage Unable to access the response before visiting a page
*/
public function testGetResponseHeaderWithoutVisit()
{
$this->getDriver()->getResponseHeaders();
}
/**
* @expectedException \Behat\Mink\Exception\DriverException
* @expectedExceptionMessage Unable to access the response content before visiting a page
*/
public function testFindWithoutVisit()
{
$this->getDriver()->find('//html');
}
/**
* @expectedException \Behat\Mink\Exception\DriverException
* @expectedExceptionMessage Unable to access the request before visiting a page
*/
public function testGetCurrentUrlWithoutVisit()
{
$this->getDriver()->getCurrentUrl();
}
/**
* @expectedException \Behat\Mink\Exception\DriverException
* @expectedExceptionMessage The selected node has an invalid form attribute (foo)
*/
public function testNotMatchingHtml5FormId()
{
$html = <<<'HTML'
<html>
<body>
<form id="test">
<input name="test" value="foo" form="foo">
<input type="submit">
</form>
</body>
</html>
HTML;
$this->client->setNextResponse(new Response($html));
$driver = $this->getDriver();
$driver->visit('/index.php');
$driver->setValue('//input[./@name="test"]', 'bar');
}
/**
* @expectedException \Behat\Mink\Exception\DriverException
* @expectedExceptionMessage The selected node has an invalid form attribute (foo)
*/
public function testInvalidHtml5FormId()
{
$html = <<<'HTML'
<html>
<body>
<form id="test">
<input name="test" value="foo" form="foo">
<input type="submit">
</form>
<div id="foo"></div>
</body>
</html>
HTML;
$this->client->setNextResponse(new Response($html));
$driver = $this->getDriver();
$driver->visit('/index.php');
$driver->setValue('//input[./@name="test"]', 'bar');
}
/**
* @expectedException \Behat\Mink\Exception\DriverException
* @expectedExceptionMessage The selected node does not have a form ancestor.
*/
public function testManipulateInputWithoutForm()
{
$html = <<<'HTML'
<html>
<body>
<form id="test">
<input type="submit">
</form>
<div id="foo">
<input name="test" value="foo">
</div>
</body>
</html>
HTML;
$this->client->setNextResponse(new Response($html));
$driver = $this->getDriver();
$driver->visit('/index.php');
$driver->setValue('//input[./@name="test"]', 'bar');
}
/**
* @expectedException \Behat\Mink\Exception\DriverException
* @expectedExceptionMessage Behat\Mink\Driver\BrowserKitDriver supports clicking on links and submit or reset buttons only. But "div" provided
*/
public function testClickOnUnsupportedElement()
{
$html = <<<'HTML'
<html>
<body>
<div></div>
</body>
</html>
HTML;
$this->client->setNextResponse(new Response($html));
$driver = $this->getDriver();
$driver->visit('/index.php');
$driver->click('//div');
}
private function getDriver()
{
return new BrowserKitDriver($this->client);
}
}
class TestClient extends Client
{
protected $nextResponse = null;
protected $nextScript = null;
public function setNextResponse(Response $response)
{
$this->nextResponse = $response;
}
public function setNextScript($script)
{
$this->nextScript = $script;
}
protected function doRequest($request)
{
if (null === $this->nextResponse) {
return new Response();
}
$response = $this->nextResponse;
$this->nextResponse = null;
return $response;
}
}

View file

@ -0,0 +1,37 @@
<?php
namespace app;
$app = new \Silex\Application();
$app->register(new \Silex\Provider\SessionServiceProvider());
$def = realpath(__DIR__.'/../vendor/behat/mink/driver-testsuite/web-fixtures');
$ovr = realpath(__DIR__.'/web-fixtures');
$cbk = function ($file) use ($app, $def, $ovr) {
$file = str_replace('.file', '.php', $file);
$path = file_exists($ovr.'/'.$file) ? $ovr.'/'.$file : $def.'/'.$file;
$resp = null;
ob_start();
include($path);
$content = ob_get_clean();
if ($resp) {
if ('' === $resp->getContent()) {
$resp->setContent($content);
}
return $resp;
}
return $content;
};
$app->get('/{file}', $cbk)->assert('file', '.*');
$app->post('/{file}', $cbk)->assert('file', '.*');
$app['debug'] = true;
$app['exception_handler']->disable();
$app['session.test'] = true;
return $app;

View file

@ -0,0 +1,3 @@
<?php
$resp = new Symfony\Component\HttpFoundation\Response('Sorry, page not found', 404);

View file

@ -0,0 +1,3 @@
<?php
$resp = new Symfony\Component\HttpFoundation\Response('Sorry, a server error happened', 500);

View file

@ -0,0 +1,32 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru">
<head>
<title>Advanced form save</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
</head>
<body>
<?php
error_reporting(0);
$request = $app['request'];
$POST = $request->request->all();
$FILES = $request->files->all();
if (isset($POST['select_multiple_numbers']) && false !== strpos($POST['select_multiple_numbers'][0], ',')) {
$POST['select_multiple_numbers'] = explode(',', $POST['select_multiple_numbers'][0]);
}
// checkbox can have any value and will be successful in case "on"
// http://www.w3.org/TR/html401/interact/forms.html#checkbox
$POST['agreement'] = isset($POST['agreement']) ? 'on' : 'off';
ksort($POST);
echo str_replace('>', '', var_export($POST, true)) . "\n";
if (isset($FILES['about']) && file_exists($FILES['about']->getPathname())) {
echo $FILES['about']->getClientOriginalName() . "\n";
echo file_get_contents($FILES['about']->getPathname());
} else {
echo "no file";
}
?>
</body>
</html>

View file

@ -0,0 +1,15 @@
<?php
$SERVER = $app['request']->server->all();
$username = isset($SERVER['PHP_AUTH_USER']) ? $SERVER['PHP_AUTH_USER'] : false;
$password = isset($SERVER['PHP_AUTH_PW']) ? $SERVER['PHP_AUTH_PW'] : false;
if ($username == 'mink-user' && $password == 'mink-password') {
echo 'is authenticated';
} else {
$resp = new \Symfony\Component\HttpFoundation\Response();
$resp->setStatusCode(401);
$resp->headers->set('WWW-Authenticate', 'Basic realm="Mink Testing Area"');
echo 'is not authenticated';
}

View file

@ -0,0 +1,14 @@
<?php ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru">
<head>
<title>Basic Form Saving</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
</head>
<body>
<h1>Anket for <?php echo $app['request']->request->get('first_name') ?></h1>
<span id="first">Firstname: <?php echo $app['request']->request->get('first_name') ?></span>
<span id="last">Lastname: <?php echo $app['request']->request->get('last_name') ?></span>
</body>
</html>

View file

@ -0,0 +1,23 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru">
<head>
<title>Basic Get Form</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
</head>
<body>
<h1>Basic Get Form Page</h1>
<div id="serach">
<?php
$GET = $app['request']->query->all();
echo isset($GET['q']) && $GET['q'] ? $GET['q'] : 'No search query'
?>
</div>
<form>
<input name="q" value="" type="text" />
<input type="submit" value="Find" />
</form>
</body>
</html>

View file

@ -0,0 +1,17 @@
<?php
$resp = new Symfony\Component\HttpFoundation\Response();
$cook = new Symfony\Component\HttpFoundation\Cookie('srvr_cookie', 'srv_var_is_set', 0, '/');
$resp->headers->setCookie($cook);
?>
<!doctype html public "-//w3c//dtd xhtml 1.1//en" "http://www.w3.org/tr/xhtml11/dtd/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru">
<head>
<title>basic form</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<script>
</script>
</head>
<body>
basic page with cookie set from server side
</body>
</html>

View file

@ -0,0 +1,14 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru">
<head>
<title>Basic Form</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
<script>
</script>
</head>
<body>
Previous cookie: <?php
echo $app['request']->cookies->has('srvr_cookie') ? $app['request']->cookies->get('srvr_cookie') : 'NO';
?>
</body>
</html>

View file

@ -0,0 +1,20 @@
<?php
$hasCookie = $app['request']->cookies->has('foo');
$resp = new Symfony\Component\HttpFoundation\Response();
$cook = new Symfony\Component\HttpFoundation\Cookie('foo', 'bar');
$resp->headers->setCookie($cook);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru">
<head>
<title>HttpOnly Cookie Test</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
<script>
</script>
</head>
<body>
<div id="cookie-status">Has Cookie: <?php echo json_encode($hasCookie) ?></div>
</body>
</html>

View file

@ -0,0 +1,10 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru">
<head>
<title>Headers page</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
</head>
<body>
<?php print_r($app['request']->server->all()); ?>
</body>
</html>

View file

@ -0,0 +1,14 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html>
<body>
<?php
if ('1' === $app['request']->query->get('p')) {
echo '<a href="/issue130.php?p=2">Go to 2</a>';
} else {
echo '<strong>'.$app['request']->headers->get('referer').'</strong>';
}
?>
</body>

View file

@ -0,0 +1,20 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html>
<body>
<?php if ($app['request']->isMethod('POST')) {
$resp = new Symfony\Component\HttpFoundation\Response();
$cook = new Symfony\Component\HttpFoundation\Cookie('tc', $app['request']->request->get('cookie_value'));
$resp->headers->setCookie($cook);
} elseif ($app['request']->query->has('show_value')) {
echo $app['request']->cookies->get('tc');
return;
}
?>
<form method="post">
<input name="cookie_value">
<input type="submit" value="Set cookie">
</form>
</body>

View file

@ -0,0 +1,25 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru">
<head>
<title>Cookies page</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
</head>
<body>
<?php
$cookies = $app['request']->cookies->all();
unset($cookies['MOCKSESSID']);
if (isset($cookies['srvr_cookie'])) {
$srvrCookie = $cookies['srvr_cookie'];
unset($cookies['srvr_cookie']);
$cookies['_SESS'] = '';
$cookies['srvr_cookie'] = $srvrCookie;
}
foreach ($cookies as $name => $val) {
$cookies[$name] = (string)$val;
}
echo str_replace(array('>'), '', var_export($cookies, true));
?>
</body>
</html>

View file

@ -0,0 +1,3 @@
<?php
$resp = new Symfony\Component\HttpFoundation\RedirectResponse('/redirect_destination.html');

View file

@ -0,0 +1,15 @@
<?php
$resp = new Symfony\Component\HttpFoundation\Response();
$resp->headers->set('X-Mink-Test', 'response-headers');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Response headers</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<h1>Response headers</h1>
</body>
</html>

View file

@ -0,0 +1,19 @@
<?php
$session = $app['request']->getSession();
if ($app['request']->query->has('login')) {
$session->migrate();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru">
<head>
<title>Session Test</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
<script>
</script>
</head>
<body>
<div id="session-id"><?php echo $session->getId() ?></div>
</body>
</html>

View file

@ -0,0 +1,18 @@
<?php
$requestUri = $app['request']->server->get('REQUEST_URI');
$resp = new Symfony\Component\HttpFoundation\Response();
$cook = new Symfony\Component\HttpFoundation\Cookie('srvr_cookie', 'srv_var_is_set_sub_folder', 0, dirname($requestUri));
$resp->headers->setCookie($cook);
?>
<!doctype html public "-//w3c//dtd xhtml 1.1//en" "http://www.w3.org/tr/xhtml11/dtd/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru">
<head>
<title>basic form</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<script>
</script>
</head>
<body>
basic page with cookie set from server side
</body>
</html>

View file

@ -0,0 +1,18 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru">
<head>
<title>Basic Form</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
<script>
</script>
</head>
<body>
Previous cookie: <?php
if ($app['request']->cookies->has('srvr_cookie')) {
echo $app['request']->cookies->get('srvr_cookie');
} else {
echo 'NO';
}
?>
</body>
</html>