PageRenderTime 25ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/core/ReleaseCheckList.test.php

https://github.com/quarkness/piwik
PHP | 219 lines | 194 code | 17 blank | 8 comment | 8 complexity | 31e9fc775b12f199bcea53c13be0d9bb MD5 | raw file
  1. <?php
  2. if(!defined('PIWIK_CONFIG_TEST_INCLUDED'))
  3. {
  4. require_once dirname(__FILE__)."/../../tests/config_test.php";
  5. }
  6. //Zend_Loader::loadClass('Piwik_');
  7. class Test_Piwik_ReleaseCheckList extends UnitTestCase
  8. {
  9. public function test_checkThatConfigurationValuesAreProductionValues()
  10. {
  11. $this->globalConfig = _parse_ini_file(PIWIK_PATH_TEST_TO_ROOT . '/config/global.ini.php', true);
  12. // var_dump($globalConfig);
  13. $this->checkEqual(array('Debug' => 'always_archive_data_day'), '0');
  14. $this->checkEqual(array('Debug' => 'always_archive_data_period'), '0');
  15. $this->checkEqual(array('Debug' => 'enable_sql_profiler'), '0');
  16. $this->checkEqual(array('General' => 'time_before_today_archive_considered_outdated'), '10');
  17. $this->checkEqual(array('General' => 'enable_browser_archiving_triggering'), '1');
  18. $this->checkEqual(array('General' => 'default_language'), 'en');
  19. $this->checkEqual(array('Tracker' => 'record_statistics'), '1');
  20. $this->checkEqual(array('Tracker' => 'visit_standard_length'), '1800');
  21. $this->checkEqual(array('Tracker' => 'trust_visitors_cookies'), '0');
  22. // logging messages are disabled
  23. $this->checkEqual(array('log' => 'logger_message'), '');
  24. $this->checkEqual(array('log' => 'logger_exception'), array('screen'));
  25. $this->checkEqual(array('log' => 'logger_error'), array('screen'));
  26. $this->checkEqual(array('log' => 'logger_api_call'), null);
  27. }
  28. public function test_templatesDontContainDebug()
  29. {
  30. $patternFailIfFound = '{debug}';
  31. $files = Piwik::globr(PIWIK_INCLUDE_PATH . '/plugins', '*.tpl');
  32. foreach($files as $file)
  33. {
  34. $content = file_get_contents($file);
  35. $this->assertFalse(strpos($content, $patternFailIfFound), 'found in '.$file);
  36. }
  37. }
  38. private function checkEqual($key, $valueExpected)
  39. {
  40. $section = key($key);
  41. $optionName = current($key);
  42. $value = null;
  43. if(isset($this->globalConfig[$section][$optionName]))
  44. {
  45. $value = $this->globalConfig[$section][$optionName];
  46. }
  47. $this->assertEqual($value, $valueExpected, "$section -> $optionName was '".var_export($value, true)."', expected '".var_export($valueExpected, true)."'");
  48. }
  49. public function test_checkThatGivenPluginsAreDisabledByDefault()
  50. {
  51. $pluginsShouldBeDisabled = array(
  52. 'AnonymizeIP',
  53. 'DBStats',
  54. 'SecurityInfo',
  55. 'VisitorGenerator',
  56. );
  57. foreach($pluginsShouldBeDisabled as $pluginName)
  58. {
  59. if(in_array($pluginName, $this->globalConfig['Plugins']['Plugins']))
  60. {
  61. throw new Exception("Plugin $pluginName is enabled by default but shouldn't.");
  62. }
  63. }
  64. }
  65. /**
  66. * test that the profiler is disabled (mandatory on a production server)
  67. */
  68. public function test_profilingDisabledInProduction()
  69. {
  70. require_once 'Tracker/Db.php';
  71. $this->assertTrue(Piwik_Tracker_Db::isProfilingEnabled() === false, 'SQL profiler should be disabled in production! See Piwik_Tracker_Db::$profiling');
  72. }
  73. function test_piwikTrackerDebugIsOff()
  74. {
  75. $this->assertTrue(!isset($GLOBALS['PIWIK_TRACKER_DEBUG']));
  76. // hiding echoed out message on empty request
  77. ob_start();
  78. include PIWIK_PATH_TEST_TO_ROOT . "/piwik.php";
  79. ob_end_clean();
  80. $this->assertTrue($GLOBALS['PIWIK_TRACKER_DEBUG'] === false);
  81. }
  82. function test_ajaxLibraryVersions()
  83. {
  84. Piwik::createConfigObject();
  85. Zend_Registry::get('config')->setTestEnvironment();
  86. $jqueryJs = file_get_contents( PIWIK_DOCUMENT_ROOT . '/libs/jquery/jquery.js', false, NULL, 0, 512 );
  87. $this->assertTrue( preg_match('/jQuery (?:JavaScript Library )?v?([0-9.]+)/', $jqueryJs, $matches) );
  88. $this->assertEqual( $matches[1], Zend_Registry::get('config')->General->jquery_version );
  89. $jqueryuiJs = file_get_contents( PIWIK_DOCUMENT_ROOT . '/libs/jquery/jquery-ui.js', false, NULL, 0, 512 );
  90. $this->assertTrue( preg_match('/jQuery UI ([0-9.]+)/', $jqueryuiJs, $matches) );
  91. $this->assertEqual( $matches[1], Zend_Registry::get('config')->General->jqueryui_version );
  92. $swfobjectJs = file_get_contents( PIWIK_DOCUMENT_ROOT . '/libs/swfobject/swfobject.js', false, NULL, 0, 512 );
  93. $this->assertTrue( preg_match('/SWFObject v([0-9.]+)/', $swfobjectJs, $matches) );
  94. $this->assertEqual( $matches[1], Zend_Registry::get('config')->General->swfobject_version );
  95. }
  96. function test_svnEolStyle()
  97. {
  98. if(Piwik_Common::isWindows()) {
  99. // SVN native does not make this work on windows
  100. return;
  101. }
  102. foreach(Piwik::globr(PIWIK_DOCUMENT_ROOT, '*') as $file)
  103. {
  104. // skip files in these folders
  105. if(strpos($file, '/.svn/') !== false ||
  106. strpos($file, '/documentation/') !== false ||
  107. strpos($file, '/tests/') !== false ||
  108. strpos($file, '/tmp/') !== false)
  109. {
  110. continue;
  111. }
  112. // skip files with these file extensions
  113. if(preg_match('/\.(bmp|fdf|gif|deflate|gz|ico|jar|jpg|p12|pdf|png|rar|swf|vsd|z|zip|ttf)$/', $file))
  114. {
  115. continue;
  116. }
  117. if(!is_dir($file))
  118. {
  119. $contents = file_get_contents($file);
  120. // expect CRLF
  121. if(preg_match('/\.(bat|ps1)$/', $file))
  122. {
  123. $contents = str_replace("\r\n", '', $contents);
  124. $this->assertTrue(strpos($contents, "\n") === false, $file);
  125. }
  126. else
  127. {
  128. // expect native
  129. $this->assertTrue(strpos($contents, "\r\n") === false, $file);
  130. }
  131. }
  132. }
  133. }
  134. function test_svnKeywords()
  135. {
  136. /*
  137. * Piwik's .php files have $Id$
  138. */
  139. $contents = file_get_contents($file = PIWIK_DOCUMENT_ROOT . '/index.php');
  140. $this->assertTrue(strpos($contents, '$Id: '.basename($file).' ') !== false, $file);
  141. $contents = file_get_contents($file = PIWIK_DOCUMENT_ROOT . '/piwik.php');
  142. $this->assertTrue(strpos($contents, '$Id: '.basename($file).' ') !== false, $file);
  143. foreach(Piwik::globr(PIWIK_DOCUMENT_ROOT . '/core', '*.php') as $file)
  144. {
  145. $contents = file_get_contents($file);
  146. $this->assertTrue(strpos($contents, '$Id: '.basename($file).' ') !== false, $file);
  147. }
  148. foreach(Piwik::globr(PIWIK_DOCUMENT_ROOT . '/plugins', '*.php') as $file)
  149. {
  150. if(strpos($file, '/tests/') !== false
  151. || strpos($file, '/PhpSecInfo/') !== false
  152. || strpos($file, 'tcpdf_config.php') !== false)
  153. {
  154. continue;
  155. }
  156. $contents = file_get_contents($file);
  157. $this->assertTrue(strpos($contents, '$Id: ') !== false, $file ." no Id: keyword");
  158. }
  159. /*
  160. * Piwik's .js files don't have $Id$
  161. */
  162. $contents = file_get_contents($file = PIWIK_DOCUMENT_ROOT . '/piwik.js');
  163. $this->assertTrue(strpos($contents, '$Id') === false, $file);
  164. $contents = file_get_contents($file = PIWIK_DOCUMENT_ROOT . '/js/piwik.js');
  165. $this->assertTrue(strpos($contents, '$Id') === false, $file);
  166. foreach(Piwik::globr(PIWIK_DOCUMENT_ROOT . '/plugins', '*.js') as $file)
  167. {
  168. $contents = file_get_contents($file);
  169. $this->assertTrue(strpos($contents, '$Id') === false, $file);
  170. }
  171. foreach(Piwik::globr(PIWIK_DOCUMENT_ROOT . '/themes', '*.js') as $file)
  172. {
  173. $contents = file_get_contents($file);
  174. $this->assertTrue(strpos($contents, '$Id') === false, $file);
  175. }
  176. }
  177. function test_piwikJavaScript()
  178. {
  179. // check source against Snort rule 8443
  180. // @see http://dev.piwik.org/trac/ticket/2203
  181. $pattern = '/\x5b\x5c{2}.*\x5c{2}[\x22\x27]/';
  182. $contents = file_get_contents( PIWIK_DOCUMENT_ROOT . '/js/piwik.js' );
  183. $this->assertTrue( preg_match($pattern, $contents) == 0 );
  184. $contents = file_get_contents( PIWIK_DOCUMENT_ROOT . '/piwik.js' );
  185. $this->assertTrue( preg_match($pattern, $contents) == 0 );
  186. }
  187. }