From 7439ce14d456f70f8f915e2fc420ec9b1a60146f Mon Sep 17 00:00:00 2001 From: Gintautas Miselis Date: Wed, 24 Apr 2019 02:37:11 +0300 Subject: [PATCH] Merge 2.5 to 3.0 (#5479) * 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) --- src/Codeception/Lib/GroupManager.php | 5 +++++ src/Codeception/Lib/InnerBrowser.php | 10 +++++++++- src/Codeception/Module/FTP.php | 6 ++++-- src/Codeception/Module/WebDriver.php | 8 ++++++-- tests/data/gherkinGroup1 | 1 + tests/data/gherkinGroup2 | 1 + tests/data/refund2.feature | 10 ++++++++++ .../unit/Codeception/Lib/GroupManagerTest.php | 19 +++++++++++++++++++ 8 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 tests/data/gherkinGroup1 create mode 100644 tests/data/gherkinGroup2 create mode 100644 tests/data/refund2.feature diff --git a/src/Codeception/Lib/GroupManager.php b/src/Codeception/Lib/GroupManager.php index c796033bac..1eb2c5a545 100644 --- a/src/Codeception/Lib/GroupManager.php +++ b/src/Codeception/Lib/GroupManager.php @@ -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; @@ -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) { diff --git a/src/Codeception/Lib/InnerBrowser.php b/src/Codeception/Lib/InnerBrowser.php index c94289b0c2..297be8444e 100644 --- a/src/Codeception/Lib/InnerBrowser.php +++ b/src/Codeception/Lib/InnerBrowser.php @@ -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); @@ -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)); } diff --git a/src/Codeception/Module/FTP.php b/src/Codeception/Module/FTP.php index 2a392934cb..418d5d3bb9 100644 --- a/src/Codeception/Module/FTP.php +++ b/src/Codeception/Module/FTP.php @@ -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); } diff --git a/src/Codeception/Module/WebDriver.php b/src/Codeception/Module/WebDriver.php index 61feda84f5..641aa45fd9 100644 --- a/src/Codeception/Module/WebDriver.php +++ b/src/Codeception/Module/WebDriver.php @@ -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())); } diff --git a/tests/data/gherkinGroup1 b/tests/data/gherkinGroup1 new file mode 100644 index 0000000000..e92fe6e789 --- /dev/null +++ b/tests/data/gherkinGroup1 @@ -0,0 +1 @@ +tests/data/refund.feature:Jeff returns a faulty microwave \ No newline at end of file diff --git a/tests/data/gherkinGroup2 b/tests/data/gherkinGroup2 new file mode 100644 index 0000000000..537815f703 --- /dev/null +++ b/tests/data/gherkinGroup2 @@ -0,0 +1 @@ +tests/data/refund2.feature:ジェフは不完全な電子レンジを返します \ No newline at end of file diff --git a/tests/data/refund2.feature b/tests/data/refund2.feature new file mode 100644 index 0000000000..4fe179b5a4 --- /dev/null +++ b/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 diff --git a/tests/unit/Codeception/Lib/GroupManagerTest.php b/tests/unit/Codeception/Lib/GroupManagerTest.php index 7d67a2f6e4..729b02f788 100644 --- a/tests/unit/Codeception/Lib/GroupManagerTest.php +++ b/tests/unit/Codeception/Lib/GroupManagerTest.php @@ -2,6 +2,7 @@ namespace Codeception\Lib; use Codeception\Util\Stub; +use Codeception\Test\Loader\Gherkin as GherkinLoader; class GroupManagerTest extends \Codeception\Test\Unit { @@ -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(