This merge will upgrade silverstripe iframe module for compatibility with SS4

Implement namespacing
Update unit tests
This commit is contained in:
Marco Hermo 2017-04-25 01:47:34 +12:00
parent 454cee84df
commit 5b8e0ba0b1
23 changed files with 111 additions and 153 deletions

View File

@ -1,53 +1,34 @@
# See https://github.com/silverstripe/silverstripe-travis-support for setup details
language: php
sudo: false
language: php
php:
- 5.6
env:
global:
- DB=MYSQL CORE_RELEASE=3
- COMPOSER_ROOT_VERSION=1.0.x-dev
- CORE_RELEASE=4
# The path of the module when installed by composer
- MODULE_PATH=iframe
- COVERAGE=0
matrix:
fast_finish: true
include:
- php: 5.6
env: DB=MYSQL CORE_RELEASE=3.5
- php: 5.6
env: DB=PGSQL CORE_RELEASE=3.5
env: DB=MYSQL
- php: 7.0
env: DB=MYSQL
- php: 7.1
env: DB=MYSQL CORE_RELEASE=3.6
# Allowed to fail, meaning delayed code coverage reports
- php: 5.5.9
env: DB=MYSQL CORE_RELEASE=3 COVERAGE=1
allow_failures:
- php: 5.5.9
fast_finish: true
before_install:
- pip install --user codecov
env: DB=MYSQL
before_script:
- composer self-update || true
- phpenv rehash
- phpenv config-rm xdebug.ini
- 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
- composer install --prefer-dist
script:
# Execute tests with no coverage. This is the fastest option
- "if [ \"$COVERAGE\" = \"0\" ]; then vendor/bin/phpunit $MODULE_PATH/tests/; fi"
# Execute tests with coverage. Do this for a small
- "if [ \"$COVERAGE\" = \"1\" ]; then vendor/bin/phpunit --coverage-clover=coverage.clover $MODULE_PATH/tests/; fi"
after_script:
- "if [ \"$COVERAGE\" = \"1\" ]; then mv coverage.clover ~/build/$TRAVIS_REPO_SLUG/; fi"
- cd ~/build/$TRAVIS_REPO_SLUG
- wget https://scrutinizer-ci.com/ocular.phar
- "if [ \"$COVERAGE\" = \"1\" ]; then travis_retry codecov && travis_retry php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi"
- vendor/bin/phpunit $MODULE_PATH/tests

View File

