diff --git a/.gitattributes b/.gitattributes
index 475f5f2..2cab225 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -4,3 +4,4 @@
/.gitignore export-ignore
/.travis.yml export-ignore
/.scrutinizer.yml export-ignore
+/codecov.yml
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..e43b0f9
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+.DS_Store
diff --git a/.scrutinizer.yml b/.scrutinizer.yml
index 61b0c9f..4625fbf 100644
--- a/.scrutinizer.yml
+++ b/.scrutinizer.yml
@@ -1,5 +1,11 @@
inherit: true
+build:
+ nodes:
+ analysis:
+ tests:
+ override: [php-scrutinizer-run]
+
checks:
php:
code_rating: true
diff --git a/.travis.yml b/.travis.yml
index 51c2a67..e5a9263 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,34 +1,35 @@
-# See https://github.com/silverstripe/silverstripe-travis-support for setup details
language: php
-sudo: false
-
env:
global:
- - COMPOSER_ROOT_VERSION=1.0.x-dev
- - CORE_RELEASE=4
- # The path of the module when installed by composer
- - MODULE_PATH=iframe
+ - COMPOSER_ROOT_VERSION=2.0.x-dev
matrix:
- fast_finish: true
include:
- php: 5.6
- env: DB=MYSQL
+ env: DB=MYSQL PHPCS_TEST=1 PHPUNIT_TEST=1
- php: 7.0
- env: DB=MYSQL
+ env: DB=MYSQL PHPUNIT_TEST=1
- php: 7.1
- env: DB=MYSQL
+ env: DB=MYSQL PHPUNIT_COVERAGE_TEST=1
+ - php: 7.2
+ env: DB=MYSQL PHPUNIT_TEST=1
before_script:
- - composer self-update || true
+ # Init PHP
- phpenv rehash
- phpenv config-rm xdebug.ini
+ - echo 'memory_limit = 2048M' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
+
+ # Install composer dependencies
- composer validate
- - 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
- - composer install --prefer-dist
+ - composer require --no-update silverstripe/recipe-cms:1.0.x-dev
+ - composer install --prefer-dist --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile
script:
- - vendor/bin/phpunit $MODULE_PATH/tests
+ - 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 code/ tests/ *.php; fi
+
+after_success:
+ - if [[ $PHPUNIT_COVERAGE_TEST ]]; then bash <(curl -s https://codecov.io/bash) -f coverage.xml; fi
diff --git a/_config.php b/_config.php
index a4abe2d..b3d9bbc 100644
--- a/_config.php
+++ b/_config.php
@@ -1,2 +1 @@
removeFieldFromTab('Root.Main', 'Content');
$fields->addFieldToTab('Root.Main', $url = new TextField('IFrameURL', 'Iframe URL'));
- $url->setRightTitle('Can be absolute (http://silverstripe.com) or relative to this site (about-us).');
+ $url->setRightTitle(
+ 'Can be absolute (http://silverstripe.com) or relative to this site (about-us).'
+ );
$fields->addFieldToTab(
'Root.Main',
DropdownField::create('ForceProtocol', 'Force protocol?')
->setSource(array('http://' => 'http://', 'https://' => 'https://'))
->setEmptyString('')
- ->setDescription('Avoids mixed content warnings when iframe content is just available under a specific protocol'),
+ ->setDescription(
+ 'Avoids mixed content warnings when iframe content is just available under a specific protocol'
+ ),
'Metadata'
);
- $fields->addFieldToTab('Root.Main', new CheckboxField('AutoHeight', 'Auto height (only works with same domain URLs)'));
- $fields->addFieldToTab('Root.Main', new CheckboxField('AutoWidth', 'Auto width (100% of the available space)'));
- $fields->addFieldToTab('Root.Main', new NumericField('FixedHeight', 'Fixed height (in pixels)'));
- $fields->addFieldToTab('Root.Main', new NumericField('FixedWidth', 'Fixed width (in pixels)'));
- $fields->addFieldToTab('Root.Main', new HtmlEditorField('Content', 'Content (appears above iframe)'));
- $fields->addFieldToTab('Root.Main', new HtmlEditorField('BottomContent', 'Content (appears below iframe)'));
- $fields->addFieldToTab('Root.Main', new HtmlEditorField('AlternateContent', 'Alternate Content (appears when user has iframes disabled)'));
+ $fields->addFieldsToTab('Root.Main', [
+ CheckboxField::create('AutoHeight', 'Auto height (only works with same domain URLs)'),
+ CheckboxField::create('AutoWidth', 'Auto width (100% of the available space)'),
+ NumericField::create('FixedHeight', 'Fixed height (in pixels)'),
+ NumericField::create('FixedWidth', 'Fixed width (in pixels)'),
+ HtmlEditorField::create('Content', 'Content (appears above iframe)'),
+ HtmlEditorField::create('BottomContent', 'Content (appears below iframe)'),
+ HtmlEditorField::create('AlternateContent', 'Alternate Content (appears when user has iframes disabled)')
+ ]);
// Move the Metadata field to last position, but make a check for it's
// existence first.
diff --git a/code/IFramePageController.php b/code/IFramePageController.php
index 1360236..2bea203 100644
--- a/code/IFramePageController.php
+++ b/code/IFramePageController.php
@@ -11,17 +11,19 @@ class IFramePageController extends ContentController
protected function init()
{
parent::init();
-
- if ($this->ForceProtocol) {
- if ($this->ForceProtocol == 'http://' && Director::protocol() != 'http://') {
- return $this->redirect(preg_replace('#https://#', 'http://', $this->AbsoluteLink()));
- } elseif ($this->ForceProtocol == 'https://' && Director::protocol() != 'https://') {
- return $this->redirect(preg_replace('#http://#', 'https://', $this->AbsoluteLink()));
- }
+ $currentProtocol = Director::protocol();
+ $desiredProtocol = $this->ForceProtocol;
+ if ($desiredProtocol && $currentProtocol !== $desiredProtocol) {
+ $enforcedLocation = preg_replace(
+ "#^${currentProtocol}#",
+ $desiredProtocol,
+ $this->AbsoluteLink()
+ );
+ return $this->redirect($enforcedLocation);
}
if ($this->IFrameURL) {
- Requirements::javascript('iframe/javascript/iframe_page.js');
+ Requirements::javascript('silverstripe/iframe: javascript/iframe_page.js');
}
}
}
diff --git a/codecov.yml b/codecov.yml
new file mode 100644
index 0000000..69cb760
--- /dev/null
+++ b/codecov.yml
@@ -0,0 +1 @@
+comment: false
diff --git a/composer.json b/composer.json
index e425681..8fbb328 100644
--- a/composer.json
+++ b/composer.json
@@ -1,33 +1,36 @@
{
- "name": "silverstripe/iframe",
- "description": "Add an iFrame pagetype to SilverStripe, to show content from another website",
- "type": "silverstripe-module",
- "keywords": ["silverstripe"],
- "license": "BSD-3-Clause",
- "authors": [
- {
- "name": "Mateusz Uzdowski",
- "email": "mateusz@silverstripe.com"
- }
- ],
- "require": {
- "silverstripe/framework": "^4@dev",
- "silverstripe/cms": "^4@dev"
- },
- "require-dev": {
- "phpunit/PHPUnit": "^5.7"
- },
- "autoload": {
+ "name": "silverstripe/iframe",
+ "description": "Add an iFrame pagetype to SilverStripe, to show content from another website",
+ "type": "silverstripe-vendormodule",
+ "keywords": ["silverstripe"],
+ "license": "BSD-3-Clause",
+ "authors": [
+ {
+ "name": "Mateusz Uzdowski",
+ "email": "mateusz@silverstripe.com"
+ }
+ ],
+ "require": {
+ "silverstripe/cms": "^4.0"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "^5.7",
+ "squizlabs/php_codesniffer": "^3.0"
+ },
+ "autoload": {
"psr-4": {
"SilverStripe\\IFrame\\": "code/",
"SilverStripe\\IFrame\\Tests\\": "tests/"
}
},
- "extra": {
- "branch-alias": {
- "dev-master": "2.0.x-dev"
- }
- },
- "minimum-stability": "dev",
- "prefer-stable": true
+ "extra": {
+ "expose": [
+ "javascript"
+ ],
+ "branch-alias": {
+ "dev-master": "2.0.x-dev"
+ }
+ },
+ "minimum-stability": "dev",
+ "prefer-stable": true
}
diff --git a/license.md b/license.md
index 9445c8e..8794670 100644
--- a/license.md
+++ b/license.md
@@ -1,4 +1,4 @@
-Copyright (c) 2016, SilverStripe Limited
+Copyright (c) 2017, SilverStripe Limited
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
diff --git a/phpcs.xml.dist b/phpcs.xml.dist
new file mode 100644
index 0000000..1b984f8
--- /dev/null
+++ b/phpcs.xml.dist
@@ -0,0 +1,9 @@
+
+
+ CodeSniffer ruleset for SilverStripe coding conventions.
+
+
+
+
+
+
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
new file mode 100644
index 0000000..50a2f92
--- /dev/null
+++ b/phpunit.xml.dist
@@ -0,0 +1,13 @@
+
+
+ tests/
+
+
+
+ code/
+
+ tests/
+
+
+
+
diff --git a/tests/IFramePageTest.php b/tests/IFramePageTest.php
index 2b178a8..fbe0ed7 100644
--- a/tests/IFramePageTest.php
+++ b/tests/IFramePageTest.php
@@ -12,18 +12,6 @@ class IFramePageTest extends SapphireTest
{
protected $usesDatabase = true;
- public function setUp()
- {
- parent::setUp();
- Config::nest();
- }
-
- public function tearDown()
- {
- Config::unnest();
- parent::tearDown();
- }
-
public function testGetClass()
{
$iframe = new IFramePage();
@@ -109,40 +97,40 @@ class IFramePageTest extends SapphireTest
$page->URLSegment = 'iframe';
$page->IFrameURL = 'http://target.com';
- Config::inst()->update(Director::class, 'alternate_protocol', 'http');
- Config::inst()->update(Director::class, 'alternate_base_url', 'http://host.com');
+ Config::modify()->set(Director::class, 'alternate_protocol', 'http');
+ Config::modify()->set(Director::class, 'alternate_base_url', 'http://host.com');
$page->ForceProtocol = '';
$controller = new IFramePageController($page);
$controller->doInit();
$response = $controller->getResponse();
$this->assertNull($response->getHeader('Location'));
- Config::inst()->update(Director::class, 'alternate_protocol', 'https');
- Config::inst()->update(Director::class, 'alternate_base_url', 'https://host.com');
+ Config::modify()->set(Director::class, 'alternate_protocol', 'https');
+ Config::modify()->set(Director::class, 'alternate_base_url', 'https://host.com');
$page->ForceProtocol = '';
$controller = new IFramePageController($page);
$controller->doInit();
$response = $controller->getResponse();
$this->assertNull($response->getHeader('Location'));
- Config::inst()->update(Director::class, 'alternate_protocol', 'http');
- Config::inst()->update(Director::class, 'alternate_base_url', 'http://host.com');
+ Config::modify()->set(Director::class, 'alternate_protocol', 'http');
+ Config::modify()->set(Director::class, 'alternate_base_url', 'http://host.com');
$page->ForceProtocol = 'http://';
$controller = new IFramePageController($page);
$controller->doInit();
$response = $controller->getResponse();
$this->assertNull($response->getHeader('Location'));
- Config::inst()->update(Director::class, 'alternate_protocol', 'http');
- Config::inst()->update(Director::class, 'alternate_base_url', 'http://host.com');
+ Config::modify()->set(Director::class, 'alternate_protocol', 'http');
+ Config::modify()->set(Director::class, 'alternate_base_url', 'http://host.com');
$page->ForceProtocol = 'https://';
$controller = new IFramePageController($page);
$controller->doInit();
$response = $controller->getResponse();
$this->assertEquals($response->getHeader('Location'), 'https://host.com/iframe/');
- Config::inst()->update(Director::class, 'alternate_protocol', 'https');
- Config::inst()->update(Director::class, 'alternate_base_url', 'https://host.com');
+ Config::modify()->set(Director::class, 'alternate_protocol', 'https');
+ Config::modify()->set(Director::class, 'alternate_base_url', 'https://host.com');
$page->ForceProtocol = 'http://';
$controller = new IFramePageController($page);
$controller->doInit();