Skip to content

Commit

Permalink
Merge 2.5 to 3.0 (#5479)
Browse files Browse the repository at this point in the history
* Proposed solution for #5457 gherkin scenarios not loaded from group file (#5458)

* proposed solution for #5457 gherkin scenarios not loaded from group file

* testing for getMetaData method before calling it in GroupManager

* reformatting if statement to appease nitpick

* adding tests for #5457

* Update LOCAL_FILE constant for new version of phpseclib (#5461)

* Using button formaction attr in proceedSubmitForm method (#5440)

* Using button formaction attr in proceedSubmitForm method (AcceptanceTesterActions::submitForm)

* Update InnerBrowser.php

* Avoid removing required fields in cookies. (#5470)
  • Loading branch information
Naktibalda authored and DavertMik committed Apr 23, 2019
1 parent 7e7a651 commit 7439ce1
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/Codeception/Lib/GroupManager.php
Expand Up @@ -5,6 +5,7 @@
use Codeception\Test\Interfaces\Reported;
use Codeception\Test\Descriptor;
use Codeception\TestInterface;
use Codeception\Test\Gherkin;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;

Expand Down Expand Up @@ -118,6 +119,10 @@ public function groupsForTest(\PHPUnit\Framework\Test $test)
if (strpos($filename . ':' . $test->getName(false), $testPattern) === 0) {
$groups[] = $group;
}
if ($test instanceof Gherkin
&& mb_strtolower($filename . ':' . $test->getMetadata()->getFeature()) === mb_strtolower($testPattern)) {
$groups[] = $group;
}
if ($test instanceof \PHPUnit\Framework\TestSuite\DataProvider) {
$firstTest = $test->testAt(0);
if ($firstTest != false && $firstTest instanceof TestInterface) {
Expand Down
10 changes: 9 additions & 1 deletion src/Codeception/Lib/InnerBrowser.php
Expand Up @@ -831,6 +831,7 @@ protected function setCheckboxBoolValues(Crawler $form, array $params)
*/
protected function proceedSubmitForm(Crawler $frmCrawl, array $params, $button = null)
{
$url = null;
$form = $this->getFormFor($frmCrawl);
$defaults = $this->getFormValuesFor($form);
$merged = array_merge($defaults, $params);
Expand All @@ -843,10 +844,17 @@ protected function proceedSubmitForm(Crawler $frmCrawl, array $params, $button =
));
if (count($btnCrawl)) {
$requestParams[$button] = $btnCrawl->attr('value');
$formaction = $btnCrawl->attr('formaction');
if ($formaction) {
$url = $formaction;
}
}
}

$url = $this->getFormUrl($frmCrawl);
if (!$url) {
$url = $this->getFormUrl($frmCrawl);
}

if (strcasecmp($form->getMethod(), 'GET') === 0) {
$url = Uri::mergeUrls($url, '?' . http_build_query($requestParams));
}
Expand Down
6 changes: 4 additions & 2 deletions src/Codeception/Module/FTP.php
Expand Up @@ -683,12 +683,14 @@ private function _writeToFile($filename, $contents)
file_put_contents($tmp_file, $contents);

// Update variables
$this->filepath = $tmp_file;
$this->filepath = $filename;
$this->file = $contents;

// Upload the file to server
if ($this->isSFTP()) {
$uploaded = @$this->ftp->put($filename, $tmp_file, NET_SFTP_LOCAL_FILE);
$flag = defined('NET_SFTP_LOCAL_FILE') ? NET_SFTP_LOCAL_FILE : \phpseclib\Net\SFTP::SOURCE_LOCAL_FILE;

$uploaded = @$this->ftp->put($filename, $tmp_file, $flag);
} else {
$uploaded = ftp_put($this->ftp, $filename, $tmp_file, FTP_BINARY);
}
Expand Down
8 changes: 6 additions & 2 deletions src/Codeception/Module/WebDriver.php
Expand Up @@ -835,13 +835,17 @@ public function setCookie($cookie, $value, array $params = [])
}
}
// #5401 Supply defaults, otherwise chromedriver 2.46 complains.
$params = array_filter($params);
$params += [
$defaults = [
'path' => '/',
'expiry' => time() + 86400,
'secure' => false,
'httpOnly' => false,
];
foreach ($defaults as $key => $default) {
if (empty($params[$key])) {
$params[$key] = $default;
}
}
$this->webDriver->manage()->addCookie($params);
$this->debugSection('Cookies', json_encode($this->webDriver->manage()->getCookies()));
}
Expand Down
1 change: 1 addition & 0 deletions tests/data/gherkinGroup1
@@ -0,0 +1 @@
tests/data/refund.feature:Jeff returns a faulty microwave
1 change: 1 addition & 0 deletions tests/data/gherkinGroup2
@@ -0,0 +1 @@
tests/data/refund2.feature:ジェフは不完全な電子レンジを返します
10 changes: 10 additions & 0 deletions tests/data/refund2.feature
@@ -0,0 +1,10 @@
@important
Feature: Refund item
In order to get satisfaction
As a customer
I need to be able to get refunds

Scenario: ジェフは不完全な電子レンジを返します
Given Jeff has bought a microwave for "$100"
When he returns the microwave
Then Jeff should be refunded $100
19 changes: 19 additions & 0 deletions tests/unit/Codeception/Lib/GroupManagerTest.php
Expand Up @@ -2,6 +2,7 @@
namespace Codeception\Lib;

use Codeception\Util\Stub;
use Codeception\Test\Loader\Gherkin as GherkinLoader;

class GroupManagerTest extends \Codeception\Test\Unit
{
Expand Down Expand Up @@ -75,6 +76,24 @@ public function testGroupsFileHandlesWhitespace()
$this->assertEmpty($this->manager->groupsForTest($badTest));
}

public function testLoadSpecificScenarioFromFile()
{
$this->manager = new GroupManager(['gherkinGroup1' => 'tests/data/gherkinGroup1']);
$loader = new GherkinLoader();
$loader->loadTests(codecept_absolute_path('tests/data/refund.feature'));
$test = $loader->getTests()[0];
$this->assertContains('gherkinGroup1', $this->manager->groupsForTest($test));
}

public function testLoadSpecificScenarioWithMultibyteStringFromFile()
{
$this->manager = new GroupManager(['gherkinGroup2' => 'tests/data/gherkinGroup2']);
$loader = new GherkinLoader();
$loader->loadTests(codecept_absolute_path('tests/data/refund2.feature'));
$test = $loader->getTests()[0];
$this->assertContains('gherkinGroup2', $this->manager->groupsForTest($test));
}

protected function makeTestCase($file, $name = '')
{
return Stub::make(
Expand Down

0 comments on commit 7439ce1

Please sign in to comment.