Skip to content

Commit

Permalink
New test to scan for mistakes with IF_PASSED directive
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgraham committed May 21, 2019
1 parent 77992da commit 165bb50
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
46 changes: 46 additions & 0 deletions _tests/tests/unit_tests/tempcode_mistakes.php
@@ -0,0 +1,46 @@
<?php /*
Composr
Copyright (c) ocProducts, 2004-2016
See text/EN/licence.txt for full licencing information.
*/

/**
* @license http://opensource.org/licenses/cpal_1.0 Common Public Attribution License
* @copyright ocProducts Ltd
* @package testing_platform
*/

/**
* Composr test case class (unit testing).
*/
class Tempcode_mistakes_test_set extends cms_test_case
{
public function testIfPassedGuards()
{
require_code('files');
require_code('files2');
$files = get_directory_contents(get_file_base() . '/themes');

$regexp = '#\{\+START,IF_PASSED,(\w+)\}[^\{\}]*\{(?:(?!\1)\w)*\*?\}[^\{\}]*\{\+END\}#';

$exceptions = array(
'default/templates/ATTACHMENT.tpl',
'default/templates/FORM_SCREEN_INPUT_UPLOAD.tpl',
'default/templates/FORM_SCREEN_INPUT_UPLOAD_MULTI.tpl',
);

foreach ($files as $file) {
if (in_array($file, $exceptions)) {
continue;
}

if (substr($file, -4) == '.tpl') {
$c = file_get_contents(get_file_base() . '/themes/' . $file);
$this->assertTrue(preg_match($regexp, $c) == 0, 'Found dodgy looking IF_PASSED situation in ' . $file);
}
}
}
}
Expand Up @@ -399,6 +399,7 @@ public function get_file_list()
'_tests/tests/unit_tests/versioning.php',
'_tests/tests/unit_tests/dev_environment.php',
'_tests/tests/unit_tests/filter_xml.php',
'_tests/tests/unit_tests/tempcode_mistakes.php',
'_tests/tests/unit_tests/upload_directory.php',
'_tests/tests/unit_tests/sitemap.php',
'_tests/tests/unit_tests/cdn_config.php',
Expand Down

0 comments on commit 165bb50

Please sign in to comment.