diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 67c425e2a..f2af4b2a2 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -3,3 +3,5 @@ tools: - scope: file command: php tests/phpcs_runner.php %pathname% + filter: + excluded_paths: ["*/css/*", "css/*", "thirdparty/*", "*/jquery-changetracker/*", "parsers/HTML/BBCodeParser/*", "*/SSTemplateParser.php$", "docs/*", "*/images/*"] diff --git a/dev/BehatFixtureFactory.php b/dev/BehatFixtureFactory.php index a4f7a829a..f8c98e079 100644 --- a/dev/BehatFixtureFactory.php +++ b/dev/BehatFixtureFactory.php @@ -4,20 +4,20 @@ * @subpackage testing */ class BehatFixtureFactory extends \FixtureFactory { - public function createObject($name, $identifier, $data = null) { - if(!$data) $data = array(); + public function createObject($name, $identifier, $data = null) { + if(!$data) $data = array(); - // Copy identifier to some visible property unless its already defined. - // Exclude files, since they generate their own named based on the file path. - if(!$name != 'File' && !is_subclass_of($name, 'File')) { - foreach(array('Name', 'Title') as $fieldName) { - if(singleton($name)->hasField($fieldName) && !isset($data[$fieldName])) { - $data[$fieldName] = $identifier; - break; - } - } - } + // Copy identifier to some visible property unless its already defined. + // Exclude files, since they generate their own named based on the file path. + if(!$name != 'File' && !is_subclass_of($name, 'File')) { + foreach(array('Name', 'Title') as $fieldName) { + if(singleton($name)->hasField($fieldName) && !isset($data[$fieldName])) { + $data[$fieldName] = $identifier; + break; + } + } + } - return parent::createObject($name, $identifier, $data); - } -} \ No newline at end of file + return parent::createObject($name, $identifier, $data); + } +} diff --git a/forms/CheckboxField.php b/forms/CheckboxField.php index 7f0c6c814..1c07a93aa 100644 --- a/forms/CheckboxField.php +++ b/forms/CheckboxField.php @@ -56,7 +56,9 @@ class CheckboxField_Readonly extends ReadonlyField { } public function Value() { - return Convert::raw2xml($this->value ? _t('CheckboxField.YESANSWER', 'Yes') : _t('CheckboxField.NOANSWER', 'No')); + return Convert::raw2xml($this->value ? + _t('CheckboxField.YESANSWER', 'Yes') : + _t('CheckboxField.NOANSWER', 'No')); } } diff --git a/model/Database.php b/model/Database.php index e8a083ffe..020564069 100644 --- a/model/Database.php +++ b/model/Database.php @@ -1157,7 +1157,7 @@ abstract class SS_Query implements Iterator { $result .= ""; foreach($record as $k => $v) { $result .= "" . Convert::raw2xml($k) . " "; - } + } $result .= " \n"; } @@ -1234,7 +1234,7 @@ abstract class SS_Query implements Iterator { */ public function valid() { if(!$this->queryHasBegun) $this->next(); - return $this->currentRecord !== false; + return $this->currentRecord !== false; } /** diff --git a/model/Hierarchy.php b/model/Hierarchy.php index d4f6c667c..010796a12 100644 --- a/model/Hierarchy.php +++ b/model/Hierarchy.php @@ -15,7 +15,7 @@ class Hierarchy extends DataExtension { * @var Int */ protected $_cache_numChildren; - + /** * @config * @var integer The lower bounds for the amount of nodes to mark. If set, the logic will expand @@ -113,7 +113,7 @@ class Hierarchy extends DataExtension { if($limitToMarked && $rootCall) { $this->markingFinished($numChildrenMethod); } - + if($nodeCountCallback) { $nodeCountWarning = $nodeCountCallback($this->owner, $this->owner->$numChildrenMethod()); if($nodeCountWarning) return $nodeCountWarning; @@ -154,9 +154,9 @@ class Hierarchy extends DataExtension { $output .= $nodeCountWarning; $child->markClosed(); } else { - $output .= $child->getChildrenAsUL("", $titleEval, $extraArg, $limitToMarked, $childrenMethod, - $numChildrenMethod, false, $nodeCountThreshold); - } + $output .= $child->getChildrenAsUL("", $titleEval, $extraArg, $limitToMarked, $childrenMethod, + $numChildrenMethod, false, $nodeCountThreshold); + } } elseif($child->isTreeOpened()) { // Since we're not loading children, don't mark it as open either $child->markClosed(); @@ -455,7 +455,7 @@ class Hierarchy extends DataExtension { $id = $this->owner->ID; return isset(self::$treeOpened[$baseClass][$id]) ? self::$treeOpened[$baseClass][$id] : false; } - + /** * Get a list of this DataObject's and all it's descendants IDs. * @return int @@ -495,7 +495,7 @@ class Hierarchy extends DataExtension { $this->_cache_children = $result->filterByCallback(function($item) { return $item->canView(); }); - } + } return $this->_cache_children; } @@ -614,7 +614,7 @@ class Hierarchy extends DataExtension { ->exclude('ID', (int)$this->owner->ID); if (!$showAll && $this->owner->db('ShowInMenus')) { $staged = $staged->filter('ShowInMenus', 1); - } + } $this->owner->extend("augmentStageChildren", $staged, $showAll); return $staged; } @@ -640,7 +640,7 @@ class Hierarchy extends DataExtension { 'Versioned.mode' => $onlyDeletedFromStage ? 'stage_unique' : 'stage', 'Versioned.stage' => 'Live' )); - + if(!$showAll) $children = $children->filter('ShowInMenus', 1); return $children; diff --git a/tests/behat/features/bootstrap/FeatureContext.php b/tests/behat/features/bootstrap/FeatureContext.php index a9c4835d4..bf8568fa3 100644 --- a/tests/behat/features/bootstrap/FeatureContext.php +++ b/tests/behat/features/bootstrap/FeatureContext.php @@ -31,7 +31,7 @@ class FeatureContext extends SilverStripeContext * Initializes context. * Every scenario gets it's own context object. * - * @param array $parameters context parameters (set them up through behat.yml) + * @param array $parameters context parameters (set them up through behat.yml) */ public function __construct(array $parameters) { @@ -47,22 +47,22 @@ class FeatureContext extends SilverStripeContext $this->useContext('FixtureContext', $fixtureContext); // Use blueprints to set user name from identifier - $factory = $fixtureContext->getFixtureFactory(); - $blueprint = \Injector::inst()->create('FixtureBlueprint', 'Member'); - $blueprint->addCallback('beforeCreate', function($identifier, &$data, &$fixtures) { - if(!isset($data['FirstName'])) $data['FirstName'] = $identifier; - }); - $factory->define('Member', $blueprint); + $factory = $fixtureContext->getFixtureFactory(); + $blueprint = \Injector::inst()->create('FixtureBlueprint', 'Member'); + $blueprint->addCallback('beforeCreate', function($identifier, &$data, &$fixtures) { + if(!isset($data['FirstName'])) $data['FirstName'] = $identifier; + }); + $factory->define('Member', $blueprint); } public function setMinkParameters(array $parameters) - { - parent::setMinkParameters($parameters); - - if(isset($parameters['files_path'])) { - $this->getSubcontext('FixtureContext')->setFilesPath($parameters['files_path']); - } - } + { + parent::setMinkParameters($parameters); + + if(isset($parameters['files_path'])) { + $this->getSubcontext('FixtureContext')->setFilesPath($parameters['files_path']); + } + } /** * @return FixtureFactory diff --git a/tests/behat/features/bootstrap/SilverStripe/Framework/Test/Behaviour/CmsUiContext.php b/tests/behat/features/bootstrap/SilverStripe/Framework/Test/Behaviour/CmsUiContext.php index 6c528cf9d..bbc50048a 100644 --- a/tests/behat/features/bootstrap/SilverStripe/Framework/Test/Behaviour/CmsUiContext.php +++ b/tests/behat/features/bootstrap/SilverStripe/Framework/Test/Behaviour/CmsUiContext.php @@ -246,10 +246,13 @@ class CmsUiContext extends BehatContext public function thePreviewContains($content) { $driver = $this->getSession()->getDriver(); - $driver->switchToIFrame('cms-preview-iframe'); + // TODO Remove once we have native support in Mink and php-webdriver, + // see https://groups.google.com/forum/#!topic/behat/QNhOuGHKEWI + $origWindowName = $driver->getWebDriverSession()->window_handle(); + $driver->switchToIFrame('cms-preview-iframe'); $this->getMainContext()->assertPageContainsText($content); - $driver->switchToWindow(); + $driver->switchToWindow($origWindowName); } /** @@ -304,10 +307,13 @@ class CmsUiContext extends BehatContext public function thePreviewDoesNotContain($content) { $driver = $this->getSession()->getDriver(); + // TODO Remove once we have native support in Mink and php-webdriver, + // see https://groups.google.com/forum/#!topic/behat/QNhOuGHKEWI + $origWindowName = $driver->getWebDriverSession()->window_handle(); + $driver->switchToIFrame('cms-preview-iframe'); - $this->getMainContext()->assertPageNotContainsText($content); - $driver->switchToWindow(); + $driver->switchToWindow($origWindowName); } /** diff --git a/tests/control/HTTPTest.php b/tests/control/HTTPTest.php index 10b29940a..eaf313bd7 100644 --- a/tests/control/HTTPTest.php +++ b/tests/control/HTTPTest.php @@ -130,7 +130,8 @@ class HTTPTest extends SapphireTest { // background-image // Note that using /./ in urls is absolutely acceptable $test->assertEquals( - '
Content
', + '
'. + 'Content
', HTTP::absoluteURLs('
Content
') ); @@ -169,7 +170,8 @@ class HTTPTest extends SapphireTest { // background // Note that using /./ in urls is absolutely acceptable $test->assertEquals( - '
SS Blog
', + '
'. + 'SS Blog
', HTTP::absoluteURLs('
SS Blog
') ); diff --git a/tests/core/CoreTest.php b/tests/core/CoreTest.php index 5603204e1..28933b165 100644 --- a/tests/core/CoreTest.php +++ b/tests/core/CoreTest.php @@ -24,11 +24,13 @@ class CoreTest extends SapphireTest { $user = getTempFolderUsername(); // A typical Windows location for where sites are stored on IIS - $this->assertEquals(sys_get_temp_dir() . '/silverstripe-cacheC--inetpub-wwwroot-silverstripe-test-project/' . $user, + $this->assertEquals(sys_get_temp_dir() . + '/silverstripe-cacheC--inetpub-wwwroot-silverstripe-test-project/' . $user, getTempFolder('C:\\inetpub\\wwwroot\\silverstripe-test-project')); // A typical Mac OS X location for where sites are stored - $this->assertEquals(sys_get_temp_dir() . '/silverstripe-cache-Users-joebloggs-Sites-silverstripe-test-project/' . $user, + $this->assertEquals(sys_get_temp_dir() . + '/silverstripe-cache-Users-joebloggs-Sites-silverstripe-test-project/' . $user, getTempFolder('/Users/joebloggs/Sites/silverstripe-test-project')); // A typical Linux location for where sites are stored diff --git a/tests/phpcs_runner.php b/tests/phpcs_runner.php index 43a53dc00..602377e8c 100644 --- a/tests/phpcs_runner.php +++ b/tests/phpcs_runner.php @@ -12,14 +12,18 @@ if(!empty($_SERVER['argv'][1])) { $result = array('comments' => array()); -// Run each sniff +$extension = pathinfo($path, PATHINFO_EXTENSION); -// phpcs --encoding=utf-8 --standard=framework/tests/phpcs/tabs.xml -run_sniff('tabs.xml', $path, $result); +// Whitelist of extensions to check (default phpcs list) +if(in_array($extension, array('php', 'js', 'inc', 'css'))) { + // Run each sniff -// phpcs --encoding=utf-8 --tab-width=4 --standard=framework/tests/phpcs/ruleset.xml -run_sniff('ruleset.xml', $path, $result, '--tab-width=4'); + // phpcs --encoding=utf-8 --standard=framework/tests/phpcs/tabs.xml + run_sniff('tabs.xml', $path, $result); + // phpcs --encoding=utf-8 --tab-width=4 --standard=framework/tests/phpcs/ruleset.xml + run_sniff('ruleset.xml', $path, $result, '--tab-width=4'); +} echo json_encode($result); function run_sniff($standard, $path, array &$result, $extraFlags = '') {