From 88d497f58b657836f31b4aa390e45ba24284344c Mon Sep 17 00:00:00 2001 From: mattpiwik <matthieu.aubry@gmail.com> Date: Sun, 1 Mar 2009 21:25:36 +0000 Subject: [PATCH] - slightly cleaning the tests git-svn-id: http://dev.piwik.org/svn/trunk@933 59fd770c-687e-43c8-a1e3-f5a4ff64c105 --- core/Config.php | 6 -- piwik.php | 7 ++- tests/core/ArchiveProcessing/Day.test.php | 8 --- tests/core/Config.test.php | 19 +------ tests/core/DataTable/Renderer.test.php | 6 -- tests/core/Date.test.php | 1 - tests/core/PHP_Related.test.php | 15 +---- tests/core/Piwik.test.php | 14 ----- tests/core/ReleaseCheckList.test.php | 22 +++++-- tests/core/TablePartitioning.test.php | 4 -- tests/core/Tracker_Db.test.php | 36 ------------ tests/core/Updater.test.php | 13 ++--- tests/core/Url.test.php | 5 -- tests/core/UserCountry.test.php | 29 ---------- tests/core/blank.test.php | 2 +- tests/core/piwik.php.test.php | 57 ------------------- .../{core => resources}/Updater/core/0.3.php | 0 .../Updater/testpluginUpdates/0.0.1.php | 0 .../Updater/testpluginUpdates/0.1.php | 0 .../Updater/testpluginUpdates/0.1beta2.php | 0 20 files changed, 30 insertions(+), 214 deletions(-) delete mode 100644 tests/core/Tracker_Db.test.php delete mode 100644 tests/core/piwik.php.test.php rename tests/{core => resources}/Updater/core/0.3.php (100%) rename tests/{core => resources}/Updater/testpluginUpdates/0.0.1.php (100%) rename tests/{core => resources}/Updater/testpluginUpdates/0.1.php (100%) rename tests/{core => resources}/Updater/testpluginUpdates/0.1beta2.php (100%) diff --git a/core/Config.php b/core/Config.php index 2bbb63f541..8fdcdd6ec3 100644 --- a/core/Config.php +++ b/core/Config.php @@ -92,11 +92,6 @@ class Piwik_Config } $this->defaultConfig = new Zend_Config_Ini($this->pathIniFileDefaultConfig, null, true); - - if(!Zend_Loader::isReadable($this->pathIniFileUserConfig)) - { - throw new Exception("The configuration file {$this->pathIniFileUserConfig} has not been found."); - } $this->userConfig = new Zend_Config_Ini($this->pathIniFileUserConfig, null, true); // see http://bugs.php.net/bug.php?id=34206 @@ -105,7 +100,6 @@ class Piwik_Config /** * At the script shutdown, we save the new configuration file, if the user has set some values - * */ function __destruct() { diff --git a/piwik.php b/piwik.php index 94186c952c..d8a6507f73 100644 --- a/piwik.php +++ b/piwik.php @@ -7,6 +7,12 @@ * @version $Id$ */ +$GLOBALS['DEBUGPIWIK'] = false; +if(defined('ENABLE_PIWIK_TRACKER') && !ENABLE_PIWIK_TRACKER) +{ + return; +} + error_reporting(E_ALL|E_NOTICE); define('PIWIK_INCLUDE_PATH', dirname(__FILE__)); @ignore_user_abort(true); @@ -27,7 +33,6 @@ require_once "Tracker/Db.php"; require_once "Tracker/Visit.php"; require_once "Tracker/GoalManager.php"; -$GLOBALS['DEBUGPIWIK'] = false; ob_start(); if($GLOBALS['DEBUGPIWIK'] === true) diff --git a/tests/core/ArchiveProcessing/Day.test.php b/tests/core/ArchiveProcessing/Day.test.php index cb62d233ca..d4430e5da4 100644 --- a/tests/core/ArchiveProcessing/Day.test.php +++ b/tests/core/ArchiveProcessing/Day.test.php @@ -17,14 +17,6 @@ class Test_Piwik_ArchiveProcessing_Day extends UnitTestCase parent::__construct( $title ); } - public function setUp() - { - } - - public function tearDown() - { - } - function test_generateDataTable_simple() { $row1 = new Piwik_DataTable_Row( array( Piwik_DataTable_Row::COLUMNS => diff --git a/tests/core/Config.test.php b/tests/core/Config.test.php index dac5ad3e4b..04193eb137 100644 --- a/tests/core/Config.test.php +++ b/tests/core/Config.test.php @@ -7,25 +7,8 @@ if(!defined('CONFIG_TEST_INCLUDED')) require_once PATH_TEST_TO_ROOT . "/tests/config_test.php"; } -class Test_Piwik_Blank extends UnitTestCase +class Test_Piwik_Config extends UnitTestCase { - function __construct( $title = '') - { - parent::__construct( $title ); - } - - public function setUp() - { - } - - public function tearDown() - { - } - - - /** - * -> exception - */ public function testUserConfigOverwritesSectionGlobalConfigValue() { $userFile = 'tests/resources/Config/config.ini.php'; diff --git a/tests/core/DataTable/Renderer.test.php b/tests/core/DataTable/Renderer.test.php index 2ee9079af1..7304ff049e 100644 --- a/tests/core/DataTable/Renderer.test.php +++ b/tests/core/DataTable/Renderer.test.php @@ -17,11 +17,6 @@ require_once 'DataTable/Renderer/Php.php'; class Test_Piwik_DataTable_Renderer extends UnitTestCase { - function __construct( $title = '') - { - parent::__construct( $title ); - } - public function setUp() { Piwik_DataTable_Manager::getInstance()->deleteAll(); @@ -31,7 +26,6 @@ class Test_Piwik_DataTable_Renderer extends UnitTestCase { } - /** * DATA TESTS * ----------------------- diff --git a/tests/core/Date.test.php b/tests/core/Date.test.php index 10bed99742..859cc3e5aa 100644 --- a/tests/core/Date.test.php +++ b/tests/core/Date.test.php @@ -7,7 +7,6 @@ if(!defined('CONFIG_TEST_INCLUDED')) require_once PATH_TEST_TO_ROOT . "/tests/config_test.php"; } - require_once 'Date.php'; class Test_Piwik_Date extends UnitTestCase diff --git a/tests/core/PHP_Related.test.php b/tests/core/PHP_Related.test.php index 99c8ee092b..4ee6e5c5dc 100644 --- a/tests/core/PHP_Related.test.php +++ b/tests/core/PHP_Related.test.php @@ -11,23 +11,10 @@ if(!defined('CONFIG_TEST_INCLUDED')) require_once 'Timer.php'; class Test_PHP_Related extends UnitTestCase { - function __construct( $title = '') - { - parent::__construct( $title ); - } - - public function setUp() - { - } - - public function tearDown() - { - } - // conclusion: // - it's ok to have big holes in your array index values // - obvious: it's not ok to index array by strings when you can do magic and index with int - function oldtest_memoryUsageArrayIncreasingIndexOrJumps() + function oneShotTest_memoryUsageArrayIncreasingIndexOrJumps() { ini_set('memory_limit','200M'); Piwik::createConfigObject(); diff --git a/tests/core/Piwik.test.php b/tests/core/Piwik.test.php index 6f53b1dcb3..125e619d02 100644 --- a/tests/core/Piwik.test.php +++ b/tests/core/Piwik.test.php @@ -8,20 +8,6 @@ if(!defined('CONFIG_TEST_INCLUDED')) } class Test_Piwik extends UnitTestCase { - function __construct( $title = '') - { - parent::__construct( $title ); - } - - public function setUp() - { - } - - public function tearDown() - { - } - - public function test_isNumericValid() { $valid = array( diff --git a/tests/core/ReleaseCheckList.test.php b/tests/core/ReleaseCheckList.test.php index 1f8eddb2de..9bfe6b6f23 100644 --- a/tests/core/ReleaseCheckList.test.php +++ b/tests/core/ReleaseCheckList.test.php @@ -11,11 +11,6 @@ if(!defined('CONFIG_TEST_INCLUDED')) class Test_Piwik_ReleaseCheckList extends UnitTestCase { - function __construct( $title = '') - { - parent::__construct( $title ); - } - public function test_checkThatConfigurationValuesAreProductionValues() { $this->globalConfig = parse_ini_file(PATH_TEST_TO_ROOT . '/config/global.ini.php', true); @@ -61,5 +56,22 @@ class Test_Piwik_ReleaseCheckList extends UnitTestCase } } + /** + * test that the profiler is disabled (mandatory on a production server) + */ + public function test_profilingDisabledInProduction() + { + require_once 'Tracker/Db.php'; + $this->assertTrue(Piwik_Tracker_Db::isProfilingEnabled() === false, 'SQL profiler should be disabled in production! See Piwik_Tracker_Db::$profiling'); + } + + + function test_piwikTrackerDebugIsOff() + { + $this->assertTrue(!isset($GLOBALS['DEBUGPIWIK'])); + define('ENABLE_PIWIK_TRACKER', false); + include PATH_TEST_TO_ROOT . "/piwik.php"; + $this->assertTrue($GLOBALS['DEBUGPIWIK'] === false); + } } diff --git a/tests/core/TablePartitioning.test.php b/tests/core/TablePartitioning.test.php index 4e1477ede5..d672738da4 100755 --- a/tests/core/TablePartitioning.test.php +++ b/tests/core/TablePartitioning.test.php @@ -11,10 +11,6 @@ require_once "Database.test.php"; require_once 'TablePartitioning.php'; class Test_Piwik_TablePartitioning extends Test_Database { - function __construct() - { - parent::__construct(''); - } public function setUp() { parent::setUp(); diff --git a/tests/core/Tracker_Db.test.php b/tests/core/Tracker_Db.test.php deleted file mode 100644 index a4e38336db..0000000000 --- a/tests/core/Tracker_Db.test.php +++ /dev/null @@ -1,36 +0,0 @@ -<?php -if(!defined("PATH_TEST_TO_ROOT")) { - define('PATH_TEST_TO_ROOT', getcwd().'/../..'); -} -if(!defined('CONFIG_TEST_INCLUDED')) -{ - require_once PATH_TEST_TO_ROOT . "/tests/config_test.php"; -} - -require_once 'Tracker/Db.php'; - -class Test_Piwik_Tracker_Db extends UnitTestCase -{ - function __construct( $title = '') - { - parent::__construct( $title ); - } - - public function setUp() - { - } - - public function tearDown() - { - } - - - /** - * test that the profiler is disabled (mandatory on a production server) - */ - public function test_profilingDisabledInProduction() - { - $this->assertTrue(Piwik_Tracker_Db::isProfilingEnabled() === false, 'SQL profiler should be disabled in production! See Piwik_Tracker_Db::$profiling'); - } -} - diff --git a/tests/core/Updater.test.php b/tests/core/Updater.test.php index afa780501d..d95f378321 100644 --- a/tests/core/Updater.test.php +++ b/tests/core/Updater.test.php @@ -12,15 +12,10 @@ require_once "Updater.php"; require_once "Database.test.php"; class Test_Piwik_Updater extends Test_Database { - function __construct( $title = '') - { - parent::__construct( $title ); - } - public function test_updaterChecksCoreVersion_andDetectsUpdateFile() { $updater = new Piwik_Updater(); - $updater->pathUpdateFileCore = PIWIK_INCLUDE_PATH . '/tests/core/Updater/core/'; + $updater->pathUpdateFileCore = PIWIK_INCLUDE_PATH . '/tests/resources/Updater/core/'; $updater->recordComponentSuccessfullyUpdated('core', '0.1'); $updater->addComponentToCheck('core', '0.3'); $componentsWithUpdateFile = $updater->getComponentsWithUpdateFile(); @@ -31,7 +26,7 @@ class Test_Piwik_Updater extends Test_Database public function test_updaterChecksGivenPluginVersion_andDetectsMultipleUpdateFile_inOrder() { $updater = new Piwik_Updater(); - $updater->pathUpdateFilePlugins = PIWIK_INCLUDE_PATH . '/tests/core/Updater/%s/'; + $updater->pathUpdateFilePlugins = PIWIK_INCLUDE_PATH . '/tests/resources/Updater/%s/'; $updater->recordComponentSuccessfullyUpdated('testpluginUpdates', '0.1beta'); $updater->addComponentToCheck('testpluginUpdates', '0.1'); $componentsWithUpdateFile = $updater->getComponentsWithUpdateFile(); @@ -48,8 +43,8 @@ class Test_Piwik_Updater extends Test_Database public function test_updaterChecksCoreAndPlugin_checkThatCoreIsRanFirst() { $updater = new Piwik_Updater(); - $updater->pathUpdateFilePlugins = PIWIK_INCLUDE_PATH . '/tests/core/Updater/%s/'; - $updater->pathUpdateFileCore = PIWIK_INCLUDE_PATH . '/tests/core/Updater/core/'; + $updater->pathUpdateFilePlugins = PIWIK_INCLUDE_PATH . '/tests/resources/Updater/%s/'; + $updater->pathUpdateFileCore = PIWIK_INCLUDE_PATH . '/tests/resources/Updater/core/'; $updater->recordComponentSuccessfullyUpdated('testpluginUpdates', '0.1beta'); $updater->addComponentToCheck('testpluginUpdates', '0.1'); diff --git a/tests/core/Url.test.php b/tests/core/Url.test.php index 921428b1e3..bf2c75fdfc 100644 --- a/tests/core/Url.test.php +++ b/tests/core/Url.test.php @@ -11,11 +11,6 @@ require_once "Url.php"; class Test_Piwik_Url extends UnitTestCase { - function __construct( $title = '') - { - parent::__construct( $title ); - } - /** * display output of all methods */ diff --git a/tests/core/UserCountry.test.php b/tests/core/UserCountry.test.php index 39580c4f36..18eb93aee4 100644 --- a/tests/core/UserCountry.test.php +++ b/tests/core/UserCountry.test.php @@ -9,23 +9,8 @@ if(!defined('CONFIG_TEST_INCLUDED')) require 'UserCountry/functions.php'; -//Zend_Loader::loadClass('Piwik_'); - class Test_Piwik_UserCountry extends UnitTestCase { - function __construct( $title = '') - { - parent::__construct( $title ); - } - - public function setUp() - { - } - - public function tearDown() - { - } - public function test_getFlagFromCode() { $flag = Piwik_getFlagFromCode("us"); @@ -47,19 +32,5 @@ class Test_Piwik_UserCountry extends UnitTestCase $this->assertEqual( basename($flag), "xx.png" ); } - /** - * -> exception - */ - public function _test_() - { - try { - test(); - $this->fail("Exception not raised."); - } - catch (Exception $expected) { - $this->assertPattern("()", $expected->getMessage()); - return; - } - } } diff --git a/tests/core/blank.test.php b/tests/core/blank.test.php index a873cc98bf..95c21fe9df 100755 --- a/tests/core/blank.test.php +++ b/tests/core/blank.test.php @@ -24,7 +24,7 @@ class Test_Piwik_Blank extends UnitTestCase /** - * -> exception + * template function */ public function _test_() { diff --git a/tests/core/piwik.php.test.php b/tests/core/piwik.php.test.php deleted file mode 100644 index 18a0c9cf78..0000000000 --- a/tests/core/piwik.php.test.php +++ /dev/null @@ -1,57 +0,0 @@ -<?php -// we def have problems with INCLUDE_PATH on these tests.... -if(!defined("PATH_TEST_TO_ROOT")) { - define('PATH_TEST_TO_ROOT', '..'); - $content = file_get_contents('../../piwik.php'); -} -else -{ - $content = file_get_contents('../piwik.php'); -} -$GLOBALS['content'] = $content; - -if(!defined('CONFIG_TEST_INCLUDED')) -{ - require_once PATH_TEST_TO_ROOT ."/../tests/config_test.php"; - -} - -class Test_PiwikPhp extends UnitTestCase -{ - function __construct( $title = '') - { - parent::__construct( $title ); - } - - function testDebugOff() - { - // catch that the string GLOBALS['DEBUGPIWIK'] = false - $ereg = "(GLOBALS\['DEBUGPIWIK'\])([ ])*=([ ])*(false;)"; - - // first we test the regular expression - $good = array( - '$GLOBALS[\'DEBUGPIWIK\'] = false;', - '$GLOBALS[\'DEBUGPIWIK\'] = false;', - ' $GLOBALS[\'DEBUGPIWIK\'] = false;', - ); - - foreach($good as $test) - { - $this->assertTrue( ereg($ereg,$test) !== false); - } - $bad = array( - '$GLOBALS[\'DEBUGPIWIK\'] = true;', - '$GLOBALS[\'DEBUGPIWIK\'] = 1;', - ' $GLOBALS[\'DEBUGPIWIK\']=\'false\';', - ); - - foreach($bad as $test) - { - $this->assertTrue( ereg($ereg,$test) === false); - } - - // then we check that the piwik.php content does have the DEBUG variable set to off - $this->assertTrue( ereg($ereg, $GLOBALS['content']) !== false, - 'The $GLOBALS[\'DEBUGPIWIK\'] MUST BE SET TO false IN A PRODUCTION ENVIRONMENT !!!'); - } -} diff --git a/tests/core/Updater/core/0.3.php b/tests/resources/Updater/core/0.3.php similarity index 100% rename from tests/core/Updater/core/0.3.php rename to tests/resources/Updater/core/0.3.php diff --git a/tests/core/Updater/testpluginUpdates/0.0.1.php b/tests/resources/Updater/testpluginUpdates/0.0.1.php similarity index 100% rename from tests/core/Updater/testpluginUpdates/0.0.1.php rename to tests/resources/Updater/testpluginUpdates/0.0.1.php diff --git a/tests/core/Updater/testpluginUpdates/0.1.php b/tests/resources/Updater/testpluginUpdates/0.1.php similarity index 100% rename from tests/core/Updater/testpluginUpdates/0.1.php rename to tests/resources/Updater/testpluginUpdates/0.1.php diff --git a/tests/core/Updater/testpluginUpdates/0.1beta2.php b/tests/resources/Updater/testpluginUpdates/0.1beta2.php similarity index 100% rename from tests/core/Updater/testpluginUpdates/0.1beta2.php rename to tests/resources/Updater/testpluginUpdates/0.1beta2.php -- GitLab