Skip to content

Commit

Permalink
Minor fixes based on PR
Browse files Browse the repository at this point in the history
The test will fail due to regex issue
  • Loading branch information
dingo-d committed May 5, 2019
1 parent 39c08aa commit 42ded99
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
13 changes: 11 additions & 2 deletions WPThemeReview/Sniffs/CoreFunctionality/PrefixAllGlobalsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,16 @@
class PrefixAllGlobalsSniff extends WPCSPrefixAllGlobalsSniff {

/**
* List of allowed folders to check the file path against.
* The list of allowed folders to check the file path against.
*
* This array can be extended in the custom ruleset.
* If you are using PHPCS prior to the version 3.4.0 you would overwrite the current value by setting:
*
* <property name="allowed_folders" type="array" values="template-parts,templates,partials,my-template-folder">
*
* If you are using PHPCS 3.4.0 or greater you can extend this array by setting extends="true" attribute:
*
* <property name="allowed_folders" type="array" extends="true" values="my-template-folder">
*
* @var array
*/
Expand Down Expand Up @@ -73,7 +82,7 @@ protected function process_variable_assignment( $stackPtr ) {
* @return boolean
*/
private function is_from_allowed_folder( $path ) {
foreach ( $this->$allowed_folders as $folder ) {
foreach ( $this->allowed_folders as $folder ) {
if ( strrpos( $path, '/' . $folder . '/' ) !== false ) {
return true;
}
Expand Down
28 changes: 23 additions & 5 deletions WPThemeReview/Tests/CoreFunctionality/PrefixAllGlobalsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,43 @@ class PrefixAllGlobalsUnitTest extends AbstractSniffUnitTest {
* @param string $testFile The name of the file being tested.
* @return array <int line number> => <int number of errors>
*/
public function getErrorList( $testFile = 'ThemeTemplatesException/social-share.inc' ) {
public function getErrorList( $testFile = 'partials/post-edit.inc' ) {
switch ( $testFile ) {
case 'ThemeTemplatesException/social-share.inc':
case 'social-share.inc':
return array(
6 => 1,
);
case 'ThemeTemplatesException/header.inc':
case 'header.inc':
// Template file - all OK, fall through to the default case.
case 'ThemeTemplatesException/footer_widgets.inc':
case 'footer_widgets.inc':
return array(
6 => 1,
);
case 'ThemeTemplatesException/partials/post-edit.inc':
case 'post-edit.inc':
// Template file - all OK, fall through to the default case.
default:
return array();
}
}

/**
* Get a list of all test files to check.
*
* @param string $testFileBase The base path that the unit tests files will have.
*
* @return string[]
*/
protected function getTestFiles( $testFileBase ) {
$sep = \DIRECTORY_SEPARATOR;
$test_files = glob( dirname( $testFileBase ) . $sep . 'ThemeTemplatesException{' . $sep . ',' . $sep . '*' . $sep . '}*.inc', \GLOB_BRACE );

if ( ! empty( $test_files ) ) {
return $test_files;
}

return array( $testFileBase . '.inc' );
}

/**
* Returns the lines where warnings should occur.
*
Expand Down
2 changes: 2 additions & 0 deletions WPThemeReview/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,6 @@

<!-- Themes should never touch the timezone. -->
<rule ref="WordPress.WP.TimezoneChange"/>


</ruleset>

0 comments on commit 42ded99

Please sign in to comment.