Skip to content

Commit

Permalink
Update CI tool configurations to fit SS4 conventions
Browse files Browse the repository at this point in the history
Also update test class to use non-deprecated methods from core (such as
Config::update). Fix a few code sniffer errors.
  • Loading branch information
Dylan Wagstaff committed Nov 22, 2017
1 parent 4fb947d commit 352bc67
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 52 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
/.gitignore export-ignore
/.travis.yml export-ignore
/.scrutinizer.yml export-ignore
/codecov.yml
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
6 changes: 6 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
inherit: true

build:
nodes:
analysis:
tests:
override: [php-scrutinizer-run]

checks:
php:
code_rating: true
Expand Down
35 changes: 18 additions & 17 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion _config.php
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
<?php

25 changes: 16 additions & 9 deletions code/IFramePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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.
Expand Down Expand Up @@ -40,22 +41,28 @@ public function getCMSFields()

$fields->removeFieldFromTab('Root.Main', 'Content');
$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(
'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.
Expand Down
1 change: 1 addition & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
comment: false
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
}
],
"require": {
"silverstripe/recipe-cms": "^1"
"silverstripe/cms": "^4.0"
},
"require-dev": {
"phpunit/PHPUnit": "^5.7"
"phpunit/phpunit": "^5.7",
"squizlabs/php_codesniffer": "^3.0"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion license.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
9 changes: 9 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -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 changes: 13 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -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>
32 changes: 10 additions & 22 deletions tests/IFramePageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -109,40 +97,40 @@ public function testForceProtocol()
$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();
Expand Down

0 comments on commit 352bc67

Please sign in to comment.