Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'tests/PHPUnit/Integration/ReleaseCheckListTest.php')
-rw-r--r--tests/PHPUnit/Integration/ReleaseCheckListTest.php128
1 files changed, 122 insertions, 6 deletions
diff --git a/tests/PHPUnit/Integration/ReleaseCheckListTest.php b/tests/PHPUnit/Integration/ReleaseCheckListTest.php
index 4852d2cf5d..469c6df27a 100644
--- a/tests/PHPUnit/Integration/ReleaseCheckListTest.php
+++ b/tests/PHPUnit/Integration/ReleaseCheckListTest.php
@@ -28,6 +28,8 @@ class ReleaseCheckListTest extends \PHPUnit_Framework_TestCase
{
private $globalConfig;
+ const MINIMUM_PHP_VERSION = '5.3.3';
+
public function setUp()
{
$iniReader = new IniReader();
@@ -36,6 +38,21 @@ class ReleaseCheckListTest extends \PHPUnit_Framework_TestCase
parent::setUp();
}
+ public function test_minimumPHPVersion_isEnforced()
+ {
+ global $piwik_minimumPHPVersion;
+ $this->assertEquals(self::MINIMUM_PHP_VERSION, $piwik_minimumPHPVersion, 'minimum PHP version global variable correctly defined');
+ }
+
+ public function test_minimumPhpVersion_isDefinedInComposerJson()
+ {
+ $composerJson = $this->getComposerJsonAsArray();
+ $this->assertEquals(self::MINIMUM_PHP_VERSION, $composerJson['config']['platform']['php']);
+
+ $expectedRequirePhp = '>=' . self::MINIMUM_PHP_VERSION;
+ $this->assertEquals($expectedRequirePhp, $composerJson['require']['php']);
+ }
+
public function test_icoFilesIconsShouldBeInPngFormat()
{
$files = Filesystem::globr(PIWIK_INCLUDE_PATH . '/plugins', '*.ico');
@@ -121,6 +138,86 @@ class ReleaseCheckListTest extends \PHPUnit_Framework_TestCase
}
}
+ public function getTemplateFileExtensions()
+ {
+ $extensions = array(
+ array('htm'),
+ array('html'),
+ array('twig'),
+ array('tpl'),
+ );
+ return $extensions;
+ }
+
+ /**
+ * @dataProvider getTemplateFileExtensions
+ */
+ public function testTemplatesDontContainJquery($extension)
+ {
+ $patternFailIfFound = 'jquery';
+
+ // known files that will for sure not contain a "buggy" $patternFailIfFound
+ $whiteListedFiles = array(
+ PIWIK_INCLUDE_PATH . '/plugins/TestRunner/templates/travis.yml.twig',
+ PIWIK_INCLUDE_PATH . '/plugins/CoreUpdater/templates/layout.twig',
+ PIWIK_INCLUDE_PATH . '/plugins/Installation/templates/layout.twig',
+ PIWIK_INCLUDE_PATH . '/plugins/Login/templates/login.twig',
+ PIWIK_INCLUDE_PATH . '/tests/UI/screenshot-diffs/singlediff.html',
+
+ // Note: entries below are paths and any file within these paths will be automatically whitelisted
+ PIWIK_INCLUDE_PATH . '/tests/resources/overlay-test-site-real/',
+ PIWIK_INCLUDE_PATH . '/tests/resources/overlay-test-site/',
+ PIWIK_INCLUDE_PATH . '/vendor/facebook/xhprof/xhprof_html/docs/',
+ );
+
+ $files = Filesystem::globr(PIWIK_INCLUDE_PATH, '*.' . $extension);
+ $this->assertFilesDoNotContain($files, $patternFailIfFound, $whiteListedFiles);
+ }
+
+ /**
+ * @param $files
+ * @param $patternFailIfFound
+ * @param $whiteListedFiles
+ */
+ private function assertFilesDoNotContain($files, $patternFailIfFound, $whiteListedFiles)
+ {
+ $foundPatterns = array();
+ foreach ($files as $file) {
+ if($this->isFileOrPathWhitelisted($whiteListedFiles, $file)) {
+ continue;
+ }
+ $content = file_get_contents($file);
+ $foundPattern = strpos($content, $patternFailIfFound) !== false;
+
+ if($foundPattern) {
+ $foundPatterns[] = $file;
+ }
+ }
+
+ $this->assertEmpty($foundPatterns,
+ sprintf("Forbidden pattern \"%s\" was found in the following files ---> please manually delete these files from Git. \n\n\t%s",
+ $patternFailIfFound,
+ implode("\n\t", $foundPatterns)
+ )
+ );
+ }
+
+ /**
+ * @param $whiteListedFiles
+ * @param $file
+ * @return bool
+ */
+ private function isFileOrPathWhitelisted($whiteListedFiles, $file)
+ {
+ foreach ($whiteListedFiles as $whitelistFile) {
+ if (strpos($file, $whitelistFile) === 0) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+
public function testCheckThatGivenPluginsAreDisabledByDefault()
{
$pluginsShouldBeDisabled = array(
@@ -160,6 +257,7 @@ class ReleaseCheckListTest extends \PHPUnit_Framework_TestCase
{
$files = Filesystem::globr(PIWIK_INCLUDE_PATH, '*.php');
+ $tested = 0;
foreach($files as $file) {
// skip files in these folders
if (strpos($file, '/libs/') !== false) {
@@ -182,7 +280,10 @@ class ReleaseCheckListTest extends \PHPUnit_Framework_TestCase
$start = fgets($handle, strlen($expectedStart) + 1 );
$this->assertEquals($start, $expectedStart, "File $file does not start with $expectedStart");
+ $tested++;
}
+
+ $this->assertGreaterThan(2000, $tested, 'should have tested at least thousand of php files');
}
public function test_jsfilesDoNotContainFakeSpaces()
@@ -338,8 +439,12 @@ class ReleaseCheckListTest extends \PHPUnit_Framework_TestCase
shell_exec("sed '/<DEBUG>/,/<\/DEBUG>/d' < ". PIWIK_DOCUMENT_ROOT ."/js/piwik.js | sed 's/eval/replacedEvilString/' | java -jar yuicompressor-2.4.7/build/yuicompressor-2.4.7.jar --type js --line-break 1000 | sed 's/replacedEvilString/eval/' | sed 's/^[/][*]/\/*!/' > " . PIWIK_DOCUMENT_ROOT ."/piwik-minified.js");
$this->assertFileEquals(PIWIK_DOCUMENT_ROOT . '/piwik-minified.js',
- PIWIK_DOCUMENT_ROOT . '/piwik.js',
- 'minified /piwik.js is out of date, please re-generate the minified /piwik.js using instructions in /js/README'
+ PIWIK_DOCUMENT_ROOT . '/piwik.js',
+ 'minified /piwik.js is out of date, please re-generate the minified files using instructions in /js/README'
+ );
+ $this->assertFileEquals(PIWIK_DOCUMENT_ROOT . '/piwik-minified.js',
+ PIWIK_DOCUMENT_ROOT . '/js/piwik.min.js',
+ 'minified /js/piwik.min.js is out of date, please re-generate the minified files using instructions in /js/README'
);
}
@@ -398,7 +503,8 @@ class ReleaseCheckListTest extends \PHPUnit_Framework_TestCase
|| strpos($file, "tests/resources/Updater/") !== false
|| strpos($file, "Twig/Tests/") !== false
|| strpos($file, "processed/") !== false
- || strpos($file, "/vendor/") !== false;
+ || strpos($file, "/vendor/") !== false
+ || (strpos($file, "tmp/") !== false && strpos($file, 'index.php') !== false);
$isLib = strpos($file, "lib/xhprof") !== false || strpos($file, "phpunit/phpunit") !== false;
return ($isIniFile && $isIniFileInTests) || $isTestResultFile || $isLib;
@@ -526,8 +632,7 @@ class ReleaseCheckListTest extends \PHPUnit_Framework_TestCase
*/
private function getComposerRequireDevPackages()
{
- $composer = file_get_contents(PIWIK_INCLUDE_PATH . '/composer.json');
- $composerJson = json_decode($composer, $assoc = true);
+ $composerJson = $this->getComposerJsonAsArray();
$composerDependencyDevOnly = array_keys($composerJson["require-dev"]);
return $composerDependencyDevOnly;
}
@@ -657,7 +762,7 @@ class ReleaseCheckListTest extends \PHPUnit_Framework_TestCase
$countFileChecked++;
}
- $this->assertTrue($countFileChecked > 100, "expected to test at least 100 files, but tested only " . $countFileChecked);
+ $this->assertTrue($countFileChecked > 42, "expected to test at least 100 files, but tested only " . $countFileChecked);
if (!empty($errors)) {
throw new Exception(implode(",\n\n ", $errors));
@@ -672,4 +777,15 @@ class ReleaseCheckListTest extends \PHPUnit_Framework_TestCase
{
return stripos($file, "/tests/") !== false || stripos($file, "/phantomjs/") !== false;
}
+
+ /**
+ * @return mixed
+ */
+ private function getComposerJsonAsArray()
+ {
+ $composer = file_get_contents(PIWIK_INCLUDE_PATH . '/composer.json');
+ $composerJson = json_decode($composer, $assoc = true);
+ return $composerJson;
+ }
+
}