From 4cb98f1afde48dc1b6956c2fb9cc6124dd5022cd Mon Sep 17 00:00:00 2001 From: Simon Welsh Date: Wed, 21 Aug 2013 16:57:57 +1200 Subject: [PATCH 1/4] Only have Scrutinizer check PHP files --- .scrutinizer.yml | 2 ++ tests/phpcs_runner.php | 14 +++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 67c425e2a..dd2b8cd57 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$"] 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 = '') { From 2c0d03b2d62a3ab7341579a1841d292a72d927cb Mon Sep 17 00:00:00 2001 From: Simon Welsh Date: Wed, 21 Aug 2013 18:53:58 +1200 Subject: [PATCH 2/4] Exclude docs and images foldes from Scrutinizer --- .scrutinizer.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index dd2b8cd57..f2af4b2a2 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -4,4 +4,4 @@ tools: scope: file command: php tests/phpcs_runner.php %pathname% filter: - excluded_paths: ["*/css/*", "css/*", "thirdparty/*", "*/jquery-changetracker/*", "parsers/HTML/BBCodeParser/*", "*/SSTemplateParser.php$"] + excluded_paths: ["*/css/*", "css/*", "thirdparty/*", "*/jquery-changetracker/*", "parsers/HTML/BBCodeParser/*", "*/SSTemplateParser.php$", "docs/*", "*/images/*"] From c66cc952d2e1c4ec8e1b7d6dd1c57d39dfb9cbca Mon Sep 17 00:00:00 2001 From: Simon Welsh Date: Wed, 21 Aug 2013 21:27:16 +1200 Subject: [PATCH 3/4] Correct line length and indentation --- dev/BehatFixtureFactory.php | 30 +++++++++---------- forms/CheckboxField.php | 4 ++- model/Database.php | 4 +-- model/Hierarchy.php | 4 +-- .../features/bootstrap/FeatureContext.php | 28 ++++++++--------- tests/control/HTTPTest.php | 6 ++-- tests/core/CoreTest.php | 6 ++-- 7 files changed, 44 insertions(+), 38 deletions(-) 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 7f7bd1d34..ab4fb7d62 100644 --- a/forms/CheckboxField.php +++ b/forms/CheckboxField.php @@ -62,7 +62,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 598bf988f..699bb9625 100644 --- a/model/Database.php +++ b/model/Database.php @@ -1136,7 +1136,7 @@ abstract class SS_Query implements Iterator { $result .= ""; foreach($record as $k => $v) { $result .= "" . Convert::raw2xml($k) . " "; - } + } $result .= " \n"; } @@ -1213,7 +1213,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 4374d5960..e66d3e727 100644 --- a/model/Hierarchy.php +++ b/model/Hierarchy.php @@ -77,8 +77,8 @@ class Hierarchy extends DataExtension { * @param int $nodeCountThreshold The lower bounds for the amount of nodes to mark. If set, the logic will expand * nodes until it eaches at least this number, and then stops. Root nodes will always * show regardless of this settting. Further nodes can be lazy-loaded via ajax. - * This isn't a hard limit. Example: On a value of 10, with 20 root nodes, each having - * 30 children, the actual node count will be 50 (all root nodes plus first expanded child). + * This isn't a hard limit. Example: On a value of 10, with 20 root nodes, each having 30 + * children, the actual node count will be 50 (all root nodes plus first expanded child). * * @return string */ 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/control/HTTPTest.php b/tests/control/HTTPTest.php index 7cc962c70..bd4a00c06 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 73e10ffa5..b8eb66cb9 100644 --- a/tests/core/CoreTest.php +++ b/tests/core/CoreTest.php @@ -22,11 +22,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 From 54edc0ddacd421690b5d3e7a34de5bafa6fcdf58 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Thu, 22 Aug 2013 12:48:11 +0200 Subject: [PATCH 4/4] Fix Behat window switching in chrome Workaround only, see https://groups.google.com/forum/#!topic/behat/QNhOuGHKEWI --- .../Framework/Test/Behaviour/CmsUiContext.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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 f6078ff17..ed897da5b 100644 --- a/tests/behat/features/bootstrap/SilverStripe/Framework/Test/Behaviour/CmsUiContext.php +++ b/tests/behat/features/bootstrap/SilverStripe/Framework/Test/Behaviour/CmsUiContext.php @@ -245,10 +245,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); } /** @@ -257,10 +260,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); } /**