@ -1,4 +1,12 @@
<?php
namespace SilverStripe\IFrame;
use Page;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\NumericField;
use SilverStripe\Forms\HTMLEditor\HtmlEditorField;
/**
* 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.
@ -6,7 +14,7 @@
class IFramePage extends Page
{
public static $db = array(
private static $db = array(
'IFrameURL' => 'Text',
'AutoHeight' => 'Boolean(1)',
'AutoWidth' => 'Boolean(1)',
@ -17,14 +25,14 @@ class IFramePage extends Page
'ForceProtocol' => 'Varchar',
);
public static $defaults = array(
private static $defaults = array(
'AutoHeight' => '1',
'AutoWidth' => '1',
'FixedHeight' => '500',
'FixedWidth' => '0'
);
public static $description = 'Embeds an iframe into the body of the page.';
private static $description = 'Embeds an iframe into the body of the page.';
public function getCMSFields()
{
@ -113,30 +121,10 @@ class IFramePage extends Page
$allowed_schemes = array('http', 'https');
if ($matches = parse_url($this->IFrameURL)) {
if (isset($matches['scheme']) && !in_array($matches['scheme'], $allowed_schemes)) {
$result->error(_t('IFramePage.VALIDATION.BANNEDURLSCHEME', "This URL scheme is not allowed."));
$result->addError(_t('IFramePage.VALIDATION_BANNEDURLSCHEME', "This URL scheme is not allowed."));
}
}
return $result;
}
}
class IFramePage_Controller extends Page_Controller
{
public 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()));
}
}
if ($this->IFrameURL) {
Requirements::javascript('iframe/javascript/iframe_page.js');
}
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace SilverStripe\IFrame;
use SilverStripe\CMS\Controllers\ContentController;
use SilverStripe\Control\Director;
use SilverStripe\View\Requirements;
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()));
}
}
if ($this->IFrameURL) {
Requirements::javascript('iframe/javascript/iframe_page.js');
}
}
}

View File

@ -11,12 +11,23 @@
}
],
"require": {
"silverstripe/framework": "3.*",
"silverstripe/cms": "3.*"
"silverstripe/framework": "^4@dev",
"silverstripe/cms": "^4@dev"
},
"require-dev": {
"phpunit/PHPUnit": "^5.7"
},
"autoload": {
"psr-4": {
"SilverStripe\\IFrame\\": "code/",
"SilverStripe\\IFrame\\Tests\\": "tests/"
}
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
"dev-master": "2.0.x-dev"
}
}
},
"minimum-stability": "dev",
"prefer-stable": true
}

View File

@ -3,9 +3,5 @@ ar:
DESCRIPTION: 'يقوم بتضمين آى فريم بداخل جسم الصفحة.'
PLURALNAME: 'الصفحات الرئيسية'
SINGULARNAME: 'صفحة الإطار'
IframePage:
ExternalNote: 'من فضلك لاحظ قطاع المحتوى القادم و الذى من المحتمل أن يكون مستلم من مصدر خارجى (آى فريم فى صيغة اتش تى إم إل), و يمكن أن يقوم بتصرفات غير معتادة لقراء الشاشة.'
Loading: 'تحميل المحتوى'
SiteTree:
PLURALNAME: صفحات
SINGULARNAME: صفحة

View File

@ -1,5 +1,3 @@
cs:
IFramePage:
PLURALNAME: 'Základní stránky'
SiteTree:
PLURALNAME: Stránky

View File

@ -3,11 +3,6 @@ de:
DESCRIPTION: 'Bettet eine andere Seite mittels Iframe ein.'
PLURALNAME: 'Iframe Seiten'
SINGULARNAME: 'Iframe Seite'
VALIDATION:
BANNEDURLSCHEME: 'Dieses URL-Schema ist nicht erlaubt.'
IframePage:
VALIDATION_BANNEDURLSCHEME: 'Dieses URL-Schema ist nicht erlaubt.'
ExternalNote: 'Bitte beachten Sie, dass der folgende Inhalt von einer anderen Quelle eingebunden wird (mittels IFRAME) und dadurch evtl. Probleme bei Screenreadern auftreten können.'
Loading: 'Lade Inhalt...'
SiteTree:
PLURALNAME: Seiten
SINGULARNAME: Seite

View File

@ -3,11 +3,6 @@ en:
DESCRIPTION: 'Embeds an iframe into the body of the page.'
PLURALNAME: 'Base Pages'
SINGULARNAME: 'I Frame Page'
VALIDATION:
BANNEDURLSCHEME: 'This URL scheme is not allowed.'
IframePage:
VALIDATION_BANNEDURLSCHEME: 'This URL scheme is not allowed.'
ExternalNote: 'Please note the following section of content is possibly being delivered from an external source (IFRAME in HTML terms), and may present unusual experiences for screen readers.'
Loading: 'Loading content...'
SiteTree:
PLURALNAME: Pages
SINGULARNAME: Page

View File

@ -3,11 +3,6 @@ eo:
DESCRIPTION: 'Enkorpigas je iframe (kadro) en la korpon de la paĝo.'
PLURALNAME: 'Bazaj paĝoj'
SINGULARNAME: 'Paĝo de iframe (kadro)'
VALIDATION:
BANNEDURLSCHEME: 'Tiu URL-skemo be estas permesita.'
IframePage:
VALIDATION_BANNEDURLSCHEME: 'Tiu URL-skemo be estas permesita.'
ExternalNote: 'Bonvole notu ke la sekva sekcio de enhavo eble liveriĝas el ekstera fonto (IFRAME en HTML-termoj), kaj eble prezentos nekutimajn spertojn por ekranlegantoj.'
Loading: 'Ŝargas enhavon...'
SiteTree:
PLURALNAME: Paĝoj
SINGULARNAME: Paĝo

View File

@ -2,6 +2,3 @@ fa_IR:
IFramePage:
PLURALNAME: 'صفحه اصلی'
SINGULARNAME: 'صفحه I Frame'
SiteTree:
PLURALNAME: صفحات
SINGULARNAME: صفحه

View File

@ -3,9 +3,5 @@ fi:
DESCRIPTION: 'Upottaa iframen sivulle.'
PLURALNAME: 'Pohjasivut'
SINGULARNAME: 'I Frame sivu'
IframePage:
ExternalNote: 'Huomioithan, että seuraava sisältöosio on upotettu ulkopuolisesta lähteestä (HTML-kielen IFRAME-käskyllä) ja saattaa aiheuttaa odottamattoman käyttökokemuksen selaimessa.'
Loading: 'Ladataan sisältöä...'
SiteTree:
PLURALNAME: Sivut
SINGULARNAME: Sivu

View File

@ -1,4 +1 @@
id:
SiteTree:
PLURALNAME: Halaman
SINGULARNAME: Halaman

View File

@ -1,4 +1 @@
it:
SiteTree:
PLURALNAME: Pagine
SINGULARNAME: Pagina

View File

@ -1,6 +1,3 @@
lt:
IFramePage:
PLURALNAME: 'Baziniai puslapiai'
SiteTree:
PLURALNAME: Puslapiai
SINGULARNAME: Puslapis

View File

@ -3,11 +3,6 @@ lt_LT:
DESCRIPTION: 'Įtraukia iframe į puslapio body dalį'
PLURALNAME: 'Baziniai puslapiai'
SINGULARNAME: 'Iframe puslapis'
VALIDATION:
BANNEDURLSCHEME: 'Tokia URL schema neleidžiama'
IframePage:
VALIDATION_BANNEDURLSCHEME: 'Tokia URL schema neleidžiama'
ExternalNote: 'Prašome atkreipti dėmesį, jog šis turinys galimai yra iš išorinių šaltinių (IFRAME žyma HTML dokumente), tad jis gali sukeiti nepatogumų vartotojams su ekrano skaitytuvais.'
Loading: 'Turinys siunčiamas...'
SiteTree:
PLURALNAME: Puslapiai
SINGULARNAME: Puslapis

View File

@ -3,9 +3,5 @@ mi:
DESCRIPTION: 'Ka tāmau i tētahi ī-tāpare ki roto i te tinana o te whārangi.'
PLURALNAME: 'Ngā Whārangi Pūtake'
SINGULARNAME: 'Whārangi Ī-Tāpare'
IframePage:
ExternalNote: 'Me mōhio ka tukuna pea te wāhanga ihirangi e whai nei i tētahi pūtake ā-waho (he Ī-TĀPARE e pā ana ki te HTML), ā, ka whakarato pea i ngā wheako rerekē mō ngā pūpānui mata.'
Loading: 'Uta ihirangi ana...'
SiteTree:
PLURALNAME: Ngā Whārangi
SINGULARNAME: Whārangi

View File

@ -1,3 +1 @@
pl:
SiteTree:
PLURALNAME: Strony

View File

@ -1,3 +1 @@
pt_BR:
SiteTree:
PLURALNAME: Páginas

View File

@ -3,11 +3,6 @@ ru:
DESCRIPTION: 'Вставка элемента iframe в основную область страницы.'
PLURALNAME: 'Страницы iframe'
SINGULARNAME: 'Страница iframe'
VALIDATION:
BANNEDURLSCHEME: 'Данный тип ссылки запрещён.'
IframePage:
VALIDATION_BANNEDURLSCHEME: 'Данный тип ссылки запрещён.'
ExternalNote: 'Примечание: содержимое в разделе ниже может быть получено из внешнего источника (HTML-элемент IFRAME) и может воспроизводиться программами для чтения экрана некорректно.'
Loading: 'Идет загрузка...'
SiteTree:
PLURALNAME: Страницы
SINGULARNAME: Страница

View File

@ -1,6 +1,3 @@
sk:
IFramePage:
PLURALNAME: 'Základné stránky'
SiteTree:
PLURALNAME: Stránky
SINGULARNAME: Stránka

View File

@ -3,9 +3,5 @@ zh:
DESCRIPTION: '将 iframe 嵌入页面主体'
PLURALNAME: '基页'
SINGULARNAME: 'IFRAME 页面'
IframePage:
ExternalNote: '请注意下列内容可能来自外部来源HTML 中的 IFRAME 框架),在屏幕上阅读时可能会产生不一致的体验。'
Loading: '正在加载内容……'
SiteTree:
PLURALNAME: 页面
SINGULARNAME: 页面

View File

@ -1,9 +1,17 @@
<?php
namespace SilverStripe\IFrame\Tests;
use SilverStripe\Core\Config\Config;
use SilverStripe\Control\Director;
use SilverStripe\ORM\ValidationException;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\IFrame\IFramePage;
use SilverStripe\IFrame\IFramePageController;
class IFramePageTest extends SapphireTest
{
protected $usesDatabase = true;
public function setUp()
{
parent::setUp();
@ -88,7 +96,7 @@ class IFramePageTest extends SapphireTest
foreach ($tests['banned'] as $url) {
$iframe->IFrameURL = $url;
$this->setExpectedException('ValidationException');
$this->setExpectedException(ValidationException::class);
$iframe->write();
}
}
@ -101,39 +109,44 @@ class IFramePageTest extends SapphireTest
$page->URLSegment = 'iframe';
$page->IFrameURL = 'http://target.com';
Config::inst()->update('Director', 'alternate_protocol', 'http');
Config::inst()->update('Director', 'alternate_base_url', 'http://host.com');
Config::inst()->update(Director::class, 'alternate_protocol', 'http');
Config::inst()->update(Director::class, 'alternate_base_url', 'http://host.com');
$page->ForceProtocol = '';
$controller = new IFramePage_Controller($page);
$response = $controller->init();
$this->assertNull($response);
$controller = new IFramePageController($page);
$controller->doInit();
$response = $controller->getResponse();
$this->assertNull($response->getHeader('Location'));
Config::inst()->update('Director', 'alternate_protocol', 'https');
Config::inst()->update('Director', 'alternate_base_url', 'https://host.com');
Config::inst()->update(Director::class, 'alternate_protocol', 'https');
Config::inst()->update(Director::class, 'alternate_base_url', 'https://host.com');
$page->ForceProtocol = '';
$controller = new IFramePage_Controller($page);
$response = $controller->init();
$this->assertNull($response);
$controller = new IFramePageController($page);
$controller->doInit();
$response = $controller->getResponse();
$this->assertNull($response->getHeader('Location'));
Config::inst()->update('Director', 'alternate_protocol', 'http');
Config::inst()->update('Director', 'alternate_base_url', 'http://host.com');
Config::inst()->update(Director::class, 'alternate_protocol', 'http');
Config::inst()->update(Director::class, 'alternate_base_url', 'http://host.com');
$page->ForceProtocol = 'http://';
$controller = new IFramePage_Controller($page);
$response = $controller->init();
$this->assertNull($response);
$controller = new IFramePageController($page);
$controller->doInit();
$response = $controller->getResponse();
$this->assertNull($response->getHeader('Location'));
Config::inst()->update('Director', 'alternate_protocol', 'http');
Config::inst()->update('Director', 'alternate_base_url', 'http://host.com');
Config::inst()->update(Director::class, 'alternate_protocol', 'http');
Config::inst()->update(Director::class, 'alternate_base_url', 'http://host.com');
$page->ForceProtocol = 'https://';
$controller = new IFramePage_Controller($page);
$response = $controller->init();
$controller = new IFramePageController($page);
$controller->doInit();
$response = $controller->getResponse();
$this->assertEquals($response->getHeader('Location'), 'https://host.com/iframe/');
Config::inst()->update('Director', 'alternate_protocol', 'https');
Config::inst()->update('Director', 'alternate_base_url', 'https://host.com');
Config::inst()->update(Director::class, 'alternate_protocol', 'https');
Config::inst()->update(Director::class, 'alternate_base_url', 'https://host.com');
$page->ForceProtocol = 'http://';
$controller = new IFramePage_Controller($page);
$response = $controller->init();
$controller = new IFramePageController($page);
$controller->doInit();
$response = $controller->getResponse();
$this->assertEquals($response->getHeader('Location'), 'http://host.com/iframe/');
$_SERVER = $origServer;