From 6f693ad5486c00ed7a0c2ea8da939a5d0fca1935 Mon Sep 17 00:00:00 2001 From: khacoder Date: Fri, 19 Aug 2016 16:48:02 -0600 Subject: [PATCH] No Auto Generated Themes Issue #63 Verify that themes are not generated, by searching for strings contained in known auto generated packages. --- .../Sniffs/Theme/NoAutoGenerateSniff.php | 92 +++++++++++++++++++ .../Tests/Theme/NoAutoGenerateUnitTest.css | 23 +++++ .../Tests/Theme/NoAutoGenerateUnitTest.inc | 35 +++++++ .../Tests/Theme/NoAutoGenerateUnitTest.php | 68 ++++++++++++++ 4 files changed, 218 insertions(+) create mode 100644 WordPress/Sniffs/Theme/NoAutoGenerateSniff.php create mode 100644 WordPress/Tests/Theme/NoAutoGenerateUnitTest.css create mode 100644 WordPress/Tests/Theme/NoAutoGenerateUnitTest.inc create mode 100644 WordPress/Tests/Theme/NoAutoGenerateUnitTest.php diff --git a/WordPress/Sniffs/Theme/NoAutoGenerateSniff.php b/WordPress/Sniffs/Theme/NoAutoGenerateSniff.php new file mode 100644 index 0000000000..72111faccc --- /dev/null +++ b/WordPress/Sniffs/Theme/NoAutoGenerateSniff.php @@ -0,0 +1,92 @@ +getTokens(); + $token = $tokens[ $stackPtr ]; + $content = trim( $token['content'] ); + + // No need to check an empty string. + if ( '' === $content ) { + return; + } + + foreach ( $this->generated_themes as $generated_theme ) { + // The check can have false positives like artisteers but chances of that in a valid theme is low. + if ( false === strpos( strtolower( $content ), $generated_theme ) ) { + continue; + } + $phpcsFile->addError( + 'Auto generated themes are not allowed in the theme directory. Found: %s', + $stackPtr, + 'AutoGeneratedFound', + array( $generated_theme ) + ); + } + + } + +} diff --git a/WordPress/Tests/Theme/NoAutoGenerateUnitTest.css b/WordPress/Tests/Theme/NoAutoGenerateUnitTest.css new file mode 100644 index 0000000000..1cb0eb8aea --- /dev/null +++ b/WordPress/Tests/Theme/NoAutoGenerateUnitTest.css @@ -0,0 +1,23 @@ +/* +{ +Theme URI:http://TemplateToaster.com +Author:TemplateToaster +Author URI:http://TemplateToaster.com +} +*/ +/* +Theme URI: http://www.themler.com/wordpress-themes +Description: Themler-generated theme +*/ +/* +Theme URI: http://www.WpThemeGenerator.com/ +Author: WpThemeGenerator +Author URI:www.WpThemeGenerator.com +*/ +/* OK. */ +/* +Theme Name: Twenty Seventeen +Theme URI: http://example.com +Author: WordPress.org +Author URI: example.com/author +*/ diff --git a/WordPress/Tests/Theme/NoAutoGenerateUnitTest.inc b/WordPress/Tests/Theme/NoAutoGenerateUnitTest.inc new file mode 100644 index 0000000000..7f448a6e1b --- /dev/null +++ b/WordPress/Tests/Theme/NoAutoGenerateUnitTest.inc @@ -0,0 +1,35 @@ + +

Lubith

+ + => + */ + public function getErrorList( $testFile = '' ) { + switch ( $testFile ) { + case 'NoAutoGenerateUnitTest.inc': + return array( + 2 => 1, + 3 => 1, + 6 => 1, + 8 => 1, + 9 => 1, + 11 => 1, + 13 => 1, + 14 => 1, + 15 => 1, + 22 => 1, + ); + break; + case 'NoAutoGenerateUnitTest.css': + return array( + 3 => 1, + 4 => 1, + 5 => 1, + 9 => 1, + 10 => 1, + 13 => 1, + 14 => 1, + 15 => 1, + ); + break; + default: + return array(); + break; + } + } + + /** + * Returns the lines where warnings should occur. + * + * @return array => + */ + public function getWarningList() { + return array(); + } + +} // End class.