Skip to content
Browse files

Merge branch 'release/0.3.2'

  • Loading branch information...
2 parents 6af1fc4 + 8ae0ec3 commit 0760e650ac2dcf38670258203ab23eac1e2ac0e7 @everzet everzet committed Jun 20, 2011
View
2 .gitmodules
@@ -1,6 +1,6 @@
[submodule "vendor/Goutte"]
path = vendor/Goutte
- url = git://github.com/fabpot/Goutte.git
+ url = git://github.com/everzet/Goutte.git
[submodule "vendor/Symfony/Component/CssSelector"]
path = vendor/Symfony/Component/CssSelector
url = git://github.com/symfony/CssSelector.git
View
11 CHANGES.md
@@ -1,3 +1,14 @@
+0.3.2 / 2011-06-20
+==================
+
+ * Fixed file uploads in Goutte driver
+ * Fixed setting of long texts into fields
+ * Added getPlainText() (returns text without tags and whitespaces) method to the element's API
+ * Start_url is now optional parameter
+ * Default session (if needed) name now need to be always specified by hands with setDefaultSessionName()
+ * default_driver => default_session
+ * Updated Symfony Components
+
0.3.1 / 2011-05-17
==================
View
9 src/Behat/Mink/Driver/GoutteDriver.php
@@ -28,7 +28,6 @@
*/
class GoutteDriver implements DriverInterface
{
- private $startUrl;
private $session;
private $client;
private $forms = array();
@@ -37,17 +36,15 @@ class GoutteDriver implements DriverInterface
/**
* Initializes Goutte driver.
*
- * @param string $startUrl url to start from
* @param Symfony\Component\BrowserKit\Client $client BrowserKit client instance
*/
- public function __construct($startUrl, Client $client = null)
+ public function __construct(Client $client = null)
{
if (null === $client) {
$client = new GoutteClient();
}
- $this->startUrl = $startUrl;
- $this->client = $client;
+ $this->client = $client;
$this->client->followRedirects(true);
}
@@ -74,7 +71,6 @@ public function setSession(Session $session)
*/
public function start()
{
- $this->visit($this->startUrl);
$this->started = true;
}
@@ -100,7 +96,6 @@ public function stop()
public function reset()
{
$this->client->restart();
- $this->start();
}
/**
View
15 src/Behat/Mink/Driver/SahiDriver.php
@@ -25,27 +25,24 @@
class SahiDriver implements DriverInterface
{
private $started = false;
- private $startUrl;
private $browserName;
private $client;
private $session;
/**
* Initialie Sahi driver.
*
- * @param string $startUrl url to start from
* @param string $browserName browser to start (firefox, safari, ie, etc...)
* @param Behat\SahiClient\Client $client Sahi client instance
*/
- public function __construct($startUrl, $browserName, Client $client = null)
+ public function __construct($browserName, Client $client = null)
{
if (null === $client) {
$client = new Client();
}
- $this->client = $client;
- $this->startUrl = $startUrl;
- $this->browserName = $browserName;
+ $this->client = $client;
+ $this->browserName = $browserName;
}
/**
@@ -72,7 +69,6 @@ public function setSession(Session $session)
public function start()
{
$this->client->start($this->browserName);
- $this->reset();
$this->started = true;
}
@@ -96,10 +92,7 @@ public function stop()
/**
* @see Behat\Mink\Driver\DriverInterface::reset()
*/
- public function reset()
- {
- $this->visit($this->startUrl);
- }
+ public function reset() {}
/**
* @see Behat\Mink\Driver\DriverInterface::visit()
View
26 src/Behat/Mink/Element/Element.php
@@ -68,4 +68,30 @@ public function hasSelector($selector, $locator)
{
return null !== $this->find($selector, $locator);
}
+
+ /**
+ * Returns element text.
+ *
+ * @return string|null
+ */
+ abstract public function getText();
+
+ /**
+ * Returns element text with trimmed tags and non-printable chars.
+ *
+ * @return string|null
+ */
+ public function getPlainText()
+ {
+ $text = $this->getText();
+
+ if (null !== $text) {
+ $text = str_replace("\n", ' ', $text);
+ $text = preg_replace('/\<br *\/?\>/i', "\n", $text);
+ $text = strip_tags($text);
+ $text = preg_replace('/ {2,}/', ' ', $text);
+
+ return $text;
+ }
+ }
}
View
10 src/Behat/Mink/Element/NodeElement.php
@@ -139,6 +139,16 @@ public function selectOption($option)
}
/**
+ * Attach file to current node if it's a file input.
+ *
+ * @param string $path path to file (local)
+ */
+ public function attachFile($path)
+ {
+ $this->getSession()->getDriver()->attachFile($this->getXpath(), $path);
+ }
+
+ /**
* Returns current node tag name.
*
* @return string
View
6 src/Behat/Mink/Integration/MinkEnvironment.php
@@ -83,24 +83,22 @@ private function registerMinkSessions(Mink $mink)
if (null === $this->getParameter('start_url')) {
throw new \InvalidArgumentException('Specify start_url environment parameter');
}
- $startUrl = $this->getParameter('start_url');
$browser = $this->getParameter('browser') ?: 'firefox';
$config = $this->getParameter('goutte', array());
$goutte = new GoutteClient(
isset($config['zend_config']) ? $config['zend_config'] : array(),
isset($config['server_parameters']) ? $config['server_parameters'] : array()
);
- $mink->registerSession('goutte', new Session(new GoutteDriver($startUrl, $goutte)));
+ $mink->registerSession('goutte', new Session(new GoutteDriver($goutte)));
$config = $this->getParameter('sahi', array());
$client = new SahiClient(new SahiConnection(
isset($config['sid']) ? $config['sid'] : uniqid(),
isset($config['host']) ? $config['host'] : 'localhost',
isset($config['port']) ? $config['port'] : 9999
));
- $mink->registerSession('sahi', new Session(new SahiDriver($startUrl, $browser, $client)));
-
+ $mink->registerSession('sahi', new Session(new SahiDriver($browser, $client)));
foreach ($this->sessions as $name => $session) {
$mink->registerSession($name, $session);
View
17 src/Behat/Mink/Integration/support/hooks.php
@@ -11,23 +11,16 @@
*/
$hooks->beforeScenario('', function($event) {
- $scenario = $event instanceof ScenarioEvent ? $event->getScenario() : $event->getOutline();
- $environment = $event->getEnvironment();
+ $environment = $event->getEnvironment();
+ $scenario = $event instanceof ScenarioEvent ? $event->getScenario() : $event->getOutline();
+ $session = $environment->getParameter('default_session') ?: 'goutte';
- $session = null;
foreach ($scenario->getTags() as $tag) {
if ('javascript' === $tag) {
$session = 'sahi';
- } elseif (preg_match('/^mink\:([^\n]+)/', $tag, $matches)) {
+ } elseif (preg_match('/^mink\:(.+)/', $tag, $matches)) {
$session = $matches[1];
}
}
-
- $environment->getMink()->setDefaultSessionName(
- $session ?: ($environment->getParameter('default_driver') ?: 'goutte')
- );
-
- if ($environment->getSession()->isStarted()) {
- $environment->getSession()->reset();
- }
+ $environment->getMink()->setDefaultSessionName($session);
});
View
7 src/Behat/Mink/Mink.php
@@ -78,7 +78,7 @@ public function setDefaultSessionName($name)
$name = strtolower($name);
if (!isset($this->sessions[$name])) {
- throw new \InvalidArgumentException(sprintf('session "%s" is not registered.', $name));
+ throw new \InvalidArgumentException(sprintf('Session "%s" is not registered.', $name));
}
$this->defaultSessionName = $name;
@@ -106,19 +106,18 @@ public function getSession($name = null)
$name = strtolower($name) ?: $this->defaultSessionName;
if (null === $name) {
- throw new \InvalidArgumentException('specify session name to get');
+ throw new \InvalidArgumentException('Specify session name to get');
}
if (!isset($this->sessions[$name])) {
- throw new \InvalidArgumentException(sprintf('session "%s" is not registered.', $name));
+ throw new \InvalidArgumentException(sprintf('Session "%s" is not registered.', $name));
}
$session = $this->sessions[$name];
// start session if needed
if (!$session->isStarted()) {
$session->start();
- $this->defaultSessionName = $name;
}
return $session;
View
4 src/Behat/Mink/Selector/CssSelector.php
@@ -2,7 +2,7 @@
namespace Behat\Mink\Selector;
-use Symfony\Component\CssSelector\Parser;
+use Symfony\Component\CssSelector\CssSelector as CSS;
/*
* This file is part of the Behat\Mink.
@@ -24,6 +24,6 @@ class CssSelector implements SelectorInterface
*/
public function translateToXPath($locator)
{
- return Parser::cssToXpath($locator);
+ return CSS::toXPath($locator);
}
}
View
21 tests/Behat/Mink/Driver/DriverTest.php
@@ -13,21 +13,19 @@
public static function setUpBeforeClass()
{
- static::$host = $_SERVER['WEB_FIXTURES_HOST'];
- $driver = static::configureDriver();
- $driver->start();
-
- static::$session = new Session($driver, new SelectorsHandler());
+ static::$host = $_SERVER['WEB_FIXTURES_HOST'];
+ static::$session = new Session(static::configureDriver(), new SelectorsHandler());
+ static::$session->start();
}
public static function tearDownAfterClass()
{
- static::$session->getDriver()->stop();
+ static::$session->stop();
}
public function setUp()
{
- static::$session->getDriver()->reset();
+ static::$session->reset();
}
protected static function configureDriver() {}
@@ -129,6 +127,7 @@ public function testAdvancedForm()
$sex = $page->findField('sex');
$maillist = $page->findField('mail_list');
$agreement = $page->findField('agreement');
+ $about = $page->findField('about');
$this->assertNotNull($firstname);
$this->assertNotNull($lastname);
@@ -161,27 +160,29 @@ public function testAdvancedForm()
$sex->selectOption('m');
$this->assertEquals('m', $sex->getValue());
+ $about->attachFile(__DIR__ . '/web-fixtures/some_file.txt');
$button = $page->findButton('Register');
- $page->fillField('first_name', 'Foo');
+ $page->fillField('first_name', 'Foo "item"');
$page->fillField('last_name', 'Bar');
- $this->assertEquals('Foo', $firstname->getValue());
+ $this->assertEquals('Foo "item"', $firstname->getValue());
$this->assertEquals('Bar', $lastname->getValue());
$button->click();
$this->assertContains(<<<OUT
Array
(
- [first_name] => Foo
+ [first_name] => Foo "item"
[last_name] => Bar
[email] => your@email.com
[select_number] => 10
[sex] => m
[agreement] => on
)
+1 uploaded file
OUT
, $page->getContent()
View
2 tests/Behat/Mink/Driver/GoutteDriverTest.php
@@ -26,6 +26,6 @@ public function testStatuses()
protected static function configureDriver()
{
- return new GoutteDriver(static::$host . '/index.php');
+ return new GoutteDriver();
}
}
View
2 tests/Behat/Mink/Driver/SahiDriverTest.php
@@ -12,6 +12,6 @@ class SahiDriverTest extends DriverTest
{
protected static function configureDriver()
{
- return new SahiDriver(static::$host . '/index.php', $_SERVER['WEB_FIXTURES_BROWSER']);
+ return new SahiDriver($_SERVER['WEB_FIXTURES_BROWSER']);
}
}
View
6 tests/Behat/Mink/Driver/web-fixtures/advanced_form.php
@@ -7,7 +7,7 @@
<body>
<h1>ADvanced Form Page</h1>
- <form method="POST" action="/advanced_form_post.php">
+ <form method="POST" enctype="multipart/form-data" action="/advanced_form_post.php">
<input name="first_name" value="Firstname" type="text" />
<input id="lastn" name="last_name" value="Lastname" type="text" />
<label for="email">
@@ -29,7 +29,9 @@
<input type="checkbox" name="mail_list" checked="checked" />
<input type="checkbox" name="agreement" />
+ <input type="file" name="about" />
+
<input type="submit" value="Register" />
</form>
</body>
-</html>
+</html>
View
3 tests/Behat/Mink/Driver/web-fixtures/advanced_form_post.php
@@ -9,7 +9,8 @@
$_POST['agreement'] = ('1' === $_POST['agreement'] || 'on' === $_POST['agreement']) ? 'on' : 'off';
print_r($_POST);
+ echo count($_FILES) . ' ' . file_get_contents($_FILES['about']['tmp_name']);
?>
</body>
-</html>
+</html>
View
1 tests/Behat/Mink/Driver/web-fixtures/some_file.txt
@@ -0,0 +1 @@
+uploaded file
View
1 tests/Behat/Mink/Selector/CssSelectorTest.php
@@ -16,5 +16,6 @@ public function testSelector()
$this->assertEquals('descendant-or-self::h3', $selector->translateToXPath('h3'));
$this->assertEquals('descendant-or-self::h3/span', $selector->translateToXPath('h3 > span'));
+ $this->assertEquals("descendant-or-self::h3/*/descendant::*[contains(concat(' ', normalize-space(@class), ' '), ' my_div ')]", $selector->translateToXPath('h3 > .my_div'));
}
}
2 vendor/Goutte
@@ -1 +1 @@
-Subproject commit 7b70e96f88d8d4f753a65eb38b3fbf1bd8614297
+Subproject commit bba8ce35591be3bc1661d599c68ef71d934945c7
2 vendor/SahiClient
@@ -1 +1 @@
-Subproject commit f08c1fa689f0b7035c30aa3523ce362449537091
+Subproject commit 05e7401d0d8c6030cc1c84a3ee300eb28b21228f
2 vendor/Symfony/Component/CssSelector
@@ -1 +1 @@
-Subproject commit 4f94a314de30ebfb6d4ab7375230f51efd8547da
+Subproject commit 4e6c37f450ee2aa82295e90ae8d286c44b0d3d9a
2 vendor/Symfony/Component/Finder
@@ -1 +1 @@
-Subproject commit d795b96e455639d4ded903de4f6451bbdde098a2
+Subproject commit 83d148b10f3acf2a1d1cc427386a1d3d1a125206

0 comments on commit 0760e65

Please sign in to comment.
Something went wrong with that request. Please try again.