diff --git a/.travis.yml b/.travis.yml index 202ee53..6084cdc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,35 +1,31 @@ language: php -php: - - 5.5 - - 5.6 - - 7.0 - - 7.1 - env: - - DB=MYSQL CORE_RELEASE=4 + global: + - COMPOSER_ROOT_VERSION="4.x-dev" matrix: include: - - php: 7.1 - env: DB=SQLITE CORE_RELEASE=4 COVERAGE=1 - php: 5.6 - env: DB=PGSQL CORE_RELEASE=4 + env: DB=MYSQL PHPCS_TEST=1 PHPUNIT_TEST=1 + - php: 7.0 + env: DB=PGSQL PHPUNIT_TEST=1 + - php: 7.1 + env: DB=MYSQL PHPUNIT_COVERAGE_TEST=1 before_script: - - composer self-update - phpenv rehash - - git clone git://github.com/silverstripe/silverstripe-travis-support.git ~/travis-support - - php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss - - cd ~/builds/ss + - phpenv config-rm xdebug.ini + + - composer validate + - composer require --no-update silverstripe/recipe-core:4.x-dev + - if [[ $DB == PGSQL ]]; then composer require --no-update silverstripe/postgresql:2.x-dev; fi + - composer install --prefer-source --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile script: - - "if [ \"$COVERAGE\" != \"1\" ]; then vendor/bin/phpunit externalurlfield/tests; fi" - - "if [ \"$COVERAGE\" = \"1\" ]; then vendor/bin/phpunit --coverage-clover ~/coverage.xml externalurlfield/tests; fi" + - if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit; fi + - if [[ $PHPUNIT_COVERAGE_TEST ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xml; fi + - if [[ $PHPCS_TEST ]]; then vendor/bin/phpcs src tests; fi after_success: - - > - test "$COVERAGE" = "1" - && cd externalurlfield - && wget https://scrutinizer-ci.com/ocular.phar - && php ocular.phar code-coverage:upload -v --format=php-clover ~/coverage.xml + - if [[ $PHPUNIT_COVERAGE_TEST ]]; then wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload -v --format=php-clover coverage.xml; fi diff --git a/_config/config.yml b/_config/config.yml new file mode 100644 index 0000000..586e40b --- /dev/null +++ b/_config/config.yml @@ -0,0 +1,6 @@ +--- +Name: externalurlfield +--- +SilverStripe\Core\Injector\Injector: + ExternalURL: + class: BurnBright\ExternalURLField\ExternalURL diff --git a/composer.json b/composer.json index 22e4e95..fbfbfb4 100644 --- a/composer.json +++ b/composer.json @@ -1,16 +1,18 @@ { "name": "burnbright/silverstripe-externalurlfield", "description": "Provides SilverStripe with a DBField and FormField for handling external URLs.", - "type": "silverstripe-module", + "type": "silverstripe-vendormodule", "license": "MIT", "keywords": ["silverstripe", "url", "link", "form", "field"], "require": { - "silverstripe/framework": "^4.0@dev", + "silverstripe/framework": "^4.0", + "silverstripe/vendor-plugin": "^1.0", "jakeasmith/http_build_url": "^1" }, - "extra": { - "installer-name": "externalurlfield" - }, + "require-dev": { + "phpunit/phpunit": "^5.7", + "squizlabs/php_codesniffer": "^3.0" + }, "authors": [ { "name": "Jeremy Shipman", @@ -23,5 +25,6 @@ "BurnBright\\ExternalURLField\\": "src/", "BurnBright\\ExternalURLField\\Tests\\": "tests/" } - } + }, + "minimum-stability": "dev" } diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 0000000..3e2e380 --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,11 @@ + + + CodeSniffer ruleset for SilverStripe coding conventions. + + + + + + + + diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 2afe2c2..9508444 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,12 +1,9 @@ - + + - tests + tests/ - - - - src/ @@ -15,4 +12,5 @@ + diff --git a/src/ExternalURLField.php b/src/ExternalURLField.php index 60acda7..1de1323 100644 --- a/src/ExternalURLField.php +++ b/src/ExternalURLField.php @@ -33,7 +33,10 @@ class ExternalURLField extends TextField 'fragment' => false ), 'html5validation' => true, - 'validregex' => '%^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@|\d{1,3}(?:\.\d{1,3}){3}|(?:(?:[a-z\d\x{00a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)(?:\.(?:[a-z\d\x{00a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)*(?:\.[a-z\x{00a1}-\x{ffff}]{2,6}))(?::\d+)?(?:[^\s]*)?$%iu' + 'validregex' => '%^(?:(?:https?|ftp)://)(?:\S+(?::\S*)' + . '?@|\d{1,3}(?:\.\d{1,3}){3}|(?:(?:[a-z\d\x{00a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)' + . '(?:\.(?:[a-z\d\x{00a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)*(?:\.[a-z\x{00a1}-\x{ffff}]{2,6}))' + . '(?::\d+)?(?:[^\s]*)?$%iu' ); /** @@ -116,13 +119,15 @@ public function getAttributes() /** * Rebuild url on save * @param string $url + * @param array|DataObject $data {@see Form::loadDataFrom} + * @return $this */ - public function setValue($url) + public function setValue($url, $data = null) { if ($url) { $url = $this->rebuildURL($url); } - parent::setValue($url); + parent::setValue($url, $data); } /**