From 5b8e0ba0b18a39267f3c9b8a050bb4eeeb0b8a6e Mon Sep 17 00:00:00 2001 From: Marco Hermo Date: Tue, 25 Apr 2017 01:47:34 +1200 Subject: [PATCH] This merge will upgrade silverstripe iframe module for compatibility with SS4 Implement namespacing Update unit tests --- .travis.yml | 47 +++++--------- code/IFramePage.php | 36 ++++------- code/IFramePageController.php | 27 ++++++++ composer.json | 19 ++++-- lang/ar.yml | 4 -- lang/cs.yml | 2 - lang/de.yml | 7 +-- lang/en.yml | 7 +-- lang/eo.yml | 7 +-- lang/fa_IR.yml | 3 - lang/fi.yml | 4 -- lang/id.yml | 3 - lang/it.yml | 3 - lang/lt.yml | 3 - lang/lt_LT.yml | 7 +-- lang/mi.yml | 4 -- lang/pl.yml | 2 - lang/pt_BR.yml | 2 - lang/ru.yml | 7 +-- lang/sk.yml | 3 - lang/zh.yml | 4 -- .../IFrame}/Layout/IFramePage.ss | 0 tests/IFramePageTest.php | 63 +++++++++++-------- 23 files changed, 111 insertions(+), 153 deletions(-) create mode 100644 code/IFramePageController.php rename templates/{ => Silverstripe/IFrame}/Layout/IFramePage.ss (100%) diff --git a/.travis.yml b/.travis.yml index cd11882..51c2a67 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/code/IFramePage.php b/code/IFramePage.php index dd97fd6..e4e88bf 100644 --- a/code/IFramePage.php +++ b/code/IFramePage.php @@ -1,4 +1,12 @@ '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'); - } - } -} diff --git a/code/IFramePageController.php b/code/IFramePageController.php new file mode 100644 index 0000000..1360236 --- /dev/null +++ b/code/IFramePageController.php @@ -0,0 +1,27 @@ +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'); + } + } +} diff --git a/composer.json b/composer.json index aa44403..e425681 100644 --- a/composer.json +++ b/composer.json @@ -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 } diff --git a/lang/ar.yml b/lang/ar.yml index 7f103e2..7faed3e 100644 --- a/lang/ar.yml +++ b/lang/ar.yml @@ -3,9 +3,5 @@ ar: DESCRIPTION: 'يقوم بتضمين آى فريم بداخل جسم الصفحة.' PLURALNAME: 'الصفحات الرئيسية' SINGULARNAME: 'صفحة الإطار' - IframePage: ExternalNote: 'من فضلك لاحظ قطاع المحتوى القادم و الذى من المحتمل أن يكون مستلم من مصدر خارجى (آى فريم فى صيغة اتش تى إم إل), و يمكن أن يقوم بتصرفات غير معتادة لقراء الشاشة.' Loading: 'تحميل المحتوى' - SiteTree: - PLURALNAME: صفحات - SINGULARNAME: صفحة diff --git a/lang/cs.yml b/lang/cs.yml index ab1e479..eaa6002 100644 --- a/lang/cs.yml +++ b/lang/cs.yml @@ -1,5 +1,3 @@ cs: IFramePage: PLURALNAME: 'Základní stránky' - SiteTree: - PLURALNAME: Stránky diff --git a/lang/de.yml b/lang/de.yml index d01e90b..868e19c 100644 --- a/lang/de.yml +++ b/lang/de.yml @@ -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 diff --git a/lang/en.yml b/lang/en.yml index deb35bd..af39526 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -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 diff --git a/lang/eo.yml b/lang/eo.yml index b40dac6..b338c04 100644 --- a/lang/eo.yml +++ b/lang/eo.yml @@ -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 diff --git a/lang/fa_IR.yml b/lang/fa_IR.yml index 60e391a..7c58ce2 100644 --- a/lang/fa_IR.yml +++ b/lang/fa_IR.yml @@ -2,6 +2,3 @@ fa_IR: IFramePage: PLURALNAME: 'صفحه اصلی' SINGULARNAME: 'صفحه I Frame' - SiteTree: - PLURALNAME: صفحات - SINGULARNAME: صفحه diff --git a/lang/fi.yml b/lang/fi.yml index dc34f3a..361f9e5 100644 --- a/lang/fi.yml +++ b/lang/fi.yml @@ -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 diff --git a/lang/id.yml b/lang/id.yml index 437ea58..8446cba 100644 --- a/lang/id.yml +++ b/lang/id.yml @@ -1,4 +1 @@ id: - SiteTree: - PLURALNAME: Halaman - SINGULARNAME: Halaman diff --git a/lang/it.yml b/lang/it.yml index 5ee79b0..8583063 100644 --- a/lang/it.yml +++ b/lang/it.yml @@ -1,4 +1 @@ it: - SiteTree: - PLURALNAME: Pagine - SINGULARNAME: Pagina diff --git a/lang/lt.yml b/lang/lt.yml index 9ba2888..0c0d9e9 100644 --- a/lang/lt.yml +++ b/lang/lt.yml @@ -1,6 +1,3 @@ lt: IFramePage: PLURALNAME: 'Baziniai puslapiai' - SiteTree: - PLURALNAME: Puslapiai - SINGULARNAME: Puslapis diff --git a/lang/lt_LT.yml b/lang/lt_LT.yml index ceee9f1..d190569 100644 --- a/lang/lt_LT.yml +++ b/lang/lt_LT.yml @@ -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 diff --git a/lang/mi.yml b/lang/mi.yml index a50a0fb..0ecb79d 100644 --- a/lang/mi.yml +++ b/lang/mi.yml @@ -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 diff --git a/lang/pl.yml b/lang/pl.yml index f26bfab..a8e4dde 100644 --- a/lang/pl.yml +++ b/lang/pl.yml @@ -1,3 +1 @@ pl: - SiteTree: - PLURALNAME: Strony diff --git a/lang/pt_BR.yml b/lang/pt_BR.yml index 8214274..b98a6c9 100644 --- a/lang/pt_BR.yml +++ b/lang/pt_BR.yml @@ -1,3 +1 @@ pt_BR: - SiteTree: - PLURALNAME: Páginas diff --git a/lang/ru.yml b/lang/ru.yml index ce3e165..203748a 100644 --- a/lang/ru.yml +++ b/lang/ru.yml @@ -3,11 +3,6 @@ ru: DESCRIPTION: 'Вставка элемента iframe в основную область страницы.' PLURALNAME: 'Страницы iframe' SINGULARNAME: 'Страница iframe' - VALIDATION: - BANNEDURLSCHEME: 'Данный тип ссылки запрещён.' - IframePage: + VALIDATION_BANNEDURLSCHEME: 'Данный тип ссылки запрещён.' ExternalNote: 'Примечание: содержимое в разделе ниже может быть получено из внешнего источника (HTML-элемент IFRAME) и может воспроизводиться программами для чтения экрана некорректно.' Loading: 'Идет загрузка...' - SiteTree: - PLURALNAME: Страницы - SINGULARNAME: Страница diff --git a/lang/sk.yml b/lang/sk.yml index 91a2050..a10587d 100644 --- a/lang/sk.yml +++ b/lang/sk.yml @@ -1,6 +1,3 @@ sk: IFramePage: PLURALNAME: 'Základné stránky' - SiteTree: - PLURALNAME: Stránky - SINGULARNAME: Stránka diff --git a/lang/zh.yml b/lang/zh.yml index a6b95b0..51b0d54 100644 --- a/lang/zh.yml +++ b/lang/zh.yml @@ -3,9 +3,5 @@ zh: DESCRIPTION: '将 iframe 嵌入页面主体' PLURALNAME: '基页' SINGULARNAME: 'IFRAME 页面' - IframePage: ExternalNote: '请注意,下列内容可能来自外部来源(HTML 中的 IFRAME 框架),在屏幕上阅读时可能会产生不一致的体验。' Loading: '正在加载内容……' - SiteTree: - PLURALNAME: 页面 - SINGULARNAME: 页面 diff --git a/templates/Layout/IFramePage.ss b/templates/Silverstripe/IFrame/Layout/IFramePage.ss similarity index 100% rename from templates/Layout/IFramePage.ss rename to templates/Silverstripe/IFrame/Layout/IFramePage.ss diff --git a/tests/IFramePageTest.php b/tests/IFramePageTest.php index d1ba53b..2b178a8 100644 --- a/tests/IFramePageTest.php +++ b/tests/IFramePageTest.php @@ -1,9 +1,17 @@ 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;