Converted to PSR-2

This commit is contained in:
helpfulrobot 2015-11-18 16:57:44 +13:00
parent 91f9c9cb5b
commit 15ec879c70
2 changed files with 221 additions and 207 deletions

View File

@ -4,8 +4,9 @@
* CMS editor can choose width, height, or set it to attempt automatic size configuration.
*/
class IFramePage extends Page {
static $db = array(
class IFramePage extends Page
{
public static $db = array(
'IFrameURL' => 'Text',
'AutoHeight' => 'Boolean(1)',
'AutoWidth' => 'Boolean(1)',
@ -16,16 +17,17 @@ class IFramePage extends Page {
'ForceProtocol' => 'Varchar',
);
static $defaults = array(
public static $defaults = array(
'AutoHeight' => '1',
'AutoWidth' => '1',
'FixedHeight' => '500',
'FixedWidth' => '0'
);
static $description = 'Embeds an iframe into the body of the page.';
public static $description = 'Embeds an iframe into the body of the page.';
function getCMSFields() {
public function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->removeFieldFromTab('Root.Main', 'Content');
@ -53,7 +55,8 @@ class IFramePage extends Page {
/**
* Compute class from the size parameters.
*/
function getClass() {
public function getClass()
{
$class = '';
if ($this->AutoHeight) {
$class .= 'iframepage-height-auto';
@ -65,18 +68,20 @@ class IFramePage extends Page {
/**
* Compute style from the size parameters.
*/
function getStyle() {
public function getStyle()
{
$style = '';
// Always add fixed height as a fallback if autosetting or JS fails.
$height = $this->FixedHeight;
if (!$height) $height = 800;
if (!$height) {
$height = 800;
}
$style .= "height: {$height}px; ";
if ($this->AutoWidth) {
$style .= "width: 100%; ";
}
else if ($this->FixedWidth) {
} elseif ($this->FixedWidth) {
$style .= "width: {$this->FixedWidth}px; ";
}
@ -89,7 +94,8 @@ class IFramePage extends Page {
* @throws ValidationException
* @return ValidationResult
*/
public function validate() {
public function validate()
{
$result = parent::validate();
//whitelist allowed URL schemes
@ -104,8 +110,10 @@ class IFramePage extends Page {
}
}
class IFramePage_Controller extends Page_Controller {
function init() {
class IFramePage_Controller extends Page_Controller
{
public function init()
{
parent::init();
if ($this->ForceProtocol) {

View File

@ -1,18 +1,21 @@
<?php
class IFramePageTest extends SapphireTest {
public function setUp() {
class IFramePageTest extends SapphireTest
{
public function setUp()
{
parent::setUp();
Config::nest();
}
public function tearDown() {
public function tearDown()
{
Config::unnest();
parent::tearDown();
}
function testGetClass() {
public function testGetClass()
{
$iframe = new IFramePage();
$iframe->AutoHeight = 1;
$iframe->getClass();
@ -25,7 +28,8 @@ class IFramePageTest extends SapphireTest {
$this->assertNotContains('iframepage-height-auto', $iframe->getClass());
}
function testGetStyle() {
public function testGetStyle()
{
$iframe = new IFramePage();
$iframe->FixedHeight = 0;
@ -45,7 +49,8 @@ class IFramePageTest extends SapphireTest {
$this->assertContains('width: 200px', $iframe->getStyle(), 'Fixed width is settable');
}
function testAllowedUrls() {
public function testAllowedUrls()
{
$iframe = new IFramePage();
$tests = array(
@ -86,7 +91,8 @@ class IFramePageTest extends SapphireTest {
}
}
public function testForceProtocol() {
public function testForceProtocol()
{
$origServer = $_SERVER;
$page = new IFramePage();