Merge pull request #26 from creative-commoners/pulls/2.0/vendorise-miframe

Pulls/2.0/vendorise miframe
This commit is contained in:
Robbie Averill 2017-11-22 18:29:20 +13:00 committed by GitHub
commit df6bd2107e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 115 additions and 84 deletions

1
.gitattributes vendored
View File

@ -4,3 +4,4 @@
/.gitignore export-ignore /.gitignore export-ignore
/.travis.yml export-ignore /.travis.yml export-ignore
/.scrutinizer.yml export-ignore /.scrutinizer.yml export-ignore
/codecov.yml

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.DS_Store

View File

@ -1,5 +1,11 @@
inherit: true inherit: true
build:
nodes:
analysis:
tests:
override: [php-scrutinizer-run]
checks: checks:
php: php:
code_rating: true code_rating: true

View File

@ -1,34 +1,35 @@
# See https://github.com/silverstripe/silverstripe-travis-support for setup details
language: php language: php
sudo: false
env: env:
global: global:
- COMPOSER_ROOT_VERSION=1.0.x-dev - COMPOSER_ROOT_VERSION=2.0.x-dev
- CORE_RELEASE=4
# The path of the module when installed by composer
- MODULE_PATH=iframe
matrix: matrix:
fast_finish: true
include: include:
- php: 5.6 - php: 5.6
env: DB=MYSQL env: DB=MYSQL PHPCS_TEST=1 PHPUNIT_TEST=1
- php: 7.0 - php: 7.0
env: DB=MYSQL env: DB=MYSQL PHPUNIT_TEST=1
- php: 7.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: before_script:
- composer self-update || true # Init PHP
- phpenv rehash - phpenv rehash
- phpenv config-rm xdebug.ini - phpenv config-rm xdebug.ini
- echo 'memory_limit = 2048M' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
# Install composer dependencies
- composer validate - composer validate
- git clone git://github.com/silverstripe/silverstripe-travis-support.git ~/travis-support - composer require --no-update silverstripe/recipe-cms:1.0.x-dev
- php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss - composer install --prefer-dist --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile
- cd ~/builds/ss
- composer install --prefer-dist
script: 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

View File

@ -1,2 +1 @@
<?php <?php

View File

@ -7,6 +7,7 @@ use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\CheckboxField; use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\NumericField; use SilverStripe\Forms\NumericField;
use SilverStripe\Forms\HTMLEditor\HtmlEditorField; use SilverStripe\Forms\HTMLEditor\HtmlEditorField;
/** /**
* Iframe page type embeds an iframe of URL of choice into the page. * Iframe page type embeds an iframe of URL of choice into the page.
* CMS editor can choose width, height, or set it to attempt automatic size configuration. * CMS editor can choose width, height, or set it to attempt automatic size configuration.
@ -40,22 +41,28 @@ class IFramePage extends Page
$fields->removeFieldFromTab('Root.Main', 'Content'); $fields->removeFieldFromTab('Root.Main', 'Content');
$fields->addFieldToTab('Root.Main', $url = new TextField('IFrameURL', 'Iframe URL')); $fields->addFieldToTab('Root.Main', $url = new TextField('IFrameURL', 'Iframe URL'));
$url->setRightTitle('Can be absolute (<em>http://silverstripe.com</em>) or relative to this site (<em>about-us</em>).'); $url->setRightTitle(
'Can be absolute (<em>http://silverstripe.com</em>) or relative to this site (<em>about-us</em>).'
);
$fields->addFieldToTab( $fields->addFieldToTab(
'Root.Main', 'Root.Main',
DropdownField::create('ForceProtocol', 'Force protocol?') DropdownField::create('ForceProtocol', 'Force protocol?')
->setSource(array('http://' => 'http://', 'https://' => 'https://')) ->setSource(array('http://' => 'http://', 'https://' => 'https://'))
->setEmptyString('') ->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' 'Metadata'
); );
$fields->addFieldToTab('Root.Main', new CheckboxField('AutoHeight', 'Auto height (only works with same domain URLs)')); $fields->addFieldsToTab('Root.Main', [
$fields->addFieldToTab('Root.Main', new CheckboxField('AutoWidth', 'Auto width (100% of the available space)')); CheckboxField::create('AutoHeight', 'Auto height (only works with same domain URLs)'),
$fields->addFieldToTab('Root.Main', new NumericField('FixedHeight', 'Fixed height (in pixels)')); CheckboxField::create('AutoWidth', 'Auto width (100% of the available space)'),
$fields->addFieldToTab('Root.Main', new NumericField('FixedWidth', 'Fixed width (in pixels)')); NumericField::create('FixedHeight', 'Fixed height (in pixels)'),
$fields->addFieldToTab('Root.Main', new HtmlEditorField('Content', 'Content (appears above iframe)')); NumericField::create('FixedWidth', 'Fixed width (in pixels)'),
$fields->addFieldToTab('Root.Main', new HtmlEditorField('BottomContent', 'Content (appears below iframe)')); HtmlEditorField::create('Content', 'Content (appears above iframe)'),
$fields->addFieldToTab('Root.Main', new HtmlEditorField('AlternateContent', 'Alternate Content (appears when user has iframes disabled)')); 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 // Move the Metadata field to last position, but make a check for it's
// existence first. // existence first.

View File

@ -11,17 +11,19 @@ class IFramePageController extends ContentController
protected function init() protected function init()
{ {
parent::init(); parent::init();
$currentProtocol = Director::protocol();
if ($this->ForceProtocol) { $desiredProtocol = $this->ForceProtocol;
if ($this->ForceProtocol == 'http://' && Director::protocol() != 'http://') { if ($desiredProtocol && $currentProtocol !== $desiredProtocol) {
return $this->redirect(preg_replace('#https://#', 'http://', $this->AbsoluteLink())); $enforcedLocation = preg_replace(
} elseif ($this->ForceProtocol == 'https://' && Director::protocol() != 'https://') { "#^${currentProtocol}#",
return $this->redirect(preg_replace('#http://#', 'https://', $this->AbsoluteLink())); $desiredProtocol,
} $this->AbsoluteLink()
);
return $this->redirect($enforcedLocation);
} }
if ($this->IFrameURL) { if ($this->IFrameURL) {
Requirements::javascript('iframe/javascript/iframe_page.js'); Requirements::javascript('silverstripe/iframe: javascript/iframe_page.js');
} }
} }
} }

1
codecov.yml Normal file
View File

@ -0,0 +1 @@
comment: false

View File

@ -1,33 +1,36 @@
{ {
"name": "silverstripe/iframe", "name": "silverstripe/iframe",
"description": "Add an iFrame pagetype to SilverStripe, to show content from another website", "description": "Add an iFrame pagetype to SilverStripe, to show content from another website",
"type": "silverstripe-module", "type": "silverstripe-vendormodule",
"keywords": ["silverstripe"], "keywords": ["silverstripe"],
"license": "BSD-3-Clause", "license": "BSD-3-Clause",
"authors": [ "authors": [
{ {
"name": "Mateusz Uzdowski", "name": "Mateusz Uzdowski",
"email": "mateusz@silverstripe.com" "email": "mateusz@silverstripe.com"
} }
], ],
"require": { "require": {
"silverstripe/framework": "^4@dev", "silverstripe/cms": "^4.0"
"silverstripe/cms": "^4@dev" },
}, "require-dev": {
"require-dev": { "phpunit/phpunit": "^5.7",
"phpunit/PHPUnit": "^5.7" "squizlabs/php_codesniffer": "^3.0"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"SilverStripe\\IFrame\\": "code/", "SilverStripe\\IFrame\\": "code/",
"SilverStripe\\IFrame\\Tests\\": "tests/" "SilverStripe\\IFrame\\Tests\\": "tests/"
} }
}, },
"extra": { "extra": {
"branch-alias": { "expose": [
"dev-master": "2.0.x-dev" "javascript"
} ],
}, "branch-alias": {
"minimum-stability": "dev", "dev-master": "2.0.x-dev"
"prefer-stable": true }
},
"minimum-stability": "dev",
"prefer-stable": true
} }

View File

@ -1,4 +1,4 @@
Copyright (c) 2016, SilverStripe Limited Copyright (c) 2017, SilverStripe Limited
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

9
phpcs.xml.dist Normal file
View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="SilverStripe">
<description>CodeSniffer ruleset for SilverStripe coding conventions.</description>
<rule ref="PSR2" >
<!-- Current exclusions -->
<exclude name="PSR1.Methods.CamelCapsMethodName" />
</rule>
</ruleset>

13
phpunit.xml.dist Normal file
View File

@ -0,0 +1,13 @@
<phpunit bootstrap="vendor/silverstripe/cms/tests/bootstrap.php" colors="true">
<testsuite name="Default">
<directory>tests/</directory>
</testsuite>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">code/</directory>
<exclude>
<directory suffix=".php">tests/</directory>
</exclude>
</whitelist>
</filter>
</phpunit>

View File

@ -12,18 +12,6 @@ class IFramePageTest extends SapphireTest
{ {
protected $usesDatabase = true; protected $usesDatabase = true;
public function setUp()
{
parent::setUp();
Config::nest();
}
public function tearDown()
{
Config::unnest();
parent::tearDown();
}
public function testGetClass() public function testGetClass()
{ {
$iframe = new IFramePage(); $iframe = new IFramePage();
@ -109,40 +97,40 @@ class IFramePageTest extends SapphireTest
$page->URLSegment = 'iframe'; $page->URLSegment = 'iframe';
$page->IFrameURL = 'http://target.com'; $page->IFrameURL = 'http://target.com';
Config::inst()->update(Director::class, 'alternate_protocol', 'http'); Config::modify()->set(Director::class, 'alternate_protocol', 'http');
Config::inst()->update(Director::class, 'alternate_base_url', 'http://host.com'); Config::modify()->set(Director::class, 'alternate_base_url', 'http://host.com');
$page->ForceProtocol = ''; $page->ForceProtocol = '';
$controller = new IFramePageController($page); $controller = new IFramePageController($page);
$controller->doInit(); $controller->doInit();
$response = $controller->getResponse(); $response = $controller->getResponse();
$this->assertNull($response->getHeader('Location')); $this->assertNull($response->getHeader('Location'));
Config::inst()->update(Director::class, 'alternate_protocol', 'https'); Config::modify()->set(Director::class, 'alternate_protocol', 'https');
Config::inst()->update(Director::class, 'alternate_base_url', 'https://host.com'); Config::modify()->set(Director::class, 'alternate_base_url', 'https://host.com');
$page->ForceProtocol = ''; $page->ForceProtocol = '';
$controller = new IFramePageController($page); $controller = new IFramePageController($page);
$controller->doInit(); $controller->doInit();
$response = $controller->getResponse(); $response = $controller->getResponse();
$this->assertNull($response->getHeader('Location')); $this->assertNull($response->getHeader('Location'));
Config::inst()->update(Director::class, 'alternate_protocol', 'http'); Config::modify()->set(Director::class, 'alternate_protocol', 'http');
Config::inst()->update(Director::class, 'alternate_base_url', 'http://host.com'); Config::modify()->set(Director::class, 'alternate_base_url', 'http://host.com');
$page->ForceProtocol = 'http://'; $page->ForceProtocol = 'http://';
$controller = new IFramePageController($page); $controller = new IFramePageController($page);
$controller->doInit(); $controller->doInit();
$response = $controller->getResponse(); $response = $controller->getResponse();
$this->assertNull($response->getHeader('Location')); $this->assertNull($response->getHeader('Location'));
Config::inst()->update(Director::class, 'alternate_protocol', 'http'); Config::modify()->set(Director::class, 'alternate_protocol', 'http');
Config::inst()->update(Director::class, 'alternate_base_url', 'http://host.com'); Config::modify()->set(Director::class, 'alternate_base_url', 'http://host.com');
$page->ForceProtocol = 'https://'; $page->ForceProtocol = 'https://';
$controller = new IFramePageController($page); $controller = new IFramePageController($page);
$controller->doInit(); $controller->doInit();
$response = $controller->getResponse(); $response = $controller->getResponse();
$this->assertEquals($response->getHeader('Location'), 'https://host.com/iframe/'); $this->assertEquals($response->getHeader('Location'), 'https://host.com/iframe/');
Config::inst()->update(Director::class, 'alternate_protocol', 'https'); Config::modify()->set(Director::class, 'alternate_protocol', 'https');
Config::inst()->update(Director::class, 'alternate_base_url', 'https://host.com'); Config::modify()->set(Director::class, 'alternate_base_url', 'https://host.com');
$page->ForceProtocol = 'http://'; $page->ForceProtocol = 'http://';
$controller = new IFramePageController($page); $controller = new IFramePageController($page);
$controller->doInit(); $controller->doInit();