From 8ceb3bde25bdd26bcdc783ac1e5c1734b7f6fddf Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Fri, 8 Jul 2022 11:48:29 +1200 Subject: [PATCH] MNT Use GitHub Actions CI --- .github/workflows/ci.yml | 16 ++++++++++++++++ .github/workflows/keepalive.yml | 17 +++++++++++++++++ README.md | 2 +- composer.json | 9 ++------- phpcs.xml.dist | 15 +++++++++++++++ phpunit.xml.dist | 30 ------------------------------ src/FacebookWebDriver.php | 26 +++++++++++++++++--------- 7 files changed, 68 insertions(+), 47 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/keepalive.yml create mode 100644 phpcs.xml.dist delete mode 100644 phpunit.xml.dist diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..56e8d764 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,16 @@ +name: CI + +on: + push: + pull_request: + workflow_dispatch: + # Every Sunday at 1:20pm UTC + schedule: + - cron: '20 13 * * 0' + +jobs: + ci: + name: CI + # Only run cron on the silverstripe account + if: (github.event_name == 'schedule' && startsWith(github.repository, 'silverstripe/')) || (github.event_name != 'schedule') + uses: silverstripe/gha-ci/.github/workflows/ci.yml@v1 diff --git a/.github/workflows/keepalive.yml b/.github/workflows/keepalive.yml new file mode 100644 index 00000000..533388cc --- /dev/null +++ b/.github/workflows/keepalive.yml @@ -0,0 +1,17 @@ +name: Keepalive + +on: + workflow_dispatch: + # The 24th of every month at 1:50pm UTC + schedule: + - cron: '50 13 24 * *' + +jobs: + keepalive: + name: Keepalive + # Only run cron on the silverstripe account + if: (github.event_name == 'schedule' && startsWith(github.repository, 'silverstripe/')) || (github.event_name != 'schedule') + runs-on: ubuntu-latest + steps: + - name: Keepalive + uses: silverstripe/gha-keepalive@v1 diff --git a/README.md b/README.md index 72946eb4..0d0fc1c9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Mink Facebook WebDriver extension -[![Build Status](https://api.travis-ci.com/silverstripe/MinkFacebookWebDriver.svg?branch=1)](https://travis-ci.com/silverstripe/MinkFacebookWebDriver) +[![CI](https://github.com/silverstripe/MinkFacebookWebDriver/actions/workflows/ci.yml/badge.svg)](https://github.com/silverstripe/MinkFacebookWebDriver/actions/workflows/ci.yml) Currently forked from [https://github.com/minkphp/MinkSelenium2Driver/] and updated to use the [facebook php webdriver](https://github.com/facebook/php-webdriver). diff --git a/composer.json b/composer.json index cfaeed4f..2f3169d9 100644 --- a/composer.json +++ b/composer.json @@ -28,21 +28,16 @@ } ], "require": { - "php": "^5.6 | ^7", + "php": "^7 || ^8", "behat/mink": "~1.7@dev", "php-webdriver/webdriver": "^1.4" }, "require-dev": { - "mink/driver-testsuite": "dev-master" + "squizlabs/php_codesniffer": "^3.5" }, "autoload": { "psr-4": { "SilverStripe\\MinkFacebookWebDriver\\": "src/" } - }, - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } } } diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 00000000..8a84447f --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,15 @@ + + + CodeSniffer ruleset for SilverStripe coding conventions. + + src + + + + + + + + + + diff --git a/phpunit.xml.dist b/phpunit.xml.dist deleted file mode 100644 index 58a01533..00000000 --- a/phpunit.xml.dist +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - tests - vendor/mink/driver-testsuite/tests - - - - - - - - - - - - - - - - - - - - ./src - - - diff --git a/src/FacebookWebDriver.php b/src/FacebookWebDriver.php index 0f535754..bb2f0cb2 100755 --- a/src/FacebookWebDriver.php +++ b/src/FacebookWebDriver.php @@ -32,7 +32,7 @@ class FacebookWebDriver extends CoreDriver /** * Default browser */ - const DEFAULT_BROWSER = 'chrome'; + public const DEFAULT_BROWSER = 'chrome'; /** * Hostname of driver @@ -229,7 +229,7 @@ protected function initChromeCapabilities(DesiredCapabilities $caps, $config) } else { $chromeOptions[$capability] = $value; } - $caps->setCapability('chrome.'.$capability, $value); + $caps->setCapability('chrome.' . $capability, $value); } $caps->setCapability('chromeOptions', $chromeOptions); @@ -290,7 +290,7 @@ protected function withSyn() ); if (!$hasSyn) { - $synJs = file_get_contents(__DIR__.'/Resources/syn.js'); + $synJs = file_get_contents(__DIR__ . '/Resources/syn.js'); $this->webDriver->executeScript($synJs); } @@ -318,7 +318,7 @@ protected static function charToOptions($char, $modifier = null) ); if ($modifier) { - $options[$modifier.'Key'] = 1; + $options[$modifier . 'Key'] = 1; } return json_encode($options); @@ -584,7 +584,7 @@ public function findElementXpaths($xpath) $elements = array(); foreach ($nodes as $i => $node) { - $elements[] = sprintf('(%s)[%d]', $xpath, $i+1); + $elements[] = sprintf('(%s)[%d]', $xpath, $i + 1); } return $elements; @@ -734,7 +734,9 @@ public function setValue($xpath, $value) $elementType = strtolower($element->getAttribute('type')); if (in_array($elementType, array('submit', 'image', 'button', 'reset'))) { - throw new DriverException(sprintf('Impossible to set value an element with XPath "%s" as it is not a select, textarea or textbox', $xpath)); + $message = 'Impossible to set value an element with XPath "%s" as it is not a select, '; + $message = $message . 'textarea or textbox'; + throw new DriverException(sprintf($message, $xpath)); } if ('checkbox' === $elementType) { @@ -828,7 +830,8 @@ public function selectOption($xpath, $value, $multiple = false) return; } - 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)); + $message = 'Impossible to select an option on the element with XPath "%s" as it is not a select or radio input'; + throw new DriverException(sprintf($message, $xpath)); } /** @@ -1151,7 +1154,11 @@ private function selectOptionOnElement(RemoteWebElement $element, $value, $multi { $escapedValue = $this->xpathEscaper->escapeLiteral($value); // The value of an option is the normalized version of its text when it has no value attribute - $optionQuery = sprintf('.//option[@value = %s or (not(@value) and normalize-space(.) = %s)]', $escapedValue, $escapedValue); + $optionQuery = sprintf( + './/option[@value = %s or (not(@value) and normalize-space(.) = %s)]', + $escapedValue, + $escapedValue + ); $option = $this->findElement($optionQuery, $element); // Avoids selecting values from other select boxes if ($multiple || !$element->getAttribute('multiple')) { @@ -1199,7 +1206,8 @@ private function deselectAllOptions(RemoteWebElement $element) */ private function ensureInputType(RemoteWebElement $element, $xpath, $type, $action) { - if ('input' !== $element->getTagName() + if ( + 'input' !== $element->getTagName() || $type !== $element->getAttribute('type') ) { throw new DriverException(