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
path: root/tests
diff options
context:
space:
mode:
authormattab <matthieu.aubry@gmail.com>2013-03-28 03:42:39 +0400
committermattab <matthieu.aubry@gmail.com>2013-03-28 03:42:40 +0400
commitae4b03163792f0b6e933933e5d37df87dc3fd566 (patch)
treed1d7510a9728f587d3d63ebd03e4ecf3d904838b /tests
parent158c2150f5f2e13ece459b8d131244c11b763997 (diff)
Mass conversion of all files to the newly agreed coding standard: PSR 1/2
Converting Piwik core source files, PHP, JS, TPL, CSS More info: http://piwik.org/participate/coding-standards/
Diffstat (limited to 'tests')
-rwxr-xr-xtests/LocalTracker.php212
-rw-r--r--tests/PHPUnit/BaseFixture.php447
-rwxr-xr-xtests/PHPUnit/BenchmarkTestCase.php178
-rwxr-xr-xtests/PHPUnit/Benchmarks/ArchivingProcessBenchmark.php22
-rwxr-xr-xtests/PHPUnit/Benchmarks/Fixtures/OneSiteTwelveThousandVisitsOneYear.php104
-rwxr-xr-xtests/PHPUnit/Benchmarks/Fixtures/SqlDump.php107
-rwxr-xr-xtests/PHPUnit/Benchmarks/Fixtures/ThousandSitesTwelveVisitsEachOneDay.php121
-rwxr-xr-xtests/PHPUnit/Benchmarks/TrackerBenchmark.php115
-rw-r--r--tests/PHPUnit/Core/API/ResponseBuilderTest.php48
-rw-r--r--tests/PHPUnit/Core/AccessTest.php66
-rw-r--r--tests/PHPUnit/Core/ArchiveProcessing/DayTest.php194
-rw-r--r--tests/PHPUnit/Core/ArchiveProcessingTest.php227
-rw-r--r--tests/PHPUnit/Core/CommonTest.php435
-rw-r--r--tests/PHPUnit/Core/ConfigTest.php17
-rw-r--r--tests/PHPUnit/Core/CookieTest.php62
-rwxr-xr-xtests/PHPUnit/Core/DataTable/ArrayTest.php8
-rw-r--r--tests/PHPUnit/Core/DataTable/Filter/AddSummaryRowTest.php105
-rw-r--r--tests/PHPUnit/Core/DataTable/Filter/ExcludeLowPopulationTest.php83
-rw-r--r--tests/PHPUnit/Core/DataTable/Filter/LimitTest.php224
-rw-r--r--tests/PHPUnit/Core/DataTable/Filter/PatternRecursiveTest.php26
-rw-r--r--tests/PHPUnit/Core/DataTable/Filter/PatternTest.php28
-rw-r--r--tests/PHPUnit/Core/DataTable/Filter/RangeCheckTest.php28
-rw-r--r--tests/PHPUnit/Core/DataTable/Filter/SortTest.php138
-rw-r--r--tests/PHPUnit/Core/DataTable/Filter/TruncateTest.php90
-rw-r--r--tests/PHPUnit/Core/DataTable/Renderer/CSVTest.php202
-rw-r--r--tests/PHPUnit/Core/DataTable/Renderer/ConsoleTest.php126
-rw-r--r--tests/PHPUnit/Core/DataTable/Renderer/JSONTest.php206
-rw-r--r--tests/PHPUnit/Core/DataTable/Renderer/PHPTest.php438
-rw-r--r--tests/PHPUnit/Core/DataTable/Renderer/XMLTest.php184
-rw-r--r--tests/PHPUnit/Core/DataTable/RowTest.php274
-rw-r--r--tests/PHPUnit/Core/DataTableTest.php847
-rw-r--r--tests/PHPUnit/Core/DateTest.php57
-rw-r--r--tests/PHPUnit/Core/HttpTest.php98
-rw-r--r--tests/PHPUnit/Core/IPTest.php349
-rw-r--r--tests/PHPUnit/Core/JsProxyTest.php4
-rw-r--r--tests/PHPUnit/Core/NonceTest.php10
-rw-r--r--tests/PHPUnit/Core/OptionTest.php14
-rw-r--r--tests/PHPUnit/Core/Period/DayTest.php96
-rw-r--r--tests/PHPUnit/Core/Period/MonthTest.php40
-rw-r--r--tests/PHPUnit/Core/Period/RangeTest.php1048
-rw-r--r--tests/PHPUnit/Core/Period/WeekTest.php44
-rw-r--r--tests/PHPUnit/Core/Period/YearTest.php20
-rw-r--r--tests/PHPUnit/Core/PeriodTest.php34
-rw-r--r--tests/PHPUnit/Core/PiwikTest.php148
-rw-r--r--tests/PHPUnit/Core/Plugin/ConfigTest.php3
-rw-r--r--tests/PHPUnit/Core/PluginsFunctions/WidgetsListTest.php30
-rw-r--r--tests/PHPUnit/Core/RankingQueryTest.php128
-rw-r--r--tests/PHPUnit/Core/ReleaseCheckListTest.php82
-rw-r--r--tests/PHPUnit/Core/ScheduledTaskTest.php60
-rw-r--r--tests/PHPUnit/Core/ScheduledTime/DailyTest.php35
-rw-r--r--tests/PHPUnit/Core/ScheduledTime/HourlyTest.php18
-rw-r--r--tests/PHPUnit/Core/ScheduledTime/MonthlyTest.php50
-rw-r--r--tests/PHPUnit/Core/ScheduledTime/WeeklyTest.php40
-rw-r--r--tests/PHPUnit/Core/SegmentExpressionTest.php4
-rw-r--r--tests/PHPUnit/Core/SegmentTest.php189
-rw-r--r--tests/PHPUnit/Core/ServeStaticFileTest.php4
-rwxr-xr-xtests/PHPUnit/Core/SqlTest.php52
-rw-r--r--tests/PHPUnit/Core/TablePartitioningTest.php40
-rw-r--r--tests/PHPUnit/Core/TaskSchedulerTest.php611
-rw-r--r--tests/PHPUnit/Core/Tracker/ActionTest.php219
-rw-r--r--tests/PHPUnit/Core/Tracker/VisitTest.php157
-rw-r--r--tests/PHPUnit/Core/TranslationWriterTest.php17
-rw-r--r--tests/PHPUnit/Core/UnzipTest.php103
-rw-r--r--tests/PHPUnit/Core/UpdaterTest.php12
-rw-r--r--tests/PHPUnit/Core/UrlTest.php40
-rw-r--r--tests/PHPUnit/DatabaseTestCase.php19
-rw-r--r--tests/PHPUnit/FakeAccess.php128
-rw-r--r--tests/PHPUnit/Fixtures/FewVisitsWithSetVisitorId.php20
-rw-r--r--tests/PHPUnit/Fixtures/InvalidVisits.php39
-rw-r--r--tests/PHPUnit/Fixtures/ManySitesImportedLogs.php289
-rw-r--r--tests/PHPUnit/Fixtures/ManyVisitsWithGeoIP.php334
-rw-r--r--tests/PHPUnit/Fixtures/ManyVisitsWithMockLocationProvider.php374
-rw-r--r--tests/PHPUnit/Fixtures/ManyVisitsWithSubDirReferrersAndCustomVars.php23
-rw-r--r--tests/PHPUnit/Fixtures/OneVisitSeveralPageViews.php26
-rw-r--r--tests/PHPUnit/Fixtures/OneVisitWithAbnormalPageviewUrls.php18
-rw-r--r--tests/PHPUnit/Fixtures/OneVisitorTwoVisits.php127
-rw-r--r--tests/PHPUnit/Fixtures/SomeVisitsAllConversions.php26
-rw-r--r--tests/PHPUnit/Fixtures/SomeVisitsCustomVariablesCampaignsNotHeuristics.php44
-rw-r--r--tests/PHPUnit/Fixtures/SomeVisitsManyPageviewsWithTransitions.php150
-rw-r--r--tests/PHPUnit/Fixtures/SomeVisitsWithLongUrls.php16
-rw-r--r--tests/PHPUnit/Fixtures/SomeVisitsWithNonUnicodePageTitles.php148
-rw-r--r--tests/PHPUnit/Fixtures/ThreeGoalsOnePageview.php48
-rw-r--r--tests/PHPUnit/Fixtures/ThreeSitesWithManyVisitsWithSiteSearch.php318
-rw-r--r--tests/PHPUnit/Fixtures/TwoSitesEcommerceOrderWithItems.php30
-rw-r--r--tests/PHPUnit/Fixtures/TwoSitesManyVisitsOverSeveralDaysWithSearchEngineReferrers.php63
-rw-r--r--tests/PHPUnit/Fixtures/TwoSitesTwoVisitorsDifferentDays.php54
-rw-r--r--tests/PHPUnit/Fixtures/TwoSitesVisitsInPast.php18
-rw-r--r--tests/PHPUnit/Fixtures/TwoSitesWithAnnotations.php113
-rw-r--r--tests/PHPUnit/Fixtures/TwoVisitsNoKeywordWithBot.php16
-rw-r--r--tests/PHPUnit/Fixtures/TwoVisitsWithCustomVariables.php49
-rw-r--r--tests/PHPUnit/Fixtures/VisitsOverSeveralDays.php58
-rwxr-xr-xtests/PHPUnit/Integration/AnnotationsTest.php662
-rwxr-xr-xtests/PHPUnit/Integration/ApiGetReportMetadataTest.php46
-rwxr-xr-xtests/PHPUnit/Integration/ApiGetReportMetadata_yearTest.php8
-rwxr-xr-xtests/PHPUnit/Integration/BlobReportLimitingTest.php155
-rwxr-xr-xtests/PHPUnit/Integration/CsvExportTest.php10
-rwxr-xr-xtests/PHPUnit/Integration/EcommerceOrderWithItemsTest.php264
-rw-r--r--tests/PHPUnit/Integration/FlattenReportsTest.php56
-rwxr-xr-xtests/PHPUnit/Integration/ImportLogsTest.php70
-rw-r--r--tests/PHPUnit/Integration/LabelFilterTest.php124
-rwxr-xr-xtests/PHPUnit/Integration/ManyVisitorsOneWebsiteTest.php108
-rwxr-xr-xtests/PHPUnit/Integration/NoVisitTest.php6
-rwxr-xr-xtests/PHPUnit/Integration/NonUnicodeTest.php68
-rwxr-xr-xtests/PHPUnit/Integration/OneVisitorOneWebsite_SeveralDaysDateRangeTest.php90
-rwxr-xr-xtests/PHPUnit/Integration/OneVisitorOneWebsite_SeveralDaysDateRange_ArchivingTestsTest.php20
-rwxr-xr-xtests/PHPUnit/Integration/OneVisitorTwoVisitsTest.php225
-rwxr-xr-xtests/PHPUnit/Integration/OneVisitorTwoVisits_withCookieSupportTest.php2
-rw-r--r--tests/PHPUnit/Integration/OneVisitor_LongUrlsTruncatedTest.php2
-rwxr-xr-xtests/PHPUnit/Integration/OneVisitor_NoKeywordSpecifiedTest.php8
-rwxr-xr-xtests/PHPUnit/Integration/PeriodIsRange_DateIsLastN_MetadataAndNormalAPITest.php52
-rwxr-xr-xtests/PHPUnit/Integration/RowEvolutionTest.php148
-rwxr-xr-xtests/PHPUnit/Integration/SiteSearchTest.php40
-rwxr-xr-xtests/PHPUnit/Integration/TrackCustomVariablesAndCampaigns_ForceUsingVisitIdNotHeuristicsTest.php4
-rwxr-xr-xtests/PHPUnit/Integration/TrackGoals_AllowMultipleConversionsPerVisitTest.php6
-rw-r--r--tests/PHPUnit/Integration/TrackingAPI_SetVisitorIdTest.php8
-rw-r--r--tests/PHPUnit/Integration/TransitionsTest.php58
-rwxr-xr-xtests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDaysTest.php44
-rwxr-xr-xtests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDays_ArchivingDisabledTest.php8
-rwxr-xr-xtests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDays_ConversionsTest.php34
-rwxr-xr-xtests/PHPUnit/Integration/TwoVisitsWithCustomVariablesTest.php26
-rwxr-xr-xtests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentContainsTest.php20
-rwxr-xr-xtests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchALL_NoGoalDataTest.php6
-rwxr-xr-xtests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchNONETest.php8
-rwxr-xr-xtests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchVisitorTypeTest.php8
-rw-r--r--tests/PHPUnit/Integration/UrlNormalizationTest.php20
-rw-r--r--tests/PHPUnit/Integration/VisitsInPast_InvalidateOldReportsTest.php32
-rw-r--r--tests/PHPUnit/Integration/expected/test_TwoVisitors_twoWebsites_differentDays_Actions.getPageTitles_firstSite_lastN__API.getProcessedReport_day.xml4
-rw-r--r--tests/PHPUnit/Integration/expected/test_TwoVisitors_twoWebsites_differentDays_scheduled_report_in_html_tables_only__PDFReports.generateReport_month.original.html165
-rw-r--r--tests/PHPUnit/Integration/expected/test_ecommerceOrderWithItems_scheduled_report_in_html_tables_only__PDFReports.generateReport_week.original.html180
-rwxr-xr-xtests/PHPUnit/IntegrationTestCase.php1092
-rw-r--r--tests/PHPUnit/MockEventDispatcher.php19
-rwxr-xr-xtests/PHPUnit/MockLocationProvider.php81
-rw-r--r--tests/PHPUnit/MockPiwikOption.php25
-rw-r--r--tests/PHPUnit/Plugins/ActionsTest.php84
-rw-r--r--tests/PHPUnit/Plugins/AnonymizeIPTest.php45
-rwxr-xr-xtests/PHPUnit/Plugins/LanguagesManagerTest.php56
-rw-r--r--tests/PHPUnit/Plugins/LoginTest.php29
-rw-r--r--tests/PHPUnit/Plugins/MobileMessagingTest.php384
-rw-r--r--tests/PHPUnit/Plugins/MultiSitesTest.php64
-rw-r--r--tests/PHPUnit/Plugins/PDFReportsTest.php927
-rwxr-xr-xtests/PHPUnit/Plugins/PrivacyManagerTest.php466
-rw-r--r--tests/PHPUnit/Plugins/ReferersTest.php40
-rw-r--r--tests/PHPUnit/Plugins/SEOTest.php7
-rw-r--r--tests/PHPUnit/Plugins/SitesManagerTest.php579
-rw-r--r--tests/PHPUnit/Plugins/UserCountryTest.php133
-rw-r--r--tests/PHPUnit/Plugins/UserSettingsTest.php7
-rw-r--r--tests/PHPUnit/Plugins/UsersManagerTest.php651
-rw-r--r--tests/PHPUnit/bootstrap.php80
-rw-r--r--tests/PHPUnit/config.ini.travis.php20
-rw-r--r--tests/PHPUnit/proxy/index.php35
-rwxr-xr-xtests/PHPUnit/proxy/piwik.php12
-rw-r--r--tests/index.php27
152 files changed, 9580 insertions, 9844 deletions
diff --git a/tests/LocalTracker.php b/tests/LocalTracker.php
index b4d56cfff5..3afd96b452 100755
--- a/tests/LocalTracker.php
+++ b/tests/LocalTracker.php
@@ -2,123 +2,115 @@
$GLOBALS['PIWIK_TRACKER_DEBUG'] = false;
$GLOBALS['PIWIK_TRACKER_DEBUG_FORCE_SCHEDULED_TASKS'] = false;
-if (!defined('PIWIK_ENABLE_TRACKING'))
-{
- define('PIWIK_ENABLE_TRACKING', true);
+if (!defined('PIWIK_ENABLE_TRACKING')) {
+ define('PIWIK_ENABLE_TRACKING', true);
}
-require_once PIWIK_INCLUDE_PATH.'/core/Tracker.php';
-require_once PIWIK_INCLUDE_PATH.'/core/Tracker/Db.php';
-require_once PIWIK_INCLUDE_PATH.'/core/Tracker/IgnoreCookie.php';
-require_once PIWIK_INCLUDE_PATH.'/core/Tracker/Visit.php';
-require_once PIWIK_INCLUDE_PATH.'/core/Tracker/GoalManager.php';
-require_once PIWIK_INCLUDE_PATH.'/core/Tracker/Action.php';
-require_once PIWIK_INCLUDE_PATH.'/libs/PiwikTracker/PiwikTracker.php';
+require_once PIWIK_INCLUDE_PATH . '/core/Tracker.php';
+require_once PIWIK_INCLUDE_PATH . '/core/Tracker/Db.php';
+require_once PIWIK_INCLUDE_PATH . '/core/Tracker/IgnoreCookie.php';
+require_once PIWIK_INCLUDE_PATH . '/core/Tracker/Visit.php';
+require_once PIWIK_INCLUDE_PATH . '/core/Tracker/GoalManager.php';
+require_once PIWIK_INCLUDE_PATH . '/core/Tracker/Action.php';
+require_once PIWIK_INCLUDE_PATH . '/libs/PiwikTracker/PiwikTracker.php';
/**
* Tracker that uses core/Tracker.php directly.
*/
class Piwik_LocalTracker extends PiwikTracker
{
- protected function sendRequest( $url, $method = 'GET', $data = null, $force = false )
- {
- // if doing a bulk request, store the url
- if ($this->doBulkRequests && !$force)
- {
- $this->storedTrackingActions[] = $url;
- return true;
- }
-
- if ($method == 'POST')
- {
- $requests = array();
- foreach ($this->storedTrackingActions as $action)
- {
- $requests[] = $this->parseUrl($action);
- }
-
- $testEnvironmentArgs = array();
- }
- else
- {
- $testEnvironmentArgs = $this->parseUrl($url);
- $requests = array($testEnvironmentArgs);
- }
-
- // unset cached values
- Piwik_Tracker_Cache::$trackerCache = null;
- Piwik_Tracker::setForceIp(null);
- Piwik_Tracker::setForceDateTime(null);
- Piwik_Tracker::setForceVisitorId(null);
-
- // save some values
- $plugins = Piwik_Config::getInstance()->Plugins['Plugins'];
- $pluginsTracker = Piwik_Config::getInstance()->Plugins_Tracker['Plugins_Tracker'];
- $oldTrackerConfig = Piwik_Config::getInstance()->Tracker;
- Piwik_PluginsManager::getInstance()->unloadPlugins();
-
- // modify config
- $GLOBALS['PIWIK_TRACKER_MODE'] = true;
- $GLOBALS['PIWIK_TRACKER_LOCAL_TRACKING'] = true;
- Piwik_Tracker::$initTrackerMode = false;
- Piwik_Tracker::setTestEnvironment($testEnvironmentArgs, $method);
-
- // set language
- $oldLang = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : '';
- $_SERVER['HTTP_ACCEPT_LANGUAGE'] = $this->acceptLanguage;
-
- // set user agent
- $oldUserAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
- $_SERVER['HTTP_USER_AGENT'] = $this->userAgent;
-
- // set cookie
- $oldCookie = $_COOKIE;
- parse_str(parse_url($this->requestCookie, PHP_URL_QUERY), $_COOKIE);
-
- // do tracking and capture output
- ob_start();
-
- $localTracker = new Piwik_Tracker();
- $localTracker->main($requests);
-
- $output = ob_get_contents();
-
- ob_end_clean();
-
- // restore vars
- Piwik_Config::getInstance()->Plugins_Tracker['Plugins_Tracker'] = $pluginsTracker;
- Piwik_Config::getInstance()->Tracker = $oldTrackerConfig;
- $_SERVER['HTTP_ACCEPT_LANGUAGE'] = $oldLang;
- $_SERVER['HTTP_USER_AGENT'] = $oldUserAgent;
- $_COOKIE = $oldCookie;
- $GLOBALS['PIWIK_TRACKER_LOCAL_TRACKING'] = false;
- $GLOBALS['PIWIK_TRACKER_MODE'] = false;
- unset($_GET['bots']);
-
- // reload plugins
- Piwik_PluginsManager::getInstance()->loadPlugins($plugins);
-
- return $output;
- }
-
- private function parseUrl( $url )
- {
- // parse url
- $query = parse_url($url, PHP_URL_QUERY);
- if ($query === false)
- {
- return;
- }
-
- parse_str($query, $args);
-
- // make sure bots is set if needed
- if (isset($args['bots']))
- {
- $_GET['bots'] = true;
- }
-
- return $args;
- }
+ protected function sendRequest($url, $method = 'GET', $data = null, $force = false)
+ {
+ // if doing a bulk request, store the url
+ if ($this->doBulkRequests && !$force) {
+ $this->storedTrackingActions[] = $url;
+ return true;
+ }
+
+ if ($method == 'POST') {
+ $requests = array();
+ foreach ($this->storedTrackingActions as $action) {
+ $requests[] = $this->parseUrl($action);
+ }
+
+ $testEnvironmentArgs = array();
+ } else {
+ $testEnvironmentArgs = $this->parseUrl($url);
+ $requests = array($testEnvironmentArgs);
+ }
+
+ // unset cached values
+ Piwik_Tracker_Cache::$trackerCache = null;
+ Piwik_Tracker::setForceIp(null);
+ Piwik_Tracker::setForceDateTime(null);
+ Piwik_Tracker::setForceVisitorId(null);
+
+ // save some values
+ $plugins = Piwik_Config::getInstance()->Plugins['Plugins'];
+ $pluginsTracker = Piwik_Config::getInstance()->Plugins_Tracker['Plugins_Tracker'];
+ $oldTrackerConfig = Piwik_Config::getInstance()->Tracker;
+ Piwik_PluginsManager::getInstance()->unloadPlugins();
+
+ // modify config
+ $GLOBALS['PIWIK_TRACKER_MODE'] = true;
+ $GLOBALS['PIWIK_TRACKER_LOCAL_TRACKING'] = true;
+ Piwik_Tracker::$initTrackerMode = false;
+ Piwik_Tracker::setTestEnvironment($testEnvironmentArgs, $method);
+
+ // set language
+ $oldLang = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : '';
+ $_SERVER['HTTP_ACCEPT_LANGUAGE'] = $this->acceptLanguage;
+
+ // set user agent
+ $oldUserAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
+ $_SERVER['HTTP_USER_AGENT'] = $this->userAgent;
+
+ // set cookie
+ $oldCookie = $_COOKIE;
+ parse_str(parse_url($this->requestCookie, PHP_URL_QUERY), $_COOKIE);
+
+ // do tracking and capture output
+ ob_start();
+
+ $localTracker = new Piwik_Tracker();
+ $localTracker->main($requests);
+
+ $output = ob_get_contents();
+
+ ob_end_clean();
+
+ // restore vars
+ Piwik_Config::getInstance()->Plugins_Tracker['Plugins_Tracker'] = $pluginsTracker;
+ Piwik_Config::getInstance()->Tracker = $oldTrackerConfig;
+ $_SERVER['HTTP_ACCEPT_LANGUAGE'] = $oldLang;
+ $_SERVER['HTTP_USER_AGENT'] = $oldUserAgent;
+ $_COOKIE = $oldCookie;
+ $GLOBALS['PIWIK_TRACKER_LOCAL_TRACKING'] = false;
+ $GLOBALS['PIWIK_TRACKER_MODE'] = false;
+ unset($_GET['bots']);
+
+ // reload plugins
+ Piwik_PluginsManager::getInstance()->loadPlugins($plugins);
+
+ return $output;
+ }
+
+ private function parseUrl($url)
+ {
+ // parse url
+ $query = parse_url($url, PHP_URL_QUERY);
+ if ($query === false) {
+ return;
+ }
+
+ parse_str($query, $args);
+
+ // make sure bots is set if needed
+ if (isset($args['bots'])) {
+ $_GET['bots'] = true;
+ }
+
+ return $args;
+ }
}
diff --git a/tests/PHPUnit/BaseFixture.php b/tests/PHPUnit/BaseFixture.php
index 9c7f202b27..9fc5946944 100644
--- a/tests/PHPUnit/BaseFixture.php
+++ b/tests/PHPUnit/BaseFixture.php
@@ -10,43 +10,43 @@
* Base type for all integration test fixtures. Integration test fixtures
* add visit and related data to the database before a test is run. Different
* tests can use the same fixtures.
- *
+ *
* This class defines a set of helper methods for fixture types. The helper
* methods are public, but ideally they should only be used by fixture types.
- *
+ *
* NOTE: YOU SHOULD NOT CREATE A NEW FIXTURE UNLESS THERE IS NO WAY TO MODIFY
* AN EXISTING FIXTURE TO HANDLE YOUR USE CASE.
- *
+ *
* Related TODO: we should try and reduce the amount of existing fixtures by
* merging some together.
*/
abstract class Test_Piwik_BaseFixture extends PHPUnit_Framework_Assert
{
- /** Adds data to Piwik. Creates sites, tracks visits, imports log files, etc. */
- public abstract function setUp();
-
- /** Does any clean up. Most of the time there will be no need to clean up. */
- public abstract function tearDown();
-
+ /** Adds data to Piwik. Creates sites, tracks visits, imports log files, etc. */
+ public abstract function setUp();
+
+ /** Does any clean up. Most of the time there will be no need to clean up. */
+ public abstract function tearDown();
+
/**
* Creates a website, then sets its creation date to a day earlier than specified dateTime
* Useful to create a website now, but force data to be archived back in the past.
*
- * @param string $dateTime eg '2010-01-01 12:34:56'
- * @param int $ecommerce
- * @param string $siteName
+ * @param string $dateTime eg '2010-01-01 12:34:56'
+ * @param int $ecommerce
+ * @param string $siteName
*
* @return int idSite of website created
*/
- public static function createWebsite( $dateTime, $ecommerce = 0, $siteName = 'Piwik test', $siteUrl = false,
- $siteSearch = 1, $searchKeywordParameters = null,
- $searchCategoryParameters = null )
+ public static function createWebsite($dateTime, $ecommerce = 0, $siteName = 'Piwik test', $siteUrl = false,
+ $siteSearch = 1, $searchKeywordParameters = null,
+ $searchCategoryParameters = null)
{
$idSite = Piwik_SitesManager_API::getInstance()->addSite(
$siteName,
$siteUrl === false ? "http://piwik.net/" : $siteUrl,
$ecommerce,
- $siteSearch , $searchKeywordParameters, $searchCategoryParameters,
+ $siteSearch, $searchKeywordParameters, $searchCategoryParameters,
$ips = null,
$excludedQueryParameters = null,
$timezone = null,
@@ -65,39 +65,38 @@ abstract class Test_Piwik_BaseFixture extends PHPUnit_Framework_Assert
return $idSite;
}
- /**
- * Returns URL to Piwik root.
- *
- * @return string
- */
- public static function getRootUrl()
- {
- $piwikUrl = Piwik_Url::getCurrentUrlWithoutFileName();
-
- $pathBeforeRoot = 'tests';
- // Running from a plugin
- if(strpos($piwikUrl, 'plugins/') !== false)
- {
- $pathBeforeRoot = 'plugins';
- }
-
- $testsInPath = strpos($piwikUrl, $pathBeforeRoot.'/');
- if($testsInPath !== false) {
- $piwikUrl = substr($piwikUrl, 0, $testsInPath);
- }
- return $piwikUrl;
- }
-
- /**
- * Returns URL to the proxy script, used to ensure piwik.php
- * uses the test environment, and allows variable overwriting
- *
- * @return string
- */
- public static function getTrackerUrl()
- {
- return self::getRootUrl().'tests/PHPUnit/proxy/piwik.php';
- }
+ /**
+ * Returns URL to Piwik root.
+ *
+ * @return string
+ */
+ public static function getRootUrl()
+ {
+ $piwikUrl = Piwik_Url::getCurrentUrlWithoutFileName();
+
+ $pathBeforeRoot = 'tests';
+ // Running from a plugin
+ if (strpos($piwikUrl, 'plugins/') !== false) {
+ $pathBeforeRoot = 'plugins';
+ }
+
+ $testsInPath = strpos($piwikUrl, $pathBeforeRoot . '/');
+ if ($testsInPath !== false) {
+ $piwikUrl = substr($piwikUrl, 0, $testsInPath);
+ }
+ return $piwikUrl;
+ }
+
+ /**
+ * Returns URL to the proxy script, used to ensure piwik.php
+ * uses the test environment, and allows variable overwriting
+ *
+ * @return string
+ */
+ public static function getTrackerUrl()
+ {
+ return self::getRootUrl() . 'tests/PHPUnit/proxy/piwik.php';
+ }
/**
* Returns a PiwikTracker object that you can then use to track pages or goals.
@@ -108,35 +107,31 @@ abstract class Test_Piwik_BaseFixture extends PHPUnit_Framework_Assert
*
* @return PiwikTracker
*/
- public static function getTracker($idSite, $dateTime, $defaultInit = true, $useLocal = false )
+ public static function getTracker($idSite, $dateTime, $defaultInit = true, $useLocal = false)
{
- if ($useLocal)
- {
- require_once PIWIK_INCLUDE_PATH . '/tests/LocalTracker.php';
- $t = new Piwik_LocalTracker($idSite, self::getTrackerUrl());
- }
- else
- {
- $t = new PiwikTracker( $idSite, self::getTrackerUrl());
+ if ($useLocal) {
+ require_once PIWIK_INCLUDE_PATH . '/tests/LocalTracker.php';
+ $t = new Piwik_LocalTracker($idSite, self::getTrackerUrl());
+ } else {
+ $t = new PiwikTracker($idSite, self::getTrackerUrl());
}
$t->setForceVisitDateTime($dateTime);
- if($defaultInit)
- {
+ if ($defaultInit) {
$t->setIp('156.5.3.2');
// Optional tracking
- $t->setUserAgent( "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 (.NET CLR 3.5.30729)");
+ $t->setUserAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 (.NET CLR 3.5.30729)");
$t->setBrowserLanguage('fr');
- $t->setLocalTime( '12:34:06' );
- $t->setResolution( 1024, 768 );
+ $t->setLocalTime('12:34:06');
+ $t->setResolution(1024, 768);
$t->setBrowserHasCookies(true);
$t->setPlugins($flash = true, $java = true, $director = false);
}
return $t;
}
- /**
+ /**
* Checks that the response is a GIF image as expected.
* Will fail the test if the response is not the expected GIF
*
@@ -147,173 +142,167 @@ abstract class Test_Piwik_BaseFixture extends PHPUnit_Framework_Assert
$trans_gif_64 = "R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==";
$expectedResponse = base64_decode($trans_gif_64);
self::assertEquals($expectedResponse, $response, "Expected GIF beacon, got: <br/>\n"
- . var_export($response, true)
- . "\n If you are stuck, you can enable \$GLOBALS['PIWIK_TRACKER_DEBUG']=true; in piwik.php to get more debug info."
+ . var_export($response, true)
+ . "\n If you are stuck, you can enable \$GLOBALS['PIWIK_TRACKER_DEBUG']=true; in piwik.php to get more debug info."
. base64_encode($response)
);
}
-
- public static function makeLocation( $city, $region, $country, $lat = null, $long = null )
- {
- return array(Piwik_UserCountry_LocationProvider::CITY_NAME_KEY => $city,
- Piwik_UserCountry_LocationProvider::REGION_CODE_KEY => $region,
- Piwik_UserCountry_LocationProvider::COUNTRY_CODE_KEY => $country,
- Piwik_UserCountry_LocationProvider::LATITUDE_KEY => $lat,
- Piwik_UserCountry_LocationProvider::LONGITUDE_KEY => $long);
- }
-
- /**
- * Returns the super user token auth that can be used in tests. Can be used to
- * do bulk tracking.
- *
- * @return string
- */
- public static function getTokenAuth()
- {
- return Piwik_UsersManager_API::getInstance()->getTokenAuth(
- Piwik_Config::getInstance()->superuser['login'],
- Piwik_Config::getInstance()->superuser['password']
- );
+
+ public static function makeLocation($city, $region, $country, $lat = null, $long = null)
+ {
+ return array(Piwik_UserCountry_LocationProvider::CITY_NAME_KEY => $city,
+ Piwik_UserCountry_LocationProvider::REGION_CODE_KEY => $region,
+ Piwik_UserCountry_LocationProvider::COUNTRY_CODE_KEY => $country,
+ Piwik_UserCountry_LocationProvider::LATITUDE_KEY => $lat,
+ Piwik_UserCountry_LocationProvider::LONGITUDE_KEY => $long);
+ }
+
+ /**
+ * Returns the super user token auth that can be used in tests. Can be used to
+ * do bulk tracking.
+ *
+ * @return string
+ */
+ public static function getTokenAuth()
+ {
+ return Piwik_UsersManager_API::getInstance()->getTokenAuth(
+ Piwik_Config::getInstance()->superuser['login'],
+ Piwik_Config::getInstance()->superuser['password']
+ );
+ }
+
+ /**
+ * Create one MAIL and two MOBILE scheduled reports
+ *
+ * Reports sent by mail can contain PNG graphs when the user specifies it.
+ * Depending on the system under test, generated images differ slightly.
+ * Because of this discrepancy, PNG graphs are only tested if the system under test
+ * has the characteristics described in 'canImagesBeIncludedInScheduledReports'
+ *
+ * @see canImagesBeIncludedInScheduledReports
+ * @param int $idSite id of website created
+ */
+ public static function setUpScheduledReports($idSite)
+ {
+ // fake access is needed so API methods can call Piwik::getCurrentUserLogin(), e.g: 'PDFReports.addReport'
+ $pseudoMockAccess = new FakeAccess;
+ FakeAccess::$superUser = true;
+ Zend_Registry::set('access', $pseudoMockAccess);
+
+ // retrieve available reports
+ $availableReportMetadata = Piwik_PDFReports_API::getReportMetadata($idSite, Piwik_PDFReports::EMAIL_TYPE);
+
+ $availableReportIds = array();
+ foreach ($availableReportMetadata as $reportMetadata) {
+ $availableReportIds[] = $reportMetadata['uniqueId'];
+ }
+
+ //@review should we also test evolution graphs?
+ // set-up mail report
+ Piwik_PDFReports_API::getInstance()->addReport(
+ $idSite,
+ 'Mail Test report',
+ 'day', // overridden in getApiForTestingScheduledReports()
+ 0,
+ Piwik_PDFReports::EMAIL_TYPE,
+ Piwik_ReportRenderer::HTML_FORMAT, // overridden in getApiForTestingScheduledReports()
+ $availableReportIds,
+ array("displayFormat" => Piwik_PDFReports::DISPLAY_FORMAT_TABLES_ONLY)
+ );
+
+ // set-up sms report for one website
+ Piwik_PDFReports_API::getInstance()->addReport(
+ $idSite,
+ 'SMS Test report, one website',
+ 'day', // overridden in getApiForTestingScheduledReports()
+ 0,
+ Piwik_MobileMessaging::MOBILE_TYPE,
+ Piwik_MobileMessaging::SMS_FORMAT,
+ array("MultiSites_getOne"),
+ array("phoneNumbers" => array())
+ );
+
+ // set-up sms report for all websites
+ Piwik_PDFReports_API::getInstance()->addReport(
+ $idSite,
+ 'SMS Test report, all websites',
+ 'day', // overridden in getApiForTestingScheduledReports()
+ 0,
+ Piwik_MobileMessaging::MOBILE_TYPE,
+ Piwik_MobileMessaging::SMS_FORMAT,
+ array("MultiSites_getAll"),
+ array("phoneNumbers" => array())
+ );
+
+ if (self::canImagesBeIncludedInScheduledReports()) {
+ // set-up mail report with images
+ Piwik_PDFReports_API::getInstance()->addReport(
+ $idSite,
+ 'Mail Test report',
+ 'day', // overridden in getApiForTestingScheduledReports()
+ 0,
+ Piwik_PDFReports::EMAIL_TYPE,
+ Piwik_ReportRenderer::HTML_FORMAT, // overridden in getApiForTestingScheduledReports()
+ $availableReportIds,
+ array("displayFormat" => Piwik_PDFReports::DISPLAY_FORMAT_TABLES_AND_GRAPHS)
+ );
+ }
+ }
+
+ /**
+ * Return true if system under test has the following characteristics :
+ * - php_uname() contains 'precise32' or 'ubuntu'
+ * - phpversion() contains '5.3.10'
+ * - 'GD Version' equals '2.0'
+ */
+ public static function canImagesBeIncludedInScheduledReports()
+ {
+ $gdInfo = gd_info();
+ return
+ (stristr(php_uname(), 'precise32') || stristr(php_uname(), 'ubuntu')) &&
+ stristr(phpversion(), '5.3.10') &&
+ $gdInfo['GD Version'] == '2.0';
+ }
+
+ public static $geoIpDbUrl = 'http://piwik-team.s3.amazonaws.com/GeoIP.dat.gz';
+ public static $geoLiteCityDbUrl = 'http://piwik-team.s3.amazonaws.com/GeoLiteCity.dat.gz';
+
+ public static function downloadGeoIpDbs()
+ {
+ $geoIpOutputDir = PIWIK_INCLUDE_PATH . '/tests/lib/geoip-files';
+ self::downloadAndUnzip(self::$geoIpDbUrl, $geoIpOutputDir, 'GeoIP.dat');
+ self::downloadAndUnzip(self::$geoLiteCityDbUrl, $geoIpOutputDir, 'GeoIPCity.dat');
+ }
+
+ public static function downloadAndUnzip($url, $outputDir, $filename)
+ {
+ $bufferSize = 1024 * 1024;
+
+ if (!is_dir($outputDir)) {
+ mkdir($outputDir);
+ }
+
+ $deflatedOut = $outputDir . '/' . $filename;
+ $outfileName = $deflatedOut . '.gz';
+
+ if (file_exists($deflatedOut)) {
+ return;
+ }
+
+ $dump = fopen($url, 'rb');
+ $outfile = fopen($outfileName, 'wb');
+ $bytesRead = 0;
+ while (!feof($dump)) {
+ fwrite($outfile, fread($dump, $bufferSize), $bufferSize);
+ $bytesRead += $bufferSize;
+ }
+ fclose($dump);
+ fclose($outfile);
+
+ // unzip the dump
+ exec("gunzip -c \"" . $outfileName . "\" > \"$deflatedOut\"", $output, $return);
+ if ($return !== 0) {
+ throw new Exception("gunzip failed($return): " . implode("\n", $output));
+ }
}
-
- /**
- * Create one MAIL and two MOBILE scheduled reports
- *
- * Reports sent by mail can contain PNG graphs when the user specifies it.
- * Depending on the system under test, generated images differ slightly.
- * Because of this discrepancy, PNG graphs are only tested if the system under test
- * has the characteristics described in 'canImagesBeIncludedInScheduledReports'
- *
- * @see canImagesBeIncludedInScheduledReports
- * @param int $idSite id of website created
- */
- public static function setUpScheduledReports($idSite)
- {
- // fake access is needed so API methods can call Piwik::getCurrentUserLogin(), e.g: 'PDFReports.addReport'
- $pseudoMockAccess = new FakeAccess;
- FakeAccess::$superUser = true;
- Zend_Registry::set('access', $pseudoMockAccess);
-
- // retrieve available reports
- $availableReportMetadata = Piwik_PDFReports_API::getReportMetadata($idSite, Piwik_PDFReports::EMAIL_TYPE);
-
- $availableReportIds = array();
- foreach($availableReportMetadata as $reportMetadata)
- {
- $availableReportIds[] = $reportMetadata['uniqueId'];
- }
-
- //@review should we also test evolution graphs?
- // set-up mail report
- Piwik_PDFReports_API::getInstance()->addReport(
- $idSite,
- 'Mail Test report',
- 'day', // overridden in getApiForTestingScheduledReports()
- 0,
- Piwik_PDFReports::EMAIL_TYPE,
- Piwik_ReportRenderer::HTML_FORMAT, // overridden in getApiForTestingScheduledReports()
- $availableReportIds,
- array("displayFormat" => Piwik_PDFReports::DISPLAY_FORMAT_TABLES_ONLY)
- );
-
- // set-up sms report for one website
- Piwik_PDFReports_API::getInstance()->addReport(
- $idSite,
- 'SMS Test report, one website',
- 'day', // overridden in getApiForTestingScheduledReports()
- 0,
- Piwik_MobileMessaging::MOBILE_TYPE,
- Piwik_MobileMessaging::SMS_FORMAT,
- array("MultiSites_getOne"),
- array("phoneNumbers"=>array())
- );
-
- // set-up sms report for all websites
- Piwik_PDFReports_API::getInstance()->addReport(
- $idSite,
- 'SMS Test report, all websites',
- 'day', // overridden in getApiForTestingScheduledReports()
- 0,
- Piwik_MobileMessaging::MOBILE_TYPE,
- Piwik_MobileMessaging::SMS_FORMAT,
- array("MultiSites_getAll"),
- array("phoneNumbers"=>array())
- );
-
- if (self::canImagesBeIncludedInScheduledReports())
- {
- // set-up mail report with images
- Piwik_PDFReports_API::getInstance()->addReport(
- $idSite,
- 'Mail Test report',
- 'day', // overridden in getApiForTestingScheduledReports()
- 0,
- Piwik_PDFReports::EMAIL_TYPE,
- Piwik_ReportRenderer::HTML_FORMAT, // overridden in getApiForTestingScheduledReports()
- $availableReportIds,
- array("displayFormat" => Piwik_PDFReports::DISPLAY_FORMAT_TABLES_AND_GRAPHS)
- );
- }
- }
-
- /**
- * Return true if system under test has the following characteristics :
- * - php_uname() contains 'precise32' or 'ubuntu'
- * - phpversion() contains '5.3.10'
- * - 'GD Version' equals '2.0'
- */
- public static function canImagesBeIncludedInScheduledReports()
- {
- $gdInfo = gd_info();
- return
- (stristr(php_uname(), 'precise32') || stristr(php_uname(), 'ubuntu')) &&
- stristr(phpversion(), '5.3.10') &&
- $gdInfo['GD Version'] == '2.0';
- }
-
- public static $geoIpDbUrl = 'http://piwik-team.s3.amazonaws.com/GeoIP.dat.gz';
- public static $geoLiteCityDbUrl = 'http://piwik-team.s3.amazonaws.com/GeoLiteCity.dat.gz';
-
- public static function downloadGeoIpDbs()
- {
- $geoIpOutputDir = PIWIK_INCLUDE_PATH.'/tests/lib/geoip-files';
- self::downloadAndUnzip(self::$geoIpDbUrl, $geoIpOutputDir, 'GeoIP.dat');
- self::downloadAndUnzip(self::$geoLiteCityDbUrl, $geoIpOutputDir, 'GeoIPCity.dat');
- }
-
- public static function downloadAndUnzip( $url, $outputDir, $filename )
- {
- $bufferSize = 1024 * 1024;
-
- if (!is_dir($outputDir))
- {
- mkdir($outputDir);
- }
-
- $deflatedOut = $outputDir.'/'.$filename;
- $outfileName = $deflatedOut.'.gz';
-
- if (file_exists($deflatedOut))
- {
- return;
- }
-
- $dump = fopen($url, 'rb');
- $outfile = fopen($outfileName, 'wb');
- $bytesRead = 0;
- while (!feof($dump))
- {
- fwrite($outfile, fread($dump, $bufferSize), $bufferSize);
- $bytesRead += $bufferSize;
- }
- fclose($dump);
- fclose($outfile);
-
- // unzip the dump
- exec("gunzip -c \"".$outfileName."\" > \"$deflatedOut\"", $output, $return);
- if ($return !== 0)
- {
- throw new Exception("gunzip failed($return): ".implode("\n", $output));
- }
- }
}
diff --git a/tests/PHPUnit/BenchmarkTestCase.php b/tests/PHPUnit/BenchmarkTestCase.php
index 5b958edd2a..ad1dfd379e 100755
--- a/tests/PHPUnit/BenchmarkTestCase.php
+++ b/tests/PHPUnit/BenchmarkTestCase.php
@@ -9,9 +9,8 @@ require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/IntegrationTestCase.php';
require_once PIWIK_INCLUDE_PATH . '/tests/LocalTracker.php';
// require fixtures
-foreach (glob(PIWIK_INCLUDE_PATH . '/tests/PHPUnit/Benchmarks/Fixtures/*.php') as $file)
-{
- require_once $file;
+foreach (glob(PIWIK_INCLUDE_PATH . '/tests/PHPUnit/Benchmarks/Fixtures/*.php') as $file) {
+ require_once $file;
}
/**
@@ -19,82 +18,73 @@ foreach (glob(PIWIK_INCLUDE_PATH . '/tests/PHPUnit/Benchmarks/Fixtures/*.php') a
*/
abstract class BenchmarkTestCase extends IntegrationTestCase
{
- protected static $fixture;
-
- public static function setUpBeforeClass()
- {
- $dbName = false;
- if (!empty($GLOBALS['PIWIK_BENCHMARK_DATABASE']))
- {
- $dbName = $GLOBALS['PIWIK_BENCHMARK_DATABASE'];
- }
-
- // connect to database
- self::createTestConfig();
- self::connectWithoutDatabase();
-
- // create specified fixture (global var not set, use default no-data fixture (see end of this file))
- if (empty($GLOBALS['PIWIK_BENCHMARK_FIXTURE']))
- {
- $fixtureName = 'Piwik_Test_Fixture_EmptyOneSite';
- }
- else
- {
- $fixtureName = 'Piwik_Test_Fixture_'.$GLOBALS['PIWIK_BENCHMARK_FIXTURE'];
- }
- self::$fixture = new $fixtureName;
-
- // figure out if the desired fixture has already been setup, and if not empty the database
- $installedFixture = false;
- try
- {
- if (isset(self::$fixture->tablesPrefix))
- {
- Piwik_Config::getInstance()->database['tables_prefix'] = self::$fixture->tablesPrefix;
- Piwik_Common::$cachedTablePrefix = null;
- }
-
- Piwik_Query("USE ".$dbName);
- $installedFixture = Piwik_GetOption('benchmark_fixture_name');
- }
- catch (Exception $ex)
- {
- // ignore
- }
-
- $createEmptyDatabase = $fixtureName != $installedFixture;
- parent::_setUpBeforeClass($dbName, $createEmptyDatabase, $createConfig = false);
-
- // if we created an empty database, setup the fixture
- if ($createEmptyDatabase)
- {
- self::$fixture->setUp();
- Piwik_SetOption('benchmark_fixture_name', $fixtureName);
- }
- }
-
- public static function tearDownAfterClass()
- {
- // only drop the database if PIWIK_BENCHMARK_DATABASE isn't set
- $dropDatabase = empty($GLOBALS['PIWIK_BENCHMARK_DATABASE']);
- parent::_tearDownAfterClass($dropDatabase);
- }
-
- /**
- * Creates a tracking object that invokes the tracker directly (w/o going through HTTP).
- */
- public static function getLocalTracker( $idSite )
- {
- $t = new Piwik_LocalTracker($idSite, IntegrationTestCase::getTrackerUrl());
- $t->setUserAgent( "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 (.NET CLR 3.5.30729)");
- $t->setBrowserLanguage('fr');
- $t->setLocalTime('12:34:06');
- $t->setResolution(1024, 768);
- $t->setBrowserHasCookies(true);
- $t->setPlugins($flash = true, $java = true, $director = false);
- $t->setTokenAuth(self::getTokenAuth());
- return $t;
- }
+ protected static $fixture;
+
+ public static function setUpBeforeClass()
+ {
+ $dbName = false;
+ if (!empty($GLOBALS['PIWIK_BENCHMARK_DATABASE'])) {
+ $dbName = $GLOBALS['PIWIK_BENCHMARK_DATABASE'];
+ }
+
+ // connect to database
+ self::createTestConfig();
+ self::connectWithoutDatabase();
+
+ // create specified fixture (global var not set, use default no-data fixture (see end of this file))
+ if (empty($GLOBALS['PIWIK_BENCHMARK_FIXTURE'])) {
+ $fixtureName = 'Piwik_Test_Fixture_EmptyOneSite';
+ } else {
+ $fixtureName = 'Piwik_Test_Fixture_' . $GLOBALS['PIWIK_BENCHMARK_FIXTURE'];
+ }
+ self::$fixture = new $fixtureName;
+
+ // figure out if the desired fixture has already been setup, and if not empty the database
+ $installedFixture = false;
+ try {
+ if (isset(self::$fixture->tablesPrefix)) {
+ Piwik_Config::getInstance()->database['tables_prefix'] = self::$fixture->tablesPrefix;
+ Piwik_Common::$cachedTablePrefix = null;
+ }
+
+ Piwik_Query("USE " . $dbName);
+ $installedFixture = Piwik_GetOption('benchmark_fixture_name');
+ } catch (Exception $ex) {
+ // ignore
+ }
+
+ $createEmptyDatabase = $fixtureName != $installedFixture;
+ parent::_setUpBeforeClass($dbName, $createEmptyDatabase, $createConfig = false);
+
+ // if we created an empty database, setup the fixture
+ if ($createEmptyDatabase) {
+ self::$fixture->setUp();
+ Piwik_SetOption('benchmark_fixture_name', $fixtureName);
+ }
+ }
+
+ public static function tearDownAfterClass()
+ {
+ // only drop the database if PIWIK_BENCHMARK_DATABASE isn't set
+ $dropDatabase = empty($GLOBALS['PIWIK_BENCHMARK_DATABASE']);
+ parent::_tearDownAfterClass($dropDatabase);
+ }
+
+ /**
+ * Creates a tracking object that invokes the tracker directly (w/o going through HTTP).
+ */
+ public static function getLocalTracker($idSite)
+ {
+ $t = new Piwik_LocalTracker($idSite, IntegrationTestCase::getTrackerUrl());
+ $t->setUserAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 (.NET CLR 3.5.30729)");
+ $t->setBrowserLanguage('fr');
+ $t->setLocalTime('12:34:06');
+ $t->setResolution(1024, 768);
+ $t->setBrowserHasCookies(true);
+ $t->setPlugins($flash = true, $java = true, $director = false);
+ $t->setTokenAuth(self::getTokenAuth());
+ return $t;
+ }
}
/**
@@ -102,19 +92,19 @@ abstract class BenchmarkTestCase extends IntegrationTestCase
*/
class Piwik_Test_Fixture_EmptyOneSite
{
- public $date = '2010-01-01';
- public $period = 'day';
- public $idSite = 1;
-
- public function setUp()
- {
- // add one site
- IntegrationTestCase::createWebsite(
- $this->date, $ecommerce = 1, $siteName = "Site #0", $siteUrl = "http://whatever.com/");
-
- // add two goals
- $goals = Piwik_Goals_API::getInstance();
- $goals->addGoal($this->idSite, 'all', 'url', 'http', 'contains', false, 5);
- $goals->addGoal($this->idSite, 'all', 'url', 'http', 'contains');
- }
+ public $date = '2010-01-01';
+ public $period = 'day';
+ public $idSite = 1;
+
+ public function setUp()
+ {
+ // add one site
+ IntegrationTestCase::createWebsite(
+ $this->date, $ecommerce = 1, $siteName = "Site #0", $siteUrl = "http://whatever.com/");
+
+ // add two goals
+ $goals = Piwik_Goals_API::getInstance();
+ $goals->addGoal($this->idSite, 'all', 'url', 'http', 'contains', false, 5);
+ $goals->addGoal($this->idSite, 'all', 'url', 'http', 'contains');
+ }
}
diff --git a/tests/PHPUnit/Benchmarks/ArchivingProcessBenchmark.php b/tests/PHPUnit/Benchmarks/ArchivingProcessBenchmark.php
index 4cbfa0c1e3..b84afff74c 100755
--- a/tests/PHPUnit/Benchmarks/ArchivingProcessBenchmark.php
+++ b/tests/PHPUnit/Benchmarks/ArchivingProcessBenchmark.php
@@ -12,17 +12,17 @@ require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/BenchmarkTestCase.php';
*/
class ArchivingProcessBenchmark extends BenchmarkTestCase
{
- public function setUp()
- {
- BenchmarkTestCase::deleteArchiveTables();
- }
-
- /**
+ public function setUp()
+ {
+ BenchmarkTestCase::deleteArchiveTables();
+ }
+
+ /**
* @group Benchmarks
* @group ArchivingProcess
- */
- public function testArchivingProcess()
- {
- Piwik_VisitsSummary_API::get(self::$fixture->idSite, self::$fixture->period, self::$fixture->date);
- }
+ */
+ public function testArchivingProcess()
+ {
+ Piwik_VisitsSummary_API::get(self::$fixture->idSite, self::$fixture->period, self::$fixture->date);
+ }
}
diff --git a/tests/PHPUnit/Benchmarks/Fixtures/OneSiteTwelveThousandVisitsOneYear.php b/tests/PHPUnit/Benchmarks/Fixtures/OneSiteTwelveThousandVisitsOneYear.php
index d2a1b7d807..619b288fad 100755
--- a/tests/PHPUnit/Benchmarks/Fixtures/OneSiteTwelveThousandVisitsOneYear.php
+++ b/tests/PHPUnit/Benchmarks/Fixtures/OneSiteTwelveThousandVisitsOneYear.php
@@ -11,59 +11,53 @@
*/
class Piwik_Test_Fixture_OneSiteTwelveThousandVisitsOneYear
{
- public $date = '2010-01-01';
- public $period = 'year';
- public $idSite = 1;
- public $idGoal1 = 1;
- public $idGoal2 = 2;
-
- public function setUp()
- {
- // add one site
- IntegrationTestCase::createWebsite(
- $this->date, $ecommerce = 1, $siteName = "Site #0", $siteUrl = "http://whatever.com/");
-
- // add two goals
- $goals = Piwik_Goals_API::getInstance();
- $goals->addGoal($this->idSite, 'all', 'url', 'http', 'contains', false, 5);
- $goals->addGoal($this->idSite, 'all', 'url', 'http', 'contains');
-
- $urls = array();
- for ($i = 0; $i != 3; ++$i)
- {
- $url = "http://whatever.com/".($i-1)."/".($i+1);
- $title = "page view ".($i-1)." / ".($i+1);
- $urls[$url] = $title;
- }
-
- $visitTimes = array();
- $date = Piwik_Date::factory($this->date);
- for ($month = 0; $month != 12; ++$month)
- {
- for ($day = 0; $day != 25; ++$day)
- {
- $hour = ($time * 31) / 60.0;
- $visitTimes[] = $date->addPeriod($month, 'MONTH')->addDay($day)->getDatetime();
- }
- }
-
- // add 12,000 visits (1 visit a day from 40 visitors for 25 days of every month) w/ 3 pageviews each
- foreach ($visitTimes as $visitTime)
- {
- for ($visitor = 0; $visitor != 40; ++$visitor)
- {
- $t = BenchmarkTestCase::getLocalTracker($this->idSite);
-
- $ip = "157.5.6.".($visitor+1);
- $t->setIp($ip);
- $t->setForceVisitDateTime($visitTime);
-
- foreach ($urls as $url => $title)
- {
- $t->setUrl($url);
- $t->doTrackPageView($title);
- }
- }
- }
- }
+ public $date = '2010-01-01';
+ public $period = 'year';
+ public $idSite = 1;
+ public $idGoal1 = 1;
+ public $idGoal2 = 2;
+
+ public function setUp()
+ {
+ // add one site
+ IntegrationTestCase::createWebsite(
+ $this->date, $ecommerce = 1, $siteName = "Site #0", $siteUrl = "http://whatever.com/");
+
+ // add two goals
+ $goals = Piwik_Goals_API::getInstance();
+ $goals->addGoal($this->idSite, 'all', 'url', 'http', 'contains', false, 5);
+ $goals->addGoal($this->idSite, 'all', 'url', 'http', 'contains');
+
+ $urls = array();
+ for ($i = 0; $i != 3; ++$i) {
+ $url = "http://whatever.com/" . ($i - 1) . "/" . ($i + 1);
+ $title = "page view " . ($i - 1) . " / " . ($i + 1);
+ $urls[$url] = $title;
+ }
+
+ $visitTimes = array();
+ $date = Piwik_Date::factory($this->date);
+ for ($month = 0; $month != 12; ++$month) {
+ for ($day = 0; $day != 25; ++$day) {
+ $hour = ($time * 31) / 60.0;
+ $visitTimes[] = $date->addPeriod($month, 'MONTH')->addDay($day)->getDatetime();
+ }
+ }
+
+ // add 12,000 visits (1 visit a day from 40 visitors for 25 days of every month) w/ 3 pageviews each
+ foreach ($visitTimes as $visitTime) {
+ for ($visitor = 0; $visitor != 40; ++$visitor) {
+ $t = BenchmarkTestCase::getLocalTracker($this->idSite);
+
+ $ip = "157.5.6." . ($visitor + 1);
+ $t->setIp($ip);
+ $t->setForceVisitDateTime($visitTime);
+
+ foreach ($urls as $url => $title) {
+ $t->setUrl($url);
+ $t->doTrackPageView($title);
+ }
+ }
+ }
+ }
}
diff --git a/tests/PHPUnit/Benchmarks/Fixtures/SqlDump.php b/tests/PHPUnit/Benchmarks/Fixtures/SqlDump.php
index ed9c0544e8..488814877f 100755
--- a/tests/PHPUnit/Benchmarks/Fixtures/SqlDump.php
+++ b/tests/PHPUnit/Benchmarks/Fixtures/SqlDump.php
@@ -11,60 +11,57 @@
*/
class Piwik_Test_Fixture_SqlDump
{
- public static $dumpUrl = "http://piwik-team.s3.amazonaws.com/generated-logs-one-day.sql.gz";
+ public static $dumpUrl = "http://piwik-team.s3.amazonaws.com/generated-logs-one-day.sql.gz";
- public $date = '2012-09-03';
- public $period = 'day';
- public $idSite = 'all';
- public $tablesPrefix = 'piwik_';
-
- public function setUp()
- {
- $dumpPath = PIWIK_INCLUDE_PATH.'/tmp/logdump.sql.gz';
- $deflatedDumpPath = PIWIK_INCLUDE_PATH.'/tmp/logdump.sql';
- $bufferSize = 1024 * 1024;
-
- // drop all tables
- Piwik::dropTables();
-
- // download data dump
- $dump = fopen(self::$dumpUrl, 'rb');
- $outfile = fopen($dumpPath, 'wb');
- $bytesRead = 0;
- while (!feof($dump))
- {
- fwrite($outfile, fread($dump, $bufferSize), $bufferSize);
- $bytesRead += $bufferSize;
- }
- fclose($dump);
- fclose($outfile);
-
- if ($bytesRead <= 40 * 1024 * 1024) // sanity check
- {
- throw new Exception("Could not download sql dump!");
- }
-
- // unzip the dump
- exec("gunzip -c \"".$dumpPath."\" > \"$deflatedDumpPath\"", $output, $return);
- if ($return !== 0)
- {
- throw new Exception("gunzip failed: ".implode("\n", $output));
- }
-
- // load the data into the correct database
- $user = Piwik_Config::getInstance()->database['username'];
- $password = Piwik_Config::getInstance()->database['password'];
- $dbName = Piwik_Config::getInstance()->database['dbname'];
- Piwik_Config::getInstance()->database['tables_prefix'] = 'piwik_';
- Piwik_Common::$cachedTablePrefix = null;
-
- exec("mysql -u \"$user\" \"--password=$password\" $dbName < \"".$deflatedDumpPath."\" 2>&1", $output, $return);
- if ($return !== 0)
- {
- throw new Exception("Failed to load sql dump: ".implode("\n", $output));
- }
-
- // make sure archiving will be called
- Piwik_ArchiveProcessing::setBrowserTriggerArchiving(true);
- }
+ public $date = '2012-09-03';
+ public $period = 'day';
+ public $idSite = 'all';
+ public $tablesPrefix = 'piwik_';
+
+ public function setUp()
+ {
+ $dumpPath = PIWIK_INCLUDE_PATH . '/tmp/logdump.sql.gz';
+ $deflatedDumpPath = PIWIK_INCLUDE_PATH . '/tmp/logdump.sql';
+ $bufferSize = 1024 * 1024;
+
+ // drop all tables
+ Piwik::dropTables();
+
+ // download data dump
+ $dump = fopen(self::$dumpUrl, 'rb');
+ $outfile = fopen($dumpPath, 'wb');
+ $bytesRead = 0;
+ while (!feof($dump)) {
+ fwrite($outfile, fread($dump, $bufferSize), $bufferSize);
+ $bytesRead += $bufferSize;
+ }
+ fclose($dump);
+ fclose($outfile);
+
+ if ($bytesRead <= 40 * 1024 * 1024) // sanity check
+ {
+ throw new Exception("Could not download sql dump!");
+ }
+
+ // unzip the dump
+ exec("gunzip -c \"" . $dumpPath . "\" > \"$deflatedDumpPath\"", $output, $return);
+ if ($return !== 0) {
+ throw new Exception("gunzip failed: " . implode("\n", $output));
+ }
+
+ // load the data into the correct database
+ $user = Piwik_Config::getInstance()->database['username'];
+ $password = Piwik_Config::getInstance()->database['password'];
+ $dbName = Piwik_Config::getInstance()->database['dbname'];
+ Piwik_Config::getInstance()->database['tables_prefix'] = 'piwik_';
+ Piwik_Common::$cachedTablePrefix = null;
+
+ exec("mysql -u \"$user\" \"--password=$password\" $dbName < \"" . $deflatedDumpPath . "\" 2>&1", $output, $return);
+ if ($return !== 0) {
+ throw new Exception("Failed to load sql dump: " . implode("\n", $output));
+ }
+
+ // make sure archiving will be called
+ Piwik_ArchiveProcessing::setBrowserTriggerArchiving(true);
+ }
}
diff --git a/tests/PHPUnit/Benchmarks/Fixtures/ThousandSitesTwelveVisitsEachOneDay.php b/tests/PHPUnit/Benchmarks/Fixtures/ThousandSitesTwelveVisitsEachOneDay.php
index 9329ba9c5b..f42d87b6e4 100755
--- a/tests/PHPUnit/Benchmarks/Fixtures/ThousandSitesTwelveVisitsEachOneDay.php
+++ b/tests/PHPUnit/Benchmarks/Fixtures/ThousandSitesTwelveVisitsEachOneDay.php
@@ -11,74 +11,63 @@
*/
class Piwik_Test_Fixture_ThousandSitesTwelvePageViewsEachOneDay
{
- public $date = '2010-01-01';
- public $period = 'day';
- public $idSite = 'all';
-
- public function setUp()
- {
- $sitesManager = Piwik_SitesManager_API::getInstance();
- $goals = Piwik_Goals_API::getInstance();
-
- // add one thousand sites
- $allIdSites = array();
- for ($i = 0; $i < 1000; ++$i)
- {
- $allIdSites[] = IntegrationTestCase::createWebsite($this->date, $ecommerce = 1, $siteName = "Site #$i");
- }
-
- // add goals to 500 sites
- $idGoals = array();
- foreach ($allIdSites as $idSite)
- {
- if ($idSite % 2 == 0)
- {
- $idGoal1 = $goals->addGoal($idSite, 'all', 'url', 'http', 'contains', false, 5);
- $idGoal2 = $goals->addGoal($idSite, 'all', 'url', 'http', 'contains');
- $idGoals[$idSite] = array($idGoal1, $idGoal2);
- }
- else
- {
- $idGoals[$idSite] = array();
- }
- }
+ public $date = '2010-01-01';
+ public $period = 'day';
+ public $idSite = 'all';
- $urls = array();
- for ($i = 0; $i != 3; ++$i)
- {
- $url = "http://whatever.com/".($i-1)."/".($i+1);
- $title = "page view ".($i-1)." / ".($i+1);
- $urls[$url] = $title;
- }
+ public function setUp()
+ {
+ $sitesManager = Piwik_SitesManager_API::getInstance();
+ $goals = Piwik_Goals_API::getInstance();
- $visitTimes = array();
- $date = Piwik_Date::factory($this->date);
- for ($i = 0; $i != 4; ++$i)
- {
- $visitTimes[] = $date->addHour($i)->getDatetime();
- }
-
- // add 12000 visits (3 visitors with 4 visits each for each site) w/ 3 pageviews each on one day
- foreach ($visitTimes as $visitTime)
- {
- foreach ($allIdSites as $idSite)
- {
- for ($visitor = 0; $visitor != 3; ++$visitor)
- {
- $t = BenchmarkTestCase::getLocalTracker($this->idSite);
+ // add one thousand sites
+ $allIdSites = array();
+ for ($i = 0; $i < 1000; ++$i) {
+ $allIdSites[] = IntegrationTestCase::createWebsite($this->date, $ecommerce = 1, $siteName = "Site #$i");
+ }
- $ip = "157.5.6.".($visitor+1);
- $t->setIp($ip);
-
- $t->setForceVisitDateTime($visitTime);
- foreach ($urls as $url => $title)
- {
- $t->setUrl($url);
- $t->doTrackPageView($title);
- }
- }
- }
- }
- }
+ // add goals to 500 sites
+ $idGoals = array();
+ foreach ($allIdSites as $idSite) {
+ if ($idSite % 2 == 0) {
+ $idGoal1 = $goals->addGoal($idSite, 'all', 'url', 'http', 'contains', false, 5);
+ $idGoal2 = $goals->addGoal($idSite, 'all', 'url', 'http', 'contains');
+ $idGoals[$idSite] = array($idGoal1, $idGoal2);
+ } else {
+ $idGoals[$idSite] = array();
+ }
+ }
+
+ $urls = array();
+ for ($i = 0; $i != 3; ++$i) {
+ $url = "http://whatever.com/" . ($i - 1) . "/" . ($i + 1);
+ $title = "page view " . ($i - 1) . " / " . ($i + 1);
+ $urls[$url] = $title;
+ }
+
+ $visitTimes = array();
+ $date = Piwik_Date::factory($this->date);
+ for ($i = 0; $i != 4; ++$i) {
+ $visitTimes[] = $date->addHour($i)->getDatetime();
+ }
+
+ // add 12000 visits (3 visitors with 4 visits each for each site) w/ 3 pageviews each on one day
+ foreach ($visitTimes as $visitTime) {
+ foreach ($allIdSites as $idSite) {
+ for ($visitor = 0; $visitor != 3; ++$visitor) {
+ $t = BenchmarkTestCase::getLocalTracker($this->idSite);
+
+ $ip = "157.5.6." . ($visitor + 1);
+ $t->setIp($ip);
+
+ $t->setForceVisitDateTime($visitTime);
+ foreach ($urls as $url => $title) {
+ $t->setUrl($url);
+ $t->doTrackPageView($title);
+ }
+ }
+ }
+ }
+ }
}
diff --git a/tests/PHPUnit/Benchmarks/TrackerBenchmark.php b/tests/PHPUnit/Benchmarks/TrackerBenchmark.php
index 737dd13097..d92bd632a8 100755
--- a/tests/PHPUnit/Benchmarks/TrackerBenchmark.php
+++ b/tests/PHPUnit/Benchmarks/TrackerBenchmark.php
@@ -13,67 +13,60 @@ require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/BenchmarkTestCase.php';
*/
class TrackerBenchmark extends BenchmarkTestCase
{
- private $urls = array();
- private $pageTitles = array();
- private $visitDates = array();
- private $visitTimes = array();
- private $t = null;
-
- public function setUp()
- {
- // set up action URLs
- for ($i = 0; $i != 100; ++$i)
- {
- $this->urls[] = "http://whatever.com/$i/".($i+1);
- $this->pageTitles[] = "Page Title $i / ".($i+1);
- }
-
- // set dates & times
- $date = Piwik_Date::factory(self::$fixture->date);
- for ($i = 0; $i != 25; ++$i)
- {
- $this->visitDates[] = $date->addDay($i)->toString('Y-m-d');
- }
- for ($i = 0; $i != 5; ++$i)
- {
- $this->visitTimes[] = $date->addHour($i)->toString('H:i:s');
- }
-
- // create tracker before tracking test
- $this->t = $this->getTracker(self::$fixture->idSite, self::$fixture->date);
- $this->t->setTokenAuth(self::getTokenAuth());
- $this->t->enableBulkTracking();
-
- // track 12,500 actions: 50 visitors w/ 5 visits each per day for 25 days w/ 2 actions per visit
- $urlIdx = 0;
- foreach ($this->visitDates as $date)
- {
- foreach ($this->visitTimes as $time)
- {
- for ($visitor = 0; $visitor != 50; ++$visitor)
- {
- $this->t->setIp('157.5.6.'.($visitor+1));
- $this->t->setForceVisitDateTime($date.' '.$time);
- for ($action = 0; $action != 2; ++$action)
- {
- $realIdx = $urlIdx % count($this->urls);
-
- $this->t->setUrl($this->urls[$realIdx]);
- $this->t->doTrackPageView($this->pageTitles[$realIdx]);
-
- ++$urlIdx;
- }
- }
- }
- }
- }
-
- /**
+ private $urls = array();
+ private $pageTitles = array();
+ private $visitDates = array();
+ private $visitTimes = array();
+ private $t = null;
+
+ public function setUp()
+ {
+ // set up action URLs
+ for ($i = 0; $i != 100; ++$i) {
+ $this->urls[] = "http://whatever.com/$i/" . ($i + 1);
+ $this->pageTitles[] = "Page Title $i / " . ($i + 1);
+ }
+
+ // set dates & times
+ $date = Piwik_Date::factory(self::$fixture->date);
+ for ($i = 0; $i != 25; ++$i) {
+ $this->visitDates[] = $date->addDay($i)->toString('Y-m-d');
+ }
+ for ($i = 0; $i != 5; ++$i) {
+ $this->visitTimes[] = $date->addHour($i)->toString('H:i:s');
+ }
+
+ // create tracker before tracking test
+ $this->t = $this->getTracker(self::$fixture->idSite, self::$fixture->date);
+ $this->t->setTokenAuth(self::getTokenAuth());
+ $this->t->enableBulkTracking();
+
+ // track 12,500 actions: 50 visitors w/ 5 visits each per day for 25 days w/ 2 actions per visit
+ $urlIdx = 0;
+ foreach ($this->visitDates as $date) {
+ foreach ($this->visitTimes as $time) {
+ for ($visitor = 0; $visitor != 50; ++$visitor) {
+ $this->t->setIp('157.5.6.' . ($visitor + 1));
+ $this->t->setForceVisitDateTime($date . ' ' . $time);
+ for ($action = 0; $action != 2; ++$action) {
+ $realIdx = $urlIdx % count($this->urls);
+
+ $this->t->setUrl($this->urls[$realIdx]);
+ $this->t->doTrackPageView($this->pageTitles[$realIdx]);
+
+ ++$urlIdx;
+ }
+ }
+ }
+ }
+ }
+
+ /**
* @group Benchmarks
* @group TrackerBenchmark
- */
- public function testTracker()
- {
- self::checkResponse($this->t->doBulkTrack());
- }
+ */
+ public function testTracker()
+ {
+ self::checkResponse($this->t->doBulkTrack());
+ }
}
diff --git a/tests/PHPUnit/Core/API/ResponseBuilderTest.php b/tests/PHPUnit/Core/API/ResponseBuilderTest.php
index 323e727415..01c67f56df 100644
--- a/tests/PHPUnit/Core/API/ResponseBuilderTest.php
+++ b/tests/PHPUnit/Core/API/ResponseBuilderTest.php
@@ -16,15 +16,15 @@ class API_ResponseBuilderTest extends PHPUnit_Framework_TestCase
*/
public function testConvertMultiDimensionalStandardArrayToJson()
{
- $input = array( "firstElement",
- array(
- "firstElement",
- "secondElement",
- ),
- "thirdElement");
+ $input = array("firstElement",
+ array(
+ "firstElement",
+ "secondElement",
+ ),
+ "thirdElement");
$expected = json_encode($input);
- $actual = Piwik_API_ResponseBuilder::convertMultiDimensionalArrayToJson($input);
+ $actual = Piwik_API_ResponseBuilder::convertMultiDimensionalArrayToJson($input);
$this->assertEquals($expected, $actual);
}
@@ -38,15 +38,15 @@ class API_ResponseBuilderTest extends PHPUnit_Framework_TestCase
public function testConvertMultiDimensionalAssociativeArrayToJson()
{
$input = array(
- "firstElement" => "isFirst",
- "secondElement" => array(
- "firstElement" => "isFirst",
- "secondElement" => "isSecond",
- ),
- "thirdElement" => "isThird");
+ "firstElement" => "isFirst",
+ "secondElement" => array(
+ "firstElement" => "isFirst",
+ "secondElement" => "isSecond",
+ ),
+ "thirdElement" => "isThird");
$expected = json_encode($input);
- $actual = Piwik_API_ResponseBuilder::convertMultiDimensionalArrayToJson($input);
+ $actual = Piwik_API_ResponseBuilder::convertMultiDimensionalArrayToJson($input);
$this->assertEquals($expected, $actual);
}
@@ -60,19 +60,19 @@ class API_ResponseBuilderTest extends PHPUnit_Framework_TestCase
public function testConvertMultiDimensionalMixedArrayToJson()
{
$input = array(
- "firstElement" => "isFirst",
- array(
- "firstElement",
- "secondElement",
- ),
- "thirdElement" => array(
- "firstElement" => "isFirst",
- "secondElement" => "isSecond",
- )
+ "firstElement" => "isFirst",
+ array(
+ "firstElement",
+ "secondElement",
+ ),
+ "thirdElement" => array(
+ "firstElement" => "isFirst",
+ "secondElement" => "isSecond",
+ )
);
$expected = json_encode($input);
- $actual = Piwik_API_ResponseBuilder::convertMultiDimensionalArrayToJson($input);
+ $actual = Piwik_API_ResponseBuilder::convertMultiDimensionalArrayToJson($input);
$this->assertEquals($expected, $actual);
}
}
diff --git a/tests/PHPUnit/Core/AccessTest.php b/tests/PHPUnit/Core/AccessTest.php
index f050f3f9d9..5fe6d21580 100644
--- a/tests/PHPUnit/Core/AccessTest.php
+++ b/tests/PHPUnit/Core/AccessTest.php
@@ -14,7 +14,7 @@ class AccessTest extends DatabaseTestCase
public function testGetListAccess()
{
$accessList = Piwik_Access::getListAccess();
- $shouldBe = array('noaccess', 'view', 'admin', 'superuser');
+ $shouldBe = array('noaccess', 'view', 'admin', 'superuser');
$this->assertEquals($shouldBe, $accessList);
}
@@ -157,11 +157,11 @@ class AccessTest extends DatabaseTestCase
$mock = $this->getMock(
'Piwik_Access',
array('getSitesIdWithAdminAccess')
- );
+ );
$mock->expects($this->once())
- ->method('getSitesIdWithAdminAccess')
- ->will($this->returnValue(array(2, 9)));
+ ->method('getSitesIdWithAdminAccess')
+ ->will($this->returnValue(array(2, 9)));
$mock->checkUserHasSomeAdminAccess();
}
@@ -198,11 +198,11 @@ class AccessTest extends DatabaseTestCase
$mock = $this->getMock(
'Piwik_Access',
array('getSitesIdWithAtLeastViewAccess')
- );
+ );
$mock->expects($this->once())
- ->method('getSitesIdWithAtLeastViewAccess')
- ->will($this->returnValue(array(1, 2, 3, 4)));
+ ->method('getSitesIdWithAtLeastViewAccess')
+ ->will($this->returnValue(array(1, 2, 3, 4)));
$mock->checkUserHasSomeViewAccess();
}
@@ -239,11 +239,11 @@ class AccessTest extends DatabaseTestCase
$mock = $this->getMock(
'Piwik_Access',
array('getSitesIdWithAtLeastViewAccess')
- );
+ );
$mock->expects($this->once())
- ->method('getSitesIdWithAtLeastViewAccess')
- ->will($this->returnValue(array(1, 2, 3, 4)));
+ ->method('getSitesIdWithAtLeastViewAccess')
+ ->will($this->returnValue(array(1, 2, 3, 4)));
$mock->checkUserHasViewAccess('1,3');
}
@@ -257,11 +257,11 @@ class AccessTest extends DatabaseTestCase
$mock = $this->getMock(
'Piwik_Access',
array('getSitesIdWithAtLeastViewAccess')
- );
+ );
$mock->expects($this->any())
- ->method('getSitesIdWithAtLeastViewAccess')
- ->will($this->returnValue(array(1, 2, 3, 4)));
+ ->method('getSitesIdWithAtLeastViewAccess')
+ ->will($this->returnValue(array(1, 2, 3, 4)));
$mock->checkUserHasViewAccess('all');
}
@@ -276,11 +276,11 @@ class AccessTest extends DatabaseTestCase
$mock = $this->getMock(
'Piwik_Access',
array('getSitesIdWithAtLeastViewAccess')
- );
+ );
$mock->expects($this->once())
- ->method('getSitesIdWithAtLeastViewAccess')
- ->will($this->returnValue(array(1, 2, 3, 4)));
+ ->method('getSitesIdWithAtLeastViewAccess')
+ ->will($this->returnValue(array(1, 2, 3, 4)));
$mock->checkUserHasViewAccess(array(1, 5));
}
@@ -317,11 +317,11 @@ class AccessTest extends DatabaseTestCase
$mock = $this->getMock(
'Piwik_Access',
array('getSitesIdWithAdminAccess')
- );
+ );
$mock->expects($this->once())
- ->method('getSitesIdWithAdminAccess')
- ->will($this->returnValue(array(1, 2, 3, 4)));
+ ->method('getSitesIdWithAdminAccess')
+ ->will($this->returnValue(array(1, 2, 3, 4)));
$mock->checkUserHasAdminAccess('1,3');
}
@@ -335,15 +335,15 @@ class AccessTest extends DatabaseTestCase
$mock = $this->getMock(
'Piwik_Access',
array('getSitesIdWithAdminAccess', 'getSitesIdWithAtLeastViewAccess')
- );
+ );
$mock->expects($this->any())
- ->method('getSitesIdWithAdminAccess')
- ->will($this->returnValue(array(1, 2, 3, 4)));
+ ->method('getSitesIdWithAdminAccess')
+ ->will($this->returnValue(array(1, 2, 3, 4)));
$mock->expects($this->any())
- ->method('getSitesIdWithAtLeastViewAccess')
- ->will($this->returnValue(array(1, 2, 3, 4)));
+ ->method('getSitesIdWithAtLeastViewAccess')
+ ->will($this->returnValue(array(1, 2, 3, 4)));
$mock->checkUserHasAdminAccess('all');
}
@@ -358,11 +358,11 @@ class AccessTest extends DatabaseTestCase
$mock = $this->getMock(
'Piwik_Access',
array('getSitesIdWithAdminAccess')
- );
+ );
$mock->expects($this->once())
- ->method('getSitesIdWithAdminAccess')
- ->will($this->returnValue(array(1, 2, 3, 4)));
+ ->method('getSitesIdWithAdminAccess')
+ ->will($this->returnValue(array(1, 2, 3, 4)));
$mock->checkUserHasAdminAccess(array(1, 5));
}
@@ -397,8 +397,8 @@ class AccessTest extends DatabaseTestCase
{
$mock = $this->getMock('Piwik_Login_Auth', array('authenticate'));
$mock->expects($this->once())
- ->method('authenticate')
- ->will($this->returnValue(new Piwik_Auth_Result(Piwik_Auth_Result::SUCCESS, 'login', 'token' )));
+ ->method('authenticate')
+ ->will($this->returnValue(new Piwik_Auth_Result(Piwik_Auth_Result::SUCCESS, 'login', 'token')));
$access = new Piwik_Access();
Zend_Registry::set('access', $access);
@@ -414,8 +414,8 @@ class AccessTest extends DatabaseTestCase
{
$mock = $this->getMock('Piwik_Login_Auth', array('authenticate'));
$mock->expects($this->once())
- ->method('authenticate')
- ->will($this->returnValue(new Piwik_Auth_Result(Piwik_Auth_Result::SUCCESS_SUPERUSER_AUTH_CODE, 'superuser', 'superusertoken' )));
+ ->method('authenticate')
+ ->will($this->returnValue(new Piwik_Auth_Result(Piwik_Auth_Result::SUCCESS_SUPERUSER_AUTH_CODE, 'superuser', 'superusertoken')));
$access = new Piwik_Access();
Zend_Registry::set('access', $access);
@@ -431,8 +431,8 @@ class AccessTest extends DatabaseTestCase
{
$mock = $this->getMock('Piwik_Login_Auth', array('authenticate'));
$mock->expects($this->once())
- ->method('authenticate')
- ->will($this->returnValue(new Piwik_Auth_Result(Piwik_Auth_Result::FAILURE_CREDENTIAL_INVALID, null, null )));
+ ->method('authenticate')
+ ->will($this->returnValue(new Piwik_Auth_Result(Piwik_Auth_Result::FAILURE_CREDENTIAL_INVALID, null, null)));
$access = new Piwik_Access();
Zend_Registry::set('access', $access);
diff --git a/tests/PHPUnit/Core/ArchiveProcessing/DayTest.php b/tests/PHPUnit/Core/ArchiveProcessing/DayTest.php
index e466f2a1e0..369b0ef2a3 100644
--- a/tests/PHPUnit/Core/ArchiveProcessing/DayTest.php
+++ b/tests/PHPUnit/Core/ArchiveProcessing/DayTest.php
@@ -14,21 +14,21 @@ class ArchiveProcessing_DayTest extends PHPUnit_Framework_TestCase
*/
public function testGenerateDataTableSimple()
{
- $row1 = new Piwik_DataTable_Row( array( Piwik_DataTable_Row::COLUMNS =>
- array('label' => 'page1', 'visits' => 1, 'actions' => 2, '666' => 'evil' )));
-
+ $row1 = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS =>
+ array('label' => 'page1', 'visits' => 1, 'actions' => 2, '666' => 'evil')));
+
$input = array(
'page1' => $row1,
);
-
+
$table = new Piwik_DataTable;
$table->addRow($row1);
-
+
$tableGenerated = Piwik_ArchiveProcessing_Day::generateDataTable($input);
- $this->assertTrue(Piwik_DataTable::isEqual($table,$tableGenerated));
+ $this->assertTrue(Piwik_DataTable::isEqual($table, $tableGenerated));
}
-
+
/**
* @group Core
* @group ArchiveProcessing
@@ -36,25 +36,25 @@ class ArchiveProcessing_DayTest extends PHPUnit_Framework_TestCase
*/
public function testGenerateDataTable2rows()
{
- $row1 = new Piwik_DataTable_Row( array( Piwik_DataTable_Row::COLUMNS =>
- array('label' => 'page1', 'visits' => 1, 'actions' => 2)));
- $row2 = new Piwik_DataTable_Row( array( Piwik_DataTable_Row::COLUMNS =>
- array('label' => 'page2', 'visits' => 3, 'actions' => 5)));
-
+ $row1 = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS =>
+ array('label' => 'page1', 'visits' => 1, 'actions' => 2)));
+ $row2 = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS =>
+ array('label' => 'page2', 'visits' => 3, 'actions' => 5)));
+
$input = array(
'page1' => $row1,
'page2' => $row2,
);
-
+
$table = new Piwik_DataTable;
$table->addRow($row1);
$table->addRow($row2);
-
+
$tableGenerated = Piwik_ArchiveProcessing_Day::generateDataTable($input);
-
- $this->assertTrue(Piwik_DataTable::isEqual($table,$tableGenerated));
+
+ $this->assertTrue(Piwik_DataTable::isEqual($table, $tableGenerated));
}
-
+
/**
* @group Core
* @group ArchiveProcessing
@@ -62,34 +62,34 @@ class ArchiveProcessing_DayTest extends PHPUnit_Framework_TestCase
*/
public function testGenerateDataTable1row2level()
{
- $row1 = new Piwik_DataTable_Row( array( Piwik_DataTable_Row::COLUMNS =>
- array('label' => 'cat1', 'visits' => 3, 'actions' => 5 )));
-
- $rowLevel2 = new Piwik_DataTable_Row( array( Piwik_DataTable_Row::COLUMNS =>
- array('label' => 'page1', 'visits' => 3, 'actions' => 5)));
+ $row1 = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS =>
+ array('label' => 'cat1', 'visits' => 3, 'actions' => 5)));
+
+ $rowLevel2 = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS =>
+ array('label' => 'page1', 'visits' => 3, 'actions' => 5)));
$subtable = new Piwik_DataTable;
$subtable->addRow($rowLevel2);
$row1->addSubtable($subtable);
-
+
$table = new Piwik_DataTable;
$table->addRow($row1);
-
+
$input = array(
'cat1' => array(
'page1' => $rowLevel2,
)
);
-
+
$tableGenerated = Piwik_ArchiveProcessing_Day::generateDataTable($input);
-
+
$r1 = new Piwik_DataTable_Renderer_Console();
$r1->setTable($table);
$r2 = new Piwik_DataTable_Renderer_Console();
$r2->setTable($tableGenerated);
-
- $this->assertTrue(Piwik_DataTable::isEqual($table,$tableGenerated));
+
+ $this->assertTrue(Piwik_DataTable::isEqual($table, $tableGenerated));
}
-
+
/**
* @group Core
* @group ArchiveProcessing
@@ -98,57 +98,57 @@ class ArchiveProcessing_DayTest extends PHPUnit_Framework_TestCase
public function testGenerateDataTable2rows2level()
{
$table = new Piwik_DataTable;
-
+
//FIRST ROW + SUBTABLE
- $row1 = new Piwik_DataTable_Row( array( Piwik_DataTable_Row::COLUMNS =>
- array( 'label' => 'cat1', 'visits' => 3, 'actions' => 5 )));
-
- $rowLevel2a = new Piwik_DataTable_Row( array( Piwik_DataTable_Row::COLUMNS =>
- array( 'label' => 'page1', 'visits' => 3, 'actions' => 5)));
+ $row1 = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS =>
+ array('label' => 'cat1', 'visits' => 3, 'actions' => 5)));
+
+ $rowLevel2a = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS =>
+ array('label' => 'page1', 'visits' => 3, 'actions' => 5)));
$subtable = new Piwik_DataTable;
$subtable->addRow($rowLevel2a);
$row1->addSubtable($subtable);
-
+
//-- add
$table->addRow($row1);
-
+
//SECOND ROW + SUBTABLE MULTI ROWS
- $row1 = new Piwik_DataTable_Row( array( Piwik_DataTable_Row::COLUMNS =>
- array('label' => 'cat2', 'visits' => 13, 'actions' => 9 )));
-
- $rowLevel2b1 = new Piwik_DataTable_Row( array( Piwik_DataTable_Row::COLUMNS =>
- array('label' => 'page2a', 'visits' => 6, 'actions' => 8)));
-
- $rowLevel2b2 = new Piwik_DataTable_Row( array( Piwik_DataTable_Row::COLUMNS =>
- array('label' => 'page2b', 'visits' => 7, 'actions' => 1)));
+ $row1 = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS =>
+ array('label' => 'cat2', 'visits' => 13, 'actions' => 9)));
+
+ $rowLevel2b1 = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS =>
+ array('label' => 'page2a', 'visits' => 6, 'actions' => 8)));
+
+ $rowLevel2b2 = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS =>
+ array('label' => 'page2b', 'visits' => 7, 'actions' => 1)));
$subtable = new Piwik_DataTable;
$subtable->addRow($rowLevel2b1);
$subtable->addRow($rowLevel2b2);
$row1->addSubtable($subtable);
-
+
//-- add
$table->addRow($row1);
-
+
// WHAT WE TEST
$input = array(
- 'cat1' => array(
+ 'cat1' => array(
'page1' => $rowLevel2a,
- ),
- 'cat2' => array(
+ ),
+ 'cat2' => array(
'page2a' => $rowLevel2b1,
'page2b' => $rowLevel2b2,
- )
- );
+ )
+ );
$tableGenerated = Piwik_ArchiveProcessing_Day::generateDataTable($input);
-
+
$r1 = new Piwik_DataTable_Renderer_Console();
$r1->setTable($table);
$r2 = new Piwik_DataTable_Renderer_Console();
$r2->setTable($tableGenerated);
-
- $this->assertTrue(Piwik_DataTable::isEqual($table,$tableGenerated));
+
+ $this->assertTrue(Piwik_DataTable::isEqual($table, $tableGenerated));
}
-
+
/**
* @group Core
* @group ArchiveProcessing
@@ -157,52 +157,52 @@ class ArchiveProcessing_DayTest extends PHPUnit_Framework_TestCase
public function testGenerateDataTable1row4levelMultiRows()
{
$table = new Piwik_DataTable;
-
+
//FIRST ROW + SUBTABLE
- $rowcat2 = new Piwik_DataTable_Row( array( Piwik_DataTable_Row::COLUMNS =>
- array('label' => '456', 'visits' => 3, 'actions' => 5 )));
-
- $cat2 = new Piwik_DataTable_Row( array( Piwik_DataTable_Row::COLUMNS =>
- array('label' => 'cat2', 'visits' => 3, 'actions' => 5 )));
-
- $rowcat1 = new Piwik_DataTable_Row( array( Piwik_DataTable_Row::COLUMNS =>
- array('label' => 'pagecat1', 'visits' => 6, 'actions' => 4)));
-
- $cat1 = new Piwik_DataTable_Row( array( Piwik_DataTable_Row::COLUMNS =>
- array('label' => 'cat1', 'visits' => 9, 'actions' => 9 )));
-
+ $rowcat2 = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS =>
+ array('label' => '456', 'visits' => 3, 'actions' => 5)));
+
+ $cat2 = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS =>
+ array('label' => 'cat2', 'visits' => 3, 'actions' => 5)));
+
+ $rowcat1 = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS =>
+ array('label' => 'pagecat1', 'visits' => 6, 'actions' => 4)));
+
+ $cat1 = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS =>
+ array('label' => 'cat1', 'visits' => 9, 'actions' => 9)));
+
$subtablecat2 = new Piwik_DataTable;
$subtablecat2->addRow($rowcat2);
$cat2->addSubtable($subtablecat2);
-
+
$subtablecat1 = new Piwik_DataTable;
$subtablecat1->addRow($rowcat1);
$subtablecat1->addRow($cat2);
-
+
$cat1->addSubtable($subtablecat1);
-
+
//-- add
$table->addRow($cat1);
-
+
// WHAT WE TEST
$input = array(
'cat1' => array(
'pagecat1' => $rowcat1,
- 'cat2' => array(
+ 'cat2' => array(
'pagecat2' => $rowcat2,
),
),
- );
+ );
$tableGenerated = Piwik_ArchiveProcessing_Day::generateDataTable($input);
-
+
$r1 = new Piwik_DataTable_Renderer_Console();
$r1->setTable($table);
$r2 = new Piwik_DataTable_Renderer_Console();
$r2->setTable($tableGenerated);
-
- $this->assertTrue(Piwik_DataTable::isEqual($table,$tableGenerated));
+
+ $this->assertTrue(Piwik_DataTable::isEqual($table, $tableGenerated));
}
-
+
/**
* @group Core
* @group ArchiveProcessing
@@ -211,33 +211,33 @@ class ArchiveProcessing_DayTest extends PHPUnit_Framework_TestCase
public function testGenerateDataTable1row4level()
{
$table = new Piwik_DataTable;
-
- $rowpagecat3 = new Piwik_DataTable_Row( array( Piwik_DataTable_Row::COLUMNS =>
- array('label' => '123123', 'visits' => 3, 'actions' => 5 )));
-
- $rowcat3 = new Piwik_DataTable_Row( array( Piwik_DataTable_Row::COLUMNS =>
- array('label' => '789.654', 'visits' => 3, 'actions' => 5 )));
- $rowcat2 = new Piwik_DataTable_Row( array( Piwik_DataTable_Row::COLUMNS =>
- array('label' => 'cat2', 'visits' => 3, 'actions' => 5 )));
- $rowcat1 = new Piwik_DataTable_Row( array( Piwik_DataTable_Row::COLUMNS =>
- array('label' => '&*()', 'visits' => 3, 'actions' => 5 )));
+
+ $rowpagecat3 = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS =>
+ array('label' => '123123', 'visits' => 3, 'actions' => 5)));
+
+ $rowcat3 = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS =>
+ array('label' => '789.654', 'visits' => 3, 'actions' => 5)));
+ $rowcat2 = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS =>
+ array('label' => 'cat2', 'visits' => 3, 'actions' => 5)));
+ $rowcat1 = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS =>
+ array('label' => '&*()', 'visits' => 3, 'actions' => 5)));
$subtablerowpagecat3 = new Piwik_DataTable;
$subtablerowpagecat3->addRow($rowpagecat3);
$rowcat3->addSubtable($subtablerowpagecat3);
-
+
$subtablecat2 = new Piwik_DataTable;
$subtablecat2->addRow($rowcat3);
$rowcat2->addSubtable($subtablecat2);
-
-
+
+
$subtablecat1 = new Piwik_DataTable;
$subtablecat1->addRow($rowcat2);
$rowcat1->addSubtable($subtablecat1);
-
+
//-- add
$table->addRow($rowcat1);
-
+
// WHAT WE TEST
$input = array(
'&*()' => array(
@@ -248,13 +248,13 @@ class ArchiveProcessing_DayTest extends PHPUnit_Framework_TestCase
),
),
);
-
+
$tableGenerated = Piwik_ArchiveProcessing_Day::generateDataTable($input);
-
+
$r1 = new Piwik_DataTable_Renderer_Console();
$r1->setTable($table);
$r2 = new Piwik_DataTable_Renderer_Console();
$r2->setTable($tableGenerated);
- $this->assertTrue(Piwik_DataTable::isEqual($table,$tableGenerated));
+ $this->assertTrue(Piwik_DataTable::isEqual($table, $tableGenerated));
}
}
diff --git a/tests/PHPUnit/Core/ArchiveProcessingTest.php b/tests/PHPUnit/Core/ArchiveProcessingTest.php
index 07686d3366..530bcf545e 100644
--- a/tests/PHPUnit/Core/ArchiveProcessingTest.php
+++ b/tests/PHPUnit/Core/ArchiveProcessingTest.php
@@ -19,28 +19,28 @@ class ArchiveProcessingTest extends DatabaseTestCase
/**
* Creates a new website
- *
+ *
* @param string $timezone
* @return Piwik_Site
*/
private function _createWebsite($timezone = 'UTC')
{
$idSite = Piwik_SitesManager_API::getInstance()->addSite(
- "site1",
- array("http://piwik.net"),
- $ecommerce=0,
- $siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null,
- $excludedIps = "",
- $excludedQueryParameters = "",
- $timezone);
-
+ "site1",
+ array("http://piwik.net"),
+ $ecommerce = 0,
+ $siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null,
+ $excludedIps = "",
+ $excludedQueryParameters = "",
+ $timezone);
+
Piwik_Site::clearCache();
return new Piwik_Site($idSite);
}
/**
* Creates a new ArchiveProcessing object
- *
+ *
* @param string $periodLabel
* @param string $dateLabel
* @param string $siteTimezone
@@ -51,7 +51,7 @@ class ArchiveProcessingTest extends DatabaseTestCase
$site = $this->_createWebsite($siteTimezone);
$date = Piwik_Date::factory($dateLabel);
$period = Piwik_Period::factory($periodLabel, $date);
-
+
$archiveProcessing = Piwik_ArchiveProcessing::factory($periodLabel);
$archiveProcessing->setSite($site);
$archiveProcessing->setPeriod($period);
@@ -69,11 +69,11 @@ class ArchiveProcessingTest extends DatabaseTestCase
{
$siteTimezone = 'UTC+10';
$now = time();
-
+
$dateLabel = date('Y-m-d', $now);
$archiveProcessing = $this->_createArchiveProcessing('month', $dateLabel, $siteTimezone);
$archiveProcessing->time = $now;
-
+
// min finished timestamp considered when looking at archive timestamp
$timeout = Piwik_ArchiveProcessing::getTodayArchiveTimeToLive();
$this->assertTrue($timeout >= 10);
@@ -83,7 +83,7 @@ class ArchiveProcessingTest extends DatabaseTestCase
$this->assertEquals($minTimestamp, $dateMinArchived, Piwik_Date::factory($minTimestamp)->getDatetime() . " != " . Piwik_Date::factory($dateMinArchived)->getDatetime());
$this->assertTrue($archiveProcessing->isArchiveTemporary());
}
-
+
/**
* test of validity of an archive, for a month in the past
* @group Core
@@ -92,11 +92,11 @@ class ArchiveProcessingTest extends DatabaseTestCase
public function testInitDayInPast()
{
$archiveProcessing = $this->_createArchiveProcessing('day', '2010-01-01', 'UTC');
-
+
// min finished timestamp considered when looking at archive timestamp
$dateMinArchived = Piwik_Date::factory('2010-01-02')->getTimestamp();
$this->assertEquals($archiveProcessing->getMinTimeArchivedProcessed() + 1, $dateMinArchived);
-
+
$this->assertEquals('2010-01-01 00:00:00', $archiveProcessing->getStartDatetimeUTC());
$this->assertEquals('2010-01-01 23:59:59', $archiveProcessing->getEndDatetimeUTC());
$this->assertFalse($archiveProcessing->isArchiveTemporary());
@@ -114,7 +114,7 @@ class ArchiveProcessingTest extends DatabaseTestCase
// min finished timestamp considered when looking at archive timestamp
$dateMinArchived = Piwik_Date::factory('2010-01-01 18:30:00');
$this->assertEquals($archiveProcessing->getMinTimeArchivedProcessed() + 1, $dateMinArchived->getTimestamp());
-
+
$this->assertEquals('2009-12-31 18:30:00', $archiveProcessing->getStartDatetimeUTC());
$this->assertEquals('2010-01-01 18:29:59', $archiveProcessing->getEndDatetimeUTC());
$this->assertFalse($archiveProcessing->isArchiveTemporary());
@@ -132,12 +132,12 @@ class ArchiveProcessingTest extends DatabaseTestCase
// min finished timestamp considered when looking at archive timestamp
$dateMinArchived = Piwik_Date::factory('2010-02-01 05:30:00');
$this->assertEquals($archiveProcessing->getMinTimeArchivedProcessed() + 1, $dateMinArchived->getTimestamp());
-
+
$this->assertEquals('2010-01-01 05:30:00', $archiveProcessing->getStartDatetimeUTC());
$this->assertEquals('2010-02-01 05:29:59', $archiveProcessing->getEndDatetimeUTC());
$this->assertFalse($archiveProcessing->isArchiveTemporary());
}
-
+
/**
* test of validity of an archive, for today's archive
* @group Core
@@ -151,10 +151,10 @@ class ArchiveProcessingTest extends DatabaseTestCase
$dateLabel = date('Y-m-d', $timestamp);
Piwik_ArchiveProcessing::setBrowserTriggerArchiving(true);
-
+
$archiveProcessing = $this->_createArchiveProcessing('day', $dateLabel, $siteTimezone);
$archiveProcessing->time = $now;
-
+
// we look at anything processed within the time to live range
$dateMinArchived = $now - Piwik_ArchiveProcessing::getTodayArchiveTimeToLive();
$this->assertEquals($dateMinArchived, $archiveProcessing->getMinTimeArchivedProcessed());
@@ -166,14 +166,13 @@ class ArchiveProcessingTest extends DatabaseTestCase
// see isArchivingDisabled()
// Running in CLI doesn't impact the time to live today's archive we are loading
// From CLI, we will not return data that is 'stale'
- if(!Piwik_Common::isPhpCliMode())
- {
+ if (!Piwik_Common::isPhpCliMode()) {
$dateMinArchived = 0;
}
$this->assertEquals($archiveProcessing->getMinTimeArchivedProcessed(), $dateMinArchived);
-
- $this->assertEquals(date('Y-m-d', $timestamp).' 01:00:00', $archiveProcessing->getStartDatetimeUTC());
- $this->assertEquals(date('Y-m-d', $timestamp+86400).' 00:59:59', $archiveProcessing->getEndDatetimeUTC());
+
+ $this->assertEquals(date('Y-m-d', $timestamp) . ' 01:00:00', $archiveProcessing->getStartDatetimeUTC());
+ $this->assertEquals(date('Y-m-d', $timestamp + 86400) . ' 00:59:59', $archiveProcessing->getEndDatetimeUTC());
$this->assertTrue($archiveProcessing->isArchiveTemporary());
}
@@ -184,8 +183,7 @@ class ArchiveProcessingTest extends DatabaseTestCase
*/
public function testInitTodayEurope()
{
- if(!Piwik::isTimezoneSupportEnabled())
- {
+ if (!Piwik::isTimezoneSupportEnabled()) {
$this->markTestSkipped('timezones needs to be supported');
}
@@ -210,17 +208,16 @@ class ArchiveProcessingTest extends DatabaseTestCase
// see isArchivingDisabled()
// Running in CLI doesn't impact the time to live today's archive we are loading
// From CLI, we will not return data that is 'stale'
- if(!Piwik_Common::isPhpCliMode())
- {
+ if (!Piwik_Common::isPhpCliMode()) {
$dateMinArchived = 0;
}
$this->assertEquals($archiveProcessing->getMinTimeArchivedProcessed(), $dateMinArchived);
// this test varies with DST
- $this->assertTrue($archiveProcessing->getStartDatetimeUTC() == date('Y-m-d', $timestamp-86400).' 22:00:00' ||
- $archiveProcessing->getStartDatetimeUTC() == date('Y-m-d', $timestamp-86400).' 23:00:00');
- $this->assertTrue($archiveProcessing->getEndDatetimeUTC() == date('Y-m-d', $timestamp).' 21:59:59' ||
- $archiveProcessing->getEndDatetimeUTC() == date('Y-m-d', $timestamp).' 22:59:59');
+ $this->assertTrue($archiveProcessing->getStartDatetimeUTC() == date('Y-m-d', $timestamp - 86400) . ' 22:00:00' ||
+ $archiveProcessing->getStartDatetimeUTC() == date('Y-m-d', $timestamp - 86400) . ' 23:00:00');
+ $this->assertTrue($archiveProcessing->getEndDatetimeUTC() == date('Y-m-d', $timestamp) . ' 21:59:59' ||
+ $archiveProcessing->getEndDatetimeUTC() == date('Y-m-d', $timestamp) . ' 22:59:59');
$this->assertTrue($archiveProcessing->isArchiveTemporary());
}
@@ -232,8 +229,7 @@ class ArchiveProcessingTest extends DatabaseTestCase
*/
public function testInitTodayToronto()
{
- if(!Piwik::isTimezoneSupportEnabled())
- {
+ if (!Piwik::isTimezoneSupportEnabled()) {
$this->markTestSkipped('timezones needs to be supported');
}
@@ -258,17 +254,16 @@ class ArchiveProcessingTest extends DatabaseTestCase
// see isArchivingDisabled()
// Running in CLI doesn't impact the time to live today's archive we are loading
// From CLI, we will not return data that is 'stale'
- if(!Piwik_Common::isPhpCliMode())
- {
+ if (!Piwik_Common::isPhpCliMode()) {
$dateMinArchived = 0;
}
$this->assertEquals($archiveProcessing->getMinTimeArchivedProcessed(), $dateMinArchived);
// this test varies with DST
- $this->assertTrue($archiveProcessing->getStartDatetimeUTC() == date('Y-m-d', $timestamp).' 04:00:00' ||
- $archiveProcessing->getStartDatetimeUTC() == date('Y-m-d', $timestamp).' 05:00:00');
- $this->assertTrue($archiveProcessing->getEndDatetimeUTC() == date('Y-m-d', $timestamp+86400).' 03:59:59' ||
- $archiveProcessing->getEndDatetimeUTC() == date('Y-m-d', $timestamp+86400).' 04:59:59');
+ $this->assertTrue($archiveProcessing->getStartDatetimeUTC() == date('Y-m-d', $timestamp) . ' 04:00:00' ||
+ $archiveProcessing->getStartDatetimeUTC() == date('Y-m-d', $timestamp) . ' 05:00:00');
+ $this->assertTrue($archiveProcessing->getEndDatetimeUTC() == date('Y-m-d', $timestamp + 86400) . ' 03:59:59' ||
+ $archiveProcessing->getEndDatetimeUTC() == date('Y-m-d', $timestamp + 86400) . ' 04:59:59');
$this->assertTrue($archiveProcessing->isArchiveTemporary());
}
@@ -283,50 +278,49 @@ class ArchiveProcessingTest extends DatabaseTestCase
$table = Piwik_Common::prefixTable('site_url');
$data = $this->_getDataInsert();
try {
- $didWeUseBulk = Piwik::tableInsertBatch($table,
- array('idsite', 'url'),
- $data,
- $throwException = true);
-
- } catch(Exception $e) {
- $didWeUseBulk = $e->getMessage();
- }
- $this->_checkLoadDataInFileWasUsed($didWeUseBulk);
-
- if($didWeUseBulk === true) {
- $this->_checkTableIsExpected($table, $data);
-
- // INSERT again the bulk. Because we use keyword LOCAL the data will be REPLACED automatically (see mysql doc)
- Piwik::tableInsertBatch($table, array('idsite', 'url'), $data);
- $this->_checkTableIsExpected($table, $data);
- }
+ $didWeUseBulk = Piwik::tableInsertBatch($table,
+ array('idsite', 'url'),
+ $data,
+ $throwException = true);
+
+ } catch (Exception $e) {
+ $didWeUseBulk = $e->getMessage();
+ }
+ $this->_checkLoadDataInFileWasUsed($didWeUseBulk);
+
+ if ($didWeUseBulk === true) {
+ $this->_checkTableIsExpected($table, $data);
+
+ // INSERT again the bulk. Because we use keyword LOCAL the data will be REPLACED automatically (see mysql doc)
+ Piwik::tableInsertBatch($table, array('idsite', 'url'), $data);
+ $this->_checkTableIsExpected($table, $data);
+ }
}
- protected function _checkLoadDataInFileWasUsed($didWeUseBulk)
- {
- static $skippedOnce = false;
- if($didWeUseBulk !== true
- && $skippedOnce === false
- // HACK: Only alert for MysqlI since PDO is often failing and Jenkins should always run MYSQLI + PDO
- // This helps "hiding" the warning on PDO Mysql but we have to make sure mysqli tests are always executed!
- && Piwik_Config::getInstance()->database['adapter'] == 'MYSQLI'
- )
- {
- $skippedOnce = true;
- $this->fail(
- 'Performance notice: LOAD DATA [LOCAL] INFILE query is not working, so Piwik will fallback to using plain INSERTs '
- . ' which will result in a slightly slower Archiving process.'
- . ". \n"
- . ' The error Messages from MySQL were: '
- . $didWeUseBulk
- . "\n\n Learn more how to enable LOAD LOCAL DATA INFILE see the Mysql doc (http://dev.mysql.com/doc/refman/5.0/en/load-data-local.html) "
- . "\n or ask in this Piwik ticket (http://dev.piwik.org/trac/ticket/3605)"
- );
- }
- return $didWeUseBulk;
- }
-
- /**
+ protected function _checkLoadDataInFileWasUsed($didWeUseBulk)
+ {
+ static $skippedOnce = false;
+ if ($didWeUseBulk !== true
+ && $skippedOnce === false
+ // HACK: Only alert for MysqlI since PDO is often failing and Jenkins should always run MYSQLI + PDO
+ // This helps "hiding" the warning on PDO Mysql but we have to make sure mysqli tests are always executed!
+ && Piwik_Config::getInstance()->database['adapter'] == 'MYSQLI'
+ ) {
+ $skippedOnce = true;
+ $this->fail(
+ 'Performance notice: LOAD DATA [LOCAL] INFILE query is not working, so Piwik will fallback to using plain INSERTs '
+ . ' which will result in a slightly slower Archiving process.'
+ . ". \n"
+ . ' The error Messages from MySQL were: '
+ . $didWeUseBulk
+ . "\n\n Learn more how to enable LOAD LOCAL DATA INFILE see the Mysql doc (http://dev.mysql.com/doc/refman/5.0/en/load-data-local.html) "
+ . "\n or ask in this Piwik ticket (http://dev.piwik.org/trac/ticket/3605)"
+ );
+ }
+ return $didWeUseBulk;
+ }
+
+ /**
* Testing plain inserts
* @group Core
* @group ArchiveProcessing
@@ -340,16 +334,16 @@ class ArchiveProcessingTest extends DatabaseTestCase
// If we insert AGAIN, expect to throw an error because the primary key already exists
try {
- Piwik::tableInsertBatchIterate($table, array('idsite', 'url'), $data, $ignoreWhenDuplicate = false);
+ Piwik::tableInsertBatchIterate($table, array('idsite', 'url'), $data, $ignoreWhenDuplicate = false);
} catch (Exception $e) {
// However if we insert with keyword REPLACE, then the new data should be saved
- Piwik::tableInsertBatchIterate($table, array('idsite', 'url'), $data, $ignoreWhenDuplicate = true );
+ Piwik::tableInsertBatchIterate($table, array('idsite', 'url'), $data, $ignoreWhenDuplicate = true);
$this->_checkTableIsExpected($table, $data);
return;
}
$this->fail('Exception expected');
}
-
+
/**
* Testing batch insert (BLOB)
* @group Core
@@ -364,27 +358,25 @@ class ArchiveProcessingTest extends DatabaseTestCase
$table = $archiveProcessing->getTableArchiveBlobName();
$data = $this->_getBlobDataInsert();
- try {
- $didWeUseBulk = Piwik::tableInsertBatch($table,
- array('idarchive', 'name', 'idsite', 'date1', 'date2', 'period', 'ts_archived', 'value'),
- $data,
- $throwException = true);
- } catch(Exception $e) {
- $didWeUseBulk = $e->getMessage();
- }
- $this->_checkLoadDataInFileWasUsed($didWeUseBulk);
-
- // If bulk wasn't used the exception was caught and the INSERT didn't work
- if($didWeUseBulk === true)
- {
- $this->_checkTableIsExpectedBlob($table, $data);
- }
+ try {
+ $didWeUseBulk = Piwik::tableInsertBatch($table,
+ array('idarchive', 'name', 'idsite', 'date1', 'date2', 'period', 'ts_archived', 'value'),
+ $data,
+ $throwException = true);
+ } catch (Exception $e) {
+ $didWeUseBulk = $e->getMessage();
+ }
+ $this->_checkLoadDataInFileWasUsed($didWeUseBulk);
+
+ // If bulk wasn't used the exception was caught and the INSERT didn't work
+ if ($didWeUseBulk === true) {
+ $this->_checkTableIsExpectedBlob($table, $data);
+ }
// INSERT again the bulk. Because we use keyword LOCAL the data will be REPLACED automatically (see mysql doc)
- $didWeUseBulk = Piwik::tableInsertBatch($table, array('idarchive', 'name', 'idsite', 'date1', 'date2', 'period', 'ts_archived', 'value'), $data);
- if($didWeUseBulk === true)
- {
- $this->_checkTableIsExpectedBlob($table, $data);
- }
+ $didWeUseBulk = Piwik::tableInsertBatch($table, array('idarchive', 'name', 'idsite', 'date1', 'date2', 'period', 'ts_archived', 'value'), $data);
+ if ($didWeUseBulk === true) {
+ $this->_checkTableIsExpectedBlob($table, $data);
+ }
}
/**
@@ -406,21 +398,21 @@ class ArchiveProcessingTest extends DatabaseTestCase
// If we insert AGAIN, expect to throw an error because the primary key already exist
try {
- Piwik::tableInsertBatchIterate($table, array('idarchive', 'name', 'idsite', 'date1', 'date2', 'period', 'ts_archived', 'value'), $data, $ignoreWhenDuplicate = false);
+ Piwik::tableInsertBatchIterate($table, array('idarchive', 'name', 'idsite', 'date1', 'date2', 'period', 'ts_archived', 'value'), $data, $ignoreWhenDuplicate = false);
} catch (Exception $e) {
// However if we insert with keyword REPLACE, then the new data should be saved
- Piwik::tableInsertBatchIterate($table, array('idarchive', 'name', 'idsite', 'date1', 'date2', 'period', 'ts_archived', 'value'), $data, $ignoreWhenDuplicate = true );
+ Piwik::tableInsertBatchIterate($table, array('idarchive', 'name', 'idsite', 'date1', 'date2', 'period', 'ts_archived', 'value'), $data, $ignoreWhenDuplicate = true);
$this->_checkTableIsExpectedBlob($table, $data);
return;
}
$this->fail('Exception expected');
}
-
-
+
+
protected function _checkTableIsExpected($table, $data)
{
- $fetched = Piwik_FetchAll('SELECT * FROM '.$table);
- foreach($data as $id => $row) {
+ $fetched = Piwik_FetchAll('SELECT * FROM ' . $table);
+ foreach ($data as $id => $row) {
$this->assertEquals($fetched[$id]['idsite'], $data[$id][0], "record $id is not {$data[$id][0]}");
$this->assertEquals($fetched[$id]['url'], $data[$id][1], "Record $id bug, not {$data[$id][1]} BUT {$fetched[$id]['url']}");
}
@@ -428,8 +420,8 @@ class ArchiveProcessingTest extends DatabaseTestCase
protected function _checkTableIsExpectedBlob($table, $data)
{
- $fetched = Piwik_FetchAll('SELECT * FROM '.$table);
- foreach($data as $id => $row) {
+ $fetched = Piwik_FetchAll('SELECT * FROM ' . $table);
+ foreach ($data as $id => $row) {
$this->assertEquals($fetched[$id]['idarchive'], $data[$id][0], "record $id idarchive is not '{$data[$id][0]}'");
$this->assertEquals($fetched[$id]['name'], $data[$id][1], "record $id name is not '{$data[$id][1]}'");
$this->assertEquals($fetched[$id]['idsite'], $data[$id][2], "record $id idsite is not '{$data[$id][2]}'");
@@ -480,13 +472,12 @@ class ArchiveProcessingTest extends DatabaseTestCase
{
$ts = '2011-03-31 17:48:00';
$str = '';
- for($i = 0; $i < 256; $i++)
- {
+ for ($i = 0; $i < 256; $i++) {
$str .= chr($i);
}
$array[] = array(1, 'bytes 0-255', 1, '2011-03-31', '2011-03-31', Piwik::$idPeriods['day'], $ts, $str);
- $array[] = array(2, 'compressed string', 1, '2011-03-31', '2011-03-31', Piwik::$idPeriods['day'], $ts, gzcompress( " \n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942"));
+ $array[] = array(2, 'compressed string', 1, '2011-03-31', '2011-03-31', Piwik::$idPeriods['day'], $ts, gzcompress(" \n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942\n \r \t teste eigaj oegheao geaoh guoea98742983 2 342942"));
$str = file_get_contents(PIWIK_PATH_TEST_TO_ROOT . '/tests/resources/lipsum.txt');
$array[] = array(3, 'lorem ipsum', 1, '2011-03-31', '2011-03-31', Piwik::$idPeriods['day'], $ts, $str);
diff --git a/tests/PHPUnit/Core/CommonTest.php b/tests/PHPUnit/Core/CommonTest.php
index 6a37576aee..ca117c6fae 100644
--- a/tests/PHPUnit/Core/CommonTest.php
+++ b/tests/PHPUnit/Core/CommonTest.php
@@ -33,7 +33,7 @@ class Core_CommonTest extends PHPUnit_Framework_TestCase
array('testhttp://test.com', false),
);
}
-
+
/**
* @dataProvider getUrls
* @group Core
@@ -51,76 +51,76 @@ class Core_CommonTest extends PHPUnit_Framework_TestCase
public function getInputValues()
{
return array( // input, output
- // sanitize an array OK
- array(
- array('test1' => 't1', 't45', "teatae", 4568, array('test'), 1.52),
- array('test1' => 't1', 't45', "teatae", 4568, array('test'), 1.52)
- ),
- array(
- array('test1' => 't1', 't45', "teatae", 4568, array('test'), 1.52,
- array('test1' => 't1', 't45', "teatae", 4568, array('test'), 1.52),
- array('test1' => 't1', 't45', "teatae", 4568, array('test'), 1.52),
- array( array(array(array('test1' => 't1', 't45', "teatae", 4568, array('test'), 1.52)))
- )),
- array('test1' => 't1', 't45', "teatae", 4568, array('test'), 1.52,
- array('test1' => 't1', 't45', "teatae", 4568, array('test'), 1.52),
- array('test1' => 't1', 't45', "teatae", 4568, array('test'), 1.52),
- array( array(array(array('test1' => 't1', 't45', "teatae", 4568, array('test'), 1.52)))
- ))
- ),
- // sanitize an array with bad value level1
- array(
- array('test1' => 't1', 't45', 'tea1"ta"e', 568, 1 => array('t<e"st'), 1.52),
- array('test1' => 't1', 't45', 'tea1&quot;ta&quot;e', 568, 1 => array('t&lt;e&quot;st'), 1.52)
- ),
- // sanitize an array with bad value level2
- array(
- array('tea1"ta"e' => array('t<e"st' => array('tgeag454554"t')), 1.52),
- array('tea1&quot;ta&quot;e' => array('t&lt;e&quot;st' => array('tgeag454554&quot;t')), 1.52)
- ),
- // sanitize a string unicode => no change
- array(
- " Поиск в Интернете Поgqegиск страниц на рgeqg8978усском",
- " Поиск в Интернете Поgqegиск страниц на рgeqg8978усском"
- ),
- // sanitize a bad string
- array(
- '& " < > 123abc\'',
- '&amp; &quot; &lt; &gt; 123abc&#039;'
- ),
- // test filter - expect new line and null byte to be filtered out
- array(
- "New\nLine\rNull\0Byte",
- 'NewLineNullByte'
- ),
- // double encoded - no change (document as user error)
- array(
- '%48%45%4C%00%4C%4F+%57%4F%52%4C%44',
- '%48%45%4C%00%4C%4F+%57%4F%52%4C%44'
- ),
- // sanitize an integer
- array( '121564564', '121564564' ),
- array( '121564564.0121', '121564564.0121' ),
- array( 121564564.0121, 121564564.0121 ),
- array( 12121, 12121 ),
- // sanitize HTML
- array(
- "<test toto='mama' piwik=\"cool\">Piwik!!!!!</test>",
- "&lt;test toto=&#039;mama&#039; piwik=&quot;cool&quot;&gt;Piwik!!!!!&lt;/test&gt;"
- ),
- // sanitize a SQL query
- array(
- "SELECT piwik FROM piwik_tests where test= 'super\"value' AND cool=toto #comment here",
- "SELECT piwik FROM piwik_tests where test= &#039;super&quot;value&#039; AND cool=toto #comment here"
- ),
- // sanitize php variables
- array( true, true ),
- array( false, false ),
- array( null, null ),
- array( "", "" ),
- );
+ // sanitize an array OK
+ array(
+ array('test1' => 't1', 't45', "teatae", 4568, array('test'), 1.52),
+ array('test1' => 't1', 't45', "teatae", 4568, array('test'), 1.52)
+ ),
+ array(
+ array('test1' => 't1', 't45', "teatae", 4568, array('test'), 1.52,
+ array('test1' => 't1', 't45', "teatae", 4568, array('test'), 1.52),
+ array('test1' => 't1', 't45', "teatae", 4568, array('test'), 1.52),
+ array(array(array(array('test1' => 't1', 't45', "teatae", 4568, array('test'), 1.52)))
+ )),
+ array('test1' => 't1', 't45', "teatae", 4568, array('test'), 1.52,
+ array('test1' => 't1', 't45', "teatae", 4568, array('test'), 1.52),
+ array('test1' => 't1', 't45', "teatae", 4568, array('test'), 1.52),
+ array(array(array(array('test1' => 't1', 't45', "teatae", 4568, array('test'), 1.52)))
+ ))
+ ),
+ // sanitize an array with bad value level1
+ array(
+ array('test1' => 't1', 't45', 'tea1"ta"e', 568, 1 => array('t<e"st'), 1.52),
+ array('test1' => 't1', 't45', 'tea1&quot;ta&quot;e', 568, 1 => array('t&lt;e&quot;st'), 1.52)
+ ),
+ // sanitize an array with bad value level2
+ array(
+ array('tea1"ta"e' => array('t<e"st' => array('tgeag454554"t')), 1.52),
+ array('tea1&quot;ta&quot;e' => array('t&lt;e&quot;st' => array('tgeag454554&quot;t')), 1.52)
+ ),
+ // sanitize a string unicode => no change
+ array(
+ " Поиск в Интернете Поgqegиск страниц на рgeqg8978усском",
+ " Поиск в Интернете Поgqegиск страниц на рgeqg8978усском"
+ ),
+ // sanitize a bad string
+ array(
+ '& " < > 123abc\'',
+ '&amp; &quot; &lt; &gt; 123abc&#039;'
+ ),
+ // test filter - expect new line and null byte to be filtered out
+ array(
+ "New\nLine\rNull\0Byte",
+ 'NewLineNullByte'
+ ),
+ // double encoded - no change (document as user error)
+ array(
+ '%48%45%4C%00%4C%4F+%57%4F%52%4C%44',
+ '%48%45%4C%00%4C%4F+%57%4F%52%4C%44'
+ ),
+ // sanitize an integer
+ array('121564564', '121564564'),
+ array('121564564.0121', '121564564.0121'),
+ array(121564564.0121, 121564564.0121),
+ array(12121, 12121),
+ // sanitize HTML
+ array(
+ "<test toto='mama' piwik=\"cool\">Piwik!!!!!</test>",
+ "&lt;test toto=&#039;mama&#039; piwik=&quot;cool&quot;&gt;Piwik!!!!!&lt;/test&gt;"
+ ),
+ // sanitize a SQL query
+ array(
+ "SELECT piwik FROM piwik_tests where test= 'super\"value' AND cool=toto #comment here",
+ "SELECT piwik FROM piwik_tests where test= &#039;super&quot;value&#039; AND cool=toto #comment here"
+ ),
+ // sanitize php variables
+ array(true, true),
+ array(false, false),
+ array(null, null),
+ array("", ""),
+ );
}
-
+
/**
* @dataProvider getInputValues
* @group Core
@@ -129,18 +129,17 @@ class Core_CommonTest extends PHPUnit_Framework_TestCase
*/
public function testSanitizeInputValues($input, $output)
{
- if (version_compare(PHP_VERSION, '5.4') < 0)
- {
+ if (version_compare(PHP_VERSION, '5.4') < 0) {
$this->assertTrue(@set_magic_quotes_runtime(1));
$this->assertEquals(1, @get_magic_quotes_runtime());
- $this->assertEquals( $output, Piwik_Common::sanitizeInputValues($input));
-
+ $this->assertEquals($output, Piwik_Common::sanitizeInputValues($input));
+
$this->assertTrue(@set_magic_quotes_runtime(0));
$this->assertEquals(0, @get_magic_quotes_runtime());
- $this->assertEquals( $output, Piwik_Common::sanitizeInputValues($input));
+ $this->assertEquals($output, Piwik_Common::sanitizeInputValues($input));
}
}
-
+
/**
* emptyvarname => exception
* @group Core
@@ -150,14 +149,14 @@ class Core_CommonTest extends PHPUnit_Framework_TestCase
public function testGetRequestVarEmptyVarName()
{
try {
- $_GET['']=1;
+ $_GET[''] = 1;
Piwik_Common::getRequestVar('');
} catch (Exception $e) {
return;
}
$this->fail('Expected exception not raised');
}
-
+
/**
* nodefault Notype Novalue => exception
* @group Core
@@ -173,7 +172,7 @@ class Core_CommonTest extends PHPUnit_Framework_TestCase
}
$this->fail('Expected exception not raised');
}
-
+
/**
* nodefault Notype WithValue => value
* @group Core
@@ -184,9 +183,9 @@ class Core_CommonTest extends PHPUnit_Framework_TestCase
{
$_GET['test'] = 1413.431413;
$this->assertEquals($_GET['test'], Piwik_Common::getRequestVar('test'));
-
+
}
-
+
/**
* nodefault Withtype WithValue => exception cos type not matching
* @group Core
@@ -220,44 +219,44 @@ class Core_CommonTest extends PHPUnit_Framework_TestCase
$this->fail('Expected exception not raised');
}
-
+
/**
* Dataprovider for testGetRequestVar
*/
public function getRequestVarValues()
{
return array( // value of request var, default value, var type, expected
- array(1413.431413, 2, 'int', 2), // withdefault Withtype WithValue => value casted as type
- array(null, 'default', null, 'default'), // withdefault Notype NoValue => default value
- array(null, 'default', 'string', 'default'), // withdefault Withtype NoValue =>default value casted as type
- // integer as a default value / types
- array('', 45, 'int', 45),
- array(1413.431413, 45, 'int', 45),
- array('', 45, 'integer', 45),
- array('', 45.0, 'float', 45.0),
- array('', 45.25, 'float', 45.25),
- // string as a default value / types
- array('1413.431413', 45, 'int', 45),
- array('1413.431413', 45, 'string', '1413.431413'),
- array('', 45, 'string', '45'),
- array('', 'geaga', 'string', 'geaga'),
- array('', '&#039;}{}}{}{}&#039;', 'string', '&#039;}{}}{}{}&#039;'),
- array('', 'http://url?arg1=val1&arg2=val2', 'string', 'http://url?arg1=val1&amp;arg2=val2'),
- array('http://url?arg1=val1&arg2=val2', 'http://url?arg1=val1&arg2=val4', 'string', 'http://url?arg1=val1&amp;arg2=val2'),
- array(array("test", 1345524, array("gaga")), array(), 'array', array("test", 1345524, array("gaga"))), // array as a default value / types
- array(array("test", 1345524, array("gaga")), 45, 'string', "45"),
- array(array("test", 1345524, array("gaga")), array(1), 'array', array("test", 1345524, array("gaga"))),
- array(array("test", 1345524, array("gaga")), 4, 'int', 4),
- array('', array(1), 'array', array(1)),
- array('', array(), 'array', array()),
- // we give a number in a string and request for a number => it should give the string casted as a number
- array('45645646', 1, 'int', 45645646),
- array('45645646', 45, 'integer', 45645646),
- array('45645646', '45454', 'string', '45645646'),
- array('45645646', array(), 'array', array()),
- );
+ array(1413.431413, 2, 'int', 2), // withdefault Withtype WithValue => value casted as type
+ array(null, 'default', null, 'default'), // withdefault Notype NoValue => default value
+ array(null, 'default', 'string', 'default'), // withdefault Withtype NoValue =>default value casted as type
+ // integer as a default value / types
+ array('', 45, 'int', 45),
+ array(1413.431413, 45, 'int', 45),
+ array('', 45, 'integer', 45),
+ array('', 45.0, 'float', 45.0),
+ array('', 45.25, 'float', 45.25),
+ // string as a default value / types
+ array('1413.431413', 45, 'int', 45),
+ array('1413.431413', 45, 'string', '1413.431413'),
+ array('', 45, 'string', '45'),
+ array('', 'geaga', 'string', 'geaga'),
+ array('', '&#039;}{}}{}{}&#039;', 'string', '&#039;}{}}{}{}&#039;'),
+ array('', 'http://url?arg1=val1&arg2=val2', 'string', 'http://url?arg1=val1&amp;arg2=val2'),
+ array('http://url?arg1=val1&arg2=val2', 'http://url?arg1=val1&arg2=val4', 'string', 'http://url?arg1=val1&amp;arg2=val2'),
+ array(array("test", 1345524, array("gaga")), array(), 'array', array("test", 1345524, array("gaga"))), // array as a default value / types
+ array(array("test", 1345524, array("gaga")), 45, 'string', "45"),
+ array(array("test", 1345524, array("gaga")), array(1), 'array', array("test", 1345524, array("gaga"))),
+ array(array("test", 1345524, array("gaga")), 4, 'int', 4),
+ array('', array(1), 'array', array(1)),
+ array('', array(), 'array', array()),
+ // we give a number in a string and request for a number => it should give the string casted as a number
+ array('45645646', 1, 'int', 45645646),
+ array('45645646', 45, 'integer', 45645646),
+ array('45645646', '45454', 'string', '45645646'),
+ array('45645646', array(), 'array', array()),
+ );
}
-
+
/**
* @dataProvider getRequestVarValues
* @group Core
@@ -270,23 +269,23 @@ class Core_CommonTest extends PHPUnit_Framework_TestCase
$return = Piwik_Common::getRequestVar('test', $default, $type);
$this->assertEquals($expected, $return);
// validate correct type
- switch($type) {
+ switch ($type) {
case 'int':
case 'integer':
- $this->assertTrue( is_int($return) );
+ $this->assertTrue(is_int($return));
break;
case 'float':
- $this->assertTrue( is_float($return) );
+ $this->assertTrue(is_float($return));
break;
case 'string':
- $this->assertTrue( is_string($return) );
+ $this->assertTrue(is_string($return));
break;
case 'array':
- $this->assertTrue( is_array($return) );
+ $this->assertTrue(is_array($return));
break;
}
}
-
+
/**
* Dataprovider for testGetParameterFromQueryString
*/
@@ -309,28 +308,28 @@ class Core_CommonTest extends PHPUnit_Framework_TestCase
array('?x%5B%5D=A%26y%3D1', 'x', array('A%26y%3D1')),
// ?z=y&x[]=1
array('?z=y%26x%5b%5d%3d1', 'x', null),
-
+
// strange characters
array('toto=mama&mama=&tuytyt=Поиск в Интернете Поиск страниц на русском _*()!$!£$^!£$%&toto=mama second value', 'tuytyt', 'Поиск в Интернете Поиск страниц на русском _*()!$!£$^!£$%'),
-
+
// twice the parameter => returns the last value in the url
array('toto=mama&mama=&tuytyt=teaoi&toto=mama second value', 'toto', 'mama second value'),
-
+
// empty param
array('toto=mama&mama=&tuytyt=teaoi', 'mama', ''),
-
+
// missing parameter value => returns false
array('x', 'x', false),
array('toto=mama&mama&tuytyt=teaoi', 'mama', false),
-
+
// param not found => null
array('toto=mama&mama=titi', 'tot', null),
-
+
// empty query string => null
array('', 'test', null),
);
}
-
+
/**
* @dataProvider getQueryStrings
* @group Core
@@ -363,7 +362,7 @@ class Core_CommonTest extends PHPUnit_Framework_TestCase
'a' => false,
'b' => '',
'c' => '1',
- 'd' => array( false ),
+ 'd' => array(false),
'e' => array(''),
'f' => array('a'),
'g' => array('b', 'c'),
@@ -379,11 +378,10 @@ class Core_CommonTest extends PHPUnit_Framework_TestCase
public function testIsValidFilenameValidValues()
{
$valid = array(
- "test", "test.txt","test.......", "en-ZHsimplified",
- );
- foreach($valid as $toTest)
- {
- $this->assertTrue(Piwik_Common::isValidFilename($toTest), $toTest." not valid!");
+ "test", "test.txt", "test.......", "en-ZHsimplified",
+ );
+ foreach ($valid as $toTest) {
+ $this->assertTrue(Piwik_Common::isValidFilename($toTest), $toTest . " not valid!");
}
}
@@ -395,11 +393,10 @@ class Core_CommonTest extends PHPUnit_Framework_TestCase
public function testIsValidFilenameNotValidValues()
{
$notvalid = array(
- "../test", "/etc/htpasswd", '$var', ';test', '[bizarre]', '', ".htaccess", "very long long eogaioge ageja geau ghaeihieg heiagie aiughaeui hfilename",
- );
- foreach($notvalid as $toTest)
- {
- $this->assertFalse(Piwik_Common::isValidFilename($toTest), $toTest." valid but shouldn't!");
+ "../test", "/etc/htpasswd", '$var', ';test', '[bizarre]', '', ".htaccess", "very long long eogaioge ageja geau ghaeihieg heiagie aiughaeui hfilename",
+ );
+ foreach ($notvalid as $toTest) {
+ $this->assertFalse(Piwik_Common::isValidFilename($toTest), $toTest . " valid but shouldn't!");
}
}
@@ -409,36 +406,36 @@ class Core_CommonTest extends PHPUnit_Framework_TestCase
public function getBrowserLanguageData()
{
return array( // user agent, browser language
- array( "en-gb", "en-gb" ),
+ array("en-gb", "en-gb"),
- // filter quality attribute
- array( "en-us,en;q=0.5", "en-us,en" ),
+ // filter quality attribute
+ array("en-us,en;q=0.5", "en-us,en"),
- // bad user agents
- array( "en-us,chrome://global/locale/intl.properties", "en-us" ),
+ // bad user agents
+ array("en-us,chrome://global/locale/intl.properties", "en-us"),
- // unregistered language tag
- array( "en,en-securid", "en" ),
- array( "en-securid,en", "en" ),
- array( "en-us,en-securid,en", "en-us,en" ),
+ // unregistered language tag
+ array("en,en-securid", "en"),
+ array("en-securid,en", "en"),
+ array("en-us,en-securid,en", "en-us,en"),
- // accept private sub tags
- array( "en-us,x-en-securid", "en-us,x-en-securid" ),
- array( "en-us,en-x-securid", "en-us,en-x-securid" ),
+ // accept private sub tags
+ array("en-us,x-en-securid", "en-us,x-en-securid"),
+ array("en-us,en-x-securid", "en-us,en-x-securid"),
- // filter arbitrary white space
- array( "en-us, en", "en-us,en" ),
- array( "en-ca, en-us ,en", "en-ca,en-us,en" ),
+ // filter arbitrary white space
+ array("en-us, en", "en-us,en"),
+ array("en-ca, en-us ,en", "en-ca,en-us,en"),
- // handle comments
- array( " ( comment ) en-us (another comment) ", "en-us" ),
+ // handle comments
+ array(" ( comment ) en-us (another comment) ", "en-us"),
- // handle quoted pairs (embedded in comments)
- array( " ( \( start ) en-us ( \) end ) ", "en-us" ),
- array( " ( \) en-ca, \( ) en-us ( \) ,en ) ", "en-us" ),
- );
+ // handle quoted pairs (embedded in comments)
+ array(" ( \( start ) en-us ( \) end ) ", "en-us"),
+ array(" ( \) en-ca, \( ) en-us ( \) ,en ) ", "en-us"),
+ );
}
-
+
/**
* @dataProvider getBrowserLanguageData
* @group Core
@@ -447,29 +444,30 @@ class Core_CommonTest extends PHPUnit_Framework_TestCase
*/
public function testGetBrowserLanguage($useragent, $browserLanguage)
{
- $res = Piwik_Common::getBrowserLanguage( $useragent );
- $this->assertEquals( $browserLanguage, $res );
+ $res = Piwik_Common::getBrowserLanguage($useragent);
+ $this->assertEquals($browserLanguage, $res);
}
-
+
/**
* Dataprovider for testExtractCountryCodeFromBrowserLanguage
*/
- public function getCountryCodeTestData() {
-
+ public function getCountryCodeTestData()
+ {
+
return array( // browser language, valid countries, expected result
- array( "", array(), "xx" ),
- array( "", array("us" => 'amn'), "xx" ),
- array( "en", array("us" => 'amn'), "xx" ),
- array( "en-us", array("us" => 'amn'), "us" ),
- array( "en-ca", array("us" => 'amn'), "xx" ),
- array( "en-ca", array("us" => 'amn', "ca" => 'amn'), "ca" ),
- array( "fr-fr,fr-ca", array("us" => 'amn', "ca" => 'amn'), "ca" ),
- array( "fr-fr;q=1.0,fr-ca;q=0.9", array("us" => 'amn', "ca" => 'amn'), "ca" ),
- array( "fr-ca,fr;q=0.1", array("us" => 'amn', "ca" => 'amn'), "ca" ),
- array( "en-us,en;q=0.5", Piwik_Common::getCountriesList(), "us" ),
- array( "fr-ca,fr;q=0.1", array("fr" => 'eur', "us" => 'amn', "ca" => 'amn'), "ca" ),
- array( "fr-fr,fr-ca", array("fr" => 'eur', "us" => 'amn', "ca" => 'amn'), "fr" )
- );
+ array("", array(), "xx"),
+ array("", array("us" => 'amn'), "xx"),
+ array("en", array("us" => 'amn'), "xx"),
+ array("en-us", array("us" => 'amn'), "us"),
+ array("en-ca", array("us" => 'amn'), "xx"),
+ array("en-ca", array("us" => 'amn', "ca" => 'amn'), "ca"),
+ array("fr-fr,fr-ca", array("us" => 'amn', "ca" => 'amn'), "ca"),
+ array("fr-fr;q=1.0,fr-ca;q=0.9", array("us" => 'amn', "ca" => 'amn'), "ca"),
+ array("fr-ca,fr;q=0.1", array("us" => 'amn', "ca" => 'amn'), "ca"),
+ array("en-us,en;q=0.5", Piwik_Common::getCountriesList(), "us"),
+ array("fr-ca,fr;q=0.1", array("fr" => 'eur', "us" => 'amn', "ca" => 'amn'), "ca"),
+ array("fr-fr,fr-ca", array("fr" => 'eur', "us" => 'amn', "ca" => 'amn'), "fr")
+ );
}
/**
@@ -481,22 +479,23 @@ class Core_CommonTest extends PHPUnit_Framework_TestCase
public function testExtractCountryCodeFromBrowserLanguage($browserLanguage, $validCountries, $expected)
{
include 'DataFiles/LanguageToCountry.php';
-
- $this->assertEquals( $expected, Piwik_Common::extractCountryCodeFromBrowserLanguage( $browserLanguage, $validCountries, true ));
- $this->assertEquals( $expected, Piwik_Common::extractCountryCodeFromBrowserLanguage( $browserLanguage, $validCountries, false ));
+
+ $this->assertEquals($expected, Piwik_Common::extractCountryCodeFromBrowserLanguage($browserLanguage, $validCountries, true));
+ $this->assertEquals($expected, Piwik_Common::extractCountryCodeFromBrowserLanguage($browserLanguage, $validCountries, false));
}
/**
* Dataprovider for testExtractCountryCodeFromBrowserLanguageInfer
*/
- public function getCountryCodeTestDataInfer() {
-
+ public function getCountryCodeTestDataInfer()
+ {
+
return array( // browser language, valid countries, expected result (non-guess vs guess)
- array( "fr,en-us", array("us" => 'amn', "ca" => 'amn'), "us", "fr" ),
- array( "fr,en-us", array("fr" => 'eur', "us" => 'amn', "ca" => 'amn'), "us", "fr" ),
- array( "fr,fr-fr,en-us", array("fr" => 'eur', "us" => 'amn', "ca" => 'amn'), "fr", "fr" ),
- array( "fr-fr,fr,en-us", array("fr" => 'eur', "us" => 'amn', "ca" => 'amn'), "fr", "fr" )
- );
+ array("fr,en-us", array("us" => 'amn', "ca" => 'amn'), "us", "fr"),
+ array("fr,en-us", array("fr" => 'eur', "us" => 'amn', "ca" => 'amn'), "us", "fr"),
+ array("fr,fr-fr,en-us", array("fr" => 'eur', "us" => 'amn', "ca" => 'amn'), "fr", "fr"),
+ array("fr-fr,fr,en-us", array("fr" => 'eur', "us" => 'amn', "ca" => 'amn'), "fr", "fr")
+ );
}
/**
@@ -510,10 +509,10 @@ class Core_CommonTest extends PHPUnit_Framework_TestCase
include "DataFiles/LanguageToCountry.php";
// do not infer country from language
- $this->assertEquals( $expected, Piwik_Common::extractCountryCodeFromBrowserLanguage( $browserLanguage, $validCountries, $enableLanguageToCountryGuess = false ));
+ $this->assertEquals($expected, Piwik_Common::extractCountryCodeFromBrowserLanguage($browserLanguage, $validCountries, $enableLanguageToCountryGuess = false));
// infer country from language
- $this->assertEquals( $expectedInfer, Piwik_Common::extractCountryCodeFromBrowserLanguage( $browserLanguage, $validCountries, $enableLanguageToCountryGuess = true ));
+ $this->assertEquals($expectedInfer, Piwik_Common::extractCountryCodeFromBrowserLanguage($browserLanguage, $validCountries, $enableLanguageToCountryGuess = true));
}
/**
@@ -522,22 +521,22 @@ class Core_CommonTest extends PHPUnit_Framework_TestCase
public function getLanguageDataToExtract()
{
return array( // browser language, valid languages, expected result
- array( "fr-ca", array("fr"), "fr" ),
- array( "", array(), "xx" ),
- array( "", array("en"), "xx" ),
- array( "fr", array("en"), "xx" ),
- array( "en", array("en"), "en" ),
- array( "en-ca", array("en-ca"), "en-ca" ),
- array( "en-ca", array("en"), "en" ),
- array( "fr,en-us", array("fr", "en"), "fr" ),
- array( "fr,en-us", array("en", "fr"), "fr" ),
- array( "fr-fr,fr-ca", array("fr"), "fr" ),
- array( "fr-fr,fr-ca", array("fr-ca"), "fr-ca" ),
- array( "fr-fr;q=1.0,fr-ca;q=0.9", array("fr-ca"), "fr-ca" ),
- array( "fr-ca,fr;q=0.1", array("fr-ca"), "fr-ca" ),
- array( "r5,fr;q=1,de", array("fr", "de"), "fr" ),
- array( "Zen§gq1", array("en"), "xx" ),
- );
+ array("fr-ca", array("fr"), "fr"),
+ array("", array(), "xx"),
+ array("", array("en"), "xx"),
+ array("fr", array("en"), "xx"),
+ array("en", array("en"), "en"),
+ array("en-ca", array("en-ca"), "en-ca"),
+ array("en-ca", array("en"), "en"),
+ array("fr,en-us", array("fr", "en"), "fr"),
+ array("fr,en-us", array("en", "fr"), "fr"),
+ array("fr-fr,fr-ca", array("fr"), "fr"),
+ array("fr-fr,fr-ca", array("fr-ca"), "fr-ca"),
+ array("fr-fr;q=1.0,fr-ca;q=0.9", array("fr-ca"), "fr-ca"),
+ array("fr-ca,fr;q=0.1", array("fr-ca"), "fr-ca"),
+ array("r5,fr;q=1,de", array("fr", "de"), "fr"),
+ array("Zen§gq1", array("en"), "xx"),
+ );
}
/**
@@ -548,9 +547,9 @@ class Core_CommonTest extends PHPUnit_Framework_TestCase
*/
public function testExtractLanguageCodeFromBrowserLanguage($browserLanguage, $validLanguages, $expected)
{
- $this->assertEquals( $expected, Piwik_Common::extractLanguageCodeFromBrowserLanguage( $browserLanguage, $validLanguages ), "test with {$browserLanguage} failed, expected {$expected}");
+ $this->assertEquals($expected, Piwik_Common::extractLanguageCodeFromBrowserLanguage($browserLanguage, $validLanguages), "test with {$browserLanguage} failed, expected {$expected}");
}
-
+
/**
* @group Core
* @group Common
@@ -560,33 +559,27 @@ class Core_CommonTest extends PHPUnit_Framework_TestCase
include "DataFiles/SearchEngines.php";
$searchEngines = array();
- foreach($GLOBALS['Piwik_SearchEngines'] as $host => $info)
- {
- if(isset($info[2]) && $info[2] !== false)
- {
+ foreach ($GLOBALS['Piwik_SearchEngines'] as $host => $info) {
+ if (isset($info[2]) && $info[2] !== false) {
$this->assertTrue(strrpos($info[2], "{k}") !== false, $host . " search URL is not defined correctly, must contain the macro {k}");
}
- if(!array_key_exists($info[0], $searchEngines))
- {
+ if (!array_key_exists($info[0], $searchEngines)) {
$searchEngines[$info[0]] = true;
$this->assertTrue(strpos($host, '{}') === false, $host . " search URL is the master record and should not contain {}");
}
- if(isset($info[3]) && $info[3] !== false)
- {
+ if (isset($info[3]) && $info[3] !== false) {
$this->assertTrue(is_array($info[3]) || is_string($info[3]), $host . ' encoding must be either a string or an array');
- if (is_string($info[3]))
- {
+ if (is_string($info[3])) {
$this->assertTrue(trim($info[3]) !== '', $host . ' encoding cannot be an empty string');
$this->assertTrue(strpos($info[3], ' ') === false, $host . ' encoding cannot contain spaces');
}
- if (is_array($info[3]))
- {
+ if (is_array($info[3])) {
$this->assertTrue(count($info[3]) > 0, $host . ' encodings cannot be an empty array');
$this->assertTrue(strpos(serialize($info[3]), '""') === false, $host . ' encodings in array cannot be empty stringss');
$this->assertTrue(strpos(serialize($info[3]), ' ') === false, $host . ' encodings in array cannot contain spaces');
@@ -594,7 +587,7 @@ class Core_CommonTest extends PHPUnit_Framework_TestCase
}
}
}
-
+
/**
* Dataprovider for testExtractSearchEngineInformationFromUrl
*/
@@ -834,7 +827,7 @@ class Core_CommonTest extends PHPUnit_Framework_TestCase
array('name' => 'Google Images', 'keywords' => false)),
);
}
-
+
/**
* @dataProvider getSearchEngineUrls
* @group Core
@@ -867,7 +860,7 @@ class Core_CommonTest extends PHPUnit_Framework_TestCase
array('images.de.ask.com', 'images.{}.ask.com'),
);
}
-
+
/**
* @dataProvider getLossyUrls
* @group Core
diff --git a/tests/PHPUnit/Core/ConfigTest.php b/tests/PHPUnit/Core/ConfigTest.php
index 7fc7ff3f2f..ddd2619b71 100644
--- a/tests/PHPUnit/Core/ConfigTest.php
+++ b/tests/PHPUnit/Core/ConfigTest.php
@@ -59,7 +59,7 @@ class ConfigTest extends PHPUnit_Framework_TestCase
$this->assertEquals($stringWritten, $config->Category['test']);
$config->Category = array(
- 'test' => $config->Category['test'],
+ 'test' => $config->Category['test'],
'test2' => $stringWritten,
);
$this->assertEquals($stringWritten, $config->Category['test']);
@@ -145,7 +145,8 @@ class ConfigTest extends PHPUnit_Framework_TestCase
* Dataprovider for testArrayUnmerge
* @return array
*/
- public function getArrayUnmergeData() {
+ public function getArrayUnmergeData()
+ {
return array(
array('description of test', array(
array(),
@@ -211,7 +212,7 @@ class ConfigTest extends PHPUnit_Framework_TestCase
public function getDumpConfigData()
{
$header = "; <?php exit; ?> DO NOT REMOVE THIS LINE\n" .
- "; file automatically generated or modified by Piwik; you can manually override the default values in global.ini.php by redefining them in this file.\n";
+ "; file automatically generated or modified by Piwik; you can manually override the default values in global.ini.php by redefining them in this file.\n";
return array(
array('global only, not cached', array(
@@ -307,18 +308,18 @@ class ConfigTest extends PHPUnit_Framework_TestCase
array('sort, common sections', array(
array('Tracker' => array('anonymize' => '1'),
- 'General' => array('debug' => '1')),
+ 'General' => array('debug' => '1')),
array('General' => array('debug' => '0'),
- 'Tracker' => array('anonymize' => '0')),
+ 'Tracker' => array('anonymize' => '0')),
array('Tracker' => array('anonymize' => '2')),
$header . "[General]\ndebug = 1\n\n[Tracker]\nanonymize = 2\n\n",
)),
array('sort, common sections before new section', array(
array('Tracker' => array('anonymize' => '1'),
- 'General' => array('debug' => '1')),
+ 'General' => array('debug' => '1')),
array('General' => array('debug' => '0'),
- 'Tracker' => array('anonymize' => '0')),
+ 'Tracker' => array('anonymize' => '0')),
array('Segment' => array('dimension' => 'foo')),
$header . "[General]\ndebug = 1\n\n[Tracker]\nanonymize = 1\n\n[Segment]\ndimension = \"foo\"\n\n",
)),
@@ -326,7 +327,7 @@ class ConfigTest extends PHPUnit_Framework_TestCase
array('change back to default', array(
array('Tracker' => array('anonymize' => '1')),
array('Tracker' => array('anonymize' => '0'),
- 'General' => array('debug' => '1')),
+ 'General' => array('debug' => '1')),
array('Tracker' => array('anonymize' => '0')),
$header
)),
diff --git a/tests/PHPUnit/Core/CookieTest.php b/tests/PHPUnit/Core/CookieTest.php
index b64efad9b3..c3d622bbb6 100644
--- a/tests/PHPUnit/Core/CookieTest.php
+++ b/tests/PHPUnit/Core/CookieTest.php
@@ -42,11 +42,11 @@ class CookieTest extends PHPUnit_Framework_TestCase
public function testJsonSerialize($testData, $id)
{
// @see http://bugs.php.net/38680
- if(PHP_VERSION >= '5.2.0' && PHP_VERSION < '5.2.1') {
+ if (PHP_VERSION >= '5.2.0' && PHP_VERSION < '5.2.1') {
$this->markTestSkipped('see http://bugs.php.net/38680');
}
- $this->assertEquals( $testData, json_decode(json_encode($testData), $assoc = true), $id );
+ $this->assertEquals($testData, json_decode(json_encode($testData), $assoc = true), $id);
}
/**
@@ -83,10 +83,10 @@ class CookieTest extends PHPUnit_Framework_TestCase
*/
public function testSafeSerialize($id, $testData)
{
- $this->assertEquals( serialize($testData), safe_serialize($testData), $id );
- $this->assertEquals( $testData, unserialize(safe_serialize($testData)), $id );
- $this->assertSame( $testData, safe_unserialize(safe_serialize($testData)), $id );
- $this->assertSame( $testData, safe_unserialize(serialize($testData)), $id );
+ $this->assertEquals(serialize($testData), safe_serialize($testData), $id);
+ $this->assertEquals($testData, unserialize(safe_serialize($testData)), $id);
+ $this->assertSame($testData, safe_unserialize(safe_serialize($testData)), $id);
+ $this->assertSame($testData, safe_unserialize(serialize($testData)), $id);
}
/**
@@ -102,57 +102,57 @@ class CookieTest extends PHPUnit_Framework_TestCase
$testData = $tests['exp float'] = -5.0E+142;
// intentionally disabled; this doesn't work
// $this->assertEquals( safe_serialize($testData), serialize($testData) );
- $this->assertEquals( $testData, unserialize(safe_serialize($testData)) );
- $this->assertSame( $testData, safe_unserialize(safe_serialize($testData))) ;
+ $this->assertEquals($testData, unserialize(safe_serialize($testData)));
+ $this->assertSame($testData, safe_unserialize(safe_serialize($testData)));
// workaround: cast floats into strings
- $this->assertSame( $testData, safe_unserialize(serialize($testData)) );
+ $this->assertSame($testData, safe_unserialize(serialize($testData)));
$unserialized = array(
'announcement' => true,
- 'source' => array(
+ 'source' => array(
array(
'filename' => 'php-5.3.3.tar.bz2',
- 'name' => 'PHP 5.3.3 (tar.bz2)',
- 'md5' => '21ceeeb232813c10283a5ca1b4c87b48',
- 'date' => '22 July 2010',
+ 'name' => 'PHP 5.3.3 (tar.bz2)',
+ 'md5' => '21ceeeb232813c10283a5ca1b4c87b48',
+ 'date' => '22 July 2010',
),
array(
'filename' => 'php-5.3.3.tar.gz',
- 'name' => 'PHP 5.3.3 (tar.gz)',
- 'md5' => '5adf1a537895c2ec933fddd48e78d8a2',
- 'date' => '22 July 2010',
+ 'name' => 'PHP 5.3.3 (tar.gz)',
+ 'md5' => '5adf1a537895c2ec933fddd48e78d8a2',
+ 'date' => '22 July 2010',
),
),
- 'date' => '22 July 2010',
- 'version' => '5.3.3',
+ 'date' => '22 July 2010',
+ 'version' => '5.3.3',
);
$serialized = 'a:4:{s:12:"announcement";b:1;s:6:"source";a:2:{i:0;a:4:{s:8:"filename";s:17:"php-5.3.3.tar.bz2";s:4:"name";s:19:"PHP 5.3.3 (tar.bz2)";s:3:"md5";s:32:"21ceeeb232813c10283a5ca1b4c87b48";s:4:"date";s:12:"22 July 2010";}i:1;a:4:{s:8:"filename";s:16:"php-5.3.3.tar.gz";s:4:"name";s:18:"PHP 5.3.3 (tar.gz)";s:3:"md5";s:32:"5adf1a537895c2ec933fddd48e78d8a2";s:4:"date";s:12:"22 July 2010";}}s:4:"date";s:12:"22 July 2010";s:7:"version";s:5:"5.3.3";}';
- $this->assertSame( $unserialized, unserialize($serialized) );
- $this->assertEquals( $serialized, serialize($unserialized) );
+ $this->assertSame($unserialized, unserialize($serialized));
+ $this->assertEquals($serialized, serialize($unserialized));
- $this->assertSame( $unserialized, safe_unserialize($serialized) );
- $this->assertEquals( $serialized, safe_serialize($unserialized) );
- $this->assertSame( $unserialized, safe_unserialize(safe_serialize($unserialized)) );
- $this->assertEquals( $serialized, safe_serialize(safe_unserialize($serialized)) );
+ $this->assertSame($unserialized, safe_unserialize($serialized));
+ $this->assertEquals($serialized, safe_serialize($unserialized));
+ $this->assertSame($unserialized, safe_unserialize(safe_serialize($unserialized)));
+ $this->assertEquals($serialized, safe_serialize(safe_unserialize($serialized)));
$a = 'O:31:"Test_Piwik_Cookie_Phantom_Class":0:{}';
- $this->assertFalse( safe_unserialize($a), "test: unserializing an object where class not (yet) defined" );
+ $this->assertFalse(safe_unserialize($a), "test: unserializing an object where class not (yet) defined");
$a = 'O:28:"Test_Piwik_Cookie_Mock_Class":0:{}';
- $this->assertFalse( safe_unserialize($a), "test: unserializing an object where class is defined" );
+ $this->assertFalse(safe_unserialize($a), "test: unserializing an object where class is defined");
$a = 'a:1:{i:0;O:28:"Test_Piwik_Cookie_Mock_Class":0:{}}';
- $this->assertFalse( safe_unserialize($a), "test: unserializing nested object where class is defined" );
+ $this->assertFalse(safe_unserialize($a), "test: unserializing nested object where class is defined");
$a = 'a:2:{i:0;s:4:"test";i:1;O:28:"Test_Piwik_Cookie_Mock_Class":0:{}}';
- $this->assertFalse( safe_unserialize($a), "test: unserializing another nested object where class is defined" );
+ $this->assertFalse(safe_unserialize($a), "test: unserializing another nested object where class is defined");
- $a = 'O:28:"Test_Piwik_Cookie_Mock_Class":1:{s:34:"'."\0".'Test_Piwik_Cookie_Mock_Class'."\0".'name";s:4:"test";}';
- $this->assertFalse( safe_unserialize($a), "test: unserializing object with member where class is defined" );
+ $a = 'O:28:"Test_Piwik_Cookie_Mock_Class":1:{s:34:"' . "\0" . 'Test_Piwik_Cookie_Mock_Class' . "\0" . 'name";s:4:"test";}';
+ $this->assertFalse(safe_unserialize($a), "test: unserializing object with member where class is defined");
// arrays and objects cannot be used as keys, i.e., generates "Warning: Illegal offset type ..."
$a = 'a:2:{i:0;a:0:{}O:28:"Test_Piwik_Cookie_Mock_Class":0:{}s:4:"test";';
- $this->assertFalse( safe_unserialize($a), "test: unserializing with illegal key" );
+ $this->assertFalse(safe_unserialize($a), "test: unserializing with illegal key");
}
}
diff --git a/tests/PHPUnit/Core/DataTable/ArrayTest.php b/tests/PHPUnit/Core/DataTable/ArrayTest.php
index 18c44640d6..015939311a 100755
--- a/tests/PHPUnit/Core/DataTable/ArrayTest.php
+++ b/tests/PHPUnit/Core/DataTable/ArrayTest.php
@@ -14,9 +14,9 @@ class Test_Piwik_DataTable_Array extends PHPUnit_Framework_TestCase
$result = new Piwik_DataTable();
$result->addRowsFromArray(array(
- array(Piwik_DataTable_Row::COLUMNS => array('label'=> 'row1', 'col1' => 1)),
- array(Piwik_DataTable_Row::COLUMNS => array('label'=> 'row2', 'col1' => 2))
- ));
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'row1', 'col1' => 1)),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'row2', 'col1' => 2))
+ ));
return $result;
}
@@ -38,7 +38,7 @@ class Test_Piwik_DataTable_Array extends PHPUnit_Framework_TestCase
{
$dataTable = new Piwik_DataTable_Array();
- $subDataTableArray1 = $this->createInstanceWithDataTables();
+ $subDataTableArray1 = $this->createInstanceWithDataTables();
$dataTable->addTable($subDataTableArray1, 'subArray1');
$subDataTableArray2 = $this->createInstanceWithDataTables();
diff --git a/tests/PHPUnit/Core/DataTable/Filter/AddSummaryRowTest.php b/tests/PHPUnit/Core/DataTable/Filter/AddSummaryRowTest.php
index b8da1b498e..5071d2b815 100644
--- a/tests/PHPUnit/Core/DataTable/Filter/AddSummaryRowTest.php
+++ b/tests/PHPUnit/Core/DataTable/Filter/AddSummaryRowTest.php
@@ -8,7 +8,7 @@
class DataTable_Filter_AddSummaryRowTest extends PHPUnit_Framework_TestCase
{
/**
- *
+ *
* @group Core
* @group DataTable
* @group DataTable_Filter
@@ -22,9 +22,9 @@ class DataTable_Filter_AddSummaryRowTest extends PHPUnit_Framework_TestCase
$this->assertEquals(5, $table->getRowsCount());
$this->assertTrue(Piwik_DataTable_Row::isEqual($table->getLastRow(), $this->getRow4()));
}
-
+
/**
- *
+ *
* @group Core
* @group DataTable
* @group DataTable_Filter
@@ -36,14 +36,14 @@ class DataTable_Filter_AddSummaryRowTest extends PHPUnit_Framework_TestCase
$filter = new Piwik_DataTable_Filter_AddSummaryRow($table, 2);
$filter->filter($table);
$this->assertEquals(3, $table->getRowsCount());
- $expectedRow = new Piwik_DataTable_Row(array( Piwik_DataTable_Row::COLUMNS => array('label'=>Piwik_DataTable::LABEL_SUMMARY_ROW, 'nb' => 111)));
+ $expectedRow = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => array('label' => Piwik_DataTable::LABEL_SUMMARY_ROW, 'nb' => 111)));
$this->assertTrue(Piwik_DataTable_Row::isEqual($table->getLastRow(), $expectedRow));
// check that column 'label' is forced to be first in summary row
$this->assertEquals(array_keys($table->getLastRow()->getColumns()), array_keys($expectedRow->getColumns()));
}
-
+
/**
- *
+ *
* @group Core
* @group DataTable
* @group DataTable_Filter
@@ -57,9 +57,9 @@ class DataTable_Filter_AddSummaryRowTest extends PHPUnit_Framework_TestCase
$this->assertEquals(5, $table->getRowsCount());
$this->assertTrue(Piwik_DataTable_Row::isEqual($table->getLastRow(), $this->getRow4()));
}
-
+
/**
- *
+ *
* @group Core
* @group DataTable
* @group DataTable_Filter
@@ -73,12 +73,12 @@ class DataTable_Filter_AddSummaryRowTest extends PHPUnit_Framework_TestCase
$filter2 = new Piwik_DataTable_Filter_AddSummaryRow($table, 2);
$filter2->filter($table);
$this->assertEquals(3, $table->getRowsCount());
- $expectedRow = new Piwik_DataTable_Row(array( Piwik_DataTable_Row::COLUMNS => array('label'=>Piwik_DataTable::LABEL_SUMMARY_ROW, 'nb' => 111)));
+ $expectedRow = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => array('label' => Piwik_DataTable::LABEL_SUMMARY_ROW, 'nb' => 111)));
$this->assertTrue(Piwik_DataTable_Row::isEqual($table->getLastRow(), $expectedRow));
}
-
+
/**
- *
+ *
* @group Core
* @group DataTable
* @group DataTable_Filter
@@ -90,25 +90,25 @@ class DataTable_Filter_AddSummaryRowTest extends PHPUnit_Framework_TestCase
$table1 = $this->getDataTableCount5();
$filter = new Piwik_DataTable_Filter_AddSummaryRow($table1, 3);
$filter->filter($table1);
-
+
// row0, row1, rowSummary2
$table2 = $this->getDataTableCount5();
$filter = new Piwik_DataTable_Filter_AddSummaryRow($table2, 2);
$filter->filter($table2);
-
+
// we expect row0+row0, row1+row1, row2, rowSummary1+rowSummary2
$expectedTable = new Piwik_DataTable;
- $expectedTable->addRow( new Piwik_DataTable_Row(array( Piwik_DataTable_Row::COLUMNS => array('label'=>'amazon', 'nb' => 20000) )));
- $expectedTable->addRow( new Piwik_DataTable_Row(array( Piwik_DataTable_Row::COLUMNS => array('label'=>'yahoo', 'nb' => 2000) )));
- $expectedTable->addRow( new Piwik_DataTable_Row(array( Piwik_DataTable_Row::COLUMNS => array('label'=>'piwik', 'nb' => 100) )));
- $expectedTable->addRow( new Piwik_DataTable_Row(array( Piwik_DataTable_Row::COLUMNS => array('label'=>Piwik_DataTable::LABEL_SUMMARY_ROW, 'nb' => 122) )));
-
+ $expectedTable->addRow(new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => array('label' => 'amazon', 'nb' => 20000))));
+ $expectedTable->addRow(new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => array('label' => 'yahoo', 'nb' => 2000))));
+ $expectedTable->addRow(new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => array('label' => 'piwik', 'nb' => 100))));
+ $expectedTable->addRow(new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => array('label' => Piwik_DataTable::LABEL_SUMMARY_ROW, 'nb' => 122))));
+
$table1->addDataTable($table2);
$this->assertTrue(Piwik_DataTable::isEqual($expectedTable, $table1));
}
-
+
/**
- *
+ *
* @group Core
* @group DataTable
* @group DataTable_Filter
@@ -120,26 +120,26 @@ class DataTable_Filter_AddSummaryRowTest extends PHPUnit_Framework_TestCase
$table1 = $this->getDataTableCount5();
$filter = new Piwik_DataTable_Filter_AddSummaryRow($table1, 3);
$filter->filter($table1);
-
+
// row0, row1, row2, row3, row4
$table2 = $this->getDataTableCount5();
-
+
// we expect row0+row0, row1+row1, row2+row2, row3, row4, rowSummary1
$expectedTable = new Piwik_DataTable;
- $expectedTable->addRow( new Piwik_DataTable_Row(array( Piwik_DataTable_Row::COLUMNS => array('label'=>'amazon', 'nb' => 20000) )));
- $expectedTable->addRow( new Piwik_DataTable_Row(array( Piwik_DataTable_Row::COLUMNS => array('label'=>'yahoo', 'nb' => 2000) )));
- $expectedTable->addRow( new Piwik_DataTable_Row(array( Piwik_DataTable_Row::COLUMNS => array('label'=>'piwik', 'nb' => 200) )));
- $expectedTable->addRow( $this->getRow3());
- $expectedTable->addRow( $this->getRow4());
- $expectedTable->addRow( new Piwik_DataTable_Row(array( Piwik_DataTable_Row::COLUMNS => array('label'=>Piwik_DataTable::LABEL_SUMMARY_ROW, 'nb' => 11))));
-
+ $expectedTable->addRow(new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => array('label' => 'amazon', 'nb' => 20000))));
+ $expectedTable->addRow(new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => array('label' => 'yahoo', 'nb' => 2000))));
+ $expectedTable->addRow(new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => array('label' => 'piwik', 'nb' => 200))));
+ $expectedTable->addRow($this->getRow3());
+ $expectedTable->addRow($this->getRow4());
+ $expectedTable->addRow(new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => array('label' => Piwik_DataTable::LABEL_SUMMARY_ROW, 'nb' => 11))));
+
$table1->addDataTable($table2);
$this->assertTrue(Piwik_DataTable::isEqual($expectedTable, $table1));
-
+
}
-
+
/**
- *
+ *
* @group Core
* @group DataTable
* @group DataTable_Filter
@@ -148,19 +148,19 @@ class DataTable_Filter_AddSummaryRowTest extends PHPUnit_Framework_TestCase
public function testWhenRowsInRandomOrderButSortSpecifiedShouldComputeSummaryRowAfterSort()
{
$table = new Piwik_DataTable;
- $table->addRow( $this->getRow3() );
- $table->addRow( $this->getRow2() );
- $table->addRow( $this->getRow4() );
- $table->addRow( $this->getRow1() );
- $table->addRow( $this->getRow0() );
-
+ $table->addRow($this->getRow3());
+ $table->addRow($this->getRow2());
+ $table->addRow($this->getRow4());
+ $table->addRow($this->getRow1());
+ $table->addRow($this->getRow0());
+
$filter = new Piwik_DataTable_Filter_AddSummaryRow($table, 2, Piwik_DataTable::LABEL_SUMMARY_ROW, $columnToSortBy = 'nb');
$filter->filter($table);
$this->assertEquals(3, $table->getRowsCount());
- $expectedRow = new Piwik_DataTable_Row(array( Piwik_DataTable_Row::COLUMNS => array('label'=>Piwik_DataTable::LABEL_SUMMARY_ROW, 'nb' => 111)));
+ $expectedRow = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => array('label' => Piwik_DataTable::LABEL_SUMMARY_ROW, 'nb' => 111)));
$this->assertTrue(Piwik_DataTable_Row::isEqual($table->getLastRow(), $expectedRow));
}
-
+
/**
* Returns table used for the tests
*
@@ -169,31 +169,36 @@ class DataTable_Filter_AddSummaryRowTest extends PHPUnit_Framework_TestCase
protected function getDataTableCount5()
{
$table = new Piwik_DataTable;
- $table->addRow( $this->getRow0() );
- $table->addRow( $this->getRow1() );
- $table->addRow( $this->getRow2() );
- $table->addRow( $this->getRow3() );
- $table->addRow( $this->getRow4() );
+ $table->addRow($this->getRow0());
+ $table->addRow($this->getRow1());
+ $table->addRow($this->getRow2());
+ $table->addRow($this->getRow3());
+ $table->addRow($this->getRow4());
return $table;
}
+
protected function getRow0()
{
- return new Piwik_DataTable_Row(array( Piwik_DataTable_Row::COLUMNS => array('nb' => 10000, 'label'=>'amazon')));
+ return new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => array('nb' => 10000, 'label' => 'amazon')));
}
+
protected function getRow1()
{
- return new Piwik_DataTable_Row(array( Piwik_DataTable_Row::COLUMNS => array('label'=>'yahoo', 'nb' => 1000)));
+ return new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => array('label' => 'yahoo', 'nb' => 1000)));
}
+
protected function getRow2()
{
- return new Piwik_DataTable_Row(array( Piwik_DataTable_Row::COLUMNS => array('label'=>'piwik', 'nb' => 100)));
+ return new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => array('label' => 'piwik', 'nb' => 100)));
}
+
protected function getRow3()
{
- return new Piwik_DataTable_Row(array( Piwik_DataTable_Row::COLUMNS => array('label'=>'ask', 'nb' => 10)));
+ return new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => array('label' => 'ask', 'nb' => 10)));
}
+
protected function getRow4()
{
- return new Piwik_DataTable_Row(array( Piwik_DataTable_Row::COLUMNS => array('nb' => 1, 'label'=>'google')));
+ return new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => array('nb' => 1, 'label' => 'google')));
}
}
diff --git a/tests/PHPUnit/Core/DataTable/Filter/ExcludeLowPopulationTest.php b/tests/PHPUnit/Core/DataTable/Filter/ExcludeLowPopulationTest.php
index 8cc05b6b0c..5ebb772c72 100644
--- a/tests/PHPUnit/Core/DataTable/Filter/ExcludeLowPopulationTest.php
+++ b/tests/PHPUnit/Core/DataTable/Filter/ExcludeLowPopulationTest.php
@@ -12,19 +12,19 @@ class DataTable_Filter_ExcludeLowPopulationTest extends PHPUnit_Framework_TestCa
$table = new Piwik_DataTable;
$table->addRowsFromArray(
array(
- array(Piwik_DataTable_Row::COLUMNS => array('label'=>'zero', 'count' => 0)),
- array(Piwik_DataTable_Row::COLUMNS => array('label'=>'one', 'count' => 1)),
- array(Piwik_DataTable_Row::COLUMNS => array('label'=>'onedotfive', 'count' => 1.5)),
- array(Piwik_DataTable_Row::COLUMNS => array('label'=>'ten', 'count' => 10)),
- array(Piwik_DataTable_Row::COLUMNS => array('label'=>'ninety', 'count' => 90)),
- array(Piwik_DataTable_Row::COLUMNS => array('label'=>'hundred', 'count' => 100)),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'zero', 'count' => 0)),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'one', 'count' => 1)),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'onedotfive', 'count' => 1.5)),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'ten', 'count' => 10)),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'ninety', 'count' => 90)),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'hundred', 'count' => 100)),
)
);
return $table;
}
-
+
/**
- *
+ *
* @group Core
* @group DataTable
* @group DataTable_Filter
@@ -32,15 +32,15 @@ class DataTable_Filter_ExcludeLowPopulationTest extends PHPUnit_Framework_TestCa
*/
public function testStandardTable()
{
- $table = $this->getTestDataTable();
+ $table = $this->getTestDataTable();
$filter = new Piwik_DataTable_Filter_ExcludeLowPopulation($table, 'count', 1.1);
$filter->filter($table);
$this->assertEquals(4, $table->getRowsCount());
$this->assertEquals(array(1.5, 10, 90, 100), $table->getColumn('count'));
}
-
+
/**
- *
+ *
* @group Core
* @group DataTable
* @group DataTable_Filter
@@ -48,14 +48,14 @@ class DataTable_Filter_ExcludeLowPopulationTest extends PHPUnit_Framework_TestCa
*/
public function testFilterEqualOneDoesFilter()
{
- $table = $this->getTestDataTable();
+ $table = $this->getTestDataTable();
$filter = new Piwik_DataTable_Filter_ExcludeLowPopulation($table, 'count', 1);
$filter->filter($table);
$this->assertEquals(5, $table->getRowsCount());
}
-
+
/**
- *
+ *
* @group Core
* @group DataTable
* @group DataTable_Filter
@@ -63,15 +63,15 @@ class DataTable_Filter_ExcludeLowPopulationTest extends PHPUnit_Framework_TestCa
*/
public function testFilterEqualZeroDoesFilter()
{
- $table = $this->getTestDataTable();
+ $table = $this->getTestDataTable();
$filter = new Piwik_DataTable_Filter_ExcludeLowPopulation($table, 'count', 0);
$filter->filter($table);
$this->assertEquals(3, $table->getRowsCount());
$this->assertEquals(array(10, 90, 100), $table->getColumn('count'));
}
-
+
/**
- *
+ *
* @group Core
* @group DataTable
* @group DataTable_Filter
@@ -79,18 +79,17 @@ class DataTable_Filter_ExcludeLowPopulationTest extends PHPUnit_Framework_TestCa
*/
public function testFilterSpecifyExcludeLowPopulationThresholdDoesFilter()
{
- $table = $this->getTestDataTable();
+ $table = $this->getTestDataTable();
$filter = new Piwik_DataTable_Filter_ExcludeLowPopulation($table, 'count', 0, 0.4); //40%
$filter->filter($table);
$this->assertEquals(2, $table->getRowsCount());
$this->assertEquals(array(90, 100), $table->getColumn('count'));
}
-
-
+
/**
* Test to exclude low population filter
- *
+ *
* @group Core
* @group DataTable
* @group DataTable_Filter
@@ -98,36 +97,36 @@ class DataTable_Filter_ExcludeLowPopulationTest extends PHPUnit_Framework_TestCa
*/
public function testFilterLowpop1()
{
-
+
$idcol = Piwik_DataTable_Row::COLUMNS;
-
+
$table = new Piwik_DataTable();
$rows = array(
- array( $idcol => array('label'=>'google', 'nb_visits' => 897)),//0
- array( $idcol => array('label'=>'ask', 'nb_visits' => -152)),//1
- array( $idcol => array('label'=>'piwik', 'nb_visits' => 1.5)),//2
- array( $idcol => array('label'=>'piwik2', 'nb_visits' => 1.4)),//2
- array( $idcol => array('label'=>'yahoo', 'nb_visits' => 154)),//3
- array( $idcol => array('label'=>'amazon', 'nb_visits' => 30)),//4
- array( $idcol => array('label'=>'238949', 'nb_visits' => 0)),//5
- array( $idcol => array('label'=>'Q*(%&*', 'nb_visits' => 1)),//6
- array( $idcol => array('label'=>'Q*(%&*2', 'nb_visits' => -1.5)),//6
+ array($idcol => array('label' => 'google', 'nb_visits' => 897)), //0
+ array($idcol => array('label' => 'ask', 'nb_visits' => -152)), //1
+ array($idcol => array('label' => 'piwik', 'nb_visits' => 1.5)), //2
+ array($idcol => array('label' => 'piwik2', 'nb_visits' => 1.4)), //2
+ array($idcol => array('label' => 'yahoo', 'nb_visits' => 154)), //3
+ array($idcol => array('label' => 'amazon', 'nb_visits' => 30)), //4
+ array($idcol => array('label' => '238949', 'nb_visits' => 0)), //5
+ array($idcol => array('label' => 'Q*(%&*', 'nb_visits' => 1)), //6
+ array($idcol => array('label' => 'Q*(%&*2', 'nb_visits' => -1.5)), //6
);
- $table->addRowsFromArray( $rows );
-
+ $table->addRowsFromArray($rows);
+
$expectedtable = new Piwik_DataTable();
$rows = array(
- array( $idcol => array('label'=>'google', 'nb_visits' => 897)),//0
- array( $idcol => array('label'=>'piwik', 'nb_visits' => 1.5)),//2
- array( $idcol => array('label'=>'piwik2', 'nb_visits' => 1.4)),//2
- array( $idcol => array('label'=>'yahoo', 'nb_visits' => 154)),//3
- array( $idcol => array('label'=>'amazon', 'nb_visits' => 30)),//4
+ array($idcol => array('label' => 'google', 'nb_visits' => 897)), //0
+ array($idcol => array('label' => 'piwik', 'nb_visits' => 1.5)), //2
+ array($idcol => array('label' => 'piwik2', 'nb_visits' => 1.4)), //2
+ array($idcol => array('label' => 'yahoo', 'nb_visits' => 154)), //3
+ array($idcol => array('label' => 'amazon', 'nb_visits' => 30)), //4
);
- $expectedtable->addRowsFromArray( $rows );
-
+ $expectedtable->addRowsFromArray($rows);
+
$filter = new Piwik_DataTable_Filter_ExcludeLowPopulation($table, 'nb_visits', 1.4);
$filter->filter($table);
-
+
$this->assertTrue(Piwik_DataTable::isEqual($table, $expectedtable));
}
}
diff --git a/tests/PHPUnit/Core/DataTable/Filter/LimitTest.php b/tests/PHPUnit/Core/DataTable/Filter/LimitTest.php
index ccd2a17577..37a9e20d58 100644
--- a/tests/PHPUnit/Core/DataTable/Filter/LimitTest.php
+++ b/tests/PHPUnit/Core/DataTable/Filter/LimitTest.php
@@ -17,23 +17,23 @@ class DataTable_Filter_LimitTest extends PHPUnit_Framework_TestCase
$table = new Piwik_DataTable;
$idcol = Piwik_DataTable_Row::COLUMNS;
$rows = array(
- array($idcol => array('label'=> 'google', 'idRow' => 0)),
- array($idcol => array('label'=> 'ask', 'idRow' => 1)),
- array($idcol => array('label'=> 'piwik', 'idRow' => 2)),
- array($idcol => array('label'=> 'yahoo', 'idRow' => 3)),
- array($idcol => array('label'=> 'amazon', 'idRow' => 4)),
- array($idcol => array('label'=> '238949', 'idRow' => 5)),
- array($idcol => array('label'=> 'test', 'idRow' => 6)),
- array($idcol => array('label'=> 'amazing', 'idRow' => 7)),
- array($idcol => array('label'=> 'great', 'idRow' => 8)),
- Piwik_DataTable::ID_SUMMARY_ROW => array($idcol => array('label'=> 'summary row', 'idRow' => 9)),
+ array($idcol => array('label' => 'google', 'idRow' => 0)),
+ array($idcol => array('label' => 'ask', 'idRow' => 1)),
+ array($idcol => array('label' => 'piwik', 'idRow' => 2)),
+ array($idcol => array('label' => 'yahoo', 'idRow' => 3)),
+ array($idcol => array('label' => 'amazon', 'idRow' => 4)),
+ array($idcol => array('label' => '238949', 'idRow' => 5)),
+ array($idcol => array('label' => 'test', 'idRow' => 6)),
+ array($idcol => array('label' => 'amazing', 'idRow' => 7)),
+ array($idcol => array('label' => 'great', 'idRow' => 8)),
+ Piwik_DataTable::ID_SUMMARY_ROW => array($idcol => array('label' => 'summary row', 'idRow' => 9)),
);
- $table->addRowsFromArray( $rows );
+ $table->addRowsFromArray($rows);
return $table;
}
-
+
/**
- *
+ *
* @group Core
* @group DataTable
* @group DataTable_Filter
@@ -51,9 +51,9 @@ class DataTable_Filter_LimitTest extends PHPUnit_Framework_TestCase
$this->assertEquals(4, $table->getLastRow()->getColumn('idRow'));
$this->assertEquals(10, $table->getRowsCountBeforeLimitFilter());
}
-
+
/**
- *
+ *
* @group Core
* @group DataTable
* @group DataTable_Filter
@@ -71,9 +71,9 @@ class DataTable_Filter_LimitTest extends PHPUnit_Framework_TestCase
$this->assertEquals(8, $table->getLastRow()->getColumn('idRow'));
$this->assertEquals(10, $table->getRowsCountBeforeLimitFilter());
}
-
+
/**
- *
+ *
* @group Core
* @group DataTable
* @group DataTable_Filter
@@ -92,9 +92,9 @@ class DataTable_Filter_LimitTest extends PHPUnit_Framework_TestCase
$this->assertEquals(9, $table->getLastRow()->getColumn('idRow'));
$this->assertEquals(10, $table->getRowsCountBeforeLimitFilter());
}
-
+
/**
- *
+ *
* @group Core
* @group DataTable
* @group DataTable_Filter
@@ -113,9 +113,9 @@ class DataTable_Filter_LimitTest extends PHPUnit_Framework_TestCase
$this->assertEquals(9, $table->getLastRow()->getColumn('idRow'));
$this->assertEquals(10, $table->getRowsCountBeforeLimitFilter());
}
-
+
/**
- *
+ *
* @group Core
* @group DataTable
* @group DataTable_Filter
@@ -132,9 +132,9 @@ class DataTable_Filter_LimitTest extends PHPUnit_Framework_TestCase
$this->assertEquals(9, $table->getLastRow()->getColumn('idRow'));
$this->assertEquals(10, $table->getRowsCountBeforeLimitFilter());
}
-
+
/**
- *
+ *
* @group Core
* @group DataTable
* @group DataTable_Filter
@@ -152,9 +152,9 @@ class DataTable_Filter_LimitTest extends PHPUnit_Framework_TestCase
$this->assertEquals(9, $table->getLastRow()->getColumn('idRow'));
$this->assertEquals(10, $table->getRowsCountBeforeLimitFilter());
}
-
+
/**
- *
+ *
* @group Core
* @group DataTable
* @group DataTable_Filter
@@ -174,7 +174,7 @@ class DataTable_Filter_LimitTest extends PHPUnit_Framework_TestCase
}
/**
- *
+ *
* @group Core
* @group DataTable
* @group DataTable_Filter
@@ -192,9 +192,9 @@ class DataTable_Filter_LimitTest extends PHPUnit_Framework_TestCase
$this->assertEquals(9, $table->getLastRow()->getColumn('idRow'));
$this->assertEquals(10, $table->getRowsCountBeforeLimitFilter());
}
-
+
/**
- *
+ *
* @group Core
* @group DataTable
* @group DataTable_Filter
@@ -210,9 +210,9 @@ class DataTable_Filter_LimitTest extends PHPUnit_Framework_TestCase
$this->assertEquals(0, $table->getRowsCount());
$this->assertEquals(10, $table->getRowsCountBeforeLimitFilter());
}
-
+
/**
- *
+ *
* @group Core
* @group DataTable
* @group DataTable_Filter
@@ -228,10 +228,10 @@ class DataTable_Filter_LimitTest extends PHPUnit_Framework_TestCase
$this->assertEquals(0, $table->getRowsCount());
$this->assertEquals(10, $table->getRowsCountBeforeLimitFilter());
}
-
+
/**
* Test to filter a table with a offset, limit
- *
+ *
* @group Core
* @group DataTable
* @group DataTable_Filter
@@ -240,37 +240,37 @@ class DataTable_Filter_LimitTest extends PHPUnit_Framework_TestCase
public function testFilterOffsetLimit()
{
$table = new Piwik_DataTable;
-
+
$idcol = Piwik_DataTable_Row::COLUMNS;
-
+
$rows = array(
- array( $idcol => array('label'=>'google')),//0
- array( $idcol => array('label'=>'ask')),//1
- array( $idcol => array('label'=>'piwik')),//2
- array( $idcol => array('label'=>'yahoo')),//3
- array( $idcol => array('label'=>'amazon')),//4
- array( $idcol => array('label'=>'238975247578949')),//5
- array( $idcol => array('label'=>'Q*(%&*("$&%*(&"$*")"))'))//6
+ array($idcol => array('label' => 'google')), //0
+ array($idcol => array('label' => 'ask')), //1
+ array($idcol => array('label' => 'piwik')), //2
+ array($idcol => array('label' => 'yahoo')), //3
+ array($idcol => array('label' => 'amazon')), //4
+ array($idcol => array('label' => '238975247578949')), //5
+ array($idcol => array('label' => 'Q*(%&*("$&%*(&"$*")"))')) //6
);
-
- $table->addRowsFromArray( $rows );
-
+
+ $table->addRowsFromArray($rows);
+
$expectedtable = clone $table;
- $expectedtable->deleteRows(array(0,1,6));
-
+ $expectedtable->deleteRows(array(0, 1, 6));
+
$filter = new Piwik_DataTable_Filter_Limit($table, 2, 4);
$filter->filter($table);
-
- $colAfter=$colExpected=array();
- foreach($table->getRows() as $row) $colAfter[] = $row->getColumn('label');
- foreach($expectedtable->getRows() as $row) $colExpected[] = $row->getColumn('label');
-
+
+ $colAfter = $colExpected = array();
+ foreach ($table->getRows() as $row) $colAfter[] = $row->getColumn('label');
+ foreach ($expectedtable->getRows() as $row) $colExpected[] = $row->getColumn('label');
+
$this->assertEquals(array_values($expectedtable->getRows()), array_values($table->getRows()));
}
-
+
/**
* Test to filter a column with a offset, limit off bound
- *
+ *
* @group Core
* @group DataTable
* @group DataTable_Filter
@@ -279,37 +279,37 @@ class DataTable_Filter_LimitTest extends PHPUnit_Framework_TestCase
public function testFilterOffsetLimitOffbound()
{
$table = new Piwik_DataTable;
-
+
$idcol = Piwik_DataTable_Row::COLUMNS;
-
+
$rows = array(
- array( $idcol => array('label'=>'google')),//0
- array( $idcol => array('label'=>'ask')),//1
- array( $idcol => array('label'=>'piwik')),//2
- array( $idcol => array('label'=>'yahoo')),//3
- array( $idcol => array('label'=>'amazon')),//4
- array( $idcol => array('label'=>'238975247578949')),//5
- array( $idcol => array('label'=>'Q*(%&*("$&%*(&"$*")"))'))//6
+ array($idcol => array('label' => 'google')), //0
+ array($idcol => array('label' => 'ask')), //1
+ array($idcol => array('label' => 'piwik')), //2
+ array($idcol => array('label' => 'yahoo')), //3
+ array($idcol => array('label' => 'amazon')), //4
+ array($idcol => array('label' => '238975247578949')), //5
+ array($idcol => array('label' => 'Q*(%&*("$&%*(&"$*")"))')) //6
);
-
- $table->addRowsFromArray( $rows );
-
+
+ $table->addRowsFromArray($rows);
+
$expectedtable = clone $table;
- $expectedtable->deleteRows(array(0,1,3,4,5,6));
-
+ $expectedtable->deleteRows(array(0, 1, 3, 4, 5, 6));
+
$filter = new Piwik_DataTable_Filter_Limit($table, 2, 1);
$filter->filter($table);
-
- $colAfter=$colExpected=array();
- foreach($table->getRows() as $row) $colAfter[] = $row->getColumn('label');
- foreach($expectedtable->getRows() as $row) $colExpected[] = $row->getColumn('label');
-
+
+ $colAfter = $colExpected = array();
+ foreach ($table->getRows() as $row) $colAfter[] = $row->getColumn('label');
+ foreach ($expectedtable->getRows() as $row) $colExpected[] = $row->getColumn('label');
+
$this->assertEquals(array_values($expectedtable->getRows()), array_values($table->getRows()));
}
-
+
/**
* Test to filter a column with a offset, limit 2
- *
+ *
* @group Core
* @group DataTable
* @group DataTable_Filter
@@ -318,36 +318,36 @@ class DataTable_Filter_LimitTest extends PHPUnit_Framework_TestCase
public function testFilterOffsetLimit2()
{
$table = new Piwik_DataTable;
-
+
$idcol = Piwik_DataTable_Row::COLUMNS;
-
+
$rows = array(
- array( $idcol => array('label'=>'google')),//0
- array( $idcol => array('label'=>'ask')),//1
- array( $idcol => array('label'=>'piwik')),//2
- array( $idcol => array('label'=>'yahoo')),//3
- array( $idcol => array('label'=>'amazon')),//4
- array( $idcol => array('label'=>'238975247578949')),//5
- array( $idcol => array('label'=>'Q*(%&*("$&%*(&"$*")"))'))//6
+ array($idcol => array('label' => 'google')), //0
+ array($idcol => array('label' => 'ask')), //1
+ array($idcol => array('label' => 'piwik')), //2
+ array($idcol => array('label' => 'yahoo')), //3
+ array($idcol => array('label' => 'amazon')), //4
+ array($idcol => array('label' => '238975247578949')), //5
+ array($idcol => array('label' => 'Q*(%&*("$&%*(&"$*")"))')) //6
);
-
- $table->addRowsFromArray( $rows );
-
+
+ $table->addRowsFromArray($rows);
+
$expectedtable = clone $table;
-
+
$filter = new Piwik_DataTable_Filter_Limit($table, 0, 15);
$filter->filter($table);
-
- $colAfter=$colExpected=array();
- foreach($table->getRows() as $row) $colAfter[] = $row->getColumn('label');
- foreach($expectedtable->getRows() as $row) $colExpected[] = $row->getColumn('label');
-
+
+ $colAfter = $colExpected = array();
+ foreach ($table->getRows() as $row) $colAfter[] = $row->getColumn('label');
+ foreach ($expectedtable->getRows() as $row) $colExpected[] = $row->getColumn('label');
+
$this->assertEquals(array_values($expectedtable->getRows()), array_values($table->getRows()));
}
-
+
/**
* Test to filter a column with a offset, limit 3
- *
+ *
* @group Core
* @group DataTable
* @group DataTable_Filter
@@ -356,31 +356,31 @@ class DataTable_Filter_LimitTest extends PHPUnit_Framework_TestCase
public function testFilterOffsetLimit3()
{
$table = new Piwik_DataTable;
-
+
$idcol = Piwik_DataTable_Row::COLUMNS;
-
+
$rows = array(
- array( $idcol => array('label'=>'google')),//0
- array( $idcol => array('label'=>'ask')),//1
- array( $idcol => array('label'=>'piwik')),//2
- array( $idcol => array('label'=>'yahoo')),//3
- array( $idcol => array('label'=>'amazon')),//4
- array( $idcol => array('label'=>'238975247578949')),//5
- array( $idcol => array('label'=>'Q*(%&*("$&%*(&"$*")"))'))//6
+ array($idcol => array('label' => 'google')), //0
+ array($idcol => array('label' => 'ask')), //1
+ array($idcol => array('label' => 'piwik')), //2
+ array($idcol => array('label' => 'yahoo')), //3
+ array($idcol => array('label' => 'amazon')), //4
+ array($idcol => array('label' => '238975247578949')), //5
+ array($idcol => array('label' => 'Q*(%&*("$&%*(&"$*")"))')) //6
);
-
- $table->addRowsFromArray( $rows );
+
+ $table->addRowsFromArray($rows);
$expectedtable = new Piwik_DataTable;
-
+
$filter = new Piwik_DataTable_Filter_Limit($table, 8, 15);
$filter->filter($table);
-
- $colAfter=$colExpected=array();
- foreach($table->getRows() as $row) $colAfter[] = $row->getColumn('label');
- foreach($expectedtable->getRows() as $row) $colExpected[] = $row->getColumn('label');
-
+
+ $colAfter = $colExpected = array();
+ foreach ($table->getRows() as $row) $colAfter[] = $row->getColumn('label');
+ foreach ($expectedtable->getRows() as $row) $colExpected[] = $row->getColumn('label');
+
$this->assertEquals(array_values($expectedtable->getRows()), array_values($table->getRows()));
}
-
+
}
diff --git a/tests/PHPUnit/Core/DataTable/Filter/PatternRecursiveTest.php b/tests/PHPUnit/Core/DataTable/Filter/PatternRecursiveTest.php
index b107a8063a..5efc2dac7a 100644
--- a/tests/PHPUnit/Core/DataTable/Filter/PatternRecursiveTest.php
+++ b/tests/PHPUnit/Core/DataTable/Filter/PatternRecursiveTest.php
@@ -14,25 +14,25 @@ class DataTable_Filter_PatternRecursiveTest extends PHPUnit_Framework_TestCase
protected function getTable()
{
$subtableAskPath1 = new Piwik_DataTable();
- $subtableAskPath1->addRowsFromArray(array (
- array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'path1-index-page.html') ),
- array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'another-page') ),
- ));
+ $subtableAskPath1->addRowsFromArray(array(
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'path1-index-page.html')),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'another-page')),
+ ));
$subtableAsk = new Piwik_DataTable();
- $subtableAsk->addRowsFromArray(array (
- array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'path1'),
- Piwik_DataTable_Row::DATATABLE_ASSOCIATED => $subtableAskPath1),
- array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'index.html') ),
- ));
+ $subtableAsk->addRowsFromArray(array(
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'path1'),
+ Piwik_DataTable_Row::DATATABLE_ASSOCIATED => $subtableAskPath1),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'index.html')),
+ ));
$table = new Piwik_DataTable;
$rows = array(
- array( Piwik_DataTable_Row::COLUMNS => array('label'=>'http://www.ask.com'),
- Piwik_DataTable_Row::DATATABLE_ASSOCIATED => $subtableAsk),
- array( Piwik_DataTable_Row::COLUMNS => array('label'=>'yahoo')),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'http://www.ask.com'),
+ Piwik_DataTable_Row::DATATABLE_ASSOCIATED => $subtableAsk),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'yahoo')),
);
- $table->addRowsFromArray( $rows );
+ $table->addRowsFromArray($rows);
return $table;
}
diff --git a/tests/PHPUnit/Core/DataTable/Filter/PatternTest.php b/tests/PHPUnit/Core/DataTable/Filter/PatternTest.php
index 4536a2f611..d90de04a44 100644
--- a/tests/PHPUnit/Core/DataTable/Filter/PatternTest.php
+++ b/tests/PHPUnit/Core/DataTable/Filter/PatternTest.php
@@ -14,17 +14,17 @@ class DataTable_Filter_PatternTest extends PHPUnit_Framework_TestCase
{
return array(
array(array('ask', array(1))),
- array(array('oo', array(0,3))),
+ array(array('oo', array(0, 3))),
array(array('^yah', array(3))),
array(array('\*', array(6))),
array(array('2/4', array(5))),
- array(array('amazon|yahoo', array(3,4))),
+ array(array('amazon|yahoo', array(3, 4))),
);
}
/**
* Test to filter a column with a pattern
- *
+ *
* @group Core
* @group DataTable
* @group DataTable_Filter
@@ -34,21 +34,21 @@ class DataTable_Filter_PatternTest extends PHPUnit_Framework_TestCase
public function testFilterPattern($test)
{
$table = new Piwik_DataTable;
-
+
$idcol = Piwik_DataTable_Row::COLUMNS;
-
+
$rows = array(
- array( $idcol => array('label'=>'google')),
- array( $idcol => array('label'=>'ask')),
- array( $idcol => array('label'=>'piwik')),
- array( $idcol => array('label'=>'yahoo')),
- array( Piwik_DataTable_Row::METADATA => array('label'=>'amazon')),
- array( $idcol => array('label'=>'2389752/47578949')),
- array( $idcol => array('label'=>'Q*(%&*("$&%*(&"$*")"))'))
+ array($idcol => array('label' => 'google')),
+ array($idcol => array('label' => 'ask')),
+ array($idcol => array('label' => 'piwik')),
+ array($idcol => array('label' => 'yahoo')),
+ array(Piwik_DataTable_Row::METADATA => array('label' => 'amazon')),
+ array($idcol => array('label' => '2389752/47578949')),
+ array($idcol => array('label' => 'Q*(%&*("$&%*(&"$*")"))'))
);
- $table->addRowsFromArray( $rows );
+ $table->addRowsFromArray($rows);
$rowIds = array_keys($rows);
-
+
$pattern = $test[0];
$expectedRows = $test[1];
$rowToDelete = array_diff($rowIds, $expectedRows);
diff --git a/tests/PHPUnit/Core/DataTable/Filter/RangeCheckTest.php b/tests/PHPUnit/Core/DataTable/Filter/RangeCheckTest.php
index 53c91c8520..397333ce29 100644
--- a/tests/PHPUnit/Core/DataTable/Filter/RangeCheckTest.php
+++ b/tests/PHPUnit/Core/DataTable/Filter/RangeCheckTest.php
@@ -8,7 +8,7 @@
class DataTable_Filter_RangeCheckTest extends PHPUnit_Framework_TestCase
{
/**
- *
+ *
* @group Core
* @group DataTable
* @group DataTable_Filter
@@ -18,12 +18,12 @@ class DataTable_Filter_RangeCheckTest extends PHPUnit_Framework_TestCase
{
$table = new Piwik_DataTable();
$table->addRowsFromArray(array(
- array(Piwik_DataTable_Row::COLUMNS => array('label' => 'ask', 'count' => 3)), // --> 5
- array(Piwik_DataTable_Row::COLUMNS => array('label' => 'nintendo', 'count' => 5)), // --> 5
- array(Piwik_DataTable_Row::COLUMNS => array('label' => 'test', 'count' => 7.5)), // --> 7.5
- array(Piwik_DataTable_Row::COLUMNS => array('label' => 'google', 'count' => 9)), // --> 9
- array(Piwik_DataTable_Row::COLUMNS => array('label' => 'yahoo', 'count' => 10.1) // --> 10
- )));
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'ask', 'count' => 3)), // --> 5
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'nintendo', 'count' => 5)), // --> 5
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'test', 'count' => 7.5)), // --> 7.5
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'google', 'count' => 9)), // --> 9
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'yahoo', 'count' => 10.1) // --> 10
+ )));
$filter = new Piwik_DataTable_Filter_RangeCheck($table, 'count', 5, 10);
$filter->filter($table);
$expectedOrder = array(5, 5, 7.5, 9, 10);
@@ -42,13 +42,13 @@ class DataTable_Filter_RangeCheckTest extends PHPUnit_Framework_TestCase
{
$table = new Piwik_DataTable();
$table->addRowsFromArray(array(
- array(Piwik_DataTable_Row::COLUMNS => array('label' => 'ask', 'count' => '3')), // 3 is below minimum
- array(Piwik_DataTable_Row::COLUMNS => array('label' => 'nintendo', 'count' => 'test')), // no number is below minimum
- array(Piwik_DataTable_Row::COLUMNS => array('label' => 'test', 'count' => 0x1232)), // number is over maximum
- array(Piwik_DataTable_Row::COLUMNS => array('label' => 'piwik', 'count' => 0x005)), // converted to 5 is ok
- array(Piwik_DataTable_Row::COLUMNS => array('label' => 'google', 'count' => '9test')), // converted to 9 is ok, so string will be kept
- array(Piwik_DataTable_Row::COLUMNS => array('label' => 'yahoo', 'count' => 'test4') // can't be converted to number
- )));
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'ask', 'count' => '3')), // 3 is below minimum
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'nintendo', 'count' => 'test')), // no number is below minimum
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'test', 'count' => 0x1232)), // number is over maximum
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'piwik', 'count' => 0x005)), // converted to 5 is ok
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'google', 'count' => '9test')), // converted to 9 is ok, so string will be kept
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'yahoo', 'count' => 'test4') // can't be converted to number
+ )));
$filter = new Piwik_DataTable_Filter_RangeCheck($table, 'count', 3.97, 10);
$filter->filter($table);
$expectedOrder = array(3.97, 3.97, 10, 5, '9test', 3.97);
diff --git a/tests/PHPUnit/Core/DataTable/Filter/SortTest.php b/tests/PHPUnit/Core/DataTable/Filter/SortTest.php
index ca08a3596d..eb793bd136 100644
--- a/tests/PHPUnit/Core/DataTable/Filter/SortTest.php
+++ b/tests/PHPUnit/Core/DataTable/Filter/SortTest.php
@@ -8,124 +8,124 @@
class DataTable_Filter_SortTest extends PHPUnit_Framework_TestCase
{
/**
- *
+ *
* @group Core
* @group DataTable
* @group DataTable_Filter
* @group DataTable_Filter_Sort
*/
- public function testNormalSortDescending ()
+ public function testNormalSortDescending()
{
$table = new Piwik_DataTable();
$table->addRowsFromArray(array(
- array(Piwik_DataTable_Row::COLUMNS => array('label' => 'ask', 'count' => 100)),
- array(Piwik_DataTable_Row::COLUMNS => array('label' => 'nintendo', 'count' => 0)),
- array(Piwik_DataTable_Row::COLUMNS => array('label' => 'yahoo', 'count' => 10)
- )));
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'ask', 'count' => 100)),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'nintendo', 'count' => 0)),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'yahoo', 'count' => 10)
+ )));
$filter = new Piwik_DataTable_Filter_Sort($table, 'count', 'desc');
$filter->filter($table);
- $expectedOrder = array('ask' , 'yahoo' , 'nintendo');
+ $expectedOrder = array('ask', 'yahoo', 'nintendo');
$this->assertEquals($expectedOrder, $table->getColumn('label'));
}
-
+
/**
- *
+ *
* @group Core
* @group DataTable
* @group DataTable_Filter
* @group DataTable_Filter_Sort
*/
- public function testNormalSortAscending ()
+ public function testNormalSortAscending()
{
$table = new Piwik_DataTable();
$table->addRowsFromArray(array(
- array(Piwik_DataTable_Row::COLUMNS => array('label' => 'ask', 'count' => 100.5)),
- array(Piwik_DataTable_Row::COLUMNS => array('label' => 'nintendo', 'count' => 0.5)),
- array(Piwik_DataTable_Row::COLUMNS => array('label' => 'yahoo', 'count' => 10.5)
- )));
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'ask', 'count' => 100.5)),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'nintendo', 'count' => 0.5)),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'yahoo', 'count' => 10.5)
+ )));
$filter = new Piwik_DataTable_Filter_Sort($table, 'count', 'asc');
$filter->filter($table);
- $expectedOrder = array('nintendo' , 'yahoo' , 'ask');
+ $expectedOrder = array('nintendo', 'yahoo', 'ask');
$this->assertEquals($expectedOrder, $table->getColumn('label'));
}
-
+
/**
- *
+ *
* @group Core
* @group DataTable
* @group DataTable_Filter
* @group DataTable_Filter_Sort
*/
- public function testMissingColumnValuesShouldAppearLastAfterSortAsc ()
+ public function testMissingColumnValuesShouldAppearLastAfterSortAsc()
{
$table = new Piwik_DataTable();
$table->addRowsFromArray(array(
- array(Piwik_DataTable_Row::COLUMNS => array('label' => 'nintendo', 'count' => 1)),
- array(Piwik_DataTable_Row::COLUMNS => array('label' => 'nocolumn')),
- array(Piwik_DataTable_Row::COLUMNS => array('label' => 'nocolumnbis')),
- array(Piwik_DataTable_Row::COLUMNS => array('label' => 'ask', 'count' => 2)),
- array(Piwik_DataTable_Row::COLUMNS => array('label' => 'amazing')),
- Piwik_DataTable::ID_SUMMARY_ROW => array(Piwik_DataTable_Row::COLUMNS => array('label' => 'summary' , 'count' => 10)
- )));
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'nintendo', 'count' => 1)),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'nocolumn')),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'nocolumnbis')),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'ask', 'count' => 2)),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'amazing')),
+ Piwik_DataTable::ID_SUMMARY_ROW => array(Piwik_DataTable_Row::COLUMNS => array('label' => 'summary', 'count' => 10)
+ )));
$filter = new Piwik_DataTable_Filter_Sort($table, 'count', 'asc');
$filter->filter($table);
- $expectedOrder = array('nintendo' , 'ask' , 'amazing' , 'nocolumnbis' , 'nocolumn' , 'summary');
+ $expectedOrder = array('nintendo', 'ask', 'amazing', 'nocolumnbis', 'nocolumn', 'summary');
$this->assertEquals($expectedOrder, $table->getColumn('label'));
}
-
+
/**
- *
+ *
* @group Core
* @group DataTable
* @group DataTable_Filter
* @group DataTable_Filter_Sort
*/
- public function testMissingColumnValuesShouldAppearLastAfterSortDesc ()
+ public function testMissingColumnValuesShouldAppearLastAfterSortDesc()
{
$table = new Piwik_DataTable();
$table->addRowsFromArray(array(
- array(Piwik_DataTable_Row::COLUMNS => array('label' => 'nintendo' , 'count' => 1)),
- array(Piwik_DataTable_Row::COLUMNS => array('label' => 'ask' , 'count' => 2)),
- array(Piwik_DataTable_Row::COLUMNS => array('label' => 'amazing')),
- Piwik_DataTable::ID_SUMMARY_ROW => array(Piwik_DataTable_Row::COLUMNS => array('label' => 'summary' , 'count' => 10)
- )));
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'nintendo', 'count' => 1)),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'ask', 'count' => 2)),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'amazing')),
+ Piwik_DataTable::ID_SUMMARY_ROW => array(Piwik_DataTable_Row::COLUMNS => array('label' => 'summary', 'count' => 10)
+ )));
$filter = new Piwik_DataTable_Filter_Sort($table, 'count', 'desc');
$filter->filter($table);
- $expectedOrder = array('ask' , 'nintendo' , 'amazing' , 'summary');
+ $expectedOrder = array('ask', 'nintendo', 'amazing', 'summary');
$this->assertEquals($expectedOrder, $table->getColumn('label'));
}
-
+
/**
* Test to sort by label
- *
+ *
* @group Core
* @group DataTable
* @group DataTable_Filter
* @group DataTable_Filter_Sort
*/
- public function testFilterSortString ()
+ public function testFilterSortString()
{
$idcol = Piwik_DataTable_Row::COLUMNS;
$table = new Piwik_DataTable();
$rows = array(
- array($idcol => array('label' => 'google')) , //0
- array($idcol => array('label' => 'ask')) , //1
- array($idcol => array('label' => 'piwik')) , //2
- array($idcol => array('label' => 'yahoo')) , //3
- array($idcol => array('label' => 'amazon')) , //4
- array($idcol => array('label' => '238975247578949')) , //5
+ array($idcol => array('label' => 'google')), //0
+ array($idcol => array('label' => 'ask')), //1
+ array($idcol => array('label' => 'piwik')), //2
+ array($idcol => array('label' => 'yahoo')), //3
+ array($idcol => array('label' => 'amazon')), //4
+ array($idcol => array('label' => '238975247578949')), //5
array($idcol => array('label' => 'Q*(%&*("$&%*(&"$*")"))')) //6
);
$table->addRowsFromArray($rows);
$expectedtable = new Piwik_DataTable();
$rows = array(
- array($idcol => array('label' => '238975247578949')) , //5
- array($idcol => array('label' => 'amazon')) , //4
- array($idcol => array('label' => 'ask')) , //1
- array($idcol => array('label' => 'google')) , //0
- array($idcol => array('label' => 'piwik')) , //2
- array($idcol => array('label' => 'Q*(%&*("$&%*(&"$*")"))')) , //6
- array($idcol => array('label' => 'yahoo') )//3
+ array($idcol => array('label' => '238975247578949')), //5
+ array($idcol => array('label' => 'amazon')), //4
+ array($idcol => array('label' => 'ask')), //1
+ array($idcol => array('label' => 'google')), //0
+ array($idcol => array('label' => 'piwik')), //2
+ array($idcol => array('label' => 'Q*(%&*("$&%*(&"$*")"))')), //6
+ array($idcol => array('label' => 'yahoo')) //3
);
$expectedtable->addRowsFromArray($rows);
$expectedtableReverse = new Piwik_DataTable();
@@ -139,39 +139,39 @@ class DataTable_Filter_SortTest extends PHPUnit_Framework_TestCase
$filter->filter($table);
$this->assertTrue(Piwik_DataTable::isEqual($table, $expectedtableReverse));
}
-
+
/**
* Test to sort by visit
- *
+ *
* @group Core
* @group DataTable
* @group DataTable_Filter
* @group DataTable_Filter_Sort
*/
- public function testFilterSortNumeric ()
+ public function testFilterSortNumeric()
{
$idcol = Piwik_DataTable_Row::COLUMNS;
$table = new Piwik_DataTable();
$rows = array(
- array($idcol => array('label' => 'google', 'nb_visits' => 897)) , //0
- array($idcol => array('label' => 'ask', 'nb_visits' => - 152)) , //1
- array($idcol => array('label' => 'piwik', 'nb_visits' => 1.5)) , //2
- array($idcol => array('label' => 'yahoo', 'nb_visits' => 154)) , //3
- array($idcol => array('label' => 'amazon', 'nb_visits' => 30)) , //4
- array($idcol => array('label' => '238949', 'nb_visits' => 0)) , //5
- array($idcol => array('label' => 'Q*(%&*', 'nb_visits' => 1))//6
+ array($idcol => array('label' => 'google', 'nb_visits' => 897)), //0
+ array($idcol => array('label' => 'ask', 'nb_visits' => -152)), //1
+ array($idcol => array('label' => 'piwik', 'nb_visits' => 1.5)), //2
+ array($idcol => array('label' => 'yahoo', 'nb_visits' => 154)), //3
+ array($idcol => array('label' => 'amazon', 'nb_visits' => 30)), //4
+ array($idcol => array('label' => '238949', 'nb_visits' => 0)), //5
+ array($idcol => array('label' => 'Q*(%&*', 'nb_visits' => 1)) //6
);
$table->addRowsFromArray($rows);
$expectedtable = new Piwik_DataTable();
$rows = array(
- array($idcol => array('label' => 'ask', 'nb_visits' => - 152)) , //1
- array($idcol => array('label' => '238949', 'nb_visits' => 0)) , //5
- array($idcol => array('label' => 'Q*(%&*', 'nb_visits' => 1)) , //6
- array($idcol => array('label' => 'piwik', 'nb_visits' => 1.5)) , //2
- array($idcol => array('label' => 'amazon', 'nb_visits' => 30)) , //4
- array($idcol => array('label' => 'yahoo', 'nb_visits' => 154)) , //3
- array($idcol => array('label' => 'google', 'nb_visits' => 897))//0
- );
+ array($idcol => array('label' => 'ask', 'nb_visits' => -152)), //1
+ array($idcol => array('label' => '238949', 'nb_visits' => 0)), //5
+ array($idcol => array('label' => 'Q*(%&*', 'nb_visits' => 1)), //6
+ array($idcol => array('label' => 'piwik', 'nb_visits' => 1.5)), //2
+ array($idcol => array('label' => 'amazon', 'nb_visits' => 30)), //4
+ array($idcol => array('label' => 'yahoo', 'nb_visits' => 154)), //3
+ array($idcol => array('label' => 'google', 'nb_visits' => 897)) //0
+ );
$expectedtable->addRowsFromArray($rows);
$expectedtableReverse = new Piwik_DataTable();
$expectedtableReverse->addRowsFromArray(array_reverse($rows));
diff --git a/tests/PHPUnit/Core/DataTable/Filter/TruncateTest.php b/tests/PHPUnit/Core/DataTable/Filter/TruncateTest.php
index 0c37cf3f1f..1d46658e63 100644
--- a/tests/PHPUnit/Core/DataTable/Filter/TruncateTest.php
+++ b/tests/PHPUnit/Core/DataTable/Filter/TruncateTest.php
@@ -8,57 +8,57 @@
class DataTable_Filter_TruncateTest extends PHPUnit_Framework_TestCase
{
/**
- * @group Core
- * @group DataTable
- * @group DataTable_Filter
- * @group DataTable_Filter_Truncate
- */
- public function testUnrelatedDataTableNotFiltered()
- {
- // remark: this unit test would become invalid and would need to be rewritten if
- // AddSummaryRow filter stops calling getRowsCount() on the DataTable being filtered.
- $mockedDataTable = $this->getMock('Piwik_DataTable', array('getRowsCount'));
- $mockedDataTable->expects($this->never())->method('getRowsCount');
+ * @group Core
+ * @group DataTable
+ * @group DataTable_Filter
+ * @group DataTable_Filter_Truncate
+ */
+ public function testUnrelatedDataTableNotFiltered()
+ {
+ // remark: this unit test would become invalid and would need to be rewritten if
+ // AddSummaryRow filter stops calling getRowsCount() on the DataTable being filtered.
+ $mockedDataTable = $this->getMock('Piwik_DataTable', array('getRowsCount'));
+ $mockedDataTable->expects($this->never())->method('getRowsCount');
- $dataTableBeingFiltered = new Piwik_DataTable();
- $rowBeingFiltered = new Piwik_DataTable_Row();
- $dataTableBeingFiltered->addRow($rowBeingFiltered);
+ $dataTableBeingFiltered = new Piwik_DataTable();
+ $rowBeingFiltered = new Piwik_DataTable_Row();
+ $dataTableBeingFiltered->addRow($rowBeingFiltered);
- // we simulate the fact that the value of Piwik_DataTable_Row::DATATABLE_ASSOCIATED retrieved
- // from the database is in conflict with one of the Piwik_DataTable_Manager managed table identifiers.
- // This is a rare but legitimate case as identifiers are not thoroughly synchronized
- // when the expanded parameter is false.
- $rowBeingFiltered->c[Piwik_DataTable_Row::DATATABLE_ASSOCIATED] = $mockedDataTable->getId();
+ // we simulate the fact that the value of Piwik_DataTable_Row::DATATABLE_ASSOCIATED retrieved
+ // from the database is in conflict with one of the Piwik_DataTable_Manager managed table identifiers.
+ // This is a rare but legitimate case as identifiers are not thoroughly synchronized
+ // when the expanded parameter is false.
+ $rowBeingFiltered->c[Piwik_DataTable_Row::DATATABLE_ASSOCIATED] = $mockedDataTable->getId();
- $filter = new Piwik_DataTable_Filter_Truncate($dataTableBeingFiltered, 1);
- $filter->filter($dataTableBeingFiltered);
- }
+ $filter = new Piwik_DataTable_Filter_Truncate($dataTableBeingFiltered, 1);
+ $filter->filter($dataTableBeingFiltered);
+ }
- /**
- *
- * @group Core
- * @group DataTable
- * @group DataTable_Filter
- * @group DataTable_Filter_Truncate
- */
- public function testForInfiniteRecursion()
- {
- $dataTableBeingFiltered = new Piwik_DataTable();
+ /**
+ *
+ * @group Core
+ * @group DataTable
+ * @group DataTable_Filter
+ * @group DataTable_Filter_Truncate
+ */
+ public function testForInfiniteRecursion()
+ {
+ $dataTableBeingFiltered = new Piwik_DataTable();
- // remark: this unit test would become invalid and would need to be rewritten if
- // Truncate filter stops calling getIdSubDataTable() on rows associated with a SubDataTable
- $rowBeingFiltered = $this->getMock('Piwik_DataTable_Row', array('getIdSubDataTable'));
- $rowBeingFiltered->expects($this->never())->method('getIdSubDataTable');
+ // remark: this unit test would become invalid and would need to be rewritten if
+ // Truncate filter stops calling getIdSubDataTable() on rows associated with a SubDataTable
+ $rowBeingFiltered = $this->getMock('Piwik_DataTable_Row', array('getIdSubDataTable'));
+ $rowBeingFiltered->expects($this->never())->method('getIdSubDataTable');
- $dataTableBeingFiltered->addRow($rowBeingFiltered);
+ $dataTableBeingFiltered->addRow($rowBeingFiltered);
- // we simulate a legitimate but rare circular reference between a Piwik_DataTable_Row and its
- // enclosing Piwik_DataTable.
- // This can happen because identifiers are not thoroughly synchronized when the expanded parameter
- // is false.
- $rowBeingFiltered->c[Piwik_DataTable_Row::DATATABLE_ASSOCIATED] = $dataTableBeingFiltered->getId();
+ // we simulate a legitimate but rare circular reference between a Piwik_DataTable_Row and its
+ // enclosing Piwik_DataTable.
+ // This can happen because identifiers are not thoroughly synchronized when the expanded parameter
+ // is false.
+ $rowBeingFiltered->c[Piwik_DataTable_Row::DATATABLE_ASSOCIATED] = $dataTableBeingFiltered->getId();
- $filter = new Piwik_DataTable_Filter_Truncate($dataTableBeingFiltered, 1);
- $filter->filter($dataTableBeingFiltered);
- }
+ $filter = new Piwik_DataTable_Filter_Truncate($dataTableBeingFiltered, 1);
+ $filter->filter($dataTableBeingFiltered);
+ }
}
diff --git a/tests/PHPUnit/Core/DataTable/Renderer/CSVTest.php b/tests/PHPUnit/Core/DataTable/Renderer/CSVTest.php
index 03082336bf..2780534248 100644
--- a/tests/PHPUnit/Core/DataTable/Renderer/CSVTest.php
+++ b/tests/PHPUnit/Core/DataTable/Renderer/CSVTest.php
@@ -23,30 +23,30 @@ class DataTable_Renderer_CSVTest extends PHPUnit_Framework_TestCase
protected function _getDataTableTest()
{
$dataTable = new Piwik_DataTable();
-
- $arraySubTableForRow2 = array (
- array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'sub1', 'count' => 1, 'bool' => false) ),
- array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'sub2', 'count' => 2, 'bool' => true) ),
+
+ $arraySubTableForRow2 = array(
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'sub1', 'count' => 1, 'bool' => false)),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'sub2', 'count' => 2, 'bool' => true)),
);
$subDataTableForRow2 = new Piwik_DataTable();
$subDataTableForRow2->addRowsFromArray($arraySubTableForRow2);
- $array = array (
- array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'Google&copy;', 'bool' => false, 'goals' => array('idgoal=1' => array('revenue'=> 5.5, 'nb_conversions' => 10)), 'nb_uniq_visitors' => 11, 'nb_visits' => 11, 'nb_actions' => 17, 'max_actions' => '5', 'sum_visit_length' => 517, 'bounce_count' => 9),
- Piwik_DataTable_Row::METADATA => array('url' => 'http://www.google.com/display"and,properly', 'logo' => './plugins/Referers/images/searchEngines/www.google.com.png'),
- ),
- array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'Yahoo!', 'nb_uniq_visitors' => 15, 'bool' => true, 'nb_visits' => 151, 'nb_actions' => 147, 'max_actions' => '50', 'sum_visit_length' => 517, 'bounce_count' => 90),
- Piwik_DataTable_Row::METADATA => array('url' => 'http://www.yahoo.com', 'logo' => './plugins/Referers/images/searchEngines/www.yahoo.com.png'),
- Piwik_DataTable_Row::DATATABLE_ASSOCIATED => $subDataTableForRow2,
- )
- );
+ $array = array(
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'Google&copy;', 'bool' => false, 'goals' => array('idgoal=1' => array('revenue' => 5.5, 'nb_conversions' => 10)), 'nb_uniq_visitors' => 11, 'nb_visits' => 11, 'nb_actions' => 17, 'max_actions' => '5', 'sum_visit_length' => 517, 'bounce_count' => 9),
+ Piwik_DataTable_Row::METADATA => array('url' => 'http://www.google.com/display"and,properly', 'logo' => './plugins/Referers/images/searchEngines/www.google.com.png'),
+ ),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'Yahoo!', 'nb_uniq_visitors' => 15, 'bool' => true, 'nb_visits' => 151, 'nb_actions' => 147, 'max_actions' => '50', 'sum_visit_length' => 517, 'bounce_count' => 90),
+ Piwik_DataTable_Row::METADATA => array('url' => 'http://www.yahoo.com', 'logo' => './plugins/Referers/images/searchEngines/www.yahoo.com.png'),
+ Piwik_DataTable_Row::DATATABLE_ASSOCIATED => $subDataTableForRow2,
+ )
+ );
$dataTable->addRowsFromArray($array);
return $dataTable;
}
protected function _getDataTableSimpleTest()
{
- $array = array ( 'max_actions' => 14.0, 'nb_uniq_visitors' => 57.0, 'nb_visits' => 66.0, 'nb_actions' => 151.0, 'sum_visit_length' => 5118.0, 'bounce_count' => 44.0, );
+ $array = array('max_actions' => 14.0, 'nb_uniq_visitors' => 57.0, 'nb_visits' => 66.0, 'nb_actions' => 151.0, 'sum_visit_length' => 5118.0, 'bounce_count' => 44.0,);
$table = new Piwik_DataTable_Simple;
$table->addRowsFromArray($array);
@@ -55,7 +55,7 @@ class DataTable_Renderer_CSVTest extends PHPUnit_Framework_TestCase
protected function _getDataTableSimpleOneRowTest()
{
- $array = array ( 'nb_visits' => 14.0 );
+ $array = array('nb_visits' => 14.0);
$table = new Piwik_DataTable_Simple;
$table->addRowsFromArray($array);
@@ -70,7 +70,7 @@ class DataTable_Renderer_CSVTest extends PHPUnit_Framework_TestCase
protected function _getDataTableSimpleOneZeroRowTest()
{
- $array = array ( 'nb_visits' => 0 );
+ $array = array('nb_visits' => 0);
$table = new Piwik_DataTable_Simple;
$table->addRowsFromArray($array);
return $table;
@@ -78,7 +78,7 @@ class DataTable_Renderer_CSVTest extends PHPUnit_Framework_TestCase
protected function _getDataTableSimpleOneFalseRowTest()
{
- $array = array ( 'is_excluded' => false );
+ $array = array('is_excluded' => false);
$table = new Piwik_DataTable_Simple;
$table->addRowsFromArray($array);
return $table;
@@ -94,13 +94,13 @@ class DataTable_Renderer_CSVTest extends PHPUnit_Framework_TestCase
public function testCSVTest1()
{
$dataTable = $this->_getDataTableTest();
-
+
$render = new Piwik_DataTable_Renderer_Csv();
$render->setTable($dataTable);
$render->convertToUnicode = false;
$expected = "label,bool,goals_idgoal=1_revenue,goals_idgoal=1_nb_conversions,nb_uniq_visitors,nb_visits,nb_actions,max_actions,sum_visit_length,bounce_count,metadata_url,metadata_logo\n" .
- "Google©,0,5.5,10,11,11,17,5,517,9,\"http://www.google.com/display\"\"and,properly\",./plugins/Referers/images/searchEngines/www.google.com.png\n" .
- "Yahoo!,1,,,15,151,147,50,517,90,http://www.yahoo.com,./plugins/Referers/images/searchEngines/www.yahoo.com.png";
+ "Google©,0,5.5,10,11,11,17,5,517,9,\"http://www.google.com/display\"\"and,properly\",./plugins/Referers/images/searchEngines/www.google.com.png\n" .
+ "Yahoo!,1,,,15,151,147,50,517,90,http://www.yahoo.com,./plugins/Referers/images/searchEngines/www.yahoo.com.png";
$rendered = $render->render();
$this->assertEquals($expected, $rendered);
@@ -198,26 +198,26 @@ class DataTable_Renderer_CSVTest extends PHPUnit_Framework_TestCase
protected function _getDataTableArrayTest()
{
- $array1 = array (
- array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'Google', 'nb_uniq_visitors' => 11, 'nb_visits' => 11, ),
- Piwik_DataTable_Row::METADATA => array('url' => 'http://www.google.com', 'logo' => './plugins/Referers/images/searchEngines/www.google.com.png'),
- ),
- array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'Yahoo!', 'nb_uniq_visitors' => 15, 'nb_visits' => 151, ),
- Piwik_DataTable_Row::METADATA => array('url' => 'http://www.yahoo.com', 'logo' => './plugins/Referers/images/searchEngines/www.yahoo.com.png'),
- )
- );
+ $array1 = array(
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'Google', 'nb_uniq_visitors' => 11, 'nb_visits' => 11,),
+ Piwik_DataTable_Row::METADATA => array('url' => 'http://www.google.com', 'logo' => './plugins/Referers/images/searchEngines/www.google.com.png'),
+ ),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'Yahoo!', 'nb_uniq_visitors' => 15, 'nb_visits' => 151,),
+ Piwik_DataTable_Row::METADATA => array('url' => 'http://www.yahoo.com', 'logo' => './plugins/Referers/images/searchEngines/www.yahoo.com.png'),
+ )
+ );
$table1 = new Piwik_DataTable();
$table1->addRowsFromArray($array1);
- $array2 = array (
- array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'Google1&copy;', 'nb_uniq_visitors' => 110, 'nb_visits' => 110,),
- Piwik_DataTable_Row::METADATA => array('url' => 'http://www.google.com1', 'logo' => './plugins/Referers/images/searchEngines/www.google.com.png1'),
- ),
- array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'Yahoo!1', 'nb_uniq_visitors' => 150, 'nb_visits' => 1510,),
- Piwik_DataTable_Row::METADATA => array('url' => 'http://www.yahoo.com1', 'logo' => './plugins/Referers/images/searchEngines/www.yahoo.com.png1'),
- )
- );
+ $array2 = array(
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'Google1&copy;', 'nb_uniq_visitors' => 110, 'nb_visits' => 110,),
+ Piwik_DataTable_Row::METADATA => array('url' => 'http://www.google.com1', 'logo' => './plugins/Referers/images/searchEngines/www.google.com.png1'),
+ ),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'Yahoo!1', 'nb_uniq_visitors' => 150, 'nb_visits' => 1510,),
+ Piwik_DataTable_Row::METADATA => array('url' => 'http://www.yahoo.com1', 'logo' => './plugins/Referers/images/searchEngines/www.yahoo.com.png1'),
+ )
+ );
$table2 = new Piwik_DataTable();
$table2->addRowsFromArray($array2);
@@ -235,11 +235,11 @@ class DataTable_Renderer_CSVTest extends PHPUnit_Framework_TestCase
protected function _getDataTableSimpleArrayTest()
{
- $array1 = array ( 'max_actions' => 14.0, 'nb_uniq_visitors' => 57.0, );
+ $array1 = array('max_actions' => 14.0, 'nb_uniq_visitors' => 57.0,);
$table1 = new Piwik_DataTable_Simple;
$table1->addRowsFromArray($array1);
- $array2 = array ( 'max_actions' => 140.0, 'nb_uniq_visitors' => 570.0, );
+ $array2 = array('max_actions' => 140.0, 'nb_uniq_visitors' => 570.0,);
$table2 = new Piwik_DataTable_Simple;
$table2->addRowsFromArray($array2);
@@ -256,10 +256,10 @@ class DataTable_Renderer_CSVTest extends PHPUnit_Framework_TestCase
protected function _getDataTableSimpleOneRowArrayTest()
{
- $array1 = array ( 'nb_visits' => 14.0 );
+ $array1 = array('nb_visits' => 14.0);
$table1 = new Piwik_DataTable_Simple;
$table1->addRowsFromArray($array1);
- $array2 = array ( 'nb_visits' => 15.0 );
+ $array2 = array('nb_visits' => 15.0);
$table2 = new Piwik_DataTable_Simple;
$table2->addRowsFromArray($array2);
@@ -311,10 +311,10 @@ class DataTable_Renderer_CSVTest extends PHPUnit_Framework_TestCase
$render->setTable($dataTable);
$render->convertToUnicode = false;
$expected = "testKey,label,nb_uniq_visitors,nb_visits,metadata_url,metadata_logo\n" .
- "date1,Google,11,11,http://www.google.com,./plugins/Referers/images/searchEngines/www.google.com.png\n" .
- "date1,Yahoo!,15,151,http://www.yahoo.com,./plugins/Referers/images/searchEngines/www.yahoo.com.png\n" .
- "date2,Google1©,110,110,http://www.google.com1,./plugins/Referers/images/searchEngines/www.google.com.png1\n" .
- "date2,Yahoo!1,150,1510,http://www.yahoo.com1,./plugins/Referers/images/searchEngines/www.yahoo.com.png1";
+ "date1,Google,11,11,http://www.google.com,./plugins/Referers/images/searchEngines/www.google.com.png\n" .
+ "date1,Yahoo!,15,151,http://www.yahoo.com,./plugins/Referers/images/searchEngines/www.yahoo.com.png\n" .
+ "date2,Google1©,110,110,http://www.google.com1,./plugins/Referers/images/searchEngines/www.google.com.png1\n" .
+ "date2,Yahoo!1,150,1510,http://www.yahoo.com1,./plugins/Referers/images/searchEngines/www.yahoo.com.png1";
$rendered = $render->render();
$this->assertEquals($expected, $rendered);
@@ -368,13 +368,13 @@ class DataTable_Renderer_CSVTest extends PHPUnit_Framework_TestCase
$render->setTable($dataTable);
$render->convertToUnicode = false;
$expected = "parentArrayKey,testKey,label,nb_uniq_visitors,nb_visits,metadata_url,metadata_logo\n" .
- "idSite,date1,Google,11,11,http://www.google.com,./plugins/Referers/images/searchEngines/www.google.com.png\n" .
- "idSite,date1,Yahoo!,15,151,http://www.yahoo.com,./plugins/Referers/images/searchEngines/www.yahoo.com.png\n" .
- "idSite,date2,Google1©,110,110,http://www.google.com1,./plugins/Referers/images/searchEngines/www.google.com.png1\n" .
- "idSite,date2,Yahoo!1,150,1510,http://www.yahoo.com1,./plugins/Referers/images/searchEngines/www.yahoo.com.png1";
+ "idSite,date1,Google,11,11,http://www.google.com,./plugins/Referers/images/searchEngines/www.google.com.png\n" .
+ "idSite,date1,Yahoo!,15,151,http://www.yahoo.com,./plugins/Referers/images/searchEngines/www.yahoo.com.png\n" .
+ "idSite,date2,Google1©,110,110,http://www.google.com1,./plugins/Referers/images/searchEngines/www.google.com.png1\n" .
+ "idSite,date2,Yahoo!1,150,1510,http://www.yahoo.com1,./plugins/Referers/images/searchEngines/www.yahoo.com.png1";
$rendered = $render->render();
- $this->assertEquals( $expected,$rendered);
+ $this->assertEquals($expected, $rendered);
}
/**
@@ -411,79 +411,79 @@ class DataTable_Renderer_CSVTest extends PHPUnit_Framework_TestCase
$rendered = $render->render();
$this->assertEquals($expected, $rendered);
}
-
- /**
- * @group Core
- * @group DataTable
- * @group DataTable_Renderer
- * @group DataTable_Renderer_XML
- */
- public function testRenderArray1()
- {
- $data = array();
-
+
+ /**
+ * @group Core
+ * @group DataTable
+ * @group DataTable_Renderer
+ * @group DataTable_Renderer_XML
+ */
+ public function testRenderArray1()
+ {
+ $data = array();
+
$render = new Piwik_DataTable_Renderer_Csv();
$render->setTable($data);
$render->convertToUnicode = false;
$expected = 'No data available';
-
+
$this->assertEquals($expected, $render->render());
- }
-
- /**
- * @group Core
- * @group DataTable
- * @group DataTable_Renderer
- * @group DataTable_Renderer_XML
- */
- public function testRenderArray2()
- {
- $data = array('a', 'b', 'c');
-
+ }
+
+ /**
+ * @group Core
+ * @group DataTable
+ * @group DataTable_Renderer
+ * @group DataTable_Renderer_XML
+ */
+ public function testRenderArray2()
+ {
+ $data = array('a', 'b', 'c');
+
$render = new Piwik_DataTable_Renderer_Csv();
$render->setTable($data);
$render->convertToUnicode = false;
$expected = 'a
b
c';
-
+
$this->assertEquals($expected, $render->render());
- }
-
- /**
- * @group Core
- * @group DataTable
- * @group DataTable_Renderer
- * @group DataTable_Renderer_XML
- */
- public function testRenderArray3()
- {
- $data = array('a' => 'b', 'c' => 'd', 'e' => 'f', 5 => 'g');
-
+ }
+
+ /**
+ * @group Core
+ * @group DataTable
+ * @group DataTable_Renderer
+ * @group DataTable_Renderer_XML
+ */
+ public function testRenderArray3()
+ {
+ $data = array('a' => 'b', 'c' => 'd', 'e' => 'f', 5 => 'g');
+
$render = new Piwik_DataTable_Renderer_Csv();
$render->setTable($data);
$render->convertToUnicode = false;
$expected = 'a,c,e,5
b,d,f,g';
-
+
$this->assertEquals($expected, $render->render());
- }
-
- /**
- * @group Core
- * @group DataTable
- * @group DataTable_Renderer
- * @group DataTable_Renderer_XML
- */
- public function testRenderArray4()
- {
- $data = array('a' => 'b');
-
+ }
+
+ /**
+ * @group Core
+ * @group DataTable
+ * @group DataTable_Renderer
+ * @group DataTable_Renderer_XML
+ */
+ public function testRenderArray4()
+ {
+ $data = array('a' => 'b');
+
$render = new Piwik_DataTable_Renderer_Csv();
$render->setTable($data);
$render->convertToUnicode = false;
$expected = 'b';
-
+
$this->assertEquals($expected, $render->render());
- }
+ }
}
diff --git a/tests/PHPUnit/Core/DataTable/Renderer/ConsoleTest.php b/tests/PHPUnit/Core/DataTable/Renderer/ConsoleTest.php
index 9821a8af20..9af0b9b640 100644
--- a/tests/PHPUnit/Core/DataTable/Renderer/ConsoleTest.php
+++ b/tests/PHPUnit/Core/DataTable/Renderer/ConsoleTest.php
@@ -26,30 +26,30 @@ class DataTable_Renderer_ConsoleTest extends PHPUnit_Framework_TestCase
public function testConsole2SubLevelAnd2Different()
{
$table = new Piwik_DataTable;
- $table->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array( 'visits'=>245,'visitors'=>245),
- Piwik_DataTable_Row::METADATA => array('logo' => 'test.png'),)
+ $table->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array('visits' => 245, 'visitors' => 245),
+ Piwik_DataTable_Row::METADATA => array('logo' => 'test.png'),)
);
$subsubtable = new Piwik_DataTable;
$idsubsubtable = $subsubtable->getId();
- $subsubtable->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array( 'visits'=>2)));
+ $subsubtable->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array('visits' => 2)));
$subtable = new Piwik_DataTable;
$idsubtable1 = $subtable->getId();
- $subtable->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array( 'visits'=>1),
- Piwik_DataTable_Row::DATATABLE_ASSOCIATED => $subsubtable));
+ $subtable->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array('visits' => 1),
+ Piwik_DataTable_Row::DATATABLE_ASSOCIATED => $subsubtable));
- $table->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array( 'visits'=>3),
- Piwik_DataTable_Row::DATATABLE_ASSOCIATED => $subtable)
+ $table->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array('visits' => 3),
+ Piwik_DataTable_Row::DATATABLE_ASSOCIATED => $subtable)
);
$subtable2 = new Piwik_DataTable;
$idsubtable2 = $subtable2->getId();
- $subtable2->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array( 'visits'=>5),));
+ $subtable2->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array('visits' => 5),));
- $table->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array( 'visits'=>9),
- Piwik_DataTable_Row::DATATABLE_ASSOCIATED => $subtable2)
+ $table->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array('visits' => 9),
+ Piwik_DataTable_Row::DATATABLE_ASSOCIATED => $subtable2)
);
$expected = "- 1 ['visits' => 245, 'visitors' => 245] ['logo' => 'test.png'] [idsubtable = ]<br />\n- 2 ['visits' => 3] [] [idsubtable = $idsubtable1]<br />\n*- 1 ['visits' => 1] [] [idsubtable = $idsubsubtable]<br />\n**- 1 ['visits' => 2] [] [idsubtable = ]<br />\n- 3 ['visits' => 9] [] [idsubtable = $idsubtable2]<br />\n*- 1 ['visits' => 5] [] [idsubtable = ]<br />\n";
@@ -74,8 +74,8 @@ class DataTable_Renderer_ConsoleTest extends PHPUnit_Framework_TestCase
public function testConsoleSimple()
{
$table = new Piwik_DataTable;
- $table->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array( 'visits'=>245,'visitors'=>245),
- Piwik_DataTable_Row::METADATA => array('logo' => 'test.png'),)
+ $table->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array('visits' => 245, 'visitors' => 245),
+ Piwik_DataTable_Row::METADATA => array('logo' => 'test.png'),)
);
@@ -88,77 +88,77 @@ class DataTable_Renderer_ConsoleTest extends PHPUnit_Framework_TestCase
$this->assertEquals($expected, $rendered);
}
- /**
- * @group Core
- * @group DataTable
- * @group DataTable_Renderer
- * @group DataTable_Renderer_XML
- */
- public function testRenderArray1()
- {
- $data = array();
-
+ /**
+ * @group Core
+ * @group DataTable
+ * @group DataTable_Renderer
+ * @group DataTable_Renderer_XML
+ */
+ public function testRenderArray1()
+ {
+ $data = array();
+
$render = new Piwik_DataTable_Renderer_Console();
$render->setTable($data);
$expected = 'Empty table<br />
';
-
+
$this->assertEquals($expected, $render->render());
- }
-
- /**
- * @group Core
- * @group DataTable
- * @group DataTable_Renderer
- * @group DataTable_Renderer_XML
- */
- public function testRenderArray2()
- {
- $data = array('a', 'b', 'c');
-
+ }
+
+ /**
+ * @group Core
+ * @group DataTable
+ * @group DataTable_Renderer
+ * @group DataTable_Renderer_XML
+ */
+ public function testRenderArray2()
+ {
+ $data = array('a', 'b', 'c');
+
$render = new Piwik_DataTable_Renderer_Console();
$render->setTable($data);
$expected = "- 1 ['0' => 'a'] [] [idsubtable = ]<br />
- 2 ['0' => 'b'] [] [idsubtable = ]<br />
- 3 ['0' => 'c'] [] [idsubtable = ]<br />
";
-
+
$this->assertEquals($expected, $render->render());
- }
-
- /**
- * @group Core
- * @group DataTable
- * @group DataTable_Renderer
- * @group DataTable_Renderer_XML
- */
- public function testRenderArray3()
- {
- $data = array('a' => 'b', 'c' => 'd', 'e' => 'f', 5 => 'g');
-
+ }
+
+ /**
+ * @group Core
+ * @group DataTable
+ * @group DataTable_Renderer
+ * @group DataTable_Renderer_XML
+ */
+ public function testRenderArray3()
+ {
+ $data = array('a' => 'b', 'c' => 'd', 'e' => 'f', 5 => 'g');
+
$render = new Piwik_DataTable_Renderer_Console();
$render->setTable($data);
$expected = "- 1 ['a' => 'b', 'c' => 'd', 'e' => 'f', '5' => 'g'] [] [idsubtable = ]<br />
";
-
+
$this->assertEquals($expected, $render->render());
- }
-
- /**
- * @group Core
- * @group DataTable
- * @group DataTable_Renderer
- * @group DataTable_Renderer_XML
- */
- public function testRenderArray4()
- {
- $data = array('a' => 'b');
-
+ }
+
+ /**
+ * @group Core
+ * @group DataTable
+ * @group DataTable_Renderer
+ * @group DataTable_Renderer_XML
+ */
+ public function testRenderArray4()
+ {
+ $data = array('a' => 'b');
+
$render = new Piwik_DataTable_Renderer_Console();
$render->setTable($data);
$expected = "- 1 ['0' => 'b'] [] [idsubtable = ]<br />
";
-
+
$this->assertEquals($expected, $render->render());
- }
+ }
}
diff --git a/tests/PHPUnit/Core/DataTable/Renderer/JSONTest.php b/tests/PHPUnit/Core/DataTable/Renderer/JSONTest.php
index d03e0226bf..1572ce1097 100644
--- a/tests/PHPUnit/Core/DataTable/Renderer/JSONTest.php
+++ b/tests/PHPUnit/Core/DataTable/Renderer/JSONTest.php
@@ -23,30 +23,30 @@ class DataTable_Renderer_JSONTest extends PHPUnit_Framework_TestCase
protected function _getDataTableTest()
{
$dataTable = new Piwik_DataTable();
-
- $arraySubTableForRow2 = array (
- array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'sub1', 'count' => 1, 'bool' => false) ),
- array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'sub2', 'count' => 2, 'bool' => true) ),
+
+ $arraySubTableForRow2 = array(
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'sub1', 'count' => 1, 'bool' => false)),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'sub2', 'count' => 2, 'bool' => true)),
);
$subDataTableForRow2 = new Piwik_DataTable();
$subDataTableForRow2->addRowsFromArray($arraySubTableForRow2);
- $array = array (
- array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'Google&copy;', 'bool' => false, 'goals' => array('idgoal=1' => array('revenue'=> 5.5, 'nb_conversions' => 10)), 'nb_uniq_visitors' => 11, 'nb_visits' => 11, 'nb_actions' => 17, 'max_actions' => '5', 'sum_visit_length' => 517, 'bounce_count' => 9),
- Piwik_DataTable_Row::METADATA => array('url' => 'http://www.google.com/display"and,properly', 'logo' => './plugins/Referers/images/searchEngines/www.google.com.png'),
- ),
- array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'Yahoo!', 'nb_uniq_visitors' => 15, 'bool' => true, 'nb_visits' => 151, 'nb_actions' => 147, 'max_actions' => '50', 'sum_visit_length' => 517, 'bounce_count' => 90),
- Piwik_DataTable_Row::METADATA => array('url' => 'http://www.yahoo.com', 'logo' => './plugins/Referers/images/searchEngines/www.yahoo.com.png'),
- Piwik_DataTable_Row::DATATABLE_ASSOCIATED => $subDataTableForRow2,
- )
- );
+ $array = array(
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'Google&copy;', 'bool' => false, 'goals' => array('idgoal=1' => array('revenue' => 5.5, 'nb_conversions' => 10)), 'nb_uniq_visitors' => 11, 'nb_visits' => 11, 'nb_actions' => 17, 'max_actions' => '5', 'sum_visit_length' => 517, 'bounce_count' => 9),
+ Piwik_DataTable_Row::METADATA => array('url' => 'http://www.google.com/display"and,properly', 'logo' => './plugins/Referers/images/searchEngines/www.google.com.png'),
+ ),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'Yahoo!', 'nb_uniq_visitors' => 15, 'bool' => true, 'nb_visits' => 151, 'nb_actions' => 147, 'max_actions' => '50', 'sum_visit_length' => 517, 'bounce_count' => 90),
+ Piwik_DataTable_Row::METADATA => array('url' => 'http://www.yahoo.com', 'logo' => './plugins/Referers/images/searchEngines/www.yahoo.com.png'),
+ Piwik_DataTable_Row::DATATABLE_ASSOCIATED => $subDataTableForRow2,
+ )
+ );
$dataTable->addRowsFromArray($array);
return $dataTable;
}
protected function _getDataTableSimpleTest()
{
- $array = array ( 'max_actions' => 14.0, 'nb_uniq_visitors' => 57.0, 'nb_visits' => 66.0, 'nb_actions' => 151.0, 'sum_visit_length' => 5118.0, 'bounce_count' => 44.0, );
+ $array = array('max_actions' => 14.0, 'nb_uniq_visitors' => 57.0, 'nb_visits' => 66.0, 'nb_actions' => 151.0, 'sum_visit_length' => 5118.0, 'bounce_count' => 44.0,);
$table = new Piwik_DataTable_Simple;
$table->addRowsFromArray($array);
@@ -55,7 +55,7 @@ class DataTable_Renderer_JSONTest extends PHPUnit_Framework_TestCase
protected function _getDataTableSimpleOneRowTest()
{
- $array = array ( 'nb_visits' => 14.0 );
+ $array = array('nb_visits' => 14.0);
$table = new Piwik_DataTable_Simple;
$table->addRowsFromArray($array);
@@ -70,7 +70,7 @@ class DataTable_Renderer_JSONTest extends PHPUnit_Framework_TestCase
protected function _getDataTableSimpleOneZeroRowTest()
{
- $array = array ( 'nb_visits' => 0 );
+ $array = array('nb_visits' => 0);
$table = new Piwik_DataTable_Simple;
$table->addRowsFromArray($array);
return $table;
@@ -78,7 +78,7 @@ class DataTable_Renderer_JSONTest extends PHPUnit_Framework_TestCase
protected function _getDataTableSimpleOneFalseRowTest()
{
- $array = array ( 'is_excluded' => false );
+ $array = array('is_excluded' => false);
$table = new Piwik_DataTable_Simple;
$table->addRowsFromArray($array);
return $table;
@@ -186,26 +186,26 @@ class DataTable_Renderer_JSONTest extends PHPUnit_Framework_TestCase
protected function _getDataTableArrayTest()
{
- $array1 = array (
- array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'Google', 'nb_uniq_visitors' => 11, 'nb_visits' => 11, ),
- Piwik_DataTable_Row::METADATA => array('url' => 'http://www.google.com', 'logo' => './plugins/Referers/images/searchEngines/www.google.com.png'),
- ),
- array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'Yahoo!', 'nb_uniq_visitors' => 15, 'nb_visits' => 151, ),
- Piwik_DataTable_Row::METADATA => array('url' => 'http://www.yahoo.com', 'logo' => './plugins/Referers/images/searchEngines/www.yahoo.com.png'),
- )
- );
+ $array1 = array(
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'Google', 'nb_uniq_visitors' => 11, 'nb_visits' => 11,),
+ Piwik_DataTable_Row::METADATA => array('url' => 'http://www.google.com', 'logo' => './plugins/Referers/images/searchEngines/www.google.com.png'),
+ ),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'Yahoo!', 'nb_uniq_visitors' => 15, 'nb_visits' => 151,),
+ Piwik_DataTable_Row::METADATA => array('url' => 'http://www.yahoo.com', 'logo' => './plugins/Referers/images/searchEngines/www.yahoo.com.png'),
+ )
+ );
$table1 = new Piwik_DataTable();
$table1->addRowsFromArray($array1);
- $array2 = array (
- array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'Google1&copy;', 'nb_uniq_visitors' => 110, 'nb_visits' => 110,),
- Piwik_DataTable_Row::METADATA => array('url' => 'http://www.google.com1', 'logo' => './plugins/Referers/images/searchEngines/www.google.com.png1'),
- ),
- array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'Yahoo!1', 'nb_uniq_visitors' => 150, 'nb_visits' => 1510,),
- Piwik_DataTable_Row::METADATA => array('url' => 'http://www.yahoo.com1', 'logo' => './plugins/Referers/images/searchEngines/www.yahoo.com.png1'),
- )
- );
+ $array2 = array(
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'Google1&copy;', 'nb_uniq_visitors' => 110, 'nb_visits' => 110,),
+ Piwik_DataTable_Row::METADATA => array('url' => 'http://www.google.com1', 'logo' => './plugins/Referers/images/searchEngines/www.google.com.png1'),
+ ),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'Yahoo!1', 'nb_uniq_visitors' => 150, 'nb_visits' => 1510,),
+ Piwik_DataTable_Row::METADATA => array('url' => 'http://www.yahoo.com1', 'logo' => './plugins/Referers/images/searchEngines/www.yahoo.com.png1'),
+ )
+ );
$table2 = new Piwik_DataTable();
$table2->addRowsFromArray($array2);
@@ -223,11 +223,11 @@ class DataTable_Renderer_JSONTest extends PHPUnit_Framework_TestCase
protected function _getDataTableSimpleArrayTest()
{
- $array1 = array ( 'max_actions' => 14.0, 'nb_uniq_visitors' => 57.0, );
+ $array1 = array('max_actions' => 14.0, 'nb_uniq_visitors' => 57.0,);
$table1 = new Piwik_DataTable_Simple;
$table1->addRowsFromArray($array1);
- $array2 = array ( 'max_actions' => 140.0, 'nb_uniq_visitors' => 570.0, );
+ $array2 = array('max_actions' => 140.0, 'nb_uniq_visitors' => 570.0,);
$table2 = new Piwik_DataTable_Simple;
$table2->addRowsFromArray($array2);
@@ -244,10 +244,10 @@ class DataTable_Renderer_JSONTest extends PHPUnit_Framework_TestCase
protected function _getDataTableSimpleOneRowArrayTest()
{
- $array1 = array ( 'nb_visits' => 14.0 );
+ $array1 = array('nb_visits' => 14.0);
$table1 = new Piwik_DataTable_Simple;
$table1->addRowsFromArray($array1);
- $array2 = array ( 'nb_visits' => 15.0 );
+ $array2 = array('nb_visits' => 15.0);
$table2 = new Piwik_DataTable_Simple;
$table2->addRowsFromArray($array2);
@@ -390,89 +390,89 @@ class DataTable_Renderer_JSONTest extends PHPUnit_Framework_TestCase
$this->assertEquals($expected, $rendered);
}
- /**
- * @group Core
- * @group DataTable
- * @group DataTable_Renderer
- * @group DataTable_Renderer_XML
- */
- public function testRenderArray1()
- {
- $data = array();
-
+ /**
+ * @group Core
+ * @group DataTable
+ * @group DataTable_Renderer
+ * @group DataTable_Renderer_XML
+ */
+ public function testRenderArray1()
+ {
+ $data = array();
+
$render = new Piwik_DataTable_Renderer_Json();
$render->setTable($data);
$expected = '[]';
-
+
$this->assertEquals($expected, $render->render());
- }
-
- /**
- * @group Core
- * @group DataTable
- * @group DataTable_Renderer
- * @group DataTable_Renderer_JSON
- */
- public function testRenderArray2()
- {
- $data = array('a', 'b', 'c', array('a' => 'b'), array(1, 2));
-
+ }
+
+ /**
+ * @group Core
+ * @group DataTable
+ * @group DataTable_Renderer
+ * @group DataTable_Renderer_JSON
+ */
+ public function testRenderArray2()
+ {
+ $data = array('a', 'b', 'c', array('a' => 'b'), array(1, 2));
+
$render = new Piwik_DataTable_Renderer_Json();
$render->setTable($data);
$expected = '["a","b","c",{"a":"b"},[1,2]]';
-
+
$this->assertEquals($expected, $render->render());
- }
-
- /**
- * @group Core
- * @group DataTable
- * @group DataTable_Renderer
- * @group DataTable_Renderer_JSON
- */
- public function testRenderArray3()
- {
- $data = array('a' => 'b', 'c' => 'd', 'e' => 'f', 5 => 'g');
-
+ }
+
+ /**
+ * @group Core
+ * @group DataTable
+ * @group DataTable_Renderer
+ * @group DataTable_Renderer_JSON
+ */
+ public function testRenderArray3()
+ {
+ $data = array('a' => 'b', 'c' => 'd', 'e' => 'f', 5 => 'g');
+
$render = new Piwik_DataTable_Renderer_Json();
$render->setTable($data);
$expected = '[{"a":"b","c":"d","e":"f","5":"g"}]';
-
+
$this->assertEquals($expected, $render->render());
- }
-
- /**
- * @group Core
- * @group DataTable
- * @group DataTable_Renderer
- * @group DataTable_Renderer_JSON
- */
- public function testRenderArray4()
- {
- $data = array('a' => 'b', 'c' => array(1,2,3,4), 'e' => array('f' => 'g', 'h' => 'i', 'j' => 'k'));
-
+ }
+
+ /**
+ * @group Core
+ * @group DataTable
+ * @group DataTable_Renderer
+ * @group DataTable_Renderer_JSON
+ */
+ public function testRenderArray4()
+ {
+ $data = array('a' => 'b', 'c' => array(1, 2, 3, 4), 'e' => array('f' => 'g', 'h' => 'i', 'j' => 'k'));
+
$render = new Piwik_DataTable_Renderer_Json();
$render->setTable($data);
$expected = '{"a":"b","c":[1,2,3,4],"e":{"f":"g","h":"i","j":"k"}}';
-
+
$this->assertEquals($expected, $render->render());
- }
-
- /**
- * @group Core
- * @group DataTable
- * @group DataTable_Renderer
- * @group DataTable_Renderer_JSON
- */
- public function testRenderArray5()
- {
- $data = array('a' => 'b');
-
+ }
+
+ /**
+ * @group Core
+ * @group DataTable
+ * @group DataTable_Renderer
+ * @group DataTable_Renderer_JSON
+ */
+ public function testRenderArray5()
+ {
+ $data = array('a' => 'b');
+
$render = new Piwik_DataTable_Renderer_Json();
- $render->setTable($data);
- $expected = '[{"a":"b"}]';
-
+ $render->setTable($data);
+ $expected = '[{"a":"b"}]';
+
$this->assertEquals($expected, $render->render());
- }
+ }
}
diff --git a/tests/PHPUnit/Core/DataTable/Renderer/PHPTest.php b/tests/PHPUnit/Core/DataTable/Renderer/PHPTest.php
index 249a19ec5b..3058a513dd 100644
--- a/tests/PHPUnit/Core/DataTable/Renderer/PHPTest.php
+++ b/tests/PHPUnit/Core/DataTable/Renderer/PHPTest.php
@@ -23,30 +23,30 @@ class DataTable_Renderer_PHPTest extends PHPUnit_Framework_TestCase
protected function _getDataTableTest()
{
$dataTable = new Piwik_DataTable();
-
- $arraySubTableForRow2 = array (
- array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'sub1', 'count' => 1, 'bool' => false) ),
- array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'sub2', 'count' => 2, 'bool' => true) ),
+
+ $arraySubTableForRow2 = array(
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'sub1', 'count' => 1, 'bool' => false)),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'sub2', 'count' => 2, 'bool' => true)),
);
$subDataTableForRow2 = new Piwik_DataTable();
$subDataTableForRow2->addRowsFromArray($arraySubTableForRow2);
- $array = array (
- array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'Google&copy;', 'bool' => false, 'goals' => array('idgoal=1' => array('revenue'=> 5.5, 'nb_conversions' => 10)), 'nb_uniq_visitors' => 11, 'nb_visits' => 11, 'nb_actions' => 17, 'max_actions' => '5', 'sum_visit_length' => 517, 'bounce_count' => 9),
- Piwik_DataTable_Row::METADATA => array('url' => 'http://www.google.com/display"and,properly', 'logo' => './plugins/Referers/images/searchEngines/www.google.com.png'),
- ),
- array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'Yahoo!', 'nb_uniq_visitors' => 15, 'bool' => true, 'nb_visits' => 151, 'nb_actions' => 147, 'max_actions' => '50', 'sum_visit_length' => 517, 'bounce_count' => 90),
- Piwik_DataTable_Row::METADATA => array('url' => 'http://www.yahoo.com', 'logo' => './plugins/Referers/images/searchEngines/www.yahoo.com.png'),
- Piwik_DataTable_Row::DATATABLE_ASSOCIATED => $subDataTableForRow2,
- )
- );
+ $array = array(
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'Google&copy;', 'bool' => false, 'goals' => array('idgoal=1' => array('revenue' => 5.5, 'nb_conversions' => 10)), 'nb_uniq_visitors' => 11, 'nb_visits' => 11, 'nb_actions' => 17, 'max_actions' => '5', 'sum_visit_length' => 517, 'bounce_count' => 9),
+ Piwik_DataTable_Row::METADATA => array('url' => 'http://www.google.com/display"and,properly', 'logo' => './plugins/Referers/images/searchEngines/www.google.com.png'),
+ ),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'Yahoo!', 'nb_uniq_visitors' => 15, 'bool' => true, 'nb_visits' => 151, 'nb_actions' => 147, 'max_actions' => '50', 'sum_visit_length' => 517, 'bounce_count' => 90),
+ Piwik_DataTable_Row::METADATA => array('url' => 'http://www.yahoo.com', 'logo' => './plugins/Referers/images/searchEngines/www.yahoo.com.png'),
+ Piwik_DataTable_Row::DATATABLE_ASSOCIATED => $subDataTableForRow2,
+ )
+ );
$dataTable->addRowsFromArray($array);
return $dataTable;
}
protected function _getDataTableSimpleTest()
{
- $array = array ( 'max_actions' => 14.0, 'nb_uniq_visitors' => 57.0, 'nb_visits' => 66.0, 'nb_actions' => 151.0, 'sum_visit_length' => 5118.0, 'bounce_count' => 44.0, );
+ $array = array('max_actions' => 14.0, 'nb_uniq_visitors' => 57.0, 'nb_visits' => 66.0, 'nb_actions' => 151.0, 'sum_visit_length' => 5118.0, 'bounce_count' => 44.0,);
$table = new Piwik_DataTable_Simple;
$table->addRowsFromArray($array);
@@ -55,7 +55,7 @@ class DataTable_Renderer_PHPTest extends PHPUnit_Framework_TestCase
protected function _getDataTableSimpleOneRowTest()
{
- $array = array ( 'nb_visits' => 14.0 );
+ $array = array('nb_visits' => 14.0);
$table = new Piwik_DataTable_Simple;
$table->addRowsFromArray($array);
@@ -70,7 +70,7 @@ class DataTable_Renderer_PHPTest extends PHPUnit_Framework_TestCase
protected function _getDataTableSimpleOneZeroRowTest()
{
- $array = array ( 'nb_visits' => 0 );
+ $array = array('nb_visits' => 0);
$table = new Piwik_DataTable_Simple;
$table->addRowsFromArray($array);
return $table;
@@ -78,7 +78,7 @@ class DataTable_Renderer_PHPTest extends PHPUnit_Framework_TestCase
protected function _getDataTableSimpleOneFalseRowTest()
{
- $array = array ( 'is_excluded' => false );
+ $array = array('is_excluded' => false);
$table = new Piwik_DataTable_Simple;
$table->addRowsFromArray($array);
return $table;
@@ -98,56 +98,56 @@ class DataTable_Renderer_PHPTest extends PHPUnit_Framework_TestCase
$render->setTable($dataTable);
$render->setRenderSubTables(true);
- $expected = serialize(array (
- 0 =>
- array (
- 'label' => 'Google&copy;',
- 'bool' => false,
- 'goals' => array(
- 'idgoal=1' => array(
- 'revenue' => 5.5,
- 'nb_conversions' => 10,
- ),
- ),
- 'nb_uniq_visitors' => 11,
- 'nb_visits' => 11,
- 'nb_actions' => 17,
- 'max_actions' => '5',
- 'sum_visit_length' => 517,
- 'bounce_count' => 9,
- 'url' => 'http://www.google.com/display"and,properly',
- 'logo' => './plugins/Referers/images/searchEngines/www.google.com.png',
- ),
- 1 =>
- array (
- 'label' => 'Yahoo!',
- 'nb_uniq_visitors' => 15,
- 'bool' => true,
- 'nb_visits' => 151,
- 'nb_actions' => 147,
- 'max_actions' => '50',
- 'sum_visit_length' => 517,
- 'bounce_count' => 90,
- 'url' => 'http://www.yahoo.com',
- 'logo' => './plugins/Referers/images/searchEngines/www.yahoo.com.png',
- 'idsubdatatable' => 2,
- 'subtable' =>
- array (
- 0 =>
- array (
- 'label' => 'sub1',
- 'count' => 1,
- 'bool' => false,
- ),
- 1 =>
- array (
- 'label' => 'sub2',
- 'count' => 2,
- 'bool' => true,
- ),
- ),
- ),
- ));
+ $expected = serialize(array(
+ 0 =>
+ array(
+ 'label' => 'Google&copy;',
+ 'bool' => false,
+ 'goals' => array(
+ 'idgoal=1' => array(
+ 'revenue' => 5.5,
+ 'nb_conversions' => 10,
+ ),
+ ),
+ 'nb_uniq_visitors' => 11,
+ 'nb_visits' => 11,
+ 'nb_actions' => 17,
+ 'max_actions' => '5',
+ 'sum_visit_length' => 517,
+ 'bounce_count' => 9,
+ 'url' => 'http://www.google.com/display"and,properly',
+ 'logo' => './plugins/Referers/images/searchEngines/www.google.com.png',
+ ),
+ 1 =>
+ array(
+ 'label' => 'Yahoo!',
+ 'nb_uniq_visitors' => 15,
+ 'bool' => true,
+ 'nb_visits' => 151,
+ 'nb_actions' => 147,
+ 'max_actions' => '50',
+ 'sum_visit_length' => 517,
+ 'bounce_count' => 90,
+ 'url' => 'http://www.yahoo.com',
+ 'logo' => './plugins/Referers/images/searchEngines/www.yahoo.com.png',
+ 'idsubdatatable' => 2,
+ 'subtable' =>
+ array(
+ 0 =>
+ array(
+ 'label' => 'sub1',
+ 'count' => 1,
+ 'bool' => false,
+ ),
+ 1 =>
+ array(
+ 'label' => 'sub2',
+ 'count' => 2,
+ 'bool' => true,
+ ),
+ ),
+ ),
+ ));
$rendered = $render->render(null);
$this->assertEquals($expected, $rendered);
}
@@ -163,14 +163,14 @@ class DataTable_Renderer_PHPTest extends PHPUnit_Framework_TestCase
$dataTable = $this->_getDataTableSimpleTest();
$render = new Piwik_DataTable_Renderer_Php();
$render->setTable($dataTable);
- $expected = serialize(array (
- 'max_actions' => 14.0,
- 'nb_uniq_visitors' => 57.0,
- 'nb_visits' => 66.0,
- 'nb_actions' => 151.0,
- 'sum_visit_length' => 5118.0,
- 'bounce_count' => 44.0,
- ));
+ $expected = serialize(array(
+ 'max_actions' => 14.0,
+ 'nb_uniq_visitors' => 57.0,
+ 'nb_visits' => 66.0,
+ 'nb_actions' => 151.0,
+ 'sum_visit_length' => 5118.0,
+ 'bounce_count' => 44.0,
+ ));
$this->assertEquals($expected, $render->render());
}
@@ -242,26 +242,26 @@ class DataTable_Renderer_PHPTest extends PHPUnit_Framework_TestCase
protected function _getDataTableArrayTest()
{
- $array1 = array (
- array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'Google', 'nb_uniq_visitors' => 11, 'nb_visits' => 11, ),
- Piwik_DataTable_Row::METADATA => array('url' => 'http://www.google.com', 'logo' => './plugins/Referers/images/searchEngines/www.google.com.png'),
- ),
- array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'Yahoo!', 'nb_uniq_visitors' => 15, 'nb_visits' => 151, ),
- Piwik_DataTable_Row::METADATA => array('url' => 'http://www.yahoo.com', 'logo' => './plugins/Referers/images/searchEngines/www.yahoo.com.png'),
- )
- );
+ $array1 = array(
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'Google', 'nb_uniq_visitors' => 11, 'nb_visits' => 11,),
+ Piwik_DataTable_Row::METADATA => array('url' => 'http://www.google.com', 'logo' => './plugins/Referers/images/searchEngines/www.google.com.png'),
+ ),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'Yahoo!', 'nb_uniq_visitors' => 15, 'nb_visits' => 151,),
+ Piwik_DataTable_Row::METADATA => array('url' => 'http://www.yahoo.com', 'logo' => './plugins/Referers/images/searchEngines/www.yahoo.com.png'),
+ )
+ );
$table1 = new Piwik_DataTable();
$table1->addRowsFromArray($array1);
- $array2 = array (
- array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'Google1&copy;', 'nb_uniq_visitors' => 110, 'nb_visits' => 110,),
- Piwik_DataTable_Row::METADATA => array('url' => 'http://www.google.com1', 'logo' => './plugins/Referers/images/searchEngines/www.google.com.png1'),
- ),
- array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'Yahoo!1', 'nb_uniq_visitors' => 150, 'nb_visits' => 1510,),
- Piwik_DataTable_Row::METADATA => array('url' => 'http://www.yahoo.com1', 'logo' => './plugins/Referers/images/searchEngines/www.yahoo.com.png1'),
- )
- );
+ $array2 = array(
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'Google1&copy;', 'nb_uniq_visitors' => 110, 'nb_visits' => 110,),
+ Piwik_DataTable_Row::METADATA => array('url' => 'http://www.google.com1', 'logo' => './plugins/Referers/images/searchEngines/www.google.com.png1'),
+ ),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'Yahoo!1', 'nb_uniq_visitors' => 150, 'nb_visits' => 1510,),
+ Piwik_DataTable_Row::METADATA => array('url' => 'http://www.yahoo.com1', 'logo' => './plugins/Referers/images/searchEngines/www.yahoo.com.png1'),
+ )
+ );
$table2 = new Piwik_DataTable();
$table2->addRowsFromArray($array2);
@@ -279,11 +279,11 @@ class DataTable_Renderer_PHPTest extends PHPUnit_Framework_TestCase
protected function _getDataTableSimpleArrayTest()
{
- $array1 = array ( 'max_actions' => 14.0, 'nb_uniq_visitors' => 57.0, );
+ $array1 = array('max_actions' => 14.0, 'nb_uniq_visitors' => 57.0,);
$table1 = new Piwik_DataTable_Simple;
$table1->addRowsFromArray($array1);
- $array2 = array ( 'max_actions' => 140.0, 'nb_uniq_visitors' => 570.0, );
+ $array2 = array('max_actions' => 140.0, 'nb_uniq_visitors' => 570.0,);
$table2 = new Piwik_DataTable_Simple;
$table2->addRowsFromArray($array2);
@@ -300,10 +300,10 @@ class DataTable_Renderer_PHPTest extends PHPUnit_Framework_TestCase
protected function _getDataTableSimpleOneRowArrayTest()
{
- $array1 = array ( 'nb_visits' => 14.0 );
+ $array1 = array('nb_visits' => 14.0);
$table1 = new Piwik_DataTable_Simple;
$table1->addRowsFromArray($array1);
- $array2 = array ( 'nb_visits' => 15.0 );
+ $array2 = array('nb_visits' => 15.0);
$table2 = new Piwik_DataTable_Simple;
$table2->addRowsFromArray($array2);
@@ -356,47 +356,47 @@ class DataTable_Renderer_PHPTest extends PHPUnit_Framework_TestCase
$render->setTable($dataTable);
$rendered = $render->render();
- $expected = serialize(array (
- 'date1' =>
- array (
- 0 =>
- array (
- 'label' => 'Google',
- 'nb_uniq_visitors' => 11,
- 'nb_visits' => 11,
- 'url' => 'http://www.google.com',
- 'logo' => './plugins/Referers/images/searchEngines/www.google.com.png',
- ),
- 1 =>
- array (
- 'label' => 'Yahoo!',
- 'nb_uniq_visitors' => 15,
- 'nb_visits' => 151,
- 'url' => 'http://www.yahoo.com',
- 'logo' => './plugins/Referers/images/searchEngines/www.yahoo.com.png',
- ),
- ),
- 'date2' =>
- array (
- 0 =>
- array (
- 'label' => 'Google1&copy;',
- 'nb_uniq_visitors' => 110,
- 'nb_visits' => 110,
- 'url' => 'http://www.google.com1',
- 'logo' => './plugins/Referers/images/searchEngines/www.google.com.png1',
- ),
- 1 =>
- array (
- 'label' => 'Yahoo!1',
- 'nb_uniq_visitors' => 150,
- 'nb_visits' => 1510,
- 'url' => 'http://www.yahoo.com1',
- 'logo' => './plugins/Referers/images/searchEngines/www.yahoo.com.png1',
- ),
- ),
- 'date3' => array (),
- ));
+ $expected = serialize(array(
+ 'date1' =>
+ array(
+ 0 =>
+ array(
+ 'label' => 'Google',
+ 'nb_uniq_visitors' => 11,
+ 'nb_visits' => 11,
+ 'url' => 'http://www.google.com',
+ 'logo' => './plugins/Referers/images/searchEngines/www.google.com.png',
+ ),
+ 1 =>
+ array(
+ 'label' => 'Yahoo!',
+ 'nb_uniq_visitors' => 15,
+ 'nb_visits' => 151,
+ 'url' => 'http://www.yahoo.com',
+ 'logo' => './plugins/Referers/images/searchEngines/www.yahoo.com.png',
+ ),
+ ),
+ 'date2' =>
+ array(
+ 0 =>
+ array(
+ 'label' => 'Google1&copy;',
+ 'nb_uniq_visitors' => 110,
+ 'nb_visits' => 110,
+ 'url' => 'http://www.google.com1',
+ 'logo' => './plugins/Referers/images/searchEngines/www.google.com.png1',
+ ),
+ 1 =>
+ array(
+ 'label' => 'Yahoo!1',
+ 'nb_uniq_visitors' => 150,
+ 'nb_visits' => 1510,
+ 'url' => 'http://www.yahoo.com1',
+ 'logo' => './plugins/Referers/images/searchEngines/www.yahoo.com.png1',
+ ),
+ ),
+ 'date3' => array(),
+ ));
$this->assertEquals($expected, $rendered);
}
@@ -413,21 +413,20 @@ class DataTable_Renderer_PHPTest extends PHPUnit_Framework_TestCase
$render->setTable($dataTable);
$rendered = $render->render();
- $expected = serialize(array (
- 'row1' =>
- array (
- 'max_actions' => 14.0,
- 'nb_uniq_visitors' => 57.0,
- ),
- 'row2' =>
- array (
- 'max_actions' => 140.0,
- 'nb_uniq_visitors' => 570.0,
- ),
- 'row3' =>
- array (
- ),
- ));
+ $expected = serialize(array(
+ 'row1' =>
+ array(
+ 'max_actions' => 14.0,
+ 'nb_uniq_visitors' => 57.0,
+ ),
+ 'row2' =>
+ array(
+ 'max_actions' => 140.0,
+ 'nb_uniq_visitors' => 570.0,
+ ),
+ 'row3' =>
+ array(),
+ ));
$this->assertEquals($expected, $rendered);
}
@@ -444,11 +443,11 @@ class DataTable_Renderer_PHPTest extends PHPUnit_Framework_TestCase
$render->setTable($dataTable);
$rendered = $render->render();
- $expected = serialize(array (
- 'row1' => 14.0,
- 'row2' => 15.0,
- 'row3' => array(),
- ));
+ $expected = serialize(array(
+ 'row1' => 14.0,
+ 'row2' => 15.0,
+ 'row3' => array(),
+ ));
$this->assertEquals($expected, $rendered);
}
@@ -465,48 +464,48 @@ class DataTable_Renderer_PHPTest extends PHPUnit_Framework_TestCase
$render->setTable($dataTable);
$rendered = $render->render();
- $expected = serialize(array('idSite'=>
- array (
- 'date1' =>
- array (
- 0 =>
- array (
- 'label' => 'Google',
- 'nb_uniq_visitors' => 11,
- 'nb_visits' => 11,
- 'url' => 'http://www.google.com',
- 'logo' => './plugins/Referers/images/searchEngines/www.google.com.png',
- ),
- 1 =>
- array (
- 'label' => 'Yahoo!',
- 'nb_uniq_visitors' => 15,
- 'nb_visits' => 151,
- 'url' => 'http://www.yahoo.com',
- 'logo' => './plugins/Referers/images/searchEngines/www.yahoo.com.png',
- ),
- ),
- 'date2' =>
- array (
- 0 =>
- array (
- 'label' => 'Google1&copy;',
- 'nb_uniq_visitors' => 110,
- 'nb_visits' => 110,
- 'url' => 'http://www.google.com1',
- 'logo' => './plugins/Referers/images/searchEngines/www.google.com.png1',
- ),
- 1 =>
- array (
- 'label' => 'Yahoo!1',
- 'nb_uniq_visitors' => 150,
- 'nb_visits' => 1510,
- 'url' => 'http://www.yahoo.com1',
- 'logo' => './plugins/Referers/images/searchEngines/www.yahoo.com.png1',
- ),
- ),
- 'date3' => array (),
- )));
+ $expected = serialize(array('idSite' =>
+ array(
+ 'date1' =>
+ array(
+ 0 =>
+ array(
+ 'label' => 'Google',
+ 'nb_uniq_visitors' => 11,
+ 'nb_visits' => 11,
+ 'url' => 'http://www.google.com',
+ 'logo' => './plugins/Referers/images/searchEngines/www.google.com.png',
+ ),
+ 1 =>
+ array(
+ 'label' => 'Yahoo!',
+ 'nb_uniq_visitors' => 15,
+ 'nb_visits' => 151,
+ 'url' => 'http://www.yahoo.com',
+ 'logo' => './plugins/Referers/images/searchEngines/www.yahoo.com.png',
+ ),
+ ),
+ 'date2' =>
+ array(
+ 0 =>
+ array(
+ 'label' => 'Google1&copy;',
+ 'nb_uniq_visitors' => 110,
+ 'nb_visits' => 110,
+ 'url' => 'http://www.google.com1',
+ 'logo' => './plugins/Referers/images/searchEngines/www.google.com.png1',
+ ),
+ 1 =>
+ array(
+ 'label' => 'Yahoo!1',
+ 'nb_uniq_visitors' => 150,
+ 'nb_visits' => 1510,
+ 'url' => 'http://www.yahoo.com1',
+ 'logo' => './plugins/Referers/images/searchEngines/www.yahoo.com.png1',
+ ),
+ ),
+ 'date3' => array(),
+ )));
$this->assertEquals($expected, $rendered);
}
@@ -524,22 +523,21 @@ class DataTable_Renderer_PHPTest extends PHPUnit_Framework_TestCase
$render->setTable($dataTable);
$rendered = $render->render();
- $expected = serialize(array ('idSite'=>
- array(
- 'row1' =>
- array (
- 'max_actions' => 14.0,
- 'nb_uniq_visitors' => 57.0,
- ),
- 'row2' =>
- array (
- 'max_actions' => 140.0,
- 'nb_uniq_visitors' => 570.0,
- ),
- 'row3' =>
- array (
- ),
- )));
+ $expected = serialize(array('idSite' =>
+ array(
+ 'row1' =>
+ array(
+ 'max_actions' => 14.0,
+ 'nb_uniq_visitors' => 57.0,
+ ),
+ 'row2' =>
+ array(
+ 'max_actions' => 140.0,
+ 'nb_uniq_visitors' => 570.0,
+ ),
+ 'row3' =>
+ array(),
+ )));
$this->assertEquals($expected, $rendered);
}
@@ -556,12 +554,12 @@ class DataTable_Renderer_PHPTest extends PHPUnit_Framework_TestCase
$render->setTable($dataTable);
$rendered = $render->render();
- $expected = serialize(array ('idSite'=>
- array(
- 'row1' => 14.0,
- 'row2' => 15.0,
- 'row3' => array(),
- )));
+ $expected = serialize(array('idSite' =>
+ array(
+ 'row1' => 14.0,
+ 'row2' => 15.0,
+ 'row3' => array(),
+ )));
$this->assertEquals($expected, $rendered);
}
}
diff --git a/tests/PHPUnit/Core/DataTable/Renderer/XMLTest.php b/tests/PHPUnit/Core/DataTable/Renderer/XMLTest.php
index 13384f1a69..d4e676f5eb 100644
--- a/tests/PHPUnit/Core/DataTable/Renderer/XMLTest.php
+++ b/tests/PHPUnit/Core/DataTable/Renderer/XMLTest.php
@@ -23,30 +23,30 @@ class DataTable_Renderer_XMLTest extends PHPUnit_Framework_TestCase
protected function _getDataTableTest()
{
$dataTable = new Piwik_DataTable();
-
- $arraySubTableForRow2 = array (
- array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'sub1', 'count' => 1, 'bool' => false) ),
- array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'sub2', 'count' => 2, 'bool' => true) ),
+
+ $arraySubTableForRow2 = array(
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'sub1', 'count' => 1, 'bool' => false)),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'sub2', 'count' => 2, 'bool' => true)),
);
$subDataTableForRow2 = new Piwik_DataTable();
$subDataTableForRow2->addRowsFromArray($arraySubTableForRow2);
- $array = array (
- array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'Google&copy;', 'bool' => false, 'goals' => array('idgoal=1' => array('revenue'=> 5.5, 'nb_conversions' => 10)), 'nb_uniq_visitors' => 11, 'nb_visits' => 11, 'nb_actions' => 17, 'max_actions' => '5', 'sum_visit_length' => 517, 'bounce_count' => 9),
- Piwik_DataTable_Row::METADATA => array('url' => 'http://www.google.com/display"and,properly', 'logo' => './plugins/Referers/images/searchEngines/www.google.com.png'),
- ),
- array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'Yahoo!', 'nb_uniq_visitors' => 15, 'bool' => true, 'nb_visits' => 151, 'nb_actions' => 147, 'max_actions' => '50', 'sum_visit_length' => 517, 'bounce_count' => 90),
- Piwik_DataTable_Row::METADATA => array('url' => 'http://www.yahoo.com', 'logo' => './plugins/Referers/images/searchEngines/www.yahoo.com.png'),
- Piwik_DataTable_Row::DATATABLE_ASSOCIATED => $subDataTableForRow2,
- )
- );
+ $array = array(
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'Google&copy;', 'bool' => false, 'goals' => array('idgoal=1' => array('revenue' => 5.5, 'nb_conversions' => 10)), 'nb_uniq_visitors' => 11, 'nb_visits' => 11, 'nb_actions' => 17, 'max_actions' => '5', 'sum_visit_length' => 517, 'bounce_count' => 9),
+ Piwik_DataTable_Row::METADATA => array('url' => 'http://www.google.com/display"and,properly', 'logo' => './plugins/Referers/images/searchEngines/www.google.com.png'),
+ ),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'Yahoo!', 'nb_uniq_visitors' => 15, 'bool' => true, 'nb_visits' => 151, 'nb_actions' => 147, 'max_actions' => '50', 'sum_visit_length' => 517, 'bounce_count' => 90),
+ Piwik_DataTable_Row::METADATA => array('url' => 'http://www.yahoo.com', 'logo' => './plugins/Referers/images/searchEngines/www.yahoo.com.png'),
+ Piwik_DataTable_Row::DATATABLE_ASSOCIATED => $subDataTableForRow2,
+ )
+ );
$dataTable->addRowsFromArray($array);
return $dataTable;
}
protected function _getDataTableSimpleTest()
{
- $array = array ( 'max_actions' => 14.0, 'nb_uniq_visitors' => 57.0, 'nb_visits' => 66.0, 'nb_actions' => 151.0, 'sum_visit_length' => 5118.0, 'bounce_count' => 44.0, );
+ $array = array('max_actions' => 14.0, 'nb_uniq_visitors' => 57.0, 'nb_visits' => 66.0, 'nb_actions' => 151.0, 'sum_visit_length' => 5118.0, 'bounce_count' => 44.0,);
$table = new Piwik_DataTable_Simple;
$table->addRowsFromArray($array);
@@ -55,7 +55,7 @@ class DataTable_Renderer_XMLTest extends PHPUnit_Framework_TestCase
protected function _getDataTableSimpleOneRowTest()
{
- $array = array ( 'nb_visits' => 14.0 );
+ $array = array('nb_visits' => 14.0);
$table = new Piwik_DataTable_Simple;
$table->addRowsFromArray($array);
@@ -70,7 +70,7 @@ class DataTable_Renderer_XMLTest extends PHPUnit_Framework_TestCase
protected function _getDataTableSimpleOneZeroRowTest()
{
- $array = array ( 'nb_visits' => 0 );
+ $array = array('nb_visits' => 0);
$table = new Piwik_DataTable_Simple;
$table->addRowsFromArray($array);
return $table;
@@ -78,7 +78,7 @@ class DataTable_Renderer_XMLTest extends PHPUnit_Framework_TestCase
protected function _getDataTableSimpleOneFalseRowTest()
{
- $array = array ( 'is_excluded' => false );
+ $array = array('is_excluded' => false);
$table = new Piwik_DataTable_Simple;
$table->addRowsFromArray($array);
return $table;
@@ -242,26 +242,26 @@ class DataTable_Renderer_XMLTest extends PHPUnit_Framework_TestCase
protected function _getDataTableArrayTest()
{
- $array1 = array (
- array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'Google', 'nb_uniq_visitors' => 11, 'nb_visits' => 11, ),
- Piwik_DataTable_Row::METADATA => array('url' => 'http://www.google.com', 'logo' => './plugins/Referers/images/searchEngines/www.google.com.png'),
- ),
- array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'Yahoo!', 'nb_uniq_visitors' => 15, 'nb_visits' => 151, ),
- Piwik_DataTable_Row::METADATA => array('url' => 'http://www.yahoo.com', 'logo' => './plugins/Referers/images/searchEngines/www.yahoo.com.png'),
- )
- );
+ $array1 = array(
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'Google', 'nb_uniq_visitors' => 11, 'nb_visits' => 11,),
+ Piwik_DataTable_Row::METADATA => array('url' => 'http://www.google.com', 'logo' => './plugins/Referers/images/searchEngines/www.google.com.png'),
+ ),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'Yahoo!', 'nb_uniq_visitors' => 15, 'nb_visits' => 151,),
+ Piwik_DataTable_Row::METADATA => array('url' => 'http://www.yahoo.com', 'logo' => './plugins/Referers/images/searchEngines/www.yahoo.com.png'),
+ )
+ );
$table1 = new Piwik_DataTable();
$table1->addRowsFromArray($array1);
- $array2 = array (
- array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'Google1&copy;', 'nb_uniq_visitors' => 110, 'nb_visits' => 110,),
- Piwik_DataTable_Row::METADATA => array('url' => 'http://www.google.com1', 'logo' => './plugins/Referers/images/searchEngines/www.google.com.png1'),
- ),
- array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'Yahoo!1', 'nb_uniq_visitors' => 150, 'nb_visits' => 1510,),
- Piwik_DataTable_Row::METADATA => array('url' => 'http://www.yahoo.com1', 'logo' => './plugins/Referers/images/searchEngines/www.yahoo.com.png1'),
- )
- );
+ $array2 = array(
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'Google1&copy;', 'nb_uniq_visitors' => 110, 'nb_visits' => 110,),
+ Piwik_DataTable_Row::METADATA => array('url' => 'http://www.google.com1', 'logo' => './plugins/Referers/images/searchEngines/www.google.com.png1'),
+ ),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'Yahoo!1', 'nb_uniq_visitors' => 150, 'nb_visits' => 1510,),
+ Piwik_DataTable_Row::METADATA => array('url' => 'http://www.yahoo.com1', 'logo' => './plugins/Referers/images/searchEngines/www.yahoo.com.png1'),
+ )
+ );
$table2 = new Piwik_DataTable();
$table2->addRowsFromArray($array2);
@@ -279,11 +279,11 @@ class DataTable_Renderer_XMLTest extends PHPUnit_Framework_TestCase
protected function _getDataTableSimpleArrayTest()
{
- $array1 = array ( 'max_actions' => 14.0, 'nb_uniq_visitors' => 57.0, );
+ $array1 = array('max_actions' => 14.0, 'nb_uniq_visitors' => 57.0,);
$table1 = new Piwik_DataTable_Simple;
$table1->addRowsFromArray($array1);
- $array2 = array ( 'max_actions' => 140.0, 'nb_uniq_visitors' => 570.0, );
+ $array2 = array('max_actions' => 140.0, 'nb_uniq_visitors' => 570.0,);
$table2 = new Piwik_DataTable_Simple;
$table2->addRowsFromArray($array2);
@@ -300,10 +300,10 @@ class DataTable_Renderer_XMLTest extends PHPUnit_Framework_TestCase
protected function _getDataTableSimpleOneRowArrayTest()
{
- $array1 = array ( 'nb_visits' => 14.0 );
+ $array1 = array('nb_visits' => 14.0);
$table1 = new Piwik_DataTable_Simple;
$table1->addRowsFromArray($array1);
- $array2 = array ( 'nb_visits' => 15.0 );
+ $array2 = array('nb_visits' => 15.0);
$table2 = new Piwik_DataTable_Simple;
$table2->addRowsFromArray($array2);
@@ -546,38 +546,38 @@ class DataTable_Renderer_XMLTest extends PHPUnit_Framework_TestCase
$rendered = $render->render();
$this->assertEquals($expected, $rendered);
}
-
- /**
- * @group Core
- * @group DataTable
- * @group DataTable_Renderer
- * @group DataTable_Renderer_XML
- */
- public function testRenderArray1()
- {
- $data = array();
-
+
+ /**
+ * @group Core
+ * @group DataTable
+ * @group DataTable_Renderer
+ * @group DataTable_Renderer_XML
+ */
+ public function testRenderArray1()
+ {
+ $data = array();
+
$render = new Piwik_DataTable_Renderer_Xml();
$render->setTable($data);
$expected = '<?xml version="1.0" encoding="utf-8" ?>
<result />';
-
+
$this->assertEquals($expected, $render->render());
- }
-
- /**
- * @group Core
- * @group DataTable
- * @group DataTable_Renderer
- * @group DataTable_Renderer_XML
- */
- public function testRenderArray2()
- {
- $data = array("firstElement",
- array("firstElement",
- "secondElement"),
- "thirdElement");
-
+ }
+
+ /**
+ * @group Core
+ * @group DataTable
+ * @group DataTable_Renderer
+ * @group DataTable_Renderer_XML
+ */
+ public function testRenderArray2()
+ {
+ $data = array("firstElement",
+ array("firstElement",
+ "secondElement"),
+ "thirdElement");
+
$render = new Piwik_DataTable_Renderer_Xml();
$render->setTable($data);
$expected = '<?xml version="1.0" encoding="utf-8" ?>
@@ -589,20 +589,20 @@ class DataTable_Renderer_XMLTest extends PHPUnit_Framework_TestCase
</row>
<row>thirdElement</row>
</result>';
-
+
$this->assertEquals($expected, $render->render());
- }
-
- /**
- * @group Core
- * @group DataTable
- * @group DataTable_Renderer
- * @group DataTable_Renderer_XML
- */
- public function testRenderArray3()
- {
- $data = array('a' => 'b', 'c' => 'd', 'e' => 'f', 5 => 'g');
-
+ }
+
+ /**
+ * @group Core
+ * @group DataTable
+ * @group DataTable_Renderer
+ * @group DataTable_Renderer_XML
+ */
+ public function testRenderArray3()
+ {
+ $data = array('a' => 'b', 'c' => 'd', 'e' => 'f', 5 => 'g');
+
$render = new Piwik_DataTable_Renderer_Xml();
$render->setTable($data);
$expected = '<?xml version="1.0" encoding="utf-8" ?>
@@ -614,20 +614,20 @@ class DataTable_Renderer_XMLTest extends PHPUnit_Framework_TestCase
<row key="5">g</row>
</row>
</result>';
-
+
$this->assertEquals($expected, $render->render());
- }
-
- /**
- * @group Core
- * @group DataTable
- * @group DataTable_Renderer
- * @group DataTable_Renderer_XML
- */
- public function testRenderArray4()
- {
- $data = array('c' => array(1,2,3,4), 'e' => array('f' => 'g', 'h' => 'i', 'j' => 'k'));
-
+ }
+
+ /**
+ * @group Core
+ * @group DataTable
+ * @group DataTable_Renderer
+ * @group DataTable_Renderer_XML
+ */
+ public function testRenderArray4()
+ {
+ $data = array('c' => array(1, 2, 3, 4), 'e' => array('f' => 'g', 'h' => 'i', 'j' => 'k'));
+
$render = new Piwik_DataTable_Renderer_Xml();
$render->setTable($data);
$expected = '<?xml version="1.0" encoding="utf-8" ?>
@@ -644,7 +644,7 @@ class DataTable_Renderer_XMLTest extends PHPUnit_Framework_TestCase
<j>k</j>
</e>
</result>';
-
+
$this->assertEquals($expected, $render->render());
- }
+ }
}
diff --git a/tests/PHPUnit/Core/DataTable/RowTest.php b/tests/PHPUnit/Core/DataTable/RowTest.php
index d138903ca9..2effe961c4 100644
--- a/tests/PHPUnit/Core/DataTable/RowTest.php
+++ b/tests/PHPUnit/Core/DataTable/RowTest.php
@@ -7,141 +7,141 @@
*/
class RowTest extends PHPUnit_Framework_TestCase
{
- /**
- *
- * @group Core
- * @group DataTable
- * @group Piwik_DataTable_Row
- */
- public function testDataTableAssociatedIsNegativeWhenSubDataTableInMemory()
- {
- $testRow = $this->getTestRowWithSubDataTableLoaded();
- $this->assertTrue($testRow->c[Piwik_DataTable_Row::DATATABLE_ASSOCIATED] < 0);
- }
-
- /**
- *
- * @group Core
- * @group DataTable
- * @group Piwik_DataTable_Row
- */
- public function testDataTableAssociatedIsNegativeWhenSubDataTableAdded()
- {
- $testRow = $this->getTestRowWithSubDataTableNotLoaded();
- $testRow->addSubtable($this->getTestSubDataTable());
- $this->assertTrue($testRow->c[Piwik_DataTable_Row::DATATABLE_ASSOCIATED] < 0);
- }
-
- /**
- *
- * @group Core
- * @group DataTable
- * @group Piwik_DataTable_Row
- */
- public function testDataTableAssociatedIsNegativeWhenSubDataTableSetted()
- {
- $testRow = $this->getTestRowWithSubDataTableNotLoaded();
- $testRow->setSubtable($this->getTestSubDataTable());
- $this->assertTrue($testRow->c[Piwik_DataTable_Row::DATATABLE_ASSOCIATED] < 0);
- }
-
- /**
- *
- * @group Core
- * @group DataTable
- * @group Piwik_DataTable_Row
- */
- public function testIdSubDataTabledIsPositiveWhenSubDataTableInMemory()
- {
- $testRow = $this->getTestRowWithSubDataTableLoaded();
- $this->assertTrue($testRow->getIdSubDataTable() > 0);
- }
-
-
- /**
- * @group Core
- * @group DataTable
- * @group Piwik_DataTable_Row
- */
- public function testDataTableAssociatedIsPositiveOnSerializedRow()
- {
- $testRow = $this->getTestRowWithSubDataTableLoaded();
-
- // testDataTableAssociatedIsPositiveOnSerializedRow is only valid as long as the Row is not modified after being unserialized
- $this->assertFalse(method_exists($testRow, '__wakeup'));
-
- $serializedTestRow = serialize($testRow);
- $unserializedTestRow = unserialize($serializedTestRow);
-
- $this->assertTrue($unserializedTestRow->c[Piwik_DataTable_Row::DATATABLE_ASSOCIATED] > 0);
- }
-
- /**
- * @group Core
- * @group DataTable
- * @group Piwik_DataTable_Row
- */
- public function testDataTableAssociatedIsNegativeAfterSerialize()
- {
- $testRow = $this->getTestRowWithSubDataTableLoaded();
-
- serialize($testRow);
-
- $testRow->cleanPostSerialize();
-
- $this->assertTrue($testRow->c[Piwik_DataTable_Row::DATATABLE_ASSOCIATED] < 0);
- }
-
- /**
- *
- * @group Core
- * @group DataTable
- * @group Piwik_DataTable_Row
- */
- public function testIsSubDataTableLoadedIsTrueWhenSubDataTableInMemory()
- {
- $testRow = $this->getTestRowWithSubDataTableLoaded();
- $this->assertTrue($testRow->isSubtableLoaded());
- }
-
- /**
- *
- * @group Core
- * @group DataTable
- * @group Piwik_DataTable_Row
- */
- public function testIsSubDataTableLoadedIsFalseWhenSubDataTableNotInMemory()
- {
- $testRow = $this->getTestRowWithSubDataTableNotLoaded();
- $this->assertFalse($testRow->isSubtableLoaded());
- }
-
- protected function getTestRowWithSubDataTableLoaded()
- {
- $testSubDataTable = $this->getTestSubDataTable();
-
- $testRow = new Piwik_DataTable_Row(
- array(
- Piwik_DataTable_Row::DATATABLE_ASSOCIATED => $testSubDataTable
- )
- );
-
- return $testRow;
- }
-
- protected function getTestSubDataTable()
- {
- return new Piwik_DataTable();
- }
-
- protected function getTestRowWithSubDataTableNotLoaded()
- {
- $testRow = new Piwik_DataTable_Row(
- array(
- Piwik_DataTable_Row::DATATABLE_ASSOCIATED => 50
- )
- );
-
- return $testRow;
- }
+ /**
+ *
+ * @group Core
+ * @group DataTable
+ * @group Piwik_DataTable_Row
+ */
+ public function testDataTableAssociatedIsNegativeWhenSubDataTableInMemory()
+ {
+ $testRow = $this->getTestRowWithSubDataTableLoaded();
+ $this->assertTrue($testRow->c[Piwik_DataTable_Row::DATATABLE_ASSOCIATED] < 0);
+ }
+
+ /**
+ *
+ * @group Core
+ * @group DataTable
+ * @group Piwik_DataTable_Row
+ */
+ public function testDataTableAssociatedIsNegativeWhenSubDataTableAdded()
+ {
+ $testRow = $this->getTestRowWithSubDataTableNotLoaded();
+ $testRow->addSubtable($this->getTestSubDataTable());
+ $this->assertTrue($testRow->c[Piwik_DataTable_Row::DATATABLE_ASSOCIATED] < 0);
+ }
+
+ /**
+ *
+ * @group Core
+ * @group DataTable
+ * @group Piwik_DataTable_Row
+ */
+ public function testDataTableAssociatedIsNegativeWhenSubDataTableSetted()
+ {
+ $testRow = $this->getTestRowWithSubDataTableNotLoaded();
+ $testRow->setSubtable($this->getTestSubDataTable());
+ $this->assertTrue($testRow->c[Piwik_DataTable_Row::DATATABLE_ASSOCIATED] < 0);
+ }
+
+ /**
+ *
+ * @group Core
+ * @group DataTable
+ * @group Piwik_DataTable_Row
+ */
+ public function testIdSubDataTabledIsPositiveWhenSubDataTableInMemory()
+ {
+ $testRow = $this->getTestRowWithSubDataTableLoaded();
+ $this->assertTrue($testRow->getIdSubDataTable() > 0);
+ }
+
+
+ /**
+ * @group Core
+ * @group DataTable
+ * @group Piwik_DataTable_Row
+ */
+ public function testDataTableAssociatedIsPositiveOnSerializedRow()
+ {
+ $testRow = $this->getTestRowWithSubDataTableLoaded();
+
+ // testDataTableAssociatedIsPositiveOnSerializedRow is only valid as long as the Row is not modified after being unserialized
+ $this->assertFalse(method_exists($testRow, '__wakeup'));
+
+ $serializedTestRow = serialize($testRow);
+ $unserializedTestRow = unserialize($serializedTestRow);
+
+ $this->assertTrue($unserializedTestRow->c[Piwik_DataTable_Row::DATATABLE_ASSOCIATED] > 0);
+ }
+
+ /**
+ * @group Core
+ * @group DataTable
+ * @group Piwik_DataTable_Row
+ */
+ public function testDataTableAssociatedIsNegativeAfterSerialize()
+ {
+ $testRow = $this->getTestRowWithSubDataTableLoaded();
+
+ serialize($testRow);
+
+ $testRow->cleanPostSerialize();
+
+ $this->assertTrue($testRow->c[Piwik_DataTable_Row::DATATABLE_ASSOCIATED] < 0);
+ }
+
+ /**
+ *
+ * @group Core
+ * @group DataTable
+ * @group Piwik_DataTable_Row
+ */
+ public function testIsSubDataTableLoadedIsTrueWhenSubDataTableInMemory()
+ {
+ $testRow = $this->getTestRowWithSubDataTableLoaded();
+ $this->assertTrue($testRow->isSubtableLoaded());
+ }
+
+ /**
+ *
+ * @group Core
+ * @group DataTable
+ * @group Piwik_DataTable_Row
+ */
+ public function testIsSubDataTableLoadedIsFalseWhenSubDataTableNotInMemory()
+ {
+ $testRow = $this->getTestRowWithSubDataTableNotLoaded();
+ $this->assertFalse($testRow->isSubtableLoaded());
+ }
+
+ protected function getTestRowWithSubDataTableLoaded()
+ {
+ $testSubDataTable = $this->getTestSubDataTable();
+
+ $testRow = new Piwik_DataTable_Row(
+ array(
+ Piwik_DataTable_Row::DATATABLE_ASSOCIATED => $testSubDataTable
+ )
+ );
+
+ return $testRow;
+ }
+
+ protected function getTestSubDataTable()
+ {
+ return new Piwik_DataTable();
+ }
+
+ protected function getTestRowWithSubDataTableNotLoaded()
+ {
+ $testRow = new Piwik_DataTable_Row(
+ array(
+ Piwik_DataTable_Row::DATATABLE_ASSOCIATED => 50
+ )
+ );
+
+ return $testRow;
+ }
}
diff --git a/tests/PHPUnit/Core/DataTableTest.php b/tests/PHPUnit/Core/DataTableTest.php
index 0a18e25fc8..9249d7ea72 100644
--- a/tests/PHPUnit/Core/DataTableTest.php
+++ b/tests/PHPUnit/Core/DataTableTest.php
@@ -15,26 +15,26 @@ class DataTableTest extends PHPUnit_Framework_TestCase
{
$table = $this->_getDataTable1ForTest();
$this->assertEquals(4, $table->getRowsCount());
- $table->filter('Limit', array(2,2));
+ $table->filter('Limit', array(2, 2));
$this->assertEquals(2, $table->getRowsCount());
- $table->filter('Piwik_DataTable_Filter_Limit', array(0,1));
+ $table->filter('Piwik_DataTable_Filter_Limit', array(0, 1));
$this->assertEquals(1, $table->getRowsCount());
}
-
+
protected function _getSimpleTestDataTable()
{
$table = new Piwik_DataTable;
$table->addRowsFromArray(
- array(
- array(Piwik_DataTable_Row::COLUMNS => array('label'=>'ten', 'count' => 10)),
- array(Piwik_DataTable_Row::COLUMNS => array('label'=>'ninety', 'count' => 90)),
- array(Piwik_DataTable_Row::COLUMNS => array('label'=>'hundred', 'count' => 100)),
- Piwik_DataTable::ID_SUMMARY_ROW => array( Piwik_DataTable_Row::COLUMNS => array('label'=> 'summary', 'count' => 200))
+ array(
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'ten', 'count' => 10)),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'ninety', 'count' => 90)),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'hundred', 'count' => 100)),
+ Piwik_DataTable::ID_SUMMARY_ROW => array(Piwik_DataTable_Row::COLUMNS => array('label' => 'summary', 'count' => 200))
)
);
return $table;
}
-
+
/**
* @group Core
* @group DataTable
@@ -42,10 +42,10 @@ class DataTableTest extends PHPUnit_Framework_TestCase
public function testRenameColumn()
{
$table = $this->_getSimpleTestDataTable();
- $this->assertEquals(array(10,90,100,200), $table->getColumn('count'));
+ $this->assertEquals(array(10, 90, 100, 200), $table->getColumn('count'));
$table->renameColumn('count', 'renamed');
$this->assertEquals(array(false, false, false, false), $table->getColumn('count'));
- $this->assertEquals(array(10,90,100,200), $table->getColumn('renamed'));
+ $this->assertEquals(array(10, 90, 100, 200), $table->getColumn('renamed'));
}
/**
@@ -55,7 +55,7 @@ class DataTableTest extends PHPUnit_Framework_TestCase
public function testDeleteColumn()
{
$table = $this->_getSimpleTestDataTable();
- $this->assertEquals(array(10,90,100,200), $table->getColumn('count'));
+ $this->assertEquals(array(10, 90, 100, 200), $table->getColumn('count'));
$table->deleteColumn('count');
$this->assertEquals(array(false, false, false, false), $table->getColumn('count'));
}
@@ -67,7 +67,7 @@ class DataTableTest extends PHPUnit_Framework_TestCase
public function testDeleteRow()
{
$table = $this->_getSimpleTestDataTable();
-
+
// normal row
$idToDelete = 1;
$this->assertEquals(2, count($table->getRowFromId($idToDelete)->getColumns()));
@@ -80,7 +80,7 @@ class DataTableTest extends PHPUnit_Framework_TestCase
$table->deleteRow($idToDelete);
$this->assertFalse($table->getRowFromId($idToDelete));
}
-
+
/**
* @group Core
* @group DataTable
@@ -92,10 +92,10 @@ class DataTableTest extends PHPUnit_Framework_TestCase
$this->assertEquals($table->getLastRow(), $table->getRowFromId(Piwik_DataTable::ID_SUMMARY_ROW));
$table->deleteRow(Piwik_DataTable::ID_SUMMARY_ROW);
-
- $this->assertEquals($table->getLastRow(), $table->getRowFromId($rowsCount-2));
+
+ $this->assertEquals($table->getLastRow(), $table->getRowFromId($rowsCount - 2));
}
-
+
/**
* @group Core
* @group DataTable
@@ -106,228 +106,226 @@ class DataTableTest extends PHPUnit_Framework_TestCase
$idTable1 = $table1->getId();
$table2 = $this->_getDataTable2ForTest();
$this->assertFalse($table2->getRowFromIdSubDataTable($idTable1));
-
+
$table2->getFirstRow()->addSubtable($table1);
$this->assertEquals($table2->getRowFromIdSubDataTable($idTable1), $table2->getFirstRow());
-
+
$table3 = $this->_getDataTable1ForTest();
$idTable3 = $table3->getId();
$table2->getLastRow()->addSubtable($table3);
$this->assertEquals($table2->getRowFromIdSubDataTable($idTable3), $table2->getLastRow());
}
-
+
/**
* we test the count rows and the count rows recursive version
* on a Simple array (1 level only)
- *
+ *
* @group Core
* @group DataTable
*/
public function testCountRowsSimple()
{
-
- $table = new Piwik_DataTable;
- $idcol = Piwik_DataTable_Row::COLUMNS;
- $rows = array(
- array( $idcol => array('label'=>'google')),
- array( $idcol => array('label'=>'ask')),
- array( $idcol => array('label'=>'piwik')),
- array( $idcol => array('label'=>'yahoo')),
- array( $idcol => array('label'=>'amazon')),
- array( $idcol => array('label'=>'238975247578949')),
- array( $idcol => array('label'=>'Q*(%&*("$&%*(&"$*")"))')));
-
- $table->addRowsFromArray( $rows );
-
- $this->assertEquals(count($rows), $table->getRowsCount());
- $this->assertEquals(count($rows), $table->getRowsCountRecursive());
+
+ $table = new Piwik_DataTable;
+ $idcol = Piwik_DataTable_Row::COLUMNS;
+ $rows = array(
+ array($idcol => array('label' => 'google')),
+ array($idcol => array('label' => 'ask')),
+ array($idcol => array('label' => 'piwik')),
+ array($idcol => array('label' => 'yahoo')),
+ array($idcol => array('label' => 'amazon')),
+ array($idcol => array('label' => '238975247578949')),
+ array($idcol => array('label' => 'Q*(%&*("$&%*(&"$*")"))')));
+
+ $table->addRowsFromArray($rows);
+
+ $this->assertEquals(count($rows), $table->getRowsCount());
+ $this->assertEquals(count($rows), $table->getRowsCountRecursive());
}
+
/**
* we test the count rows and the count rows recursive version
* on a Complex array (rows with 2 and 3 levels only)
- *
- * the recursive count returns
- * the sum of the number of rows of all the subtables
+ *
+ * the recursive count returns
+ * the sum of the number of rows of all the subtables
* + the number of rows in the parent table
- *
+ *
* @group Core
* @group DataTable
*/
public function testCountRowsComplex()
{
-
+
$idcol = Piwik_DataTable_Row::COLUMNS;
$idsubtable = Piwik_DataTable_Row::DATATABLE_ASSOCIATED;
-
+
// table to go in the SUB table of RoW1
$tableSubOfSubOfRow1 = new Piwik_DataTable;
$rows1sub = array(
- array( $idcol => array('label'=>'google')),
- array( $idcol => array('label'=>'google78')),
- array( $idcol => array('label'=>'googlaegge')),
- array( $idcol => array('label'=>'gogeoggle')),
- array( $idcol => array('label'=>'goaegaegaogle')),
- array( $idcol => array('label'=>'ask')),
- array( $idcol => array('label'=>'238975247578949')),
+ array($idcol => array('label' => 'google')),
+ array($idcol => array('label' => 'google78')),
+ array($idcol => array('label' => 'googlaegge')),
+ array($idcol => array('label' => 'gogeoggle')),
+ array($idcol => array('label' => 'goaegaegaogle')),
+ array($idcol => array('label' => 'ask')),
+ array($idcol => array('label' => '238975247578949')),
);
- $tableSubOfSubOfRow1->addRowsFromArray( $rows1sub );
-
+ $tableSubOfSubOfRow1->addRowsFromArray($rows1sub);
+
// table to go in row1
$tableSubOfRow1 = new Piwik_DataTable;
$rows1 = array(
- array( $idcol => array('label'=>'google'), $idsubtable =>$tableSubOfSubOfRow1),
- array( $idcol => array('label'=>'ask')),
- array( $idcol => array('label'=>'238975247578949')),
+ array($idcol => array('label' => 'google'), $idsubtable => $tableSubOfSubOfRow1),
+ array($idcol => array('label' => 'ask')),
+ array($idcol => array('label' => '238975247578949')),
);
- $tableSubOfRow1->addRowsFromArray( $rows1 );
-
+ $tableSubOfRow1->addRowsFromArray($rows1);
+
// table to go in row2
$tableSubOfRow2 = new Piwik_DataTable;
$rows2 = array(
- array( $idcol => array('label'=>'google')),
- array( $idcol => array('label'=>'ask')),
- array( $idcol => array('label'=>'238975247578949')),
- array( $idcol => array('label'=>'agaegaesk')),
- array( $idcol => array('label'=>'23g 8975247578949')),
+ array($idcol => array('label' => 'google')),
+ array($idcol => array('label' => 'ask')),
+ array($idcol => array('label' => '238975247578949')),
+ array($idcol => array('label' => 'agaegaesk')),
+ array($idcol => array('label' => '23g 8975247578949')),
);
- $tableSubOfRow2->addRowsFromArray( $rows2 );
-
+ $tableSubOfRow2->addRowsFromArray($rows2);
+
// main parent table
$table = new Piwik_DataTable;
$rows = array(
- array( $idcol => array('label'=>'row1')),
- array( $idcol => array('label'=>'row2'),
- $idsubtable => $tableSubOfRow1),
- array( $idcol => array('label'=>'row3'),
- $idsubtable => $tableSubOfRow2),
+ array($idcol => array('label' => 'row1')),
+ array($idcol => array('label' => 'row2'),
+ $idsubtable => $tableSubOfRow1),
+ array($idcol => array('label' => 'row3'),
+ $idsubtable => $tableSubOfRow2),
);
- $table->addRowsFromArray( $rows );
-
-
+ $table->addRowsFromArray($rows);
+
+
$this->assertEquals(count($rows), $table->getRowsCount());
- $countAllRows = count($rows)+count($rows1)+count($rows2) + count($rows1sub);
+ $countAllRows = count($rows) + count($rows1) + count($rows2) + count($rows1sub);
$this->assertEquals($countAllRows, $table->getRowsCountRecursive());
}
-
+
/**
* Simple test of the DataTable_Row
- *
+ *
* @group Core
* @group DataTable
*/
public function testRow()
{
- $columns = array('test_column'=> 145,
- 092582495 => new Piwik_Timer,
- 'super'=>array('this column has an array value, amazing'));
- $metadata = array('logo'=> 'piwik.png',
- 'super'=>array('this column has an array value, amazing'));
+ $columns = array('test_column' => 145,
+ 092582495 => new Piwik_Timer,
+ 'super' => array('this column has an array value, amazing'));
+ $metadata = array('logo' => 'piwik.png',
+ 'super' => array('this column has an array value, amazing'));
$arrayRow = array(
- Piwik_DataTable_Row::COLUMNS => $columns,
+ Piwik_DataTable_Row::COLUMNS => $columns,
Piwik_DataTable_Row::METADATA => $metadata,
- 'fake useless key'=>38959,
- 43905724897=>'value');
+ 'fake useless key' => 38959,
+ 43905724897 => 'value');
$row = new Piwik_DataTable_Row($arrayRow);
-
+
$this->assertEquals($columns, $row->getColumns());
$this->assertEquals($metadata, $row->getMetadata());
$this->assertNull($row->getIdSubDataTable());
-
+
}
-
+
/**
* Simple test of the DataTable_Row
- *
+ *
* @group Core
* @group DataTable
*/
public function testSumRow()
{
- $columns = array('test_int'=> 145,
- 'test_float'=> 145.5,
- 'test_float3'=> 1.5,
- 'test_stringint'=> "145",
- "test" => 'string fake',
- 'integerArrayToSum'=>array( 1 => 1, 2 => 10.0, 3 => array(1 => 2, 2 => 3)),
- );
- $metadata = array('logo'=> 'piwik.png',
- 'super'=>array('this column has an array value, amazing'));
+ $columns = array('test_int' => 145,
+ 'test_float' => 145.5,
+ 'test_float3' => 1.5,
+ 'test_stringint' => "145",
+ "test" => 'string fake',
+ 'integerArrayToSum' => array(1 => 1, 2 => 10.0, 3 => array(1 => 2, 2 => 3)),
+ );
+ $metadata = array('logo' => 'piwik.png',
+ 'super' => array('this column has an array value, amazing'));
$arrayRow = array(
- Piwik_DataTable_Row::COLUMNS => $columns,
+ Piwik_DataTable_Row::COLUMNS => $columns,
Piwik_DataTable_Row::METADATA => $metadata,
- 'fake useless key'=>38959,
- 43905724897=>'value');
+ 'fake useless key' => 38959,
+ 43905724897 => 'value');
$row1 = new Piwik_DataTable_Row($arrayRow);
-
- $columns2 = array('test_int'=> 5,
- 'test_float'=> 4.5,
- 'test_float2'=> 14.5,
- 'test_stringint'=> "5",
- 0925824 => 'toto',
- 'integerArrayToSum'=>array( 1 => 5, 2 => 5.5, 3 => array(2 => 4)),
- );
- $finalRow = new Piwik_DataTable_Row( array(Piwik_DataTable_Row::COLUMNS => $columns2));
+
+ $columns2 = array('test_int' => 5,
+ 'test_float' => 4.5,
+ 'test_float2' => 14.5,
+ 'test_stringint' => "5",
+ 0925824 => 'toto',
+ 'integerArrayToSum' => array(1 => 5, 2 => 5.5, 3 => array(2 => 4)),
+ );
+ $finalRow = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => $columns2));
$finalRow->sumRow($row1);
- $columnsWanted = array('test_int'=> 150,
- 'test_float'=> 150.0,
- 'test_float2'=> 14.5,
- 'test_float3'=> 1.5,
- 'test_stringint'=> 150, //add also strings!!
- 'test' => 'string fake',
- 'integerArrayToSum' => array( 1 => 6, 2 => 15.5, 3 => array(1 => 2, 2 => 7)),
- 0925824 => 'toto',
- );
-
- // Also testing that metadata is copied over
- $rowWanted = new Piwik_DataTable_Row( array(Piwik_DataTable_Row::COLUMNS => $columnsWanted,Piwik_DataTable_Row::METADATA => $metadata));
- $this->assertTrue( Piwik_DataTable_Row::isEqual($rowWanted, $finalRow));
-
-
- // testing that, 'sumRow' does not result in extra unwanted attributes being serialized
- $expectedRow = 'O:19:"Piwik_DataTable_Row":1:{s:1:"c";a:3:{i:0;a:8:{s:8:"test_int";i:150;s:10:"test_float";d:150;s:11:"test_float2";d:14.5;s:14:"test_stringint";i:150;i:0;s:4:"toto";s:17:"integerArrayToSum";a:3:{i:1;i:6;i:2;d:15.5;i:3;a:2:{i:2;i:7;i:1;i:2;}}s:11:"test_float3";d:1.5;s:4:"test";s:11:"string fake";}i:1;a:2:{s:4:"logo";s:9:"piwik.png";s:5:"super";a:1:{i:0;s:39:"this column has an array value, amazing";}}i:3;N;}}';
- $this->assertEquals( serialize($finalRow), $expectedRow);
-
- // Testing sumRow with disabled metadata sum
- $rowWanted = new Piwik_DataTable_Row( array(Piwik_DataTable_Row::COLUMNS => $columnsWanted)); // no metadata
- $finalRow = new Piwik_DataTable_Row( array(Piwik_DataTable_Row::COLUMNS => $columns2));
- $finalRow->sumRow($row1, $enableCopyMetadata = false);
- $this->assertTrue( Piwik_DataTable_Row::isEqual($rowWanted, $finalRow));
+ $columnsWanted = array('test_int' => 150,
+ 'test_float' => 150.0,
+ 'test_float2' => 14.5,
+ 'test_float3' => 1.5,
+ 'test_stringint' => 150, //add also strings!!
+ 'test' => 'string fake',
+ 'integerArrayToSum' => array(1 => 6, 2 => 15.5, 3 => array(1 => 2, 2 => 7)),
+ 0925824 => 'toto',
+ );
+
+ // Also testing that metadata is copied over
+ $rowWanted = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => $columnsWanted, Piwik_DataTable_Row::METADATA => $metadata));
+ $this->assertTrue(Piwik_DataTable_Row::isEqual($rowWanted, $finalRow));
+
+
+ // testing that, 'sumRow' does not result in extra unwanted attributes being serialized
+ $expectedRow = 'O:19:"Piwik_DataTable_Row":1:{s:1:"c";a:3:{i:0;a:8:{s:8:"test_int";i:150;s:10:"test_float";d:150;s:11:"test_float2";d:14.5;s:14:"test_stringint";i:150;i:0;s:4:"toto";s:17:"integerArrayToSum";a:3:{i:1;i:6;i:2;d:15.5;i:3;a:2:{i:2;i:7;i:1;i:2;}}s:11:"test_float3";d:1.5;s:4:"test";s:11:"string fake";}i:1;a:2:{s:4:"logo";s:9:"piwik.png";s:5:"super";a:1:{i:0;s:39:"this column has an array value, amazing";}}i:3;N;}}';
+ $this->assertEquals(serialize($finalRow), $expectedRow);
+
+ // Testing sumRow with disabled metadata sum
+ $rowWanted = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => $columnsWanted)); // no metadata
+ $finalRow = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => $columns2));
+ $finalRow->sumRow($row1, $enableCopyMetadata = false);
+ $this->assertTrue(Piwik_DataTable_Row::isEqual($rowWanted, $finalRow));
}
- /**
- * Test that adding two string column values results in an exception.
- *
+ /**
+ * Test that adding two string column values results in an exception.
+ *
* @group Core
* @group DataTable
- */
- public function testSumRow_stringException()
- {
- $columns = array(
- 'super'=>array('this column has an array string that will be 0 when algorithm sums the value'),
- );
- $row1 = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => $columns));
-
- $columns2 = array(
- 'super'=>array('this column has geagaean array value, amazing'),
- );
- $row2 = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => $columns2));
-
- // TODO: when phpunit 3.7 is released, can do check w/ "@expectedException Exception"
- try
- {
- $row2->sumRow($row1);
- $this->fail("sumRow did not throw when adding two string columns.");
- }
- catch (Exception $ex)
- {
- // pass
- }
- }
-
+ */
+ public function testSumRow_stringException()
+ {
+ $columns = array(
+ 'super' => array('this column has an array string that will be 0 when algorithm sums the value'),
+ );
+ $row1 = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => $columns));
+
+ $columns2 = array(
+ 'super' => array('this column has geagaean array value, amazing'),
+ );
+ $row2 = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => $columns2));
+
+ // TODO: when phpunit 3.7 is released, can do check w/ "@expectedException Exception"
+ try {
+ $row2->sumRow($row1);
+ $this->fail("sumRow did not throw when adding two string columns.");
+ } catch (Exception $ex) {
+ // pass
+ }
+ }
+
/**
* Test serialize with an infinite recursion (a row linked to a table in the parent hierarchy)
* After 100 recursion must throw an exception
- *
+ *
* @group Core
* @group DataTable
*/
@@ -335,8 +333,8 @@ class DataTableTest extends PHPUnit_Framework_TestCase
{
try {
$table = new Piwik_DataTable;
- $table->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array( 'visits'=>245,'visitors'=>245),
- Piwik_DataTable_Row::DATATABLE_ASSOCIATED => $table,));
+ $table->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array('visits' => 245, 'visitors' => 245),
+ Piwik_DataTable_Row::DATATABLE_ASSOCIATED => $table,));
$table->getSerialized();
} catch (Exception $e) {
@@ -344,57 +342,57 @@ class DataTableTest extends PHPUnit_Framework_TestCase
}
$this->fail('Expected exception not raised');
}
-
-
+
+
/**
* Test queing filters
- *
+ *
* @group Core
* @group DataTable
*/
public function testFilterQueueSortString()
{
-
+
$idcol = Piwik_DataTable_Row::COLUMNS;
-
+
$table = new Piwik_DataTable;
$rows = array(
- array( $idcol => array('label'=>'google')),//0
- array( $idcol => array('label'=>'tsk')),//1
- array( $idcol => array('label'=>'Q*(%&*("$&%*(&"$*")"))')),//2
- );
- $table->addRowsFromArray( $rows );
-
+ array($idcol => array('label' => 'google')), //0
+ array($idcol => array('label' => 'tsk')), //1
+ array($idcol => array('label' => 'Q*(%&*("$&%*(&"$*")"))')), //2
+ );
+ $table->addRowsFromArray($rows);
+
$expectedtable = new Piwik_DataTable;
$rows = array(
- array( $idcol => array('label'=>'google')),//0
- array( $idcol => array('label'=>'Q*(%&*("$&%*(&"$*")"))')),//2
- array( $idcol => array('label'=>'tsk')),//1
- );
- $expectedtable->addRowsFromArray( $rows );
-
+ array($idcol => array('label' => 'google')), //0
+ array($idcol => array('label' => 'Q*(%&*("$&%*(&"$*")"))')), //2
+ array($idcol => array('label' => 'tsk')), //1
+ );
+ $expectedtable->addRowsFromArray($rows);
+
$expectedtableReverse = new Piwik_DataTable;
$expectedtableReverse->addRowsFromArray(array_reverse($rows));
-
+
$tableCopy = clone $table;
$this->assertTrue(Piwik_DataTable::isEqual($tableCopy, $table));
-
+
// queue the filter and check the table didnt change
$table->queueFilter("Sort", array('label', 'asc'));
$this->assertTrue(Piwik_DataTable::isEqual($tableCopy, $table));
-
+
// apply filter and check the table is sorted
$table->applyQueuedFilters();
$this->assertTrue(Piwik_DataTable::isEqual($expectedtable, $table));
-
+
// apply one more filter check it hasnt changed
$table->queueFilter("Sort", array('label', 'desc'));
$this->assertTrue(Piwik_DataTable::isEqual($expectedtable, $table));
-
+
// now apply the second sort and check it is correctly sorted
$table->applyQueuedFilters();
$this->assertTrue(Piwik_DataTable::isEqual($expectedtableReverse, $table));
-
+
// do one more time to make sure it doesnt change
$table->applyQueuedFilters();
$this->assertTrue(Piwik_DataTable::isEqual($expectedtableReverse, $table));
@@ -402,11 +400,11 @@ class DataTableTest extends PHPUnit_Framework_TestCase
/**
* General tests that tries to test the normal behaviour of DataTable
- *
+ *
* We create some tables, add rows, some of the rows link to sub tables
- *
+ *
* Then we serialize everything, and we check that the unserialize give the same object back
- *
+ *
* @group Core
* @group DataTable
*/
@@ -417,11 +415,11 @@ class DataTableTest extends PHPUnit_Framework_TestCase
* does not take in consideration those tables
*/
$useless1 = new Piwik_DataTable;
- $useless1->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array( 13,),));
+ $useless1->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array(13,),));
/*
* end fake tables
*/
-
+
/*
* MAIN TABLE
*/
@@ -429,95 +427,94 @@ class DataTableTest extends PHPUnit_Framework_TestCase
$subtable = new Piwik_DataTable;
$idtable = $table->getId();
$idsubtable = $subtable->getId();
-
+
/*
* create some fake tables to make sure that the serialized array of the first TABLE
* does not take in consideration those tables
* -> we check that the DataTable_Manager is not impacting DataTable
*/
$useless2 = new Piwik_DataTable;
- $useless1->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array( 8487,),));
+ $useless1->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array(8487,),));
$useless3 = new Piwik_DataTable;
- $useless3->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array( 8487,),));
+ $useless3->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array(8487,),));
/*
* end fake tables
*/
-
- $row = array(Piwik_DataTable_Row::COLUMNS => array( 0 => 1554, 1 => 42, 2 => 657,3 => 155744,),
- Piwik_DataTable_Row::METADATA => array('logo' => 'test.png'));
+
+ $row = array(Piwik_DataTable_Row::COLUMNS => array(0 => 1554, 1 => 42, 2 => 657, 3 => 155744,),
+ Piwik_DataTable_Row::METADATA => array('logo' => 'test.png'));
$row = new Piwik_DataTable_Row($row);
-
+
$table->addRow($row);
- $table->addRowFromArray(array( Piwik_DataTable_Row::COLUMNS => array( 0 => 1554,1 => 42,),
- Piwik_DataTable_Row::METADATA => array('url' => 'piwik.org')));
-
- $table->addRowFromArray(array( Piwik_DataTable_Row::COLUMNS => array( 0 => 787877888787,),
- Piwik_DataTable_Row::METADATA => array('url' => 'OUPLA ADDED'),
- Piwik_DataTable_Row::DATATABLE_ASSOCIATED => $subtable));
-
+ $table->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array(0 => 1554, 1 => 42,),
+ Piwik_DataTable_Row::METADATA => array('url' => 'piwik.org')));
+
+ $table->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array(0 => 787877888787,),
+ Piwik_DataTable_Row::METADATA => array('url' => 'OUPLA ADDED'),
+ Piwik_DataTable_Row::DATATABLE_ASSOCIATED => $subtable));
+
/*
* SUB TABLE
- */
-
-
- $row = array( Piwik_DataTable_Row::COLUMNS => array( 0 => 1554,),
- Piwik_DataTable_Row::METADATA => array('searchengine' => 'google'),
- );
+ */
+
+
+ $row = array(Piwik_DataTable_Row::COLUMNS => array(0 => 1554,),
+ Piwik_DataTable_Row::METADATA => array('searchengine' => 'google'),
+ );
$subtable->addRowFromArray($row);
-
- $row = array( Piwik_DataTable_Row::COLUMNS => array( 0 => 84894,),
- Piwik_DataTable_Row::METADATA => array('searchengine' => 'yahoo'),
- );
+
+ $row = array(Piwik_DataTable_Row::COLUMNS => array(0 => 84894,),
+ Piwik_DataTable_Row::METADATA => array('searchengine' => 'yahoo'),
+ );
$subtable->addRowFromArray($row);
- $row = array( Piwik_DataTable_Row::COLUMNS => array( 0 => 4898978989,),
- Piwik_DataTable_Row::METADATA => array('searchengine' => 'ask'),
- );
+ $row = array(Piwik_DataTable_Row::COLUMNS => array(0 => 4898978989,),
+ Piwik_DataTable_Row::METADATA => array('searchengine' => 'ask'),
+ );
$subtable->addRowFromArray($row);
-
-
+
+
/*
* SUB SUB TABLE
*/
$subsubtable = new Piwik_DataTable;
- $subsubtable->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array( 245),
- Piwik_DataTable_Row::METADATA => array('yes' => 'subsubmetadata1'),)
- );
-
- $subsubtable->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array( 13,),
- Piwik_DataTable_Row::METADATA => array('yes' => 'subsubmetadata2'),)
- );
-
- $row = array( Piwik_DataTable_Row::COLUMNS => array( 0 => 666666666666666,),
- Piwik_DataTable_Row::METADATA => array('url' => 'NEW ROW ADDED'),
- Piwik_DataTable_Row::DATATABLE_ASSOCIATED => $subsubtable);
-
+ $subsubtable->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array(245),
+ Piwik_DataTable_Row::METADATA => array('yes' => 'subsubmetadata1'),)
+ );
+
+ $subsubtable->addRowFromArray(array(Piwik_DataTable_Row::COLUMNS => array(13,),
+ Piwik_DataTable_Row::METADATA => array('yes' => 'subsubmetadata2'),)
+ );
+
+ $row = array(Piwik_DataTable_Row::COLUMNS => array(0 => 666666666666666,),
+ Piwik_DataTable_Row::METADATA => array('url' => 'NEW ROW ADDED'),
+ Piwik_DataTable_Row::DATATABLE_ASSOCIATED => $subsubtable);
+
$subtable->addRowFromArray($row);
-
+
$idsubsubtable = $subsubtable->getId();
-
+
$serialized = ($table->getSerialized());
-
- $this->assertEquals(array_keys($serialized), array($idsubsubtable,$idsubtable,0));
-
- // In the next test we compare an unserialized datatable with its original instance.
- // The unserialized datatable rows will have positive DATATABLE_ASSOCIATED ids.
- // Positive DATATABLE_ASSOCIATED ids mean that the associated sub-datatables are not loaded in memory.
- // In this case, this is NOT true: we know that the sub-datatable is loaded in memory.
- // HOWEVER, because of datatable id conflicts happening in the datatable manager, it is not yet
- // possible to know, after unserializing a datatable, if its sub-datatables are loaded in memory.
- $expectedTableRows = array();
- foreach ($table->getRows() as $currentRow) {
- $expectedTableRow = clone $currentRow;
-
- $currentRowAssociatedDatatableId = $currentRow->c[Piwik_DataTable_Row::DATATABLE_ASSOCIATED];
- if($currentRowAssociatedDatatableId != null)
- {
- // making DATATABLE_ASSOCIATED ids positive
- $expectedTableRow->c[Piwik_DataTable_Row::DATATABLE_ASSOCIATED] = -1 * $currentRowAssociatedDatatableId;
- }
-
- $expectedTableRows[] = $expectedTableRow;
- }
+
+ $this->assertEquals(array_keys($serialized), array($idsubsubtable, $idsubtable, 0));
+
+ // In the next test we compare an unserialized datatable with its original instance.
+ // The unserialized datatable rows will have positive DATATABLE_ASSOCIATED ids.
+ // Positive DATATABLE_ASSOCIATED ids mean that the associated sub-datatables are not loaded in memory.
+ // In this case, this is NOT true: we know that the sub-datatable is loaded in memory.
+ // HOWEVER, because of datatable id conflicts happening in the datatable manager, it is not yet
+ // possible to know, after unserializing a datatable, if its sub-datatables are loaded in memory.
+ $expectedTableRows = array();
+ foreach ($table->getRows() as $currentRow) {
+ $expectedTableRow = clone $currentRow;
+
+ $currentRowAssociatedDatatableId = $currentRow->c[Piwik_DataTable_Row::DATATABLE_ASSOCIATED];
+ if ($currentRowAssociatedDatatableId != null) {
+ // making DATATABLE_ASSOCIATED ids positive
+ $expectedTableRow->c[Piwik_DataTable_Row::DATATABLE_ASSOCIATED] = -1 * $currentRowAssociatedDatatableId;
+ }
+
+ $expectedTableRows[] = $expectedTableRow;
+ }
$tableAfter = new Piwik_DataTable;
$tableAfter->addRowsFromSerializedArray($serialized[0]);
@@ -526,12 +523,12 @@ class DataTableTest extends PHPUnit_Framework_TestCase
$subsubtableAfter = new Piwik_DataTable;
$subsubtableAfter->addRowsFromSerializedArray($serialized[$idsubsubtable]);
- $this->assertEquals($subsubtable->getRows(),$subsubtableAfter->getRows());
-
+ $this->assertEquals($subsubtable->getRows(), $subsubtableAfter->getRows());
+
$this->assertEquals($table, Piwik_DataTable_Manager::getInstance()->getTable($idtable));
$this->assertEquals($subsubtable, Piwik_DataTable_Manager::getInstance()->getTable($idsubsubtable));
}
-
+
/**
* for all datatable->addDatatable tests we check that
* - row uniqueness is based on the label + presence of the SUBTABLE id
@@ -539,11 +536,11 @@ class DataTableTest extends PHPUnit_Framework_TestCase
* - no metadata are lost in the first datatable rows that have been changed
* - when a subtable
*/
-
-
+
+
/**
* add an empty datatable to a normal datatable
- *
+ *
* @group Core
* @group DataTable
*/
@@ -553,12 +550,12 @@ class DataTableTest extends PHPUnit_Framework_TestCase
$tableEmpty = new Piwik_DataTable;
$tableAfter = clone $table;
$tableAfter->addDataTable($tableEmpty);
- $this->assertTrue( Piwik_DataTable::isEqual($table, $tableAfter) );
+ $this->assertTrue(Piwik_DataTable::isEqual($table, $tableAfter));
}
-
+
/**
* add a normal datatable to an empty datatable
- *
+ *
* @group Core
* @group DataTable
*/
@@ -567,12 +564,12 @@ class DataTableTest extends PHPUnit_Framework_TestCase
$table = $this->_getDataTable1ForTest();
$tableEmpty = new Piwik_DataTable;
$tableEmpty->addDataTable($table);
- $this->assertTrue( Piwik_DataTable::isEqual($tableEmpty, $table) );
+ $this->assertTrue(Piwik_DataTable::isEqual($tableEmpty, $table));
}
/**
* add to the datatable another datatable// they don't have any row in common
- *
+ *
* @group Core
* @group DataTable
*/
@@ -580,234 +577,234 @@ class DataTableTest extends PHPUnit_Framework_TestCase
{
$table1 = $this->_getDataTable1ForTest();
$table2 = $this->_getDataTable2ForTest();
-
+
$table1->addDataTable($table2);
-
- $rowsExpected = array_merge($this->_getRowsDataTable1ForTest(),$this->_getRowsDataTable2ForTest());
+
+ $rowsExpected = array_merge($this->_getRowsDataTable1ForTest(), $this->_getRowsDataTable2ForTest());
$tableExpected = new Piwik_DataTable;
- $tableExpected->addRowsFromArray( $rowsExpected );
-
- $this->assertTrue( Piwik_DataTable::isEqual($table1, $tableExpected) );
+ $tableExpected->addRowsFromArray($rowsExpected);
+
+ $this->assertTrue(Piwik_DataTable::isEqual($table1, $tableExpected));
}
-
+
/**
* add 2 datatable with some common rows
- *
+ *
* @group Core
* @group DataTable
*/
public function testAddSimpleSomeCommonRow()
{
-
+
$idcol = Piwik_DataTable_Row::COLUMNS;
-
+
$rows = array(
- array( $idcol => array('label'=>'google', 'visits' => 1)),
- array( $idcol => array('label'=>'ask', 'visits' => 2)),
- array( $idcol => array('label'=>'123', 'visits' => 2)),
- Piwik_DataTable::ID_SUMMARY_ROW => array( $idcol => array('label'=>Piwik_DataTable::LABEL_SUMMARY_ROW, 'visits' => 7))
- );
+ array($idcol => array('label' => 'google', 'visits' => 1)),
+ array($idcol => array('label' => 'ask', 'visits' => 2)),
+ array($idcol => array('label' => '123', 'visits' => 2)),
+ Piwik_DataTable::ID_SUMMARY_ROW => array($idcol => array('label' => Piwik_DataTable::LABEL_SUMMARY_ROW, 'visits' => 7))
+ );
$table = new Piwik_DataTable;
- $table->addRowsFromArray( $rows );
-
+ $table->addRowsFromArray($rows);
+
$rows2 = array(
- array( $idcol => array('label'=>'test', 'visits' => 1)),
- array( $idcol => array('label'=>'ask', 'visits' => 111)),
- array( $idcol => array('label'=>' google ', 'visits' => 5)),
- array( $idcol => array('label'=>'123', 'visits' => 2)),
- );
+ array($idcol => array('label' => 'test', 'visits' => 1)),
+ array($idcol => array('label' => 'ask', 'visits' => 111)),
+ array($idcol => array('label' => ' google ', 'visits' => 5)),
+ array($idcol => array('label' => '123', 'visits' => 2)),
+ );
$table2 = new Piwik_DataTable;
- $table2->addRowsFromArray( $rows2 );
-
+ $table2->addRowsFromArray($rows2);
+
$table->addDataTable($table2);
-
+
$rowsExpected = array(
- array( $idcol => array('label'=>'google', 'visits' => 1)),
- array( $idcol => array('label'=>'ask', 'visits' => 113)),
- array( $idcol => array('label'=>'123', 'visits' => 4)),
- array( $idcol => array('label'=>'test', 'visits' => 1)),
- array( $idcol => array('label'=>' google ', 'visits' => 5)),
- Piwik_DataTable::ID_SUMMARY_ROW => array( $idcol => array('label'=>Piwik_DataTable::LABEL_SUMMARY_ROW, 'visits' => 7))
- );
+ array($idcol => array('label' => 'google', 'visits' => 1)),
+ array($idcol => array('label' => 'ask', 'visits' => 113)),
+ array($idcol => array('label' => '123', 'visits' => 4)),
+ array($idcol => array('label' => 'test', 'visits' => 1)),
+ array($idcol => array('label' => ' google ', 'visits' => 5)),
+ Piwik_DataTable::ID_SUMMARY_ROW => array($idcol => array('label' => Piwik_DataTable::LABEL_SUMMARY_ROW, 'visits' => 7))
+ );
$tableExpected = new Piwik_DataTable;
- $tableExpected->addRowsFromArray( $rowsExpected );
-
- $this->assertTrue( Piwik_DataTable::isEqual($table, $tableExpected) );
+ $tableExpected->addRowsFromArray($rowsExpected);
+
+ $this->assertTrue(Piwik_DataTable::isEqual($table, $tableExpected));
}
-
+
/**
* add 2 datatable with only common rows
- *
+ *
* @group Core
* @group DataTable
*/
public function testAddSimpleAllCommonRow()
{
$idcol = Piwik_DataTable_Row::COLUMNS;
-
+
$rows = array(
- array( $idcol => array('label'=>'google', 'visits' => 1)),
- array( $idcol => array('label'=>'ask', 'visits' => 2)),
- array( $idcol => array('label'=>'123', 'visits' => 2)),
- Piwik_DataTable::ID_SUMMARY_ROW => array( $idcol => array('label'=>Piwik_DataTable::LABEL_SUMMARY_ROW, 'visits' => 7))
- );
+ array($idcol => array('label' => 'google', 'visits' => 1)),
+ array($idcol => array('label' => 'ask', 'visits' => 2)),
+ array($idcol => array('label' => '123', 'visits' => 2)),
+ Piwik_DataTable::ID_SUMMARY_ROW => array($idcol => array('label' => Piwik_DataTable::LABEL_SUMMARY_ROW, 'visits' => 7))
+ );
$table = new Piwik_DataTable;
- $table->addRowsFromArray( $rows );
-
+ $table->addRowsFromArray($rows);
+
$rows2 = array(
- array( $idcol => array('label'=>'google', 'visits' => -1)),
- array( $idcol => array('label'=>'ask', 'visits' => 0)),
- array( $idcol => array('label'=>'123', 'visits' => 1.5)),
- Piwik_DataTable::ID_SUMMARY_ROW => array( $idcol => array('label'=>Piwik_DataTable::LABEL_SUMMARY_ROW, 'visits' => 8))
- );
+ array($idcol => array('label' => 'google', 'visits' => -1)),
+ array($idcol => array('label' => 'ask', 'visits' => 0)),
+ array($idcol => array('label' => '123', 'visits' => 1.5)),
+ Piwik_DataTable::ID_SUMMARY_ROW => array($idcol => array('label' => Piwik_DataTable::LABEL_SUMMARY_ROW, 'visits' => 8))
+ );
$table2 = new Piwik_DataTable;
- $table2->addRowsFromArray( $rows2 );
-
+ $table2->addRowsFromArray($rows2);
+
$table->addDataTable($table2);
-
+
$rowsExpected = array(
- array( $idcol => array('label'=>'google', 'visits' => 0)),
- array( $idcol => array('label'=>'ask', 'visits' => 2)),
- array( $idcol => array('label'=>'123', 'visits' => 3.5)),
- Piwik_DataTable::ID_SUMMARY_ROW => array( $idcol => array('label'=>Piwik_DataTable::LABEL_SUMMARY_ROW, 'visits' => 15))
- );
+ array($idcol => array('label' => 'google', 'visits' => 0)),
+ array($idcol => array('label' => 'ask', 'visits' => 2)),
+ array($idcol => array('label' => '123', 'visits' => 3.5)),
+ Piwik_DataTable::ID_SUMMARY_ROW => array($idcol => array('label' => Piwik_DataTable::LABEL_SUMMARY_ROW, 'visits' => 15))
+ );
$tableExpected = new Piwik_DataTable;
- $tableExpected->addRowsFromArray( $rowsExpected );
-
- $this->assertTrue( Piwik_DataTable::isEqual($table, $tableExpected) );
+ $tableExpected->addRowsFromArray($rowsExpected);
+
+ $this->assertTrue(Piwik_DataTable::isEqual($table, $tableExpected));
}
/**
* test add 2 different tables to the same table
- *
+ *
* @group Core
* @group DataTable
*/
public function testAddDataTable2times()
{
-
+
$idcol = Piwik_DataTable_Row::COLUMNS;
-
+
$rows = array(
- array( $idcol => array('label'=>'google', 'visits' => 1)),
- array( $idcol => array('label'=>'ask', 'visits' => 0)),
- array( $idcol => array('label'=>'123', 'visits' => 2)),
- Piwik_DataTable::ID_SUMMARY_ROW => array( $idcol => array('label'=>Piwik_DataTable::LABEL_SUMMARY_ROW, 'visits' => 1))
- );
+ array($idcol => array('label' => 'google', 'visits' => 1)),
+ array($idcol => array('label' => 'ask', 'visits' => 0)),
+ array($idcol => array('label' => '123', 'visits' => 2)),
+ Piwik_DataTable::ID_SUMMARY_ROW => array($idcol => array('label' => Piwik_DataTable::LABEL_SUMMARY_ROW, 'visits' => 1))
+ );
$table = new Piwik_DataTable;
- $table->addRowsFromArray( $rows );
-
+ $table->addRowsFromArray($rows);
+
$rows2 = array(
- array( $idcol => array('label'=>'google2', 'visits' => -1)),
- array( $idcol => array('label'=>'ask', 'visits' => 100)),
- array( $idcol => array('label'=>'123456', 'visits' => 1.5)),
- );
+ array($idcol => array('label' => 'google2', 'visits' => -1)),
+ array($idcol => array('label' => 'ask', 'visits' => 100)),
+ array($idcol => array('label' => '123456', 'visits' => 1.5)),
+ );
$table2 = new Piwik_DataTable;
- $table2->addRowsFromArray( $rows2 );
-
+ $table2->addRowsFromArray($rows2);
+
$rows3 = array(
- array( $idcol => array('label'=>'google2', 'visits' => -1)),
- array( $idcol => array('label'=>'ask', 'visits' => -10)),
- array( $idcol => array('label'=>'123ab', 'visits' => 1.5)),
- Piwik_DataTable::ID_SUMMARY_ROW => array( $idcol => array('label'=>Piwik_DataTable::LABEL_SUMMARY_ROW, 'visits' => 3))
- );
+ array($idcol => array('label' => 'google2', 'visits' => -1)),
+ array($idcol => array('label' => 'ask', 'visits' => -10)),
+ array($idcol => array('label' => '123ab', 'visits' => 1.5)),
+ Piwik_DataTable::ID_SUMMARY_ROW => array($idcol => array('label' => Piwik_DataTable::LABEL_SUMMARY_ROW, 'visits' => 3))
+ );
$table3 = new Piwik_DataTable;
- $table3->addRowsFromArray( $rows3 );
-
+ $table3->addRowsFromArray($rows3);
+
// add the 2 tables
$table->addDataTable($table2);
$table->addDataTable($table3);
-
+
$rowsExpected = array(
- array( $idcol => array('label'=>'google', 'visits' => 1)),
- array( $idcol => array('label'=>'ask', 'visits' => 90)),
- array( $idcol => array('label'=>'123', 'visits' => 2)),
- array( $idcol => array('label'=>'google2', 'visits' => -2)),
- array( $idcol => array('label'=>'123456', 'visits' => 1.5)),
- array( $idcol => array('label'=>'123ab', 'visits' => 1.5)),
- Piwik_DataTable::ID_SUMMARY_ROW => array( $idcol => array('label'=>Piwik_DataTable::LABEL_SUMMARY_ROW, 'visits' => 4))
+ array($idcol => array('label' => 'google', 'visits' => 1)),
+ array($idcol => array('label' => 'ask', 'visits' => 90)),
+ array($idcol => array('label' => '123', 'visits' => 2)),
+ array($idcol => array('label' => 'google2', 'visits' => -2)),
+ array($idcol => array('label' => '123456', 'visits' => 1.5)),
+ array($idcol => array('label' => '123ab', 'visits' => 1.5)),
+ Piwik_DataTable::ID_SUMMARY_ROW => array($idcol => array('label' => Piwik_DataTable::LABEL_SUMMARY_ROW, 'visits' => 4))
);
$tableExpected = new Piwik_DataTable;
- $tableExpected->addRowsFromArray( $rowsExpected );
-
- $this->assertTrue( Piwik_DataTable::isEqual($table, $tableExpected) );
+ $tableExpected->addRowsFromArray($rowsExpected);
+
+ $this->assertTrue(Piwik_DataTable::isEqual($table, $tableExpected));
+ }
+
+
+ /**
+ * @group Core
+ * @group DataTable
+ */
+ public function testUnrelatedDataTableNotDestructed()
+ {
+ $mockedDataTable = $this->getMock('Piwik_DataTable', array('__destruct'));
+ $mockedDataTable->expects($this->never())->method('__destruct');
+
+ $rowBeingDestructed = new Piwik_DataTable_Row();
+
+ // we simulate the fact that the value of Piwik_DataTable_Row::DATATABLE_ASSOCIATED retrieved
+ // from the database is in conflict with one of the Piwik_DataTable_Manager managed table identifiers.
+ // This is a rare but legitimate case as identifiers are not thoroughly synchronized
+ // when the expanded parameter is false.
+ $rowBeingDestructed->c[Piwik_DataTable_Row::DATATABLE_ASSOCIATED] = $mockedDataTable->getId();
+
+ destroy($rowBeingDestructed);
}
+ /**
+ * @group Core
+ * @group DataTable
+ */
+ public function testGetSerializedCallsCleanPostSerialize()
+ {
+ $mockedDataTableRow = $this->getMock('Piwik_DataTable_Row', array('cleanPostSerialize'));
+ $mockedDataTableRow->expects($this->once())->method('cleanPostSerialize');
- /**
- * @group Core
- * @group DataTable
- */
- public function testUnrelatedDataTableNotDestructed()
- {
- $mockedDataTable = $this->getMock('Piwik_DataTable', array('__destruct'));
- $mockedDataTable->expects($this->never())->method('__destruct');
-
- $rowBeingDestructed = new Piwik_DataTable_Row();
-
- // we simulate the fact that the value of Piwik_DataTable_Row::DATATABLE_ASSOCIATED retrieved
- // from the database is in conflict with one of the Piwik_DataTable_Manager managed table identifiers.
- // This is a rare but legitimate case as identifiers are not thoroughly synchronized
- // when the expanded parameter is false.
- $rowBeingDestructed->c[Piwik_DataTable_Row::DATATABLE_ASSOCIATED] = $mockedDataTable->getId();
-
- destroy($rowBeingDestructed);
- }
-
- /**
- * @group Core
- * @group DataTable
- */
- public function testGetSerializedCallsCleanPostSerialize()
- {
- $mockedDataTableRow = $this->getMock('Piwik_DataTable_Row', array('cleanPostSerialize'));
- $mockedDataTableRow->expects($this->once())->method('cleanPostSerialize');
-
- $dataTableBeingSerialized = new Piwik_DataTable();
- $dataTableBeingSerialized->addRow($mockedDataTableRow);
-
- $dataTableBeingSerialized->getSerialized();
- }
-
- /**
- * @group Core
- * @group DataTable
- */
- public function testSubDataTableIsDestructed()
- {
- $mockedDataTable = $this->getMock('Piwik_DataTable', array('__destruct'));
- $mockedDataTable->expects($this->once())->method('__destruct');
-
- $rowBeingDestructed = new Piwik_DataTable_Row();
- $rowBeingDestructed->setSubtable($mockedDataTable);
-
- destroy($rowBeingDestructed);
- }
-
- protected function _getDataTable1ForTest()
+ $dataTableBeingSerialized = new Piwik_DataTable();
+ $dataTableBeingSerialized->addRow($mockedDataTableRow);
+
+ $dataTableBeingSerialized->getSerialized();
+ }
+
+ /**
+ * @group Core
+ * @group DataTable
+ */
+ public function testSubDataTableIsDestructed()
+ {
+ $mockedDataTable = $this->getMock('Piwik_DataTable', array('__destruct'));
+ $mockedDataTable->expects($this->once())->method('__destruct');
+
+ $rowBeingDestructed = new Piwik_DataTable_Row();
+ $rowBeingDestructed->setSubtable($mockedDataTable);
+
+ destroy($rowBeingDestructed);
+ }
+
+ protected function _getDataTable1ForTest()
{
$rows = $this->_getRowsDataTable1ForTest();
$table = new Piwik_DataTable;
- $table->addRowsFromArray( $rows );
+ $table->addRowsFromArray($rows);
return $table;
}
protected function _getDataTable2ForTest()
{
- $rows = $this->_getRowsDataTable2ForTest();
+ $rows = $this->_getRowsDataTable2ForTest();
$table = new Piwik_DataTable;
- $table->addRowsFromArray( $rows );
+ $table->addRowsFromArray($rows);
return $table;
}
-
+
protected function _getRowsDataTable1ForTest()
{
$rows = array(
- array( Piwik_DataTable_Row::COLUMNS => array('label'=>'google', 'visits' => 1)),
- array( Piwik_DataTable_Row::COLUMNS => array('label'=>'ask', 'visits' => 2)),
- array( Piwik_DataTable_Row::COLUMNS => array('label'=>'123', 'visits' => 2)),
- Piwik_DataTable::ID_SUMMARY_ROW => array( Piwik_DataTable_Row::COLUMNS => array('label'=>Piwik_DataTable::LABEL_SUMMARY_ROW, 'visits' => 4))
-
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'google', 'visits' => 1)),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'ask', 'visits' => 2)),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => '123', 'visits' => 2)),
+ Piwik_DataTable::ID_SUMMARY_ROW => array(Piwik_DataTable_Row::COLUMNS => array('label' => Piwik_DataTable::LABEL_SUMMARY_ROW, 'visits' => 4))
+
);
return $rows;
}
@@ -815,9 +812,9 @@ class DataTableTest extends PHPUnit_Framework_TestCase
protected function _getRowsDataTable2ForTest()
{
$rows = array(
- array( Piwik_DataTable_Row::COLUMNS => array('label'=>'test', 'visits' => 1)),
- array( Piwik_DataTable_Row::COLUMNS => array('label'=>' google ', 'visits' => 3)),
- array( Piwik_DataTable_Row::COLUMNS => array('label'=>'123a', 'visits' => 2)),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => 'test', 'visits' => 1)),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => ' google ', 'visits' => 3)),
+ array(Piwik_DataTable_Row::COLUMNS => array('label' => '123a', 'visits' => 2)),
);
return $rows;
}
diff --git a/tests/PHPUnit/Core/DateTest.php b/tests/PHPUnit/Core/DateTest.php
index 860b2d3b34..45d2e1af12 100644
--- a/tests/PHPUnit/Core/DateTest.php
+++ b/tests/PHPUnit/Core/DateTest.php
@@ -9,31 +9,31 @@ class DateTest extends PHPUnit_Framework_TestCase
{
/**
* create today object check that timestamp is correct (midnight)
- *
+ *
* @group Core
* @group Date
*/
public function testToday()
{
$date = Piwik_Date::today();
- $this->assertEquals( strtotime(date("Y-m-d "). " 00:00:00"), $date->getTimestamp());
-
+ $this->assertEquals(strtotime(date("Y-m-d ") . " 00:00:00"), $date->getTimestamp());
+
// test getDatetime()
- $this->assertEquals( $date->getDatetime(), $date->getDateStartUTC());
+ $this->assertEquals($date->getDatetime(), $date->getDateStartUTC());
$date = $date->setTime('12:00:00');
- $this->assertEquals( date('Y-m-d') . ' 12:00:00', $date->getDatetime());
+ $this->assertEquals(date('Y-m-d') . ' 12:00:00', $date->getDatetime());
}
-
+
/**
* create today object check that timestamp is correct (midnight)
- *
+ *
* @group Core
* @group Date
*/
public function testYesterday()
{
$date = Piwik_Date::yesterday();
- $this->assertEquals( strtotime(date("Y-m-d",strtotime('-1day')). " 00:00:00"), $date->getTimestamp());
+ $this->assertEquals(strtotime(date("Y-m-d", strtotime('-1day')) . " 00:00:00"), $date->getTimestamp());
}
/**
@@ -65,14 +65,13 @@ class DateTest extends PHPUnit_Framework_TestCase
$date = Piwik_Date::factory('now', 'Africa/Brazzaville');
$dateExpected = Piwik_Date::factory('now')->addHour(1);
$this->assertEquals($dateExpected->getDatetime(), $date->getDatetime());
-
+
// yesterday same time in Congo is the same as today in Congo - 24 hours
$date = Piwik_Date::factory('yesterdaySameTime', 'Africa/Brazzaville');
$dateExpected = Piwik_Date::factory('now', 'Africa/Brazzaville')->subHour(24);
$this->assertEquals($dateExpected->getDatetime(), $date->getDatetime());
- if(Piwik::isTimezoneSupportEnabled())
- {
+ if (Piwik::isTimezoneSupportEnabled()) {
// convert to/from local time
$now = time();
$date = Piwik_Date::factory($now, 'America/New_York');
@@ -84,7 +83,7 @@ class DateTest extends PHPUnit_Framework_TestCase
$this->assertEquals($now, $time);
}
}
-
+
/**
* @group Core
* @group Date
@@ -92,30 +91,29 @@ class DateTest extends PHPUnit_Framework_TestCase
public function testSetTimezoneDayInUTC()
{
$date = Piwik_Date::factory('2010-01-01');
-
+
$dayStart = '2010-01-01 00:00:00';
$dayEnd = '2010-01-01 23:59:59';
$this->assertEquals($dayStart, $date->getDateStartUTC());
$this->assertEquals($dayEnd, $date->getDateEndUTC());
-
+
// try with empty timezone
$date = $date->setTimezone('');
$this->assertEquals($dayStart, $date->getDateStartUTC());
$this->assertEquals($dayEnd, $date->getDateEndUTC());
-
+
$date = $date->setTimezone('UTC');
$this->assertEquals($dayStart, $date->getDateStartUTC());
$this->assertEquals($dayEnd, $date->getDateEndUTC());
- if(Piwik::isTimezoneSupportEnabled())
- {
+ if (Piwik::isTimezoneSupportEnabled()) {
$date = $date->setTimezone('Europe/Paris');
$utcDayStart = '2009-12-31 23:00:00';
$utcDayEnd = '2010-01-01 22:59:59';
$this->assertEquals($utcDayStart, $date->getDateStartUTC());
$this->assertEquals($utcDayEnd, $date->getDateEndUTC());
}
-
+
$date = $date->setTimezone('UTC+1');
$utcDayStart = '2009-12-31 23:00:00';
$utcDayEnd = '2010-01-01 22:59:59';
@@ -128,8 +126,7 @@ class DateTest extends PHPUnit_Framework_TestCase
$this->assertEquals($utcDayStart, $date->getDateStartUTC());
$this->assertEquals($utcDayEnd, $date->getDateEndUTC());
- if(Piwik::isTimezoneSupportEnabled())
- {
+ if (Piwik::isTimezoneSupportEnabled()) {
$date = $date->setTimezone('America/Vancouver');
$utcDayStart = '2010-01-01 08:00:00';
$utcDayEnd = '2010-01-02 07:59:59';
@@ -137,7 +134,7 @@ class DateTest extends PHPUnit_Framework_TestCase
$this->assertEquals($utcDayEnd, $date->getDateEndUTC());
}
}
-
+
/**
* @group Core
* @group Date
@@ -146,14 +143,13 @@ class DateTest extends PHPUnit_Framework_TestCase
{
$date = Piwik_Date::factory('2010-01-01');
$date = $date->setTimezone('UTC-1');
-
+
$timestamp = $date->getTimestamp();
$date = $date->addHour(0)->addHour(0)->addHour(0);
$this->assertEquals($timestamp, $date->getTimestamp());
-
- if(Piwik::isTimezoneSupportEnabled())
- {
+
+ if (Piwik::isTimezoneSupportEnabled()) {
$date = Piwik_Date::factory('2010-01-01')->setTimezone('Europe/Paris');
$dateExpected = clone $date;
$date = $date->addHour(2);
@@ -161,15 +157,14 @@ class DateTest extends PHPUnit_Framework_TestCase
$this->assertEquals($dateExpected->getTimestamp(), $date->getTimestamp());
}
}
-
+
/**
* @group Core
* @group Date
*/
public function testGetDateStartUTCEndDuringDstTimezone()
{
- if(Piwik::isTimezoneSupportEnabled())
- {
+ if (Piwik::isTimezoneSupportEnabled()) {
$date = Piwik_Date::factory('2010-03-28');
$date = $date->setTimezone('Europe/Paris');
@@ -180,7 +175,7 @@ class DateTest extends PHPUnit_Framework_TestCase
$this->assertEquals($utcDayEnd, $date->getDateEndUTC());
}
}
-
+
/**
* @group Core
* @group Date
@@ -194,12 +189,12 @@ class DateTest extends PHPUnit_Framework_TestCase
$this->assertEquals($dayExpected, $date->getDatetime());
$date = $date->subHour(0.3);
$this->assertEquals($dayStart, $date->getDatetime());
-
+
// add partial hours
$dayExpected = '2010-03-28 05:45:00';
$date = Piwik_Date::factory($dayStart)->addHour(5.75);
$this->assertEquals($dayExpected, $date->getDatetime());
-
+
// remove partial hours
$dayExpected = '2010-03-27 18:15:00';
$date = Piwik_Date::factory($dayStart)->subHour(5.75);
diff --git a/tests/PHPUnit/Core/HttpTest.php b/tests/PHPUnit/Core/HttpTest.php
index de285b2278..3d3ab62b8c 100644
--- a/tests/PHPUnit/Core/HttpTest.php
+++ b/tests/PHPUnit/Core/HttpTest.php
@@ -28,7 +28,7 @@ class HttpTest extends PHPUnit_Framework_TestCase
{
$this->assertNotNull(Piwik_Http::getTransportMethod());
$version = Piwik_Http::sendHttpRequestBy($method, 'http://api.piwik.org/1.0/getLatestVersion/', 5);
- $this->assertTrue( (boolean)preg_match('/^([0-9.]+)$/', $version) );
+ $this->assertTrue((boolean)preg_match('/^([0-9.]+)$/', $version));
}
/**
@@ -40,7 +40,7 @@ class HttpTest extends PHPUnit_Framework_TestCase
$destinationPath = PIWIK_USER_PATH . '/tmp/latest/LATEST';
Piwik_Http::fetchRemoteFile('http://api.piwik.org/1.0/getLatestVersion/', $destinationPath, 3);
$this->assertFileExists($destinationPath);
- $this->assertGreaterThan( 0, filesize($destinationPath) );
+ $this->assertGreaterThan(0, filesize($destinationPath));
}
/**
@@ -52,71 +52,69 @@ class HttpTest extends PHPUnit_Framework_TestCase
$destinationPath = PIWIK_USER_PATH . '/tmp/latest/latest.zip';
Piwik_Http::fetchRemoteFile('http://builds.piwik.org/latest.zip', $destinationPath, 3);
$this->assertFileExists($destinationPath);
- $this->assertGreaterThan( 0, filesize($destinationPath) );
+ $this->assertGreaterThan(0, filesize($destinationPath));
}
-
+
/**
* @group Core
* @group Http
* @dataProvider getMethodsToTest
*/
- public function testCustomByteRange( $method )
+ public function testCustomByteRange($method)
{
$result = Piwik_Http::sendHttpRequestBy(
- $method,
- 'http://builds.piwik.org/latest.zip',
- 5,
- $userAgent = null,
- $destinationPath = null,
- $file = null,
- $followDepth = 0,
- $acceptLanguage = false,
- $acceptInvalidSslCertificate = false,
- $byteRange = array(10, 20),
- $getExtendedInfo = true
- );
-
- if ($method != 'fopen')
- {
- $this->assertEquals(206, $result['status']);
- $this->assertTrue(isset($result['headers']['Content-Range']));
- $this->assertEquals('bytes 10-20/', substr($result['headers']['Content-Range'], 0, 12));
- $this->assertEquals('application/zip', $result['headers']['Content-Type']);
+ $method,
+ 'http://builds.piwik.org/latest.zip',
+ 5,
+ $userAgent = null,
+ $destinationPath = null,
+ $file = null,
+ $followDepth = 0,
+ $acceptLanguage = false,
+ $acceptInvalidSslCertificate = false,
+ $byteRange = array(10, 20),
+ $getExtendedInfo = true
+ );
+
+ if ($method != 'fopen') {
+ $this->assertEquals(206, $result['status']);
+ $this->assertTrue(isset($result['headers']['Content-Range']));
+ $this->assertEquals('bytes 10-20/', substr($result['headers']['Content-Range'], 0, 12));
+ $this->assertEquals('application/zip', $result['headers']['Content-Type']);
}
}
-
+
/**
* @group Core
* @group Http
* @dataProvider getMethodsToTest
*/
- public function testHEADOperation( $method )
+ public function testHEADOperation($method)
{
- if ($method == 'fopen')
- {
- return; // not supported w/ this method
- }
-
+ if ($method == 'fopen') {
+ return; // not supported w/ this method
+ }
+
$result = Piwik_Http::sendHttpRequestBy(
- $method,
- 'http://builds.piwik.org/latest.zip',
- 5,
- $userAgent = null,
- $destinationPath = null,
- $file = null,
- $followDepth = 0,
- $acceptLanguage = false,
- $acceptInvalidSslCertificate = false,
- $byteRange = false,
- $getExtendedInfo = true,
- $httpMethod = 'HEAD'
- );
-
- $this->assertEquals('', $result['data']);
- $this->assertEquals(200, $result['status']);
+ $method,
+ 'http://builds.piwik.org/latest.zip',
+ 5,
+ $userAgent = null,
+ $destinationPath = null,
+ $file = null,
+ $followDepth = 0,
+ $acceptLanguage = false,
+ $acceptInvalidSslCertificate = false,
+ $byteRange = false,
+ $getExtendedInfo = true,
+ $httpMethod = 'HEAD'
+ );
+
+ $this->assertEquals('', $result['data']);
+ $this->assertEquals(200, $result['status']);
- $this->assertTrue(isset($result['headers']['Content-Length']), "Content-Length header not set!");
- $this->assertTrue(is_numeric($result['headers']['Content-Length']), "Content-Length header not numeric!");
- $this->assertEquals('application/zip', $result['headers']['Content-Type']);
+ $this->assertTrue(isset($result['headers']['Content-Length']), "Content-Length header not set!");
+ $this->assertTrue(is_numeric($result['headers']['Content-Length']), "Content-Length header not numeric!");
+ $this->assertEquals('application/zip', $result['headers']['Content-Type']);
}
}
diff --git a/tests/PHPUnit/Core/IPTest.php b/tests/PHPUnit/Core/IPTest.php
index 8f477743b1..d319c2924e 100644
--- a/tests/PHPUnit/Core/IPTest.php
+++ b/tests/PHPUnit/Core/IPTest.php
@@ -10,7 +10,8 @@ class IPTest extends PHPUnit_Framework_TestCase
/**
* Dataprovider for testSanitizeIp
*/
- public function getIPData() {
+ public function getIPData()
+ {
return array( // input, output
// single IPv4 address
array('127.0.0.1', '127.0.0.1'),
@@ -48,7 +49,7 @@ class IPTest extends PHPUnit_Framework_TestCase
array('example.com:80', 'example.com'),
);
}
-
+
/**
* @dataProvider getIPData
* @group Core
@@ -89,7 +90,7 @@ class IPTest extends PHPUnit_Framework_TestCase
array('2001:5c0:1000:b::90f8/64', '2001:5c0:1000:b::90f8/64'),
);
}
-
+
/**
* @dataProvider getIPRangeData
* @group Core
@@ -165,7 +166,7 @@ class IPTest extends PHPUnit_Framework_TestCase
*/
public function testP2NInvalidInput($P)
{
- $this->assertEquals( "\x00\x00\x00\x00", Piwik_IP::P2N($P) );
+ $this->assertEquals("\x00\x00\x00\x00", Piwik_IP::P2N($P));
}
/**
@@ -369,70 +370,70 @@ class IPTest extends PHPUnit_Framework_TestCase
array('0', false),
// single IPv4
- array('127.0.0.1', array( "\x7f\x00\x00\x01", "\x7f\x00\x00\x01" )),
+ array('127.0.0.1', array("\x7f\x00\x00\x01", "\x7f\x00\x00\x01")),
// IPv4 with wildcards
- array('192.168.1.*', array( "\xc0\xa8\x01\x00", "\xc0\xa8\x01\xff" )),
- array('192.168.*.*', array( "\xc0\xa8\x00\x00", "\xc0\xa8\xff\xff" )),
- array('192.*.*.*', array( "\xc0\x00\x00\x00", "\xc0\xff\xff\xff" )),
- array('*.*.*.*', array( "\x00\x00\x00\x00", "\xff\xff\xff\xff" )),
+ array('192.168.1.*', array("\xc0\xa8\x01\x00", "\xc0\xa8\x01\xff")),
+ array('192.168.*.*', array("\xc0\xa8\x00\x00", "\xc0\xa8\xff\xff")),
+ array('192.*.*.*', array("\xc0\x00\x00\x00", "\xc0\xff\xff\xff")),
+ array('*.*.*.*', array("\x00\x00\x00\x00", "\xff\xff\xff\xff")),
// single IPv4 in expected CIDR notation
- array('192.168.1.1/24', array( "\xc0\xa8\x01\x00", "\xc0\xa8\x01\xff" )),
-
- array('192.168.1.127/32', array( "\xc0\xa8\x01\x7f", "\xc0\xa8\x01\x7f" )),
- array('192.168.1.127/31', array( "\xc0\xa8\x01\x7e", "\xc0\xa8\x01\x7f" )),
- array('192.168.1.127/30', array( "\xc0\xa8\x01\x7c", "\xc0\xa8\x01\x7f" )),
- array('192.168.1.127/29', array( "\xc0\xa8\x01\x78", "\xc0\xa8\x01\x7f" )),
- array('192.168.1.127/28', array( "\xc0\xa8\x01\x70", "\xc0\xa8\x01\x7f" )),
- array('192.168.1.127/27', array( "\xc0\xa8\x01\x60", "\xc0\xa8\x01\x7f" )),
- array('192.168.1.127/26', array( "\xc0\xa8\x01\x40", "\xc0\xa8\x01\x7f" )),
- array('192.168.1.127/25', array( "\xc0\xa8\x01\x00", "\xc0\xa8\x01\x7f" )),
-
- array('192.168.1.255/32', array( "\xc0\xa8\x01\xff", "\xc0\xa8\x01\xff" )),
- array('192.168.1.255/31', array( "\xc0\xa8\x01\xfe", "\xc0\xa8\x01\xff" )),
- array('192.168.1.255/30', array( "\xc0\xa8\x01\xfc", "\xc0\xa8\x01\xff" )),
- array('192.168.1.255/29', array( "\xc0\xa8\x01\xf8", "\xc0\xa8\x01\xff" )),
- array('192.168.1.255/28', array( "\xc0\xa8\x01\xf0", "\xc0\xa8\x01\xff" )),
- array('192.168.1.255/27', array( "\xc0\xa8\x01\xe0", "\xc0\xa8\x01\xff" )),
- array('192.168.1.255/26', array( "\xc0\xa8\x01\xc0", "\xc0\xa8\x01\xff" )),
- array('192.168.1.255/25', array( "\xc0\xa8\x01\x80", "\xc0\xa8\x01\xff" )),
-
- array('192.168.255.255/24', array( "\xc0\xa8\xff\x00", "\xc0\xa8\xff\xff" )),
- array('192.168.255.255/23', array( "\xc0\xa8\xfe\x00", "\xc0\xa8\xff\xff" )),
- array('192.168.255.255/22', array( "\xc0\xa8\xfc\x00", "\xc0\xa8\xff\xff" )),
- array('192.168.255.255/21', array( "\xc0\xa8\xf8\x00", "\xc0\xa8\xff\xff" )),
- array('192.168.255.255/20', array( "\xc0\xa8\xf0\x00", "\xc0\xa8\xff\xff" )),
- array('192.168.255.255/19', array( "\xc0\xa8\xe0\x00", "\xc0\xa8\xff\xff" )),
- array('192.168.255.255/18', array( "\xc0\xa8\xc0\x00", "\xc0\xa8\xff\xff" )),
- array('192.168.255.255/17', array( "\xc0\xa8\x80\x00", "\xc0\xa8\xff\xff" )),
+ array('192.168.1.1/24', array("\xc0\xa8\x01\x00", "\xc0\xa8\x01\xff")),
+
+ array('192.168.1.127/32', array("\xc0\xa8\x01\x7f", "\xc0\xa8\x01\x7f")),
+ array('192.168.1.127/31', array("\xc0\xa8\x01\x7e", "\xc0\xa8\x01\x7f")),
+ array('192.168.1.127/30', array("\xc0\xa8\x01\x7c", "\xc0\xa8\x01\x7f")),
+ array('192.168.1.127/29', array("\xc0\xa8\x01\x78", "\xc0\xa8\x01\x7f")),
+ array('192.168.1.127/28', array("\xc0\xa8\x01\x70", "\xc0\xa8\x01\x7f")),
+ array('192.168.1.127/27', array("\xc0\xa8\x01\x60", "\xc0\xa8\x01\x7f")),
+ array('192.168.1.127/26', array("\xc0\xa8\x01\x40", "\xc0\xa8\x01\x7f")),
+ array('192.168.1.127/25', array("\xc0\xa8\x01\x00", "\xc0\xa8\x01\x7f")),
+
+ array('192.168.1.255/32', array("\xc0\xa8\x01\xff", "\xc0\xa8\x01\xff")),
+ array('192.168.1.255/31', array("\xc0\xa8\x01\xfe", "\xc0\xa8\x01\xff")),
+ array('192.168.1.255/30', array("\xc0\xa8\x01\xfc", "\xc0\xa8\x01\xff")),
+ array('192.168.1.255/29', array("\xc0\xa8\x01\xf8", "\xc0\xa8\x01\xff")),
+ array('192.168.1.255/28', array("\xc0\xa8\x01\xf0", "\xc0\xa8\x01\xff")),
+ array('192.168.1.255/27', array("\xc0\xa8\x01\xe0", "\xc0\xa8\x01\xff")),
+ array('192.168.1.255/26', array("\xc0\xa8\x01\xc0", "\xc0\xa8\x01\xff")),
+ array('192.168.1.255/25', array("\xc0\xa8\x01\x80", "\xc0\xa8\x01\xff")),
+
+ array('192.168.255.255/24', array("\xc0\xa8\xff\x00", "\xc0\xa8\xff\xff")),
+ array('192.168.255.255/23', array("\xc0\xa8\xfe\x00", "\xc0\xa8\xff\xff")),
+ array('192.168.255.255/22', array("\xc0\xa8\xfc\x00", "\xc0\xa8\xff\xff")),
+ array('192.168.255.255/21', array("\xc0\xa8\xf8\x00", "\xc0\xa8\xff\xff")),
+ array('192.168.255.255/20', array("\xc0\xa8\xf0\x00", "\xc0\xa8\xff\xff")),
+ array('192.168.255.255/19', array("\xc0\xa8\xe0\x00", "\xc0\xa8\xff\xff")),
+ array('192.168.255.255/18', array("\xc0\xa8\xc0\x00", "\xc0\xa8\xff\xff")),
+ array('192.168.255.255/17', array("\xc0\xa8\x80\x00", "\xc0\xa8\xff\xff")),
// single IPv6
- array('::1', array( "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01", "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01" )),
+ array('::1', array("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01", "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01")),
// single IPv6 in expected CIDR notation
- array('::1/128', array( "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01", "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01" )),
- array('::1/127', array( "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01" )),
- array('::fffe:7f00:1/120', array( "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xfe\x7f\x00\x00\x00", "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xfe\x7f\x00\x00\xff" )),
- array('::ffff:127.0.0.1/120', array( "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x7f\x00\x00\x00", "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x7f\x00\x00\xff" )),
-
- array('2001:ca11:911::b0b:15:dead/128', array( "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xde\xad", "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xde\xad" )),
- array('2001:ca11:911::b0b:15:dead/127', array( "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xde\xac", "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xde\xad" )),
- array('2001:ca11:911::b0b:15:dead/126', array( "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xde\xac", "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xde\xaf" )),
- array('2001:ca11:911::b0b:15:dead/125', array( "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xde\xa8", "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xde\xaf" )),
- array('2001:ca11:911::b0b:15:dead/124', array( "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xde\xa0", "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xde\xaf" )),
- array('2001:ca11:911::b0b:15:dead/123', array( "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xde\xa0", "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xde\xbf" )),
- array('2001:ca11:911::b0b:15:dead/122', array( "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xde\x80", "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xde\xbf" )),
- array('2001:ca11:911::b0b:15:dead/121', array( "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xde\x80", "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xde\xff" )),
- array('2001:ca11:911::b0b:15:dead/120', array( "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xde\x00", "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xde\xff" )),
- array('2001:ca11:911::b0b:15:dead/119', array( "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xde\x00", "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xdf\xff" )),
- array('2001:ca11:911::b0b:15:dead/118', array( "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xdc\x00", "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xdf\xff" )),
- array('2001:ca11:911::b0b:15:dead/117', array( "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xd8\x00", "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xdf\xff" )),
- array('2001:ca11:911::b0b:15:dead/116', array( "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xd0\x00", "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xdf\xff" )),
- array('2001:ca11:911::b0b:15:dead/115', array( "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xc0\x00", "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xdf\xff" )),
- array('2001:ca11:911::b0b:15:dead/114', array( "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xc0\x00", "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xff\xff" )),
- array('2001:ca11:911::b0b:15:dead/113', array( "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\x80\x00", "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xff\xff" )),
- array('2001:ca11:911::b0b:15:dead/112', array( "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\x00\x00", "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xff\xff" )),
+ array('::1/128', array("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01", "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01")),
+ array('::1/127', array("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01")),
+ array('::fffe:7f00:1/120', array("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xfe\x7f\x00\x00\x00", "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xfe\x7f\x00\x00\xff")),
+ array('::ffff:127.0.0.1/120', array("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x7f\x00\x00\x00", "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x7f\x00\x00\xff")),
+
+ array('2001:ca11:911::b0b:15:dead/128', array("\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xde\xad", "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xde\xad")),
+ array('2001:ca11:911::b0b:15:dead/127', array("\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xde\xac", "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xde\xad")),
+ array('2001:ca11:911::b0b:15:dead/126', array("\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xde\xac", "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xde\xaf")),
+ array('2001:ca11:911::b0b:15:dead/125', array("\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xde\xa8", "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xde\xaf")),
+ array('2001:ca11:911::b0b:15:dead/124', array("\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xde\xa0", "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xde\xaf")),
+ array('2001:ca11:911::b0b:15:dead/123', array("\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xde\xa0", "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xde\xbf")),
+ array('2001:ca11:911::b0b:15:dead/122', array("\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xde\x80", "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xde\xbf")),
+ array('2001:ca11:911::b0b:15:dead/121', array("\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xde\x80", "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xde\xff")),
+ array('2001:ca11:911::b0b:15:dead/120', array("\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xde\x00", "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xde\xff")),
+ array('2001:ca11:911::b0b:15:dead/119', array("\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xde\x00", "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xdf\xff")),
+ array('2001:ca11:911::b0b:15:dead/118', array("\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xdc\x00", "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xdf\xff")),
+ array('2001:ca11:911::b0b:15:dead/117', array("\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xd8\x00", "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xdf\xff")),
+ array('2001:ca11:911::b0b:15:dead/116', array("\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xd0\x00", "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xdf\xff")),
+ array('2001:ca11:911::b0b:15:dead/115', array("\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xc0\x00", "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xdf\xff")),
+ array('2001:ca11:911::b0b:15:dead/114', array("\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xc0\x00", "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xff\xff")),
+ array('2001:ca11:911::b0b:15:dead/113', array("\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\x80\x00", "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xff\xff")),
+ array('2001:ca11:911::b0b:15:dead/112', array("\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\x00\x00", "\x20\x01\xca\x11\x09\x11\x00\x00\x00\x00\x0b\x0b\x00\x15\xff\xff")),
);
}
@@ -453,33 +454,33 @@ class IPTest extends PHPUnit_Framework_TestCase
{
return array(
array('192.168.1.10', array(
- '192.168.1.9' => false,
- '192.168.1.10' => true,
- '192.168.1.11' => false,
+ '192.168.1.9' => false,
+ '192.168.1.10' => true,
+ '192.168.1.11' => false,
// IPv6 addresses (including IPv4 mapped) have to be compared against IPv6 address ranges
'::ffff:192.168.1.10' => false,
)),
array('::ffff:192.168.1.10', array(
- '::ffff:192.168.1.9' => false,
- '::ffff:192.168.1.10' => true,
- '::ffff:c0a8:010a' => true,
+ '::ffff:192.168.1.9' => false,
+ '::ffff:192.168.1.10' => true,
+ '::ffff:c0a8:010a' => true,
'0000:0000:0000:0000:0000:ffff:c0a8:010a' => true,
- '::ffff:192.168.1.11' => false,
+ '::ffff:192.168.1.11' => false,
// conversely, IPv4 addresses have to be compared against IPv4 address ranges
- '192.168.1.10' => false,
+ '192.168.1.10' => false,
)),
array('192.168.1.10/32', array(
- '192.168.1.9' => false,
+ '192.168.1.9' => false,
'192.168.1.10' => true,
'192.168.1.11' => false,
)),
array('192.168.1.10/31', array(
- '192.168.1.9' => false,
+ '192.168.1.9' => false,
'192.168.1.10' => true,
'192.168.1.11' => true,
'192.168.1.12' => false,
@@ -489,49 +490,49 @@ class IPTest extends PHPUnit_Framework_TestCase
'192.168.1.127' => false,
'192.168.1.128' => true,
'192.168.1.255' => true,
- '192.168.2.0' => false,
+ '192.168.2.0' => false,
)),
array('192.168.1.10/24', array(
'192.168.0.255' => false,
- '192.168.1.0' => true,
- '192.168.1.1' => true,
- '192.168.1.2' => true,
- '192.168.1.3' => true,
- '192.168.1.4' => true,
- '192.168.1.7' => true,
- '192.168.1.8' => true,
- '192.168.1.15' => true,
- '192.168.1.16' => true,
- '192.168.1.31' => true,
- '192.168.1.32' => true,
- '192.168.1.63' => true,
- '192.168.1.64' => true,
+ '192.168.1.0' => true,
+ '192.168.1.1' => true,
+ '192.168.1.2' => true,
+ '192.168.1.3' => true,
+ '192.168.1.4' => true,
+ '192.168.1.7' => true,
+ '192.168.1.8' => true,
+ '192.168.1.15' => true,
+ '192.168.1.16' => true,
+ '192.168.1.31' => true,
+ '192.168.1.32' => true,
+ '192.168.1.63' => true,
+ '192.168.1.64' => true,
'192.168.1.127' => true,
'192.168.1.128' => true,
'192.168.1.255' => true,
- '192.168.2.0' => false,
+ '192.168.2.0' => false,
)),
array('192.168.1.*', array(
'192.168.0.255' => false,
- '192.168.1.0' => true,
- '192.168.1.1' => true,
- '192.168.1.2' => true,
- '192.168.1.3' => true,
- '192.168.1.4' => true,
- '192.168.1.7' => true,
- '192.168.1.8' => true,
- '192.168.1.15' => true,
- '192.168.1.16' => true,
- '192.168.1.31' => true,
- '192.168.1.32' => true,
- '192.168.1.63' => true,
- '192.168.1.64' => true,
+ '192.168.1.0' => true,
+ '192.168.1.1' => true,
+ '192.168.1.2' => true,
+ '192.168.1.3' => true,
+ '192.168.1.4' => true,
+ '192.168.1.7' => true,
+ '192.168.1.8' => true,
+ '192.168.1.15' => true,
+ '192.168.1.16' => true,
+ '192.168.1.31' => true,
+ '192.168.1.32' => true,
+ '192.168.1.63' => true,
+ '192.168.1.64' => true,
'192.168.1.127' => true,
'192.168.1.128' => true,
'192.168.1.255' => true,
- '192.168.2.0' => false,
+ '192.168.2.0' => false,
)),
);
}
@@ -543,16 +544,15 @@ class IPTest extends PHPUnit_Framework_TestCase
*/
public function testIsIpInRange($range, $test)
{
- foreach($test as $ip => $expected)
- {
+ foreach ($test as $ip => $expected) {
// range as a string
- $this->assertEquals( $expected, Piwik_IP::isIpInRange(Piwik_IP::P2N($ip), array($range)), "$ip in $range" );
+ $this->assertEquals($expected, Piwik_IP::isIpInRange(Piwik_IP::P2N($ip), array($range)), "$ip in $range");
// range as an array(low, high)
$aRange = Piwik_IP::getIpsForRange($range);
$aRange[0] = Piwik_IP::N2P($aRange[0]);
$aRange[1] = Piwik_IP::N2P($aRange[1]);
- $this->assertEquals( $expected, Piwik_IP::isIpInRange(Piwik_IP::P2N($ip), array($aRange)), "$ip in $range" );
+ $this->assertEquals($expected, Piwik_IP::isIpInRange(Piwik_IP::P2N($ip), array($aRange)), "$ip in $range");
}
}
@@ -686,13 +686,12 @@ class IPTest extends PHPUnit_Framework_TestCase
*/
public function testGetHostByAddr()
{
- $hosts = array( 'localhost', 'localhost.localdomain', strtolower(@php_uname('n')), '127.0.0.1' );
- $this->assertTrue( in_array(strtolower(Piwik_IP::getHostByAddr('127.0.0.1')), $hosts), '127.0.0.1 -> localhost' );
+ $hosts = array('localhost', 'localhost.localdomain', strtolower(@php_uname('n')), '127.0.0.1');
+ $this->assertTrue(in_array(strtolower(Piwik_IP::getHostByAddr('127.0.0.1')), $hosts), '127.0.0.1 -> localhost');
- if (!Piwik_Common::isWindows() || PHP_VERSION >= '5.3')
- {
- $hosts = array( 'ip6-localhost', 'localhost', 'localhost.localdomain', strtolower(@php_uname('n')), '::1' );
- $this->assertTrue( in_array(strtolower(Piwik_IP::getHostByAddr('::1')), $hosts), '::1 -> ip6-localhost' );
+ if (!Piwik_Common::isWindows() || PHP_VERSION >= '5.3') {
+ $hosts = array('ip6-localhost', 'localhost', 'localhost.localdomain', strtolower(@php_uname('n')), '::1');
+ $this->assertTrue(in_array(strtolower(Piwik_IP::getHostByAddr('::1')), $hosts), '::1 -> ip6-localhost');
}
}
@@ -702,21 +701,21 @@ class IPTest extends PHPUnit_Framework_TestCase
public function getInetNtopData()
{
return array(
- array('127.0.0.1', '7f000001'),
- array('192.232.131.222', 'c0e883de'),
- array('255.0.0.0', 'ff000000'),
- array('255.255.255.255', 'ffffffff'),
- array('::1', '00000000000000000000000000000001'),
- array('::101', '00000000000000000000000000000101'),
- array('::0.1.1.1', '00000000000000000000000000010101'),
- array('2001:260:0:10::1', '20010260000000100000000000000001'),
- array('2001:0:0:260::1', '20010000000002600000000000000001'),
- array('2001::260:0:0:10:1', '20010000000002600000000000100001'),
- array('2001:5c0:1000:b::90f8', '200105c01000000b00000000000090f8'),
- array('fe80::200:4cff:fe43:172f', 'fe8000000000000002004cfffe43172f'),
- array('::ffff:127.0.0.1', '00000000000000000000ffff7f000001'),
- array('::127.0.0.1', '0000000000000000000000007f000001'),
- array('::fff0:7f00:1', '00000000000000000000fff07f000001'),
+ array('127.0.0.1', '7f000001'),
+ array('192.232.131.222', 'c0e883de'),
+ array('255.0.0.0', 'ff000000'),
+ array('255.255.255.255', 'ffffffff'),
+ array('::1', '00000000000000000000000000000001'),
+ array('::101', '00000000000000000000000000000101'),
+ array('::0.1.1.1', '00000000000000000000000000010101'),
+ array('2001:260:0:10::1', '20010260000000100000000000000001'),
+ array('2001:0:0:260::1', '20010000000002600000000000000001'),
+ array('2001::260:0:0:10:1', '20010000000002600000000000100001'),
+ array('2001:5c0:1000:b::90f8', '200105c01000000b00000000000090f8'),
+ array('fe80::200:4cff:fe43:172f', 'fe8000000000000002004cfffe43172f'),
+ array('::ffff:127.0.0.1', '00000000000000000000ffff7f000001'),
+ array('::127.0.0.1', '0000000000000000000000007f000001'),
+ array('::fff0:7f00:1', '00000000000000000000fff07f000001'),
);
}
@@ -728,7 +727,7 @@ class IPTest extends PHPUnit_Framework_TestCase
public function testPhpCompatInetNtop($k, $v)
{
$this->assertEquals($k, php_compat_inet_ntop(pack('H*', $v)));
- if(!Piwik_Common::isWindows()) {
+ if (!Piwik_Common::isWindows()) {
$this->assertEquals($k, @inet_ntop(pack('H*', $v)));
}
}
@@ -740,59 +739,59 @@ class IPTest extends PHPUnit_Framework_TestCase
public function getInetPtonTestData()
{
return array(
- array('127.0.0.1', '7f000001'),
- array('192.232.131.222', 'c0e883de'),
- array('255.0.0.0', 'ff000000'),
- array('255.255.255.255', 'ffffffff'),
- array('::', '00000000000000000000000000000000'),
- array('::0', '00000000000000000000000000000000'),
- array('0::', '00000000000000000000000000000000'),
- array('0::0', '00000000000000000000000000000000'),
- array('::1', '00000000000000000000000000000001'),
- array('2001:260:0:10::1', '20010260000000100000000000000001'),
- array('2001:5c0:1000:b::90f8', '200105c01000000b00000000000090f8'),
- array('fe80::200:4cff:fe43:172f', 'fe8000000000000002004cfffe43172f'),
- array('::ffff:127.0.0.1', '00000000000000000000ffff7f000001'),
- array('::127.0.0.1', '0000000000000000000000007f000001'),
+ array('127.0.0.1', '7f000001'),
+ array('192.232.131.222', 'c0e883de'),
+ array('255.0.0.0', 'ff000000'),
+ array('255.255.255.255', 'ffffffff'),
+ array('::', '00000000000000000000000000000000'),
+ array('::0', '00000000000000000000000000000000'),
+ array('0::', '00000000000000000000000000000000'),
+ array('0::0', '00000000000000000000000000000000'),
+ array('::1', '00000000000000000000000000000001'),
+ array('2001:260:0:10::1', '20010260000000100000000000000001'),
+ array('2001:5c0:1000:b::90f8', '200105c01000000b00000000000090f8'),
+ array('fe80::200:4cff:fe43:172f', 'fe8000000000000002004cfffe43172f'),
+ array('::ffff:127.0.0.1', '00000000000000000000ffff7f000001'),
+ array('::127.0.0.1', '0000000000000000000000007f000001'),
// relaxed rules
- array('00000::', '00000000000000000000000000000000'),
- array('1:2:3:4:5:ffff:127.0.0.1', '00010002000300040005ffff7f000001'),
+ array('00000::', '00000000000000000000000000000000'),
+ array('1:2:3:4:5:ffff:127.0.0.1', '00010002000300040005ffff7f000001'),
// invalid input
- array(null, false),
- array(false, false),
- array(true, false),
- array('', false),
- array('0', false),
- array('07.07.07.07', false),
- array('1.', false),
- array('.1', false),
- array('1.1', false),
- array('.1.1.', false),
- array('1.1.1.', false),
- array('.1.1.1', false),
- array('1.2.3.4.', false),
- array('.1.2.3.4', false),
- array('1.2.3.256', false),
- array('a.b.c.d', false),
- array('::1::', false),
- array('1:2:3:4:::5:6', false),
- array('1:2:3:4:5:6:', false),
- array(':1:2:3:4:5:6', false),
- array('1:2:3:4:5:6:7:', false),
- array(':1:2:3:4:5:6:7', false),
- array('::11111:0', false),
- array('::g', false),
- array('::ffff:127.00.0.1', false),
- array('::ffff:127.0.0.01', false),
- array('::ffff:256.0.0.1', false),
- array('::ffff:1.256.0.1', false),
- array('::ffff:65536.0.0.1', false),
- array('::ffff:256.65536.0.1', false),
- array('::ffff:65536.65536.0.1', false),
- array('::ffff:7f01:0.1', false),
- array('ffff:127.0.0.1:ffff::', false),
+ array(null, false),
+ array(false, false),
+ array(true, false),
+ array('', false),
+ array('0', false),
+ array('07.07.07.07', false),
+ array('1.', false),
+ array('.1', false),
+ array('1.1', false),
+ array('.1.1.', false),
+ array('1.1.1.', false),
+ array('.1.1.1', false),
+ array('1.2.3.4.', false),
+ array('.1.2.3.4', false),
+ array('1.2.3.256', false),
+ array('a.b.c.d', false),
+ array('::1::', false),
+ array('1:2:3:4:::5:6', false),
+ array('1:2:3:4:5:6:', false),
+ array(':1:2:3:4:5:6', false),
+ array('1:2:3:4:5:6:7:', false),
+ array(':1:2:3:4:5:6:7', false),
+ array('::11111:0', false),
+ array('::g', false),
+ array('::ffff:127.00.0.1', false),
+ array('::ffff:127.0.0.01', false),
+ array('::ffff:256.0.0.1', false),
+ array('::ffff:1.256.0.1', false),
+ array('::ffff:65536.0.0.1', false),
+ array('::ffff:256.65536.0.1', false),
+ array('::ffff:65536.65536.0.1', false),
+ array('::ffff:7f01:0.1', false),
+ array('ffff:127.0.0.1:ffff::', false),
);
}
@@ -804,7 +803,7 @@ class IPTest extends PHPUnit_Framework_TestCase
public function testPhpCompatInetPton($k, $v)
{
$this->assertEquals($v, bin2hex(php_compat_inet_pton($k)));
- if(!Piwik_Common::isWindows()) {
+ if (!Piwik_Common::isWindows()) {
$this->assertEquals($v, bin2hex(@inet_pton($k)));
}
}
diff --git a/tests/PHPUnit/Core/JsProxyTest.php b/tests/PHPUnit/Core/JsProxyTest.php
index 8bab94f010..727b72a40c 100644
--- a/tests/PHPUnit/Core/JsProxyTest.php
+++ b/tests/PHPUnit/Core/JsProxyTest.php
@@ -27,7 +27,7 @@ class Test_Piwik_JsProxy extends PHPUnit_Framework_TestCase
function testPiwikPhp()
{
$curlHandle = curl_init();
- $url = $this->getStaticSrvUrl() . '/js/?idsite=1';
+ $url = $this->getStaticSrvUrl() . '/js/?idsite=1';
curl_setopt($curlHandle, CURLOPT_URL, $url);
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
$fullResponse = curl_exec($curlHandle);
@@ -44,6 +44,6 @@ class Test_Piwik_JsProxy extends PHPUnit_Framework_TestCase
*/
private function getStaticSrvUrl()
{
- return Test_Piwik_BaseFixture::getRootUrl();
+ return Test_Piwik_BaseFixture::getRootUrl();
}
}
diff --git a/tests/PHPUnit/Core/NonceTest.php b/tests/PHPUnit/Core/NonceTest.php
index b734680b56..da64ee35c3 100644
--- a/tests/PHPUnit/Core/NonceTest.php
+++ b/tests/PHPUnit/Core/NonceTest.php
@@ -14,10 +14,10 @@ class NonceTest extends PHPUnit_Framework_TestCase
{
return array(
// HTTP_HOST => expected
- array('example.com', array( 'http://example.com', 'https://example.com' )),
- array('example.com:80', array( 'http://example.com', 'https://example.com' )),
- array('example.com:443', array( 'http://example.com', 'https://example.com' )),
- array('example.com:8080', array( 'http://example.com', 'https://example.com', 'http://example.com:8080', 'https://example.com:8080' )),
+ array('example.com', array('http://example.com', 'https://example.com')),
+ array('example.com:80', array('http://example.com', 'https://example.com')),
+ array('example.com:443', array('http://example.com', 'https://example.com')),
+ array('example.com:8080', array('http://example.com', 'https://example.com', 'http://example.com:8080', 'https://example.com:8080')),
);
}
@@ -31,6 +31,6 @@ class NonceTest extends PHPUnit_Framework_TestCase
Piwik_Config::getInstance()->General['enable_trusted_host_check'] = 0;
$_SERVER['HTTP_HOST'] = $host;
Piwik_Config::getInstance()->General['trusted_hosts'] = array('example.com');
- $this->assertEquals( $expected, Piwik_Nonce::getAcceptableOrigins(), $host );
+ $this->assertEquals($expected, Piwik_Nonce::getAcceptableOrigins(), $host);
}
}
diff --git a/tests/PHPUnit/Core/OptionTest.php b/tests/PHPUnit/Core/OptionTest.php
index 9c2ee3e9a9..63c5903636 100644
--- a/tests/PHPUnit/Core/OptionTest.php
+++ b/tests/PHPUnit/Core/OptionTest.php
@@ -19,11 +19,11 @@ class OptionTest extends DatabaseTestCase
$this->assertFalse(Piwik_Option::getInstance()->get('anonymous_defaultReport'));
// populate table, expect '1' (i.e., found)
- Piwik_Query("INSERT INTO ".Piwik_Common::prefixTable('option')." VALUES ('anonymous_defaultReport', '1', false)");
+ Piwik_Query("INSERT INTO " . Piwik_Common::prefixTable('option') . " VALUES ('anonymous_defaultReport', '1', false)");
$this->assertSame('1', Piwik_Option::getInstance()->get('anonymous_defaultReport'));
// delete row (bypassing API), expect '1' (i.e., from cache)
- Piwik_Query("DELETE FROM ".Piwik_Common::prefixTable('option')." WHERE option_name = ?", array('anonymous_defaultReport'));
+ Piwik_Query("DELETE FROM " . Piwik_Common::prefixTable('option') . " WHERE option_name = ?", array('anonymous_defaultReport'));
$this->assertSame('1', Piwik_Option::getInstance()->get('anonymous_defaultReport'));
// force cache reload, expect false (i.e., not found)
@@ -41,11 +41,11 @@ class OptionTest extends DatabaseTestCase
$this->assertFalse(Piwik_GetOption('anonymous_defaultReport'));
// populate table, expect '1' (i.e., found)
- Piwik_Query("INSERT INTO ".Piwik_Common::prefixTable('option')." VALUES ('anonymous_defaultReport', '1',true)");
+ Piwik_Query("INSERT INTO " . Piwik_Common::prefixTable('option') . " VALUES ('anonymous_defaultReport', '1',true)");
$this->assertSame('1', Piwik_GetOption('anonymous_defaultReport'));
// delete row (bypassing API), expect '1' (i.e., from cache)
- Piwik_Query("DELETE FROM ".Piwik_Common::prefixTable('option')." WHERE option_name = ?", array('anonymous_defaultReport'));
+ Piwik_Query("DELETE FROM " . Piwik_Common::prefixTable('option') . " WHERE option_name = ?", array('anonymous_defaultReport'));
$this->assertSame('1', Piwik_GetOption('anonymous_defaultReport'));
// force cache reload, expect false (i.e., not found)
@@ -60,7 +60,7 @@ class OptionTest extends DatabaseTestCase
public function testSet()
{
// empty table, expect false (i.e., not found)
- $this->assertFalse( Piwik_GetOption('anonymous_defaultReport'));
+ $this->assertFalse(Piwik_GetOption('anonymous_defaultReport'));
// populate table, expect '1'
Piwik_Option::getInstance()->set('anonymous_defaultReport', '1', true);
@@ -114,7 +114,7 @@ class OptionTest extends DatabaseTestCase
// deleted, expect false
Piwik_Option::getInstance()->delete('admin_defaultReport');
- $this->assertFalse( Piwik_Option::getInstance()->get('admin_defaultReport'));
+ $this->assertFalse(Piwik_Option::getInstance()->get('admin_defaultReport'));
}
/**
@@ -130,7 +130,7 @@ class OptionTest extends DatabaseTestCase
// insert guard - to test unescaped underscore
Piwik_SetOption('adefaultReport', '0', true);
- $this->assertTrue( Piwik_GetOption('adefaultReport') === '0' );
+ $this->assertTrue(Piwik_GetOption('adefaultReport') === '0');
// populate table, expect '1'
Piwik_SetOption('anonymous_defaultReport', '1', true);
diff --git a/tests/PHPUnit/Core/Period/DayTest.php b/tests/PHPUnit/Core/Period/DayTest.php
index aed355c512..41117c4177 100644
--- a/tests/PHPUnit/Core/Period/DayTest.php
+++ b/tests/PHPUnit/Core/Period/DayTest.php
@@ -18,13 +18,13 @@ class Period_DayTest extends PHPUnit_Framework_TestCase
public function testInvalidDate()
{
try {
- $period = new Piwik_Period_Day( 'Invalid Date' );
+ $period = new Piwik_Period_Day('Invalid Date');
} catch (Exception $e) {
return;
}
$this->fail('Expected Exception not raised');
}
-
+
/**
* @group Core
* @group Period
@@ -32,9 +32,9 @@ class Period_DayTest extends PHPUnit_Framework_TestCase
*/
public function testToString()
{
- $period = new Piwik_Period_Day( Piwik_Date::today());
+ $period = new Piwik_Period_Day(Piwik_Date::today());
$this->assertEquals(date("Y-m-d"), $period->getPrettyString());
- $this->assertEquals(date("Y-m-d"), (string) $period);
+ $this->assertEquals(date("Y-m-d"), (string)$period);
$this->assertEquals(date("Y-m-d"), $period->toString());
}
@@ -46,7 +46,7 @@ class Period_DayTest extends PHPUnit_Framework_TestCase
*/
public function testDayIsFinishedToday()
{
- $period = new Piwik_Period_Day( Piwik_Date::today());
+ $period = new Piwik_Period_Day(Piwik_Date::today());
$this->assertEquals(date("Y-m-d"), $period->toString());
$this->assertEquals(array(), $period->getSubperiods());
$this->assertEquals(0, $period->getNumberOfSubperiods());
@@ -60,13 +60,13 @@ class Period_DayTest extends PHPUnit_Framework_TestCase
*/
public function testDayIsFinishedYesterday()
{
-
- $period = new Piwik_Period_Day( Piwik_Date::yesterday());
- $this->assertEquals(date("Y-m-d", time()-86400), $period->toString());
+
+ $period = new Piwik_Period_Day(Piwik_Date::yesterday());
+ $this->assertEquals(date("Y-m-d", time() - 86400), $period->toString());
$this->assertEquals(array(), $period->getSubperiods());
$this->assertEquals(0, $period->getNumberOfSubperiods());
}
-
+
/**
* tomorrow is not finished
* @group Core
@@ -74,13 +74,13 @@ class Period_DayTest extends PHPUnit_Framework_TestCase
* @group Period_Day
*/
public function testDayIsFinishedTomorrow()
- {
- $period = new Piwik_Period_Day( Piwik_Date::factory(date("Y-m-d",time()+86400)));
- $this->assertEquals(date("Y-m-d", time()+86400), $period->toString());
+ {
+ $period = new Piwik_Period_Day(Piwik_Date::factory(date("Y-m-d", time() + 86400)));
+ $this->assertEquals(date("Y-m-d", time() + 86400), $period->toString());
$this->assertEquals(array(), $period->getSubperiods());
$this->assertEquals(0, $period->getNumberOfSubperiods());
}
-
+
/**
* test day doesnt exist 31st feb
* @group Core
@@ -88,13 +88,13 @@ class Period_DayTest extends PHPUnit_Framework_TestCase
* @group Period_Day
*/
public function testDayIsFinished31stfeb()
- {
- $period = new Piwik_Period_Day( Piwik_Date::factory("2007-02-31"));
+ {
+ $period = new Piwik_Period_Day(Piwik_Date::factory("2007-02-31"));
$this->assertEquals("2007-03-03", $period->toString());
$this->assertEquals(array(), $period->getSubperiods());
$this->assertEquals(0, $period->getNumberOfSubperiods());
}
-
+
/**
* test date that doesn't exist, should return the corresponding correct date
* @group Core
@@ -104,18 +104,18 @@ class Period_DayTest extends PHPUnit_Framework_TestCase
public function testDayGetDateStart1()
{
// create the period
- $period = new Piwik_Period_Day( Piwik_Date::factory("2007-02-31"));
-
+ $period = new Piwik_Period_Day(Piwik_Date::factory("2007-02-31"));
+
// start date
$startDate = $period->getDateStart();
-
+
// expected string
$this->assertEquals("2007-03-03", $startDate->toString());
-
+
// check that for a day, getDateStart = getStartEnd
$this->assertEquals($startDate, $period->getDateEnd());
}
-
+
/**
* test normal date
* @group Core
@@ -125,18 +125,18 @@ class Period_DayTest extends PHPUnit_Framework_TestCase
public function testDayGetDateStart2()
{
// create the period
- $period = new Piwik_Period_Day( Piwik_Date::factory("2007-01-03"));
-
+ $period = new Piwik_Period_Day(Piwik_Date::factory("2007-01-03"));
+
// start date
$startDate = $period->getDateStart();
-
+
// expected string
$this->assertEquals("2007-01-03", $startDate->toString());
-
+
// check that for a day, getDateStart = getStartEnd
- $this->assertEquals($startDate, $period->getDateEnd() );
+ $this->assertEquals($startDate, $period->getDateEnd());
}
-
+
/**
* test last day of year
* @group Core
@@ -146,18 +146,18 @@ class Period_DayTest extends PHPUnit_Framework_TestCase
public function testDayGetDateStart3()
{
// create the period
- $period = new Piwik_Period_Day( Piwik_Date::factory("2007-12-31"));
-
+ $period = new Piwik_Period_Day(Piwik_Date::factory("2007-12-31"));
+
// start date
$startDate = $period->getDateStart();
-
+
// expected string
$this->assertEquals("2007-12-31", $startDate->toString());
-
+
// check that for a day, getDateStart = getStartEnd
- $this->assertEquals($startDate, $period->getDateEnd() );
+ $this->assertEquals($startDate, $period->getDateEnd());
}
-
+
/**
* test date that doesn't exist, should return the corresponding correct date
* @group Core
@@ -167,15 +167,15 @@ class Period_DayTest extends PHPUnit_Framework_TestCase
public function testDayGetDateEnd1()
{
// create the period
- $period = new Piwik_Period_Day( Piwik_Date::factory("2007-02-31"));
-
+ $period = new Piwik_Period_Day(Piwik_Date::factory("2007-02-31"));
+
// end date
$endDate = $period->getDateEnd();
-
+
// expected string
$this->assertEquals("2007-03-03", $endDate->toString());
}
-
+
/**
* test normal date
* @group Core
@@ -185,15 +185,15 @@ class Period_DayTest extends PHPUnit_Framework_TestCase
public function testDayGetDateEnd2()
{
// create the period
- $period = new Piwik_Period_Day( Piwik_Date::factory("2007-04-15"));
-
+ $period = new Piwik_Period_Day(Piwik_Date::factory("2007-04-15"));
+
// end date
$endDate = $period->getDateEnd();
-
+
// expected string
$this->assertEquals("2007-04-15", $endDate->toString());
}
-
+
/**
* test last day of year
* @group Core
@@ -203,11 +203,11 @@ class Period_DayTest extends PHPUnit_Framework_TestCase
public function testDayGetDateEnd3()
{
// create the period
- $period = new Piwik_Period_Day( Piwik_Date::factory("2007-12-31"));
-
+ $period = new Piwik_Period_Day(Piwik_Date::factory("2007-12-31"));
+
// end date
$endDate = $period->getDateEnd();
-
+
// expected string
$this->assertEquals("2007-12-31", $endDate->toString());
}
@@ -221,7 +221,7 @@ class Period_DayTest extends PHPUnit_Framework_TestCase
public function testAddSubperiodFails()
{
// create the period
- $period = new Piwik_Period_Day( Piwik_Date::factory("2007-12-31"));
+ $period = new Piwik_Period_Day(Piwik_Date::factory("2007-12-31"));
try {
$period->addSubperiod('');
@@ -240,7 +240,7 @@ class Period_DayTest extends PHPUnit_Framework_TestCase
public function testGetLocalizedShortString()
{
Piwik_Translate::getInstance()->loadEnglishTranslation();
- $month = new Piwik_Period_Day( Piwik_Date::factory('2024-10-09'));
+ $month = new Piwik_Period_Day(Piwik_Date::factory('2024-10-09'));
$shouldBe = 'Wed 9 Oct';
$this->assertEquals($shouldBe, $month->getLocalizedShortString());
}
@@ -253,7 +253,7 @@ class Period_DayTest extends PHPUnit_Framework_TestCase
public function testGetLocalizedLongString()
{
Piwik_Translate::getInstance()->loadEnglishTranslation();
- $month = new Piwik_Period_Day( Piwik_Date::factory('2024-10-09'));
+ $month = new Piwik_Period_Day(Piwik_Date::factory('2024-10-09'));
$shouldBe = 'Wednesday 9 October 2024';
$this->assertEquals($shouldBe, $month->getLocalizedLongString());
}
@@ -266,7 +266,7 @@ class Period_DayTest extends PHPUnit_Framework_TestCase
public function testGetPrettyString()
{
Piwik_Translate::getInstance()->loadEnglishTranslation();
- $month = new Piwik_Period_Day( Piwik_Date::factory('2024-10-09'));
+ $month = new Piwik_Period_Day(Piwik_Date::factory('2024-10-09'));
$shouldBe = '2024-10-09';
$this->assertEquals($shouldBe, $month->getPrettyString());
}
diff --git a/tests/PHPUnit/Core/Period/MonthTest.php b/tests/PHPUnit/Core/Period/MonthTest.php
index 95faa87c8e..4d74cbc434 100644
--- a/tests/PHPUnit/Core/Period/MonthTest.php
+++ b/tests/PHPUnit/Core/Period/MonthTest.php
@@ -18,8 +18,8 @@ class Period_MonthTest extends PHPUnit_Framework_TestCase
*/
public function testMonthDec()
{
- $month = new Piwik_Period_Month( Piwik_Date::factory("2006-12-31"));
- $correct=array(
+ $month = new Piwik_Period_Month(Piwik_Date::factory("2006-12-31"));
+ $correct = array(
"2006-12-01",
"2006-12-02",
"2006-12-03",
@@ -54,7 +54,7 @@ class Period_MonthTest extends PHPUnit_Framework_TestCase
$this->assertEquals($correct, $month->toString());
$this->assertEquals(31, $month->getNumberOfSubperiods());
}
-
+
/**
* testing month feb leap year
* @group Core
@@ -63,8 +63,8 @@ class Period_MonthTest extends PHPUnit_Framework_TestCase
*/
public function testMonthFebLeap()
{
- $month = new Piwik_Period_Month( Piwik_Date::factory("2024-02-11"));
- $correct=array(
+ $month = new Piwik_Period_Month(Piwik_Date::factory("2024-02-11"));
+ $correct = array(
"2024-02-01",
"2024-02-02",
"2024-02-03",
@@ -97,7 +97,7 @@ class Period_MonthTest extends PHPUnit_Framework_TestCase
$this->assertEquals($correct, $month->toString());
$this->assertEquals(29, $month->getNumberOfSubperiods());
}
-
+
/**
* testing month feb non-leap year
* @group Core
@@ -106,8 +106,8 @@ class Period_MonthTest extends PHPUnit_Framework_TestCase
*/
public function testMonthFebNonLeap()
{
- $month = new Piwik_Period_Month( Piwik_Date::factory("2023-02-11"));
- $correct=array(
+ $month = new Piwik_Period_Month(Piwik_Date::factory("2023-02-11"));
+ $correct = array(
"2023-02-01",
"2023-02-02",
"2023-02-03",
@@ -139,7 +139,7 @@ class Period_MonthTest extends PHPUnit_Framework_TestCase
$this->assertEquals($correct, $month->toString());
$this->assertEquals(28, $month->getNumberOfSubperiods());
}
-
+
/**
* testing jan
* @group Core
@@ -148,8 +148,8 @@ class Period_MonthTest extends PHPUnit_Framework_TestCase
*/
public function testMonthJan()
{
- $month = new Piwik_Period_Month( Piwik_Date::factory("2007-01-01"));
- $correct=array(
+ $month = new Piwik_Period_Month(Piwik_Date::factory("2007-01-01"));
+ $correct = array(
"2007-01-01",
"2007-01-02",
"2007-01-03",
@@ -184,7 +184,7 @@ class Period_MonthTest extends PHPUnit_Framework_TestCase
$this->assertEquals($correct, $month->toString());
$this->assertEquals(31, $month->getNumberOfSubperiods());
}
-
+
/**
* testing month containing a time change (DST)
* @group Core
@@ -193,8 +193,8 @@ class Period_MonthTest extends PHPUnit_Framework_TestCase
*/
public function testMonthDSTChangeMarch()
{
- $month = new Piwik_Period_Month( Piwik_Date::factory("2007-02-31"));
- $correct=array(
+ $month = new Piwik_Period_Month(Piwik_Date::factory("2007-02-31"));
+ $correct = array(
"2007-03-01",
"2007-03-02",
"2007-03-03",
@@ -229,7 +229,7 @@ class Period_MonthTest extends PHPUnit_Framework_TestCase
$this->assertEquals($correct, $month->toString());
$this->assertEquals(31, $month->getNumberOfSubperiods());
}
-
+
/**
* @group Core
* @group Period
@@ -237,8 +237,8 @@ class Period_MonthTest extends PHPUnit_Framework_TestCase
*/
public function testMonthDSTChangeOct()
{
- $month = new Piwik_Period_Month( Piwik_Date::factory("2017-10-31"));
- $correct=array(
+ $month = new Piwik_Period_Month(Piwik_Date::factory("2017-10-31"));
+ $correct = array(
"2017-10-01",
"2017-10-02",
"2017-10-03",
@@ -282,7 +282,7 @@ class Period_MonthTest extends PHPUnit_Framework_TestCase
public function testGetLocalizedShortString()
{
Piwik_Translate::getInstance()->loadEnglishTranslation();
- $month = new Piwik_Period_Month( Piwik_Date::factory('2024-10-09'));
+ $month = new Piwik_Period_Month(Piwik_Date::factory('2024-10-09'));
$shouldBe = 'Oct 2024';
$this->assertEquals($shouldBe, $month->getLocalizedShortString());
}
@@ -295,7 +295,7 @@ class Period_MonthTest extends PHPUnit_Framework_TestCase
public function testGetLocalizedLongString()
{
Piwik_Translate::getInstance()->loadEnglishTranslation();
- $month = new Piwik_Period_Month( Piwik_Date::factory('2024-10-09'));
+ $month = new Piwik_Period_Month(Piwik_Date::factory('2024-10-09'));
$shouldBe = '2024, October';
$this->assertEquals($shouldBe, $month->getLocalizedLongString());
}
@@ -308,7 +308,7 @@ class Period_MonthTest extends PHPUnit_Framework_TestCase
public function testGetPrettyString()
{
Piwik_Translate::getInstance()->loadEnglishTranslation();
- $month = new Piwik_Period_Month( Piwik_Date::factory('2024-10-09'));
+ $month = new Piwik_Period_Month(Piwik_Date::factory('2024-10-09'));
$shouldBe = '2024-10';
$this->assertEquals($shouldBe, $month->getPrettyString());
}
diff --git a/tests/PHPUnit/Core/Period/RangeTest.php b/tests/PHPUnit/Core/Period/RangeTest.php
index 0f78925be7..ade9afc689 100644
--- a/tests/PHPUnit/Core/Period/RangeTest.php
+++ b/tests/PHPUnit/Core/Period/RangeTest.php
@@ -15,18 +15,18 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase
*/
public function testRangeToday()
{
- $range = new Piwik_Period_Range( 'day', 'last1' );
+ $range = new Piwik_Period_Range('day', 'last1');
$today = Piwik_Date::today();
- $correct=array(
+ $correct = array(
$today->toString(),
);
$correct = array_reverse($correct);
-
+
$this->assertEquals(1, $range->getNumberOfSubperiods());
$this->assertEquals($correct, $range->toString());
}
-
+
/**
* @group Core
* @group Period
@@ -35,18 +35,18 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase
public function testRangeTodayUtcPlus12()
{
// rather ugly test, UTC+23 doesn't exist, but it's a way to test that last1 in UTC+23 will be "our" UTC tomorrow
- $range = new Piwik_Period_Range( 'day', 'last1', 'UTC+23' );
+ $range = new Piwik_Period_Range('day', 'last1', 'UTC+23');
$today = Piwik_Date::now()->addHour(23);
-
- $correct=array(
+
+ $correct = array(
$today->toString(),
);
$correct = array_reverse($correct);
-
+
$this->assertEquals(1, $range->getNumberOfSubperiods());
$this->assertEquals($correct, $range->toString());
}
-
+
// test range 2
/**
* @group Core
@@ -55,19 +55,19 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase
*/
public function testRange2days()
{
- $range = new Piwik_Period_Range( 'day', 'last2' );
+ $range = new Piwik_Period_Range('day', 'last2');
$today = Piwik_Date::today();
-
- $correct=array(
+
+ $correct = array(
$today->toString(),
$today->subDay(1)->toString()
);
$correct = array_reverse($correct);
-
- $this->assertEquals(2, $range->getNumberOfSubperiods());
+
+ $this->assertEquals(2, $range->getNumberOfSubperiods());
$this->assertEquals($correct, $range->toString());
}
-
+
// test range 3
/**
* @group Core
@@ -76,20 +76,19 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase
*/
public function testRange5days()
{
- $range = new Piwik_Period_Range( 'day', 'last50' );
+ $range = new Piwik_Period_Range('day', 'last50');
$today = Piwik_Date::today();
-
+
$correct = array();
- for($i=0;$i<50;$i++)
- {
- $correct[]=$today->subDay($i)->toString();
+ for ($i = 0; $i < 50; $i++) {
+ $correct[] = $today->subDay($i)->toString();
}
$correct = array_reverse($correct);
-
+
$this->assertEquals(50, $range->getNumberOfSubperiods());
$this->assertEquals($correct, $range->toString());
}
-
+
// test range 4
/**
* @group Core
@@ -98,20 +97,19 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase
*/
public function testRangePrevious3days()
{
- $range = new Piwik_Period_Range( 'day', 'previous3' );
+ $range = new Piwik_Period_Range('day', 'previous3');
$yesterday = Piwik_Date::yesterday();
-
+
$correct = array();
- for($i=0;$i<3;$i++)
- {
- $correct[]=$yesterday->subDay($i)->toString();
+ for ($i = 0; $i < 3; $i++) {
+ $correct[] = $yesterday->subDay($i)->toString();
}
$correct = array_reverse($correct);
-
+
$this->assertEquals(3, $range->getNumberOfSubperiods());
$this->assertEquals($correct, $range->toString());
}
-
+
// test range date1,date2
/**
* @group Core
@@ -120,15 +118,15 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase
*/
public function testRangeComma1()
{
-
- $range = new Piwik_Period_Range( 'day', '2008-01-01,2008-01-03' );
-
+
+ $range = new Piwik_Period_Range('day', '2008-01-01,2008-01-03');
+
$correct = array(
- '2008-01-01',
- '2008-01-02',
- '2008-01-03',
- );
-
+ '2008-01-01',
+ '2008-01-02',
+ '2008-01-03',
+ );
+
$this->assertEquals(3, $range->getNumberOfSubperiods());
$this->assertEquals($correct, $range->toString());
}
@@ -141,29 +139,29 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase
*/
public function testRangeComma2()
{
-
- $range = new Piwik_Period_Range( 'day', '2007-12-22,2008-01-03' );
-
+
+ $range = new Piwik_Period_Range('day', '2007-12-22,2008-01-03');
+
$correct = array(
- '2007-12-22',
- '2007-12-23',
- '2007-12-24',
- '2007-12-25',
- '2007-12-26',
- '2007-12-27',
- '2007-12-28',
- '2007-12-29',
- '2007-12-30',
- '2007-12-31',
- '2008-01-01',
- '2008-01-02',
- '2008-01-03',
- );
-
+ '2007-12-22',
+ '2007-12-23',
+ '2007-12-24',
+ '2007-12-25',
+ '2007-12-26',
+ '2007-12-27',
+ '2007-12-28',
+ '2007-12-29',
+ '2007-12-30',
+ '2007-12-31',
+ '2008-01-01',
+ '2008-01-02',
+ '2008-01-03',
+ );
+
$this->assertEquals(13, $range->getNumberOfSubperiods());
$this->assertEquals($correct, $range->toString());
}
-
+
// test range date1,date2
/**
* @group Core
@@ -172,45 +170,45 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase
*/
public function testRangeWeekcomma1()
{
- $range = new Piwik_Period_Range( 'week', '2007-12-22,2008-01-03' );
- $range2 = new Piwik_Period_Range( 'week', '2007-12-19,2008-01-03' );
-
+ $range = new Piwik_Period_Range('week', '2007-12-22,2008-01-03');
+ $range2 = new Piwik_Period_Range('week', '2007-12-19,2008-01-03');
+
$correct = array(
- array(
- '2007-12-17',
- '2007-12-18',
- '2007-12-19',
- '2007-12-20',
- '2007-12-21',
- '2007-12-22',
- '2007-12-23',
- ),
- array(
- '2007-12-24',
- '2007-12-25',
- '2007-12-26',
- '2007-12-27',
- '2007-12-28',
- '2007-12-29',
- '2007-12-30',
- ),
- array(
- '2007-12-31',
- '2008-01-01',
- '2008-01-02',
- '2008-01-03',
- '2008-01-04',
- '2008-01-05',
- '2008-01-06',
- )
+ array(
+ '2007-12-17',
+ '2007-12-18',
+ '2007-12-19',
+ '2007-12-20',
+ '2007-12-21',
+ '2007-12-22',
+ '2007-12-23',
+ ),
+ array(
+ '2007-12-24',
+ '2007-12-25',
+ '2007-12-26',
+ '2007-12-27',
+ '2007-12-28',
+ '2007-12-29',
+ '2007-12-30',
+ ),
+ array(
+ '2007-12-31',
+ '2008-01-01',
+ '2008-01-02',
+ '2008-01-03',
+ '2008-01-04',
+ '2008-01-05',
+ '2008-01-06',
+ )
);
-
+
$this->assertEquals(count($correct), $range->getNumberOfSubperiods());
$this->assertEquals(count($correct), $range2->getNumberOfSubperiods());
$this->assertEquals($correct, $range->toString());
$this->assertEquals($correct, $range2->toString());
}
-
+
// test range date1,date2
/**
* @group Core
@@ -219,43 +217,43 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase
*/
public function testRangeYearcomma1()
{
- $range = new Piwik_Period_Range( 'year', '2006-12-22,2007-01-03' );
-
+ $range = new Piwik_Period_Range('year', '2006-12-22,2007-01-03');
+
$correct = array(
- array (
- 0 => '2006-01-01',
- 1 => '2006-02-01',
- 2 => '2006-03-01',
- 3 => '2006-04-01',
- 4 => '2006-05-01',
- 5 => '2006-06-01',
- 6 => '2006-07-01',
- 7 => '2006-08-01',
- 8 => '2006-09-01',
- 9 => '2006-10-01',
+ array(
+ 0 => '2006-01-01',
+ 1 => '2006-02-01',
+ 2 => '2006-03-01',
+ 3 => '2006-04-01',
+ 4 => '2006-05-01',
+ 5 => '2006-06-01',
+ 6 => '2006-07-01',
+ 7 => '2006-08-01',
+ 8 => '2006-09-01',
+ 9 => '2006-10-01',
10 => '2006-11-01',
11 => '2006-12-01',
- ),
- 1 =>
- array (
- 0 => '2007-01-01',
- 1 => '2007-02-01',
- 2 => '2007-03-01',
- 3 => '2007-04-01',
- 4 => '2007-05-01',
- 5 => '2007-06-01',
- 6 => '2007-07-01',
- 7 => '2007-08-01',
- 8 => '2007-09-01',
- 9 => '2007-10-01',
+ ),
+ 1 =>
+ array(
+ 0 => '2007-01-01',
+ 1 => '2007-02-01',
+ 2 => '2007-03-01',
+ 3 => '2007-04-01',
+ 4 => '2007-05-01',
+ 5 => '2007-06-01',
+ 6 => '2007-07-01',
+ 7 => '2007-08-01',
+ 8 => '2007-09-01',
+ 9 => '2007-10-01',
10 => '2007-11-01',
11 => '2007-12-01',
- ),
+ ),
);
$this->assertEquals(count($correct), $range->getNumberOfSubperiods());
$this->assertEquals($correct, $range->toString());
}
-
+
// test range date1,date2
/**
* @group Core
@@ -264,77 +262,77 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase
*/
public function testRangeMonthcomma1()
{
- $range = new Piwik_Period_Range( 'month', '2006-12-22,2007-01-03' );
-
+ $range = new Piwik_Period_Range('month', '2006-12-22,2007-01-03');
+
$correct = array(
- array(
- '2006-12-01',
- '2006-12-02',
- '2006-12-03',
- '2006-12-04',
- '2006-12-05',
- '2006-12-06',
- '2006-12-07',
- '2006-12-08',
- '2006-12-09',
- '2006-12-10',
- '2006-12-11',
- '2006-12-12',
- '2006-12-13',
- '2006-12-14',
- '2006-12-15',
- '2006-12-16',
- '2006-12-17',
- '2006-12-18',
- '2006-12-19',
- '2006-12-20',
- '2006-12-21',
- '2006-12-22',
- '2006-12-23',
- '2006-12-24',
- '2006-12-25',
- '2006-12-26',
- '2006-12-27',
- '2006-12-28',
- '2006-12-29',
- '2006-12-30',
- '2006-12-31',
- ),
- array(
- '2007-01-01',
- '2007-01-02',
- '2007-01-03',
- '2007-01-04',
- '2007-01-05',
- '2007-01-06',
- '2007-01-07',
- '2007-01-08',
- '2007-01-09',
- '2007-01-10',
- '2007-01-11',
- '2007-01-12',
- '2007-01-13',
- '2007-01-14',
- '2007-01-15',
- '2007-01-16',
- '2007-01-17',
- '2007-01-18',
- '2007-01-19',
- '2007-01-20',
- '2007-01-21',
- '2007-01-22',
- '2007-01-23',
- '2007-01-24',
- '2007-01-25',
- '2007-01-26',
- '2007-01-27',
- '2007-01-28',
- '2007-01-29',
- '2007-01-30',
- '2007-01-31',
- ),
+ array(
+ '2006-12-01',
+ '2006-12-02',
+ '2006-12-03',
+ '2006-12-04',
+ '2006-12-05',
+ '2006-12-06',
+ '2006-12-07',
+ '2006-12-08',
+ '2006-12-09',
+ '2006-12-10',
+ '2006-12-11',
+ '2006-12-12',
+ '2006-12-13',
+ '2006-12-14',
+ '2006-12-15',
+ '2006-12-16',
+ '2006-12-17',
+ '2006-12-18',
+ '2006-12-19',
+ '2006-12-20',
+ '2006-12-21',
+ '2006-12-22',
+ '2006-12-23',
+ '2006-12-24',
+ '2006-12-25',
+ '2006-12-26',
+ '2006-12-27',
+ '2006-12-28',
+ '2006-12-29',
+ '2006-12-30',
+ '2006-12-31',
+ ),
+ array(
+ '2007-01-01',
+ '2007-01-02',
+ '2007-01-03',
+ '2007-01-04',
+ '2007-01-05',
+ '2007-01-06',
+ '2007-01-07',
+ '2007-01-08',
+ '2007-01-09',
+ '2007-01-10',
+ '2007-01-11',
+ '2007-01-12',
+ '2007-01-13',
+ '2007-01-14',
+ '2007-01-15',
+ '2007-01-16',
+ '2007-01-17',
+ '2007-01-18',
+ '2007-01-19',
+ '2007-01-20',
+ '2007-01-21',
+ '2007-01-22',
+ '2007-01-23',
+ '2007-01-24',
+ '2007-01-25',
+ '2007-01-26',
+ '2007-01-27',
+ '2007-01-28',
+ '2007-01-29',
+ '2007-01-30',
+ '2007-01-31',
+ ),
);
-
+
$this->assertEquals(count($correct), $range->getNumberOfSubperiods());
$this->assertEquals($correct, $range->toString());
}
@@ -347,24 +345,23 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase
*/
public function testRangeWeek()
{
- $range = new Piwik_Period_Range( 'week', 'last50' );
+ $range = new Piwik_Period_Range('week', 'last50');
$today = Piwik_Date::today();
-
+
$correct = array();
- for($i=0;$i<50;$i++)
- {
- $date = $today->subDay($i*7);
+ for ($i = 0; $i < 50; $i++) {
+ $date = $today->subDay($i * 7);
$week = new Piwik_Period_Week($date);
-
- $correct[]= $week->toString();
+
+ $correct[] = $week->toString();
}
$correct = array_reverse($correct);
-
-
+
+
$this->assertEquals(50, $range->getNumberOfSubperiods());
$this->assertEquals($correct, $range->toString());
}
-
+
// test range WEEK last1
/**
* @group Core
@@ -373,12 +370,12 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase
*/
public function testRangeWeekLast1()
{
- $range = new Piwik_Period_Range( 'week', 'last1' );
+ $range = new Piwik_Period_Range('week', 'last1');
$currentWeek = new Piwik_Period_Week(Piwik_Date::today());
$this->assertEquals(1, $range->getNumberOfSubperiods());
$this->assertEquals(array($currentWeek->toString()), $range->toString());
}
-
+
// test range MONTH
/**
* @group Core
@@ -387,23 +384,22 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase
*/
public function testRangeMonth()
{
- $range = new Piwik_Period_Range( 'month', 'last20' );
+ $range = new Piwik_Period_Range('month', 'last20');
$today = Piwik_Date::today();
-
+
$correct = array();
- for($i=0;$i<20;$i++)
- {
+ for ($i = 0; $i < 20; $i++) {
$date = $today->subMonth($i);
$week = new Piwik_Period_Month($date);
-
- $correct[]= $week->toString();
+
+ $correct[] = $week->toString();
}
$correct = array_reverse($correct);
-
+
$this->assertEquals(20, $range->getNumberOfSubperiods());
$this->assertEquals($correct, $range->toString());
}
-
+
// test range MONTH last1
/**
* @group Core
@@ -412,12 +408,12 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase
*/
public function testRangeMonthLast1()
{
- $range = new Piwik_Period_Range( 'month', 'last1' );
+ $range = new Piwik_Period_Range('month', 'last1');
$month = new Piwik_Period_Month(Piwik_Date::today());
$this->assertEquals(1, $range->getNumberOfSubperiods());
$this->assertEquals(array($month->toString()), $range->toString());
}
-
+
// test range PREVIOUS MONTH
/**
* @group Core
@@ -426,21 +422,20 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase
*/
public function testRangePreviousmonth()
{
- $range = new Piwik_Period_Range( 'month', 'previous10' );
+ $range = new Piwik_Period_Range('month', 'previous10');
$end = Piwik_Date::today();
$end = $end->subMonth(1);
-
+
$correct = array();
- for($i=0;$i<10;$i++)
- {
+ for ($i = 0; $i < 10; $i++) {
$date = $end->subMonth($i);
$week = new Piwik_Period_Month($date);
-
- $correct[]= $week->toString();
+
+ $correct[] = $week->toString();
}
$correct = array_reverse($correct);
-
-
+
+
$this->assertEquals(10, $range->getNumberOfSubperiods());
$this->assertEquals($correct, $range->toString());
}
@@ -453,23 +448,22 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase
*/
public function testRangeYear()
{
- $range = new Piwik_Period_Range( 'year', 'last10' );
+ $range = new Piwik_Period_Range('year', 'last10');
$today = Piwik_Date::today();
-
+
$correct = array();
- for($i=0;$i<10;$i++)
- {
- $date = $today->subMonth(12*$i);
+ for ($i = 0; $i < 10; $i++) {
+ $date = $today->subMonth(12 * $i);
$week = new Piwik_Period_Year($date);
-
- $correct[]= $week->toString();
+
+ $correct[] = $week->toString();
}
$correct = array_reverse($correct);
-
+
$this->assertEquals(10, $range->getNumberOfSubperiods());
$this->assertEquals($correct, $range->toString());
}
-
+
// test range YEAR last1
/**
* @group Core
@@ -478,12 +472,12 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase
*/
public function testRangeYearLast1()
{
- $range = new Piwik_Period_Range( 'year', 'last1' );
+ $range = new Piwik_Period_Range('year', 'last1');
$currentYear = new Piwik_Period_Year(Piwik_Date::today());
$this->assertEquals(1, $range->getNumberOfSubperiods());
$this->assertEquals(array($currentYear->toString()), $range->toString());
}
-
+
/**
* @group Core
* @group Period
@@ -491,8 +485,8 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase
*/
public function testCustomRangeWeekInsideEndingToday()
{
- $range = new Piwik_Period_Range( 'range', '2007-12-22,2008-01-03', 'UTC', Piwik_Date::factory('2008-01-03') );
-
+ $range = new Piwik_Period_Range('range', '2007-12-22,2008-01-03', 'UTC', Piwik_Date::factory('2008-01-03'));
+
$correct = array(
'2007-12-22',
'2007-12-23',
@@ -518,7 +512,7 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase
$this->assertEquals(count($correct), $range->getNumberOfSubperiods());
$this->assertEquals($correct, $range->toString());
}
-
+
/**
* @group Core
* @group Period
@@ -533,11 +527,10 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase
Piwik_Date::factory('2008-02-14'),
Piwik_Date::factory('2009-02-14'),
);
-
- foreach($todays as $today)
- {
- $range = new Piwik_Period_Range( 'range', '2007-12-22,2008-01-03', 'UTC', $today );
-
+
+ foreach ($todays as $today) {
+ $range = new Piwik_Period_Range('range', '2007-12-22,2008-01-03', 'UTC', $today);
+
$correct = array(
'2007-12-22',
'2007-12-23',
@@ -559,7 +552,7 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase
$this->assertEquals($correct, $range->toString());
}
}
-
+
/**
* @group Core
* @group Period
@@ -567,8 +560,8 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase
*/
public function testCustomRangeOnlyDaysLessThanOneWeek()
{
- $range = new Piwik_Period_Range( 'range', '2007-12-30,2008-01-01' );
-
+ $range = new Piwik_Period_Range('range', '2007-12-30,2008-01-01');
+
$correct = array(
'2007-12-30',
'2007-12-31',
@@ -577,7 +570,7 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase
$this->assertEquals(count($correct), $range->getNumberOfSubperiods());
$this->assertEquals($correct, $range->toString());
}
-
+
/**
* @group Core
* @group Period
@@ -585,17 +578,17 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase
*/
public function testCustomRangeOneWeekOnly()
{
- $range = new Piwik_Period_Range( 'range', '2007-12-31,2008-01-06' );
-
+ $range = new Piwik_Period_Range('range', '2007-12-31,2008-01-06');
+
$correct = array(
array(
- '2007-12-31',
- '2008-01-01',
- '2008-01-02',
- '2008-01-03',
- '2008-01-04',
- '2008-01-05',
- '2008-01-06',
+ '2007-12-31',
+ '2008-01-01',
+ '2008-01-02',
+ '2008-01-03',
+ '2008-01-04',
+ '2008-01-05',
+ '2008-01-06',
)
);
$this->assertEquals(count($correct), $range->getNumberOfSubperiods());
@@ -609,17 +602,17 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase
*/
public function testCustomRangeStartsWithWeek()
{
- $range = new Piwik_Period_Range( 'range', '2007-12-31,2008-01-08' );
-
+ $range = new Piwik_Period_Range('range', '2007-12-31,2008-01-08');
+
$correct = array(
array(
- '2007-12-31',
- '2008-01-01',
- '2008-01-02',
- '2008-01-03',
- '2008-01-04',
- '2008-01-05',
- '2008-01-06',
+ '2007-12-31',
+ '2008-01-01',
+ '2008-01-02',
+ '2008-01-03',
+ '2008-01-04',
+ '2008-01-05',
+ '2008-01-06',
),
'2008-01-07',
'2008-01-08',
@@ -627,7 +620,7 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase
$this->assertEquals(count($correct), $range->getNumberOfSubperiods());
$this->assertEquals($correct, $range->toString());
}
-
+
/**
* @group Core
* @group Period
@@ -635,29 +628,29 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase
*/
public function testCustomRangeEndsWithWeek()
{
- $range = new Piwik_Period_Range( 'range', '2007-12-21,2008-01-06' );
-
+ $range = new Piwik_Period_Range('range', '2007-12-21,2008-01-06');
+
$correct = array(
'2007-12-21',
'2007-12-22',
'2007-12-23',
array(
- '2007-12-24',
- '2007-12-25',
- '2007-12-26',
- '2007-12-27',
- '2007-12-28',
- '2007-12-29',
- '2007-12-30',
+ '2007-12-24',
+ '2007-12-25',
+ '2007-12-26',
+ '2007-12-27',
+ '2007-12-28',
+ '2007-12-29',
+ '2007-12-30',
),
array(
- '2007-12-31',
- '2008-01-01',
- '2008-01-02',
- '2008-01-03',
- '2008-01-04',
- '2008-01-05',
- '2008-01-06',
+ '2007-12-31',
+ '2008-01-01',
+ '2008-01-02',
+ '2008-01-03',
+ '2008-01-04',
+ '2008-01-05',
+ '2008-01-06',
),
);
$this->assertEquals(count($correct), $range->getNumberOfSubperiods());
@@ -671,61 +664,61 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase
*/
public function testCustomRangeContainsMonthAndWeek()
{
- $range = new Piwik_Period_Range( 'range', '2011-09-18,2011-11-02', 'UTC', Piwik_Date::factory('2012-01-01') );
-
+ $range = new Piwik_Period_Range('range', '2011-09-18,2011-11-02', 'UTC', Piwik_Date::factory('2012-01-01'));
+
$correct = array(
-
- '2011-09-18',
- array(
- '2011-09-19',
- '2011-09-20',
- '2011-09-21',
- '2011-09-22',
- '2011-09-23',
- '2011-09-24',
- '2011-09-25',
- ),
-
- '2011-09-26',
- '2011-09-27',
- '2011-09-28',
- '2011-09-29',
- '2011-09-30',
- array(
- "2011-10-01",
- "2011-10-02",
- "2011-10-03",
- "2011-10-04",
- "2011-10-05",
- "2011-10-06",
- "2011-10-07",
- "2011-10-08",
- "2011-10-09",
- "2011-10-10",
- "2011-10-11",
- "2011-10-12",
- "2011-10-13",
- "2011-10-14",
- "2011-10-15",
- "2011-10-16",
- "2011-10-17",
- "2011-10-18",
- "2011-10-19",
- "2011-10-20",
- "2011-10-21",
- "2011-10-22",
- "2011-10-23",
- "2011-10-24",
- "2011-10-25",
- "2011-10-26",
- "2011-10-27",
- "2011-10-28",
- "2011-10-29",
- "2011-10-30",
- "2011-10-31",
- ),
- "2011-11-01",
- "2011-11-02",
+
+ '2011-09-18',
+ array(
+ '2011-09-19',
+ '2011-09-20',
+ '2011-09-21',
+ '2011-09-22',
+ '2011-09-23',
+ '2011-09-24',
+ '2011-09-25',
+ ),
+
+ '2011-09-26',
+ '2011-09-27',
+ '2011-09-28',
+ '2011-09-29',
+ '2011-09-30',
+ array(
+ "2011-10-01",
+ "2011-10-02",
+ "2011-10-03",
+ "2011-10-04",
+ "2011-10-05",
+ "2011-10-06",
+ "2011-10-07",
+ "2011-10-08",
+ "2011-10-09",
+ "2011-10-10",
+ "2011-10-11",
+ "2011-10-12",
+ "2011-10-13",
+ "2011-10-14",
+ "2011-10-15",
+ "2011-10-16",
+ "2011-10-17",
+ "2011-10-18",
+ "2011-10-19",
+ "2011-10-20",
+ "2011-10-21",
+ "2011-10-22",
+ "2011-10-23",
+ "2011-10-24",
+ "2011-10-25",
+ "2011-10-26",
+ "2011-10-27",
+ "2011-10-28",
+ "2011-10-29",
+ "2011-10-30",
+ "2011-10-31",
+ ),
+ "2011-11-01",
+ "2011-11-02",
);
$this->assertEquals(count($correct), $range->getNumberOfSubperiods());
$this->assertEquals($correct, $range->toString());
@@ -748,45 +741,115 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase
Piwik_Date::factory('2011-12-31'),
Piwik_Date::factory('2021-10-18')
);
- foreach($todays as $today)
- {
- $range = new Piwik_Period_Range( 'range', '2011-08-01,2011-10-17', 'UTC', $today );
-
+ foreach ($todays as $today) {
+ $range = new Piwik_Period_Range('range', '2011-08-01,2011-10-17', 'UTC', $today);
+
$correct = array(
-
- array(
- "2011-08-01",
- "2011-08-02",
- "2011-08-03",
- "2011-08-04",
- "2011-08-05",
- "2011-08-06",
- "2011-08-07",
- "2011-08-08",
- "2011-08-09",
- "2011-08-10",
- "2011-08-11",
- "2011-08-12",
- "2011-08-13",
- "2011-08-14",
- "2011-08-15",
- "2011-08-16",
- "2011-08-17",
- "2011-08-18",
- "2011-08-19",
- "2011-08-20",
- "2011-08-21",
- "2011-08-22",
- "2011-08-23",
- "2011-08-24",
- "2011-08-25",
- "2011-08-26",
- "2011-08-27",
- "2011-08-28",
- "2011-08-29",
- "2011-08-30",
- "2011-08-31",
- ),
+
+ array(
+ "2011-08-01",
+ "2011-08-02",
+ "2011-08-03",
+ "2011-08-04",
+ "2011-08-05",
+ "2011-08-06",
+ "2011-08-07",
+ "2011-08-08",
+ "2011-08-09",
+ "2011-08-10",
+ "2011-08-11",
+ "2011-08-12",
+ "2011-08-13",
+ "2011-08-14",
+ "2011-08-15",
+ "2011-08-16",
+ "2011-08-17",
+ "2011-08-18",
+ "2011-08-19",
+ "2011-08-20",
+ "2011-08-21",
+ "2011-08-22",
+ "2011-08-23",
+ "2011-08-24",
+ "2011-08-25",
+ "2011-08-26",
+ "2011-08-27",
+ "2011-08-28",
+ "2011-08-29",
+ "2011-08-30",
+ "2011-08-31",
+ ),
+ array(
+ "2011-09-01",
+ "2011-09-02",
+ "2011-09-03",
+ "2011-09-04",
+ "2011-09-05",
+ "2011-09-06",
+ "2011-09-07",
+ "2011-09-08",
+ "2011-09-09",
+ "2011-09-10",
+ "2011-09-11",
+ "2011-09-12",
+ "2011-09-13",
+ "2011-09-14",
+ "2011-09-15",
+ "2011-09-16",
+ "2011-09-17",
+ "2011-09-18",
+ "2011-09-19",
+ "2011-09-20",
+ "2011-09-21",
+ "2011-09-22",
+ "2011-09-23",
+ "2011-09-24",
+ "2011-09-25",
+ "2011-09-26",
+ "2011-09-27",
+ "2011-09-28",
+ "2011-09-29",
+ "2011-09-30",
+ ),
+ "2011-10-01",
+ "2011-10-02",
+
+ array(
+ "2011-10-03",
+ "2011-10-04",
+ "2011-10-05",
+ "2011-10-06",
+ "2011-10-07",
+ "2011-10-08",
+ "2011-10-09",
+ ),
+ array(
+ "2011-10-10",
+ "2011-10-11",
+ "2011-10-12",
+ "2011-10-13",
+ "2011-10-14",
+ "2011-10-15",
+ "2011-10-16",
+ ),
+ "2011-10-17",
+ );
+
+ $this->assertEquals(count($correct), $range->getNumberOfSubperiods());
+ $this->assertEquals($correct, $range->toString());
+ }
+ }
+
+ /**
+ * @group Core
+ * @group Period
+ * @group Period_Range
+ */
+ public function testCustomRangeOneMonthOnly()
+ {
+ $range = new Piwik_Period_Range('range', '2011-09-01,2011-09-30');
+
+ $correct = array(
array(
"2011-09-01",
"2011-09-02",
@@ -818,82 +881,11 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase
"2011-09-28",
"2011-09-29",
"2011-09-30",
- ),
- "2011-10-01",
- "2011-10-02",
-
- array(
- "2011-10-03",
- "2011-10-04",
- "2011-10-05",
- "2011-10-06",
- "2011-10-07",
- "2011-10-08",
- "2011-10-09",
- ),
- array(
- "2011-10-10",
- "2011-10-11",
- "2011-10-12",
- "2011-10-13",
- "2011-10-14",
- "2011-10-15",
- "2011-10-16",
- ),
- "2011-10-17",
- );
-
- $this->assertEquals(count($correct), $range->getNumberOfSubperiods());
- $this->assertEquals($correct, $range->toString());
- }
- }
-
- /**
- * @group Core
- * @group Period
- * @group Period_Range
- */
- public function testCustomRangeOneMonthOnly()
- {
- $range = new Piwik_Period_Range( 'range', '2011-09-01,2011-09-30' );
-
- $correct = array(
- array(
- "2011-09-01",
- "2011-09-02",
- "2011-09-03",
- "2011-09-04",
- "2011-09-05",
- "2011-09-06",
- "2011-09-07",
- "2011-09-08",
- "2011-09-09",
- "2011-09-10",
- "2011-09-11",
- "2011-09-12",
- "2011-09-13",
- "2011-09-14",
- "2011-09-15",
- "2011-09-16",
- "2011-09-17",
- "2011-09-18",
- "2011-09-19",
- "2011-09-20",
- "2011-09-21",
- "2011-09-22",
- "2011-09-23",
- "2011-09-24",
- "2011-09-25",
- "2011-09-26",
- "2011-09-27",
- "2011-09-28",
- "2011-09-29",
- "2011-09-30",
- ));
+ ));
$this->assertEquals(count($correct), $range->getNumberOfSubperiods());
$this->assertEquals($correct, $range->toString());
}
-
+
/**
* @group Core
* @group Period
@@ -901,56 +893,56 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase
*/
public function test_CustomRange_startsWithWeek_EndsWithMonth()
{
- $range = new Piwik_Period_Range( 'range', '2011-07-25,2011-08-31' );
-
+ $range = new Piwik_Period_Range('range', '2011-07-25,2011-08-31');
+
$correct = array(
-
- array(
- '2011-07-25',
- '2011-07-26',
- '2011-07-27',
- '2011-07-28',
- '2011-07-29',
- '2011-07-30',
- '2011-07-31',
- ),
- array(
- "2011-08-01",
- "2011-08-02",
- "2011-08-03",
- "2011-08-04",
- "2011-08-05",
- "2011-08-06",
- "2011-08-07",
- "2011-08-08",
- "2011-08-09",
- "2011-08-10",
- "2011-08-11",
- "2011-08-12",
- "2011-08-13",
- "2011-08-14",
- "2011-08-15",
- "2011-08-16",
- "2011-08-17",
- "2011-08-18",
- "2011-08-19",
- "2011-08-20",
- "2011-08-21",
- "2011-08-22",
- "2011-08-23",
- "2011-08-24",
- "2011-08-25",
- "2011-08-26",
- "2011-08-27",
- "2011-08-28",
- "2011-08-29",
- "2011-08-30",
- "2011-08-31",
- ));
+
+ array(
+ '2011-07-25',
+ '2011-07-26',
+ '2011-07-27',
+ '2011-07-28',
+ '2011-07-29',
+ '2011-07-30',
+ '2011-07-31',
+ ),
+ array(
+ "2011-08-01",
+ "2011-08-02",
+ "2011-08-03",
+ "2011-08-04",
+ "2011-08-05",
+ "2011-08-06",
+ "2011-08-07",
+ "2011-08-08",
+ "2011-08-09",
+ "2011-08-10",
+ "2011-08-11",
+ "2011-08-12",
+ "2011-08-13",
+ "2011-08-14",
+ "2011-08-15",
+ "2011-08-16",
+ "2011-08-17",
+ "2011-08-18",
+ "2011-08-19",
+ "2011-08-20",
+ "2011-08-21",
+ "2011-08-22",
+ "2011-08-23",
+ "2011-08-24",
+ "2011-08-25",
+ "2011-08-26",
+ "2011-08-27",
+ "2011-08-28",
+ "2011-08-29",
+ "2011-08-30",
+ "2011-08-31",
+ ));
$this->assertEquals(count($correct), $range->getNumberOfSubperiods());
$this->assertEquals($correct, $range->toString());
}
-
+
/**
* @group Core
* @group Period
@@ -959,17 +951,17 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase
public function testCustomRangeBeforeIsAfterYearRight()
{
try {
- $range = new Piwik_Period_Range( 'range', '2007-02-09,2007-02-01' );
+ $range = new Piwik_Period_Range('range', '2007-02-09,2007-02-01');
$this->assertEquals(0, $range->getNumberOfSubperiods());
$this->assertEquals(array(), $range->toString());
-
+
$range->getPrettyString();
} catch (Exception $e) {
return;
}
$this->fail('Expected exception not raised');
}
-
+
/**
* @group Core
* @group Period
@@ -977,13 +969,13 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase
*/
public function testCustomRangeLastN()
{
- $range = new Piwik_Period_Range( 'range', 'last4' );
+ $range = new Piwik_Period_Range('range', 'last4');
$range->setDefaultEndDate(Piwik_Date::factory('2008-01-03'));
$correct = array(
- '2007-12-31',
- '2008-01-01',
- '2008-01-02',
- '2008-01-03',
+ '2007-12-31',
+ '2008-01-01',
+ '2008-01-02',
+ '2008-01-03',
);
$this->assertEquals(count($correct), $range->getNumberOfSubperiods());
$this->assertEquals($correct, $range->toString());
@@ -996,17 +988,17 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase
*/
public function testCustomRangePreviousN()
{
- $range = new Piwik_Period_Range( 'range', 'previous3' );
+ $range = new Piwik_Period_Range('range', 'previous3');
$range->setDefaultEndDate(Piwik_Date::factory('2008-01-03'));
$correct = array(
- '2007-12-31',
- '2008-01-01',
- '2008-01-02',
+ '2007-12-31',
+ '2008-01-01',
+ '2008-01-02',
);
$this->assertEquals(count($correct), $range->getNumberOfSubperiods());
$this->assertEquals($correct, $range->toString());
}
-
+
/**
* @group Core
* @group Period
@@ -1014,16 +1006,16 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase
*/
public function testCustomRangePreviousNEndToday()
{
- $range = new Piwik_Period_Range( 'range', 'previous3' );
+ $range = new Piwik_Period_Range('range', 'previous3');
$correct = array(
- date('Y-m-d',time()-86400*3),
- date('Y-m-d',time()-86400*2),
- date('Y-m-d',time()-86400*1),
+ date('Y-m-d', time() - 86400 * 3),
+ date('Y-m-d', time() - 86400 * 2),
+ date('Y-m-d', time() - 86400 * 1),
);
$this->assertEquals(count($correct), $range->getNumberOfSubperiods());
$this->assertEquals($correct, $range->toString());
}
-
+
/**
* @group Core
* @group Period
@@ -1032,7 +1024,7 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase
public function testInvalidRangeThrows()
{
try {
- $range = new Piwik_Period_Range( 'range', '0001-01-01,today' );
+ $range = new Piwik_Period_Range('range', '0001-01-01,today');
$range->getLocalizedLongString();
} catch (Exception $e) {
return;
@@ -1048,7 +1040,7 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase
public function testGetLocalizedShortString()
{
Piwik_Translate::getInstance()->loadEnglishTranslation();
- $month = new Piwik_Period_Range( 'range', '2000-12-09,2001-02-01' );
+ $month = new Piwik_Period_Range('range', '2000-12-09,2001-02-01');
$shouldBe = '9 Dec 00 - 1 Feb 01';
$this->assertEquals($shouldBe, $month->getLocalizedShortString());
}
@@ -1061,7 +1053,7 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase
public function testGetLocalizedLongString()
{
Piwik_Translate::getInstance()->loadEnglishTranslation();
- $month = new Piwik_Period_Range( 'range', '2023-05-09,2023-05-21' );
+ $month = new Piwik_Period_Range('range', '2023-05-09,2023-05-21');
$shouldBe = '8 May 23 - 21 May 23';
$this->assertEquals($shouldBe, $month->getLocalizedLongString());
}
@@ -1074,31 +1066,31 @@ class Period_RangeTest extends PHPUnit_Framework_TestCase
public function testGetPrettyString()
{
Piwik_Translate::getInstance()->loadEnglishTranslation();
- $month = new Piwik_Period_Range( 'range', '2007-02-09,2007-03-15' );
+ $month = new Piwik_Period_Range('range', '2007-02-09,2007-03-15');
$shouldBe = 'From 2007-02-09 to 2007-03-15';
$this->assertEquals($shouldBe, $month->getPrettyString());
}
-
- /**
- * Data provider for testLastNLimits.
- */
- public function getDataForLastNLimitsTest()
- {
- return array(array('day', 5*365 + 1, 5*365),
- array('week', 10*52 + 1, 10*52),
- array('month', 121, 120),
- array('year', 11, 10));
- }
-
- /**
- * @group Core
- * @group Period
- * @group Period_Range
+
+ /**
+ * Data provider for testLastNLimits.
+ */
+ public function getDataForLastNLimitsTest()
+ {
+ return array(array('day', 5 * 365 + 1, 5 * 365),
+ array('week', 10 * 52 + 1, 10 * 52),
+ array('month', 121, 120),
+ array('year', 11, 10));
+ }
+
+ /**
+ * @group Core
+ * @group Period
+ * @group Period_Range
* @dataProvider getDataForLastNLimitsTest
- */
- public function testLastNLimits($period, $lastN, $expectedLastN)
- {
- $range = new Piwik_Period_Range($period, 'last'.$lastN);
- $this->assertEquals($expectedLastN, $range->getNumberOfSubperiods());
- }
+ */
+ public function testLastNLimits($period, $lastN, $expectedLastN)
+ {
+ $range = new Piwik_Period_Range($period, 'last' . $lastN);
+ $this->assertEquals($expectedLastN, $range->getNumberOfSubperiods());
+ }
}
diff --git a/tests/PHPUnit/Core/Period/WeekTest.php b/tests/PHPUnit/Core/Period/WeekTest.php
index faa866e954..a6f1c758e2 100644
--- a/tests/PHPUnit/Core/Period/WeekTest.php
+++ b/tests/PHPUnit/Core/Period/WeekTest.php
@@ -18,8 +18,8 @@ class Period_WeekTest extends PHPUnit_Framework_TestCase
*/
public function testWeekBetween2years()
{
- $week = new Piwik_Period_Week( Piwik_Date::factory("2006-01-01"));
- $correct=array(
+ $week = new Piwik_Period_Week(Piwik_Date::factory("2006-01-01"));
+ $correct = array(
"2005-12-26",
"2005-12-27",
"2005-12-28",
@@ -30,7 +30,7 @@ class Period_WeekTest extends PHPUnit_Framework_TestCase
$this->assertEquals($correct, $week->toString());
$this->assertEquals(7, $week->getNumberOfSubperiods());
}
-
+
/**
* test week between 2 months Week Mai 29 To Mai 31 2006
* @group Core
@@ -39,8 +39,8 @@ class Period_WeekTest extends PHPUnit_Framework_TestCase
*/
public function testWeekBetween2month()
{
- $week = new Piwik_Period_Week( Piwik_Date::factory("2006-05-29"));
- $correct=array(
+ $week = new Piwik_Period_Week(Piwik_Date::factory("2006-05-29"));
+ $correct = array(
"2006-05-29",
"2006-05-30",
"2006-05-31",
@@ -51,7 +51,7 @@ class Period_WeekTest extends PHPUnit_Framework_TestCase
$this->assertEquals($correct, $week->toString());
$this->assertEquals(7, $week->getNumberOfSubperiods());
}
-
+
/**
* test week between feb and march for leap year
* @group Core
@@ -60,7 +60,7 @@ class Period_WeekTest extends PHPUnit_Framework_TestCase
*/
public function testWeekFebLeapyear()
{
- $correct=array(
+ $correct = array(
'2023-02-27',
'2023-02-28',
'2023-03-01',
@@ -68,15 +68,15 @@ class Period_WeekTest extends PHPUnit_Framework_TestCase
'2023-03-03',
'2023-03-04',
'2023-03-05',);
-
- $week = new Piwik_Period_Week( Piwik_Date::factory('2023-02-27'));
+
+ $week = new Piwik_Period_Week(Piwik_Date::factory('2023-02-27'));
$this->assertEquals($correct, $week->toString());
$this->assertEquals(7, $week->getNumberOfSubperiods());
- $week = new Piwik_Period_Week( Piwik_Date::factory('2023-03-01'));
+ $week = new Piwik_Period_Week(Piwik_Date::factory('2023-03-01'));
$this->assertEquals($correct, $week->toString());
$this->assertEquals(7, $week->getNumberOfSubperiods());
}
-
+
/**
* test week between feb and march for no leap year
* @group Core
@@ -85,7 +85,7 @@ class Period_WeekTest extends PHPUnit_Framework_TestCase
*/
public function testWeekFebnonLeapyear()
{
- $correct=array(
+ $correct = array(
'2024-02-26',
'2024-02-27',
'2024-02-28',
@@ -93,15 +93,15 @@ class Period_WeekTest extends PHPUnit_Framework_TestCase
'2024-03-01',
'2024-03-02',
'2024-03-03',);
-
- $week = new Piwik_Period_Week( Piwik_Date::factory('2024-02-27'));
+
+ $week = new Piwik_Period_Week(Piwik_Date::factory('2024-02-27'));
$this->assertEquals($correct, $week->toString());
$this->assertEquals(7, $week->getNumberOfSubperiods());
- $week = new Piwik_Period_Week( Piwik_Date::factory('2024-03-01'));
+ $week = new Piwik_Period_Week(Piwik_Date::factory('2024-03-01'));
$this->assertEquals($correct, $week->toString());
$this->assertEquals(7, $week->getNumberOfSubperiods());
}
-
+
/**
* test week normal middle of the month
* @group Core
@@ -110,7 +110,7 @@ class Period_WeekTest extends PHPUnit_Framework_TestCase
*/
public function testWeekMiddleofmonth()
{
- $correct=array(
+ $correct = array(
'2024-10-07',
'2024-10-08',
'2024-10-09',
@@ -118,8 +118,8 @@ class Period_WeekTest extends PHPUnit_Framework_TestCase
'2024-10-11',
'2024-10-12',
'2024-10-13',);
-
- $week = new Piwik_Period_Week( Piwik_Date::factory('2024-10-09'));
+
+ $week = new Piwik_Period_Week(Piwik_Date::factory('2024-10-09'));
$this->assertEquals($correct, $week->toString());
$this->assertEquals(7, $week->getNumberOfSubperiods());
}
@@ -132,7 +132,7 @@ class Period_WeekTest extends PHPUnit_Framework_TestCase
public function testGetLocalizedShortString()
{
Piwik_Translate::getInstance()->loadEnglishTranslation();
- $week = new Piwik_Period_Week( Piwik_Date::factory('2024-10-09'));
+ $week = new Piwik_Period_Week(Piwik_Date::factory('2024-10-09'));
$shouldBe = '7 Oct - 13 Oct 24';
$this->assertEquals($shouldBe, $week->getLocalizedShortString());
}
@@ -145,7 +145,7 @@ class Period_WeekTest extends PHPUnit_Framework_TestCase
public function testGetLocalizedLongString()
{
Piwik_Translate::getInstance()->loadEnglishTranslation();
- $week = new Piwik_Period_Week( Piwik_Date::factory('2024-10-09'));
+ $week = new Piwik_Period_Week(Piwik_Date::factory('2024-10-09'));
$shouldBe = 'Week 7 October - 13 October 2024';
$this->assertEquals($shouldBe, $week->getLocalizedLongString());
}
@@ -158,7 +158,7 @@ class Period_WeekTest extends PHPUnit_Framework_TestCase
public function testGetPrettyString()
{
Piwik_Translate::getInstance()->loadEnglishTranslation();
- $week = new Piwik_Period_Week( Piwik_Date::factory('2024-10-09'));
+ $week = new Piwik_Period_Week(Piwik_Date::factory('2024-10-09'));
$shouldBe = 'From 2024-10-07 to 2024-10-13';
$this->assertEquals($shouldBe, $week->getPrettyString());
}
diff --git a/tests/PHPUnit/Core/Period/YearTest.php b/tests/PHPUnit/Core/Period/YearTest.php
index c96bb8c3f2..11ea08b2b0 100644
--- a/tests/PHPUnit/Core/Period/YearTest.php
+++ b/tests/PHPUnit/Core/Period/YearTest.php
@@ -18,7 +18,7 @@ class Period_YearTest extends PHPUnit_Framework_TestCase
*/
public function testYearNormalcase()
{
- $correct=array(
+ $correct = array(
'2024-01-01',
'2024-02-01',
'2024-03-01',
@@ -31,12 +31,12 @@ class Period_YearTest extends PHPUnit_Framework_TestCase
'2024-10-01',
'2024-11-01',
'2024-12-01',);
-
- $year = new Piwik_Period_Year( Piwik_Date::factory('2024-10-09'));
+
+ $year = new Piwik_Period_Year(Piwik_Date::factory('2024-10-09'));
$this->assertEquals(12, $year->getNumberOfSubperiods());
$this->assertEquals($correct, $year->toString());
}
-
+
/**
* test past
* @group Core
@@ -45,7 +45,7 @@ class Period_YearTest extends PHPUnit_Framework_TestCase
*/
public function testYearPastAndWrongdate()
{
- $correct=array(
+ $correct = array(
'2000-01-01',
'2000-02-01',
'2000-03-01',
@@ -59,8 +59,8 @@ class Period_YearTest extends PHPUnit_Framework_TestCase
'2000-11-01',
'2000-12-01',
);
-
- $year = new Piwik_Period_Year( Piwik_Date::factory('2000-02-15'));
+
+ $year = new Piwik_Period_Year(Piwik_Date::factory('2000-02-15'));
$this->assertEquals(12, $year->getNumberOfSubperiods());
$this->assertEquals($correct, $year->toString());
}
@@ -73,7 +73,7 @@ class Period_YearTest extends PHPUnit_Framework_TestCase
public function testGetLocalizedShortString()
{
Piwik_Translate::getInstance()->loadEnglishTranslation();
- $year = new Piwik_Period_Year( Piwik_Date::factory('2024-10-09'));
+ $year = new Piwik_Period_Year(Piwik_Date::factory('2024-10-09'));
$shouldBe = '2024';
$this->assertEquals($shouldBe, $year->getLocalizedShortString());
}
@@ -86,7 +86,7 @@ class Period_YearTest extends PHPUnit_Framework_TestCase
public function testGetLocalizedLongString()
{
Piwik_Translate::getInstance()->loadEnglishTranslation();
- $year = new Piwik_Period_Year( Piwik_Date::factory('2024-10-09'));
+ $year = new Piwik_Period_Year(Piwik_Date::factory('2024-10-09'));
$shouldBe = '2024';
$this->assertEquals($shouldBe, $year->getLocalizedLongString());
}
@@ -99,7 +99,7 @@ class Period_YearTest extends PHPUnit_Framework_TestCase
public function testGetPrettyString()
{
Piwik_Translate::getInstance()->loadEnglishTranslation();
- $year = new Piwik_Period_Year( Piwik_Date::factory('2024-10-09'));
+ $year = new Piwik_Period_Year(Piwik_Date::factory('2024-10-09'));
$shouldBe = '2024';
$this->assertEquals($shouldBe, $year->getPrettyString());
}
diff --git a/tests/PHPUnit/Core/PeriodTest.php b/tests/PHPUnit/Core/PeriodTest.php
index 2cabd1157f..c7ab39662b 100644
--- a/tests/PHPUnit/Core/PeriodTest.php
+++ b/tests/PHPUnit/Core/PeriodTest.php
@@ -13,37 +13,37 @@ class PeriodTest extends PHPUnit_Framework_TestCase
*/
public function testGetId()
{
- $period = new Piwik_Period_Day( Piwik_Date::today() );
- $this->assertNotEquals( 0, $period->getId() );
- $period = new Piwik_Period_Week( Piwik_Date::today() );
- $this->assertNotEquals( 0, $period->getId() );
- $period = new Piwik_Period_Month( Piwik_Date::today() );
- $this->assertNotEquals( 0, $period->getId() );
- $period = new Piwik_Period_Year( Piwik_Date::today() );
- $this->assertNotEquals( 0, $period->getId() );
+ $period = new Piwik_Period_Day(Piwik_Date::today());
+ $this->assertNotEquals(0, $period->getId());
+ $period = new Piwik_Period_Week(Piwik_Date::today());
+ $this->assertNotEquals(0, $period->getId());
+ $period = new Piwik_Period_Month(Piwik_Date::today());
+ $this->assertNotEquals(0, $period->getId());
+ $period = new Piwik_Period_Year(Piwik_Date::today());
+ $this->assertNotEquals(0, $period->getId());
}
-
+
/**
* @group Core
* @group Period
*/
public function testGetLabel()
{
- $period = new Piwik_Period_Day( Piwik_Date::today() );
+ $period = new Piwik_Period_Day(Piwik_Date::today());
$label = $period->getLabel();
- $this->assertInternalType( 'string', $label);
+ $this->assertInternalType('string', $label);
$this->assertNotEmpty($label);
- $period = new Piwik_Period_Week( Piwik_Date::today() );
+ $period = new Piwik_Period_Week(Piwik_Date::today());
$label = $period->getLabel();
- $this->assertInternalType( 'string', $label);
+ $this->assertInternalType('string', $label);
$this->assertNotEmpty($label);
- $period = new Piwik_Period_Month( Piwik_Date::today() );
+ $period = new Piwik_Period_Month(Piwik_Date::today());
$label = $period->getLabel();
- $this->assertInternalType( 'string', $label);
+ $this->assertInternalType('string', $label);
$this->assertNotEmpty($label);
- $period = new Piwik_Period_Year( Piwik_Date::today() );
+ $period = new Piwik_Period_Year(Piwik_Date::today());
$label = $period->getLabel();
- $this->assertInternalType( 'string', $label);
+ $this->assertInternalType('string', $label);
$this->assertNotEmpty($label);
}
diff --git a/tests/PHPUnit/Core/PiwikTest.php b/tests/PHPUnit/Core/PiwikTest.php
index 0061af1585..fbb7741515 100644
--- a/tests/PHPUnit/Core/PiwikTest.php
+++ b/tests/PHPUnit/Core/PiwikTest.php
@@ -13,13 +13,13 @@ class PiwikTest extends DatabaseTestCase
public function getValidNumeric()
{
$valid = array(
- -1, 0 , 1, 1.5, -1.5, 21111, 89898, 99999999999, -4565656,
- (float)-1, (float)0 , (float)1, (float)1.5, (float)-1.5, (float)21111, (float)89898, (float)99999999999, (float)-4565656,
- (int)-1, (int)0 , (int)1, (int)1.5, (int)-1.5, (int)21111, (int)89898, (int)99999999999, (int)-4565656,
- '-1', '0' , '1', '1.5', '-1.5', '21111', '89898', '99999999999', '-4565656',
- '1e3','0x123', "-1e-2",
+ -1, 0, 1, 1.5, -1.5, 21111, 89898, 99999999999, -4565656,
+ (float)-1, (float)0, (float)1, (float)1.5, (float)-1.5, (float)21111, (float)89898, (float)99999999999, (float)-4565656,
+ (int)-1, (int)0, (int)1, (int)1.5, (int)-1.5, (int)21111, (int)89898, (int)99999999999, (int)-4565656,
+ '-1', '0', '1', '1.5', '-1.5', '21111', '89898', '99999999999', '-4565656',
+ '1e3', '0x123', "-1e-2",
);
- foreach($valid AS $key => $value) {
+ foreach ($valid AS $key => $value) {
$valid[$key] = array($value);
}
return $valid;
@@ -32,7 +32,7 @@ class PiwikTest extends DatabaseTestCase
*/
public function testIsNumericValid($toTest)
{
- $this->assertTrue(is_numeric($toTest), $toTest." not valid but should!");
+ $this->assertTrue(is_numeric($toTest), $toTest . " not valid but should!");
}
/**
@@ -41,9 +41,9 @@ class PiwikTest extends DatabaseTestCase
public function getInvalidNumeric()
{
$notValid = array(
- '-1.0.0', '1,2', '--1', '-.', '- 1', '1-',
+ '-1.0.0', '1,2', '--1', '-.', '- 1', '1-',
);
- foreach($notValid AS $key => $value) {
+ foreach ($notValid AS $key => $value) {
$notValid[$key] = array($value);
}
return $notValid;
@@ -56,7 +56,7 @@ class PiwikTest extends DatabaseTestCase
*/
public function testIsNumericNotValid($toTest)
{
- $this->assertFalse(is_numeric($toTest), $toTest." valid but shouldn't!");
+ $this->assertFalse(is_numeric($toTest), $toTest . " valid but shouldn't!");
}
/**
@@ -65,13 +65,13 @@ class PiwikTest extends DatabaseTestCase
*/
public function testSecureDiv()
{
- $this->assertSame( 3, Piwik::secureDiv( 9,3 ) );
- $this->assertSame( 0, Piwik::secureDiv( 9,0 ) );
- $this->assertSame( 10, Piwik::secureDiv( 10,1 ) );
- $this->assertSame( 10.0, Piwik::secureDiv( 10.0, 1.0 ) );
- $this->assertSame( 5.5, Piwik::secureDiv( 11.0, 2 ) );
- $this->assertSame( 0, Piwik::secureDiv( 11.0, 'a' ) );
-
+ $this->assertSame(3, Piwik::secureDiv(9, 3));
+ $this->assertSame(0, Piwik::secureDiv(9, 0));
+ $this->assertSame(10, Piwik::secureDiv(10, 1));
+ $this->assertSame(10.0, Piwik::secureDiv(10.0, 1.0));
+ $this->assertSame(5.5, Piwik::secureDiv(11.0, 2));
+ $this->assertSame(0, Piwik::secureDiv(11.0, 'a'));
+
}
/**
@@ -88,8 +88,8 @@ class PiwikTest extends DatabaseTestCase
array(86400 + 3600 * 10, array('1 days 10 hours', '34:00:00')),
array(86400 * 365, array('365 days 0 hours', '8760:00:00')),
array((86400 * (365.25 + 10)), array('1 years 10 days', '9006:00:00')),
- array(1.342, array('1.342s', '00:00:01.342')),
- array(.342, array('0.342s', '00:00:00.342')),
+ array(1.342, array('1.342s', '00:00:01.342')),
+ array(.342, array('0.342s', '00:00:00.342')),
);
}
@@ -102,7 +102,7 @@ class PiwikTest extends DatabaseTestCase
{
Piwik_Translate::getInstance()->loadEnglishTranslation();
- $sentenceExpected = str_replace(' ','&nbsp;', $expected[0]);
+ $sentenceExpected = str_replace(' ', '&nbsp;', $expected[0]);
$numericExpected = $expected[1];
$this->assertEquals($sentenceExpected, Piwik::getPrettyTimeFromSeconds($seconds, $sentence = true));
$this->assertEquals($numericExpected, Piwik::getPrettyTimeFromSeconds($seconds, $sentence = false));
@@ -129,7 +129,7 @@ class PiwikTest extends DatabaseTestCase
'alpha>beta',
'alpha?beta',
);
- foreach($notValid AS $key => $value) {
+ foreach ($notValid AS $key => $value) {
$notValid[$key] = array($value);
}
return $notValid;
@@ -160,7 +160,7 @@ class PiwikTest extends DatabaseTestCase
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
'shoot_puck@the-goal.com',
);
- foreach($valid AS $key => $value) {
+ foreach ($valid AS $key => $value) {
$valid[$key] = array($value);
}
return $valid;
@@ -176,16 +176,16 @@ class PiwikTest extends DatabaseTestCase
$this->assertNull(Piwik::checkValidLoginString($toTest));
}
- /**
- * Dataprovider for testGetPrettyValue
- */
- public function getGetPrettyValueTestCases()
- {
- return array(
- array('revenue', 12, '$ 12'),
- array('revenue_evolution', '100 %', '100 %'),
- );
- }
+ /**
+ * Dataprovider for testGetPrettyValue
+ */
+ public function getGetPrettyValueTestCases()
+ {
+ return array(
+ array('revenue', 12, '$ 12'),
+ array('revenue_evolution', '100 %', '100 %'),
+ );
+ }
/**
* @group Core
@@ -194,49 +194,49 @@ class PiwikTest extends DatabaseTestCase
*/
public function testGetPrettyValue($columnName, $value, $expected)
{
- $access = new Piwik_Access();
- Zend_Registry::set('access', $access);
- $access->setSuperUser(true);
-
- $idsite = Piwik_SitesManager_API::getInstance()->addSite("test","http://test");
-
- $this->assertEquals(
- $expected,
- Piwik::getPrettyValue($idsite, $columnName, $value, false, false)
- );
- }
-
- /**
- * Data provider for testIsAssociativeArray.
- */
- public function getIsAssociativeArrayTestCases()
- {
- return array(
- array(array(0 => 'a', 1 => 'b', 2 => 'c', 3 => 'd', 4 => 'e', 5 => 'f'), false),
- array(array(-1 => 'a', 0 => 'a', 1 => 'a', 2 => 'a', 3 => 'a'), true),
- array(array(4 => 'a', 5 => 'a', 6 => 'a', 7 => 'a', 8 => 'a'), true),
- array(array(0 => 'a', 2 => 'a', 3 => 'a', 4 => 'a', 5 => 'a'), true),
- array(array('abc' => 'a', 0 => 'b', 'sdfds' => 'd'), true),
- array(array('abc' => 'def'), true)
- );
- }
-
- /**
+ $access = new Piwik_Access();
+ Zend_Registry::set('access', $access);
+ $access->setSuperUser(true);
+
+ $idsite = Piwik_SitesManager_API::getInstance()->addSite("test", "http://test");
+
+ $this->assertEquals(
+ $expected,
+ Piwik::getPrettyValue($idsite, $columnName, $value, false, false)
+ );
+ }
+
+ /**
+ * Data provider for testIsAssociativeArray.
+ */
+ public function getIsAssociativeArrayTestCases()
+ {
+ return array(
+ array(array(0 => 'a', 1 => 'b', 2 => 'c', 3 => 'd', 4 => 'e', 5 => 'f'), false),
+ array(array(-1 => 'a', 0 => 'a', 1 => 'a', 2 => 'a', 3 => 'a'), true),
+ array(array(4 => 'a', 5 => 'a', 6 => 'a', 7 => 'a', 8 => 'a'), true),
+ array(array(0 => 'a', 2 => 'a', 3 => 'a', 4 => 'a', 5 => 'a'), true),
+ array(array('abc' => 'a', 0 => 'b', 'sdfds' => 'd'), true),
+ array(array('abc' => 'def'), true)
+ );
+ }
+
+ /**
* @group Core
* @group Piwik
* @dataProvider getIsAssociativeArrayTestCases
- */
- public function testIsAssociativeArray( $array, $expected )
- {
- $this->assertEquals($expected, Piwik::isAssociativeArray($array));
- }
-
- /**
- * @group Core
- * @group Piwik
- */
- public function testCheckIfFileSystemIsNFSOnNonNFS()
- {
- $this->assertFalse(Piwik::checkIfFileSystemIsNFS());
- }
+ */
+ public function testIsAssociativeArray($array, $expected)
+ {
+ $this->assertEquals($expected, Piwik::isAssociativeArray($array));
+ }
+
+ /**
+ * @group Core
+ * @group Piwik
+ */
+ public function testCheckIfFileSystemIsNFSOnNonNFS()
+ {
+ $this->assertFalse(Piwik::checkIfFileSystemIsNFS());
+ }
}
diff --git a/tests/PHPUnit/Core/Plugin/ConfigTest.php b/tests/PHPUnit/Core/Plugin/ConfigTest.php
index a6d2924d29..db9421b94a 100644
--- a/tests/PHPUnit/Core/Plugin/ConfigTest.php
+++ b/tests/PHPUnit/Core/Plugin/ConfigTest.php
@@ -11,8 +11,7 @@ class Plugin_ConfigTest extends PHPUnit_Framework_TestCase
function setUp()
{
$path = PIWIK_USER_PATH . '/plugins/ExamplePlugin/config/local.config.php';
- if (file_exists($path))
- {
+ if (file_exists($path)) {
@unlink($path);
}
diff --git a/tests/PHPUnit/Core/PluginsFunctions/WidgetsListTest.php b/tests/PHPUnit/Core/PluginsFunctions/WidgetsListTest.php
index e50ec1e454..bd7983cdf6 100644
--- a/tests/PHPUnit/Core/PluginsFunctions/WidgetsListTest.php
+++ b/tests/PHPUnit/Core/PluginsFunctions/WidgetsListTest.php
@@ -25,7 +25,7 @@ class WidgetsListTest extends DatabaseTestCase
$_GET['idSite'] = 1;
$pluginsManager = Piwik_PluginsManager::getInstance();
- $pluginsToLoad = Piwik_Config::getInstance()->Plugins['Plugins'];
+ $pluginsToLoad = Piwik_Config::getInstance()->Plugins['Plugins'];
$pluginsManager->loadPlugins($pluginsToLoad);
Piwik_WidgetsList::_reset();
@@ -38,13 +38,13 @@ class WidgetsListTest extends DatabaseTestCase
// check if each category has the right number of widgets
$numberOfWidgets = array(
'VisitsSummary_VisitsSummary' => 6,
- 'Live!' => 3,
- 'General_Visitors' => 12,
- 'UserSettings_VisitorSettings' => 11,
- 'Actions_Actions' => 8,
- 'Actions_SubmenuSitesearch' => 5,
- 'Referers_Referers' => 7,
- 'Goals_Goals' => 1,
+ 'Live!' => 3,
+ 'General_Visitors' => 12,
+ 'UserSettings_VisitorSettings' => 11,
+ 'Actions_Actions' => 8,
+ 'Actions_SubmenuSitesearch' => 5,
+ 'Referers_Referers' => 7,
+ 'Goals_Goals' => 1,
'SEO' => 2,
'Example Widgets' => 4,
'ExamplePlugin_exampleWidgets' => 3
@@ -72,7 +72,7 @@ class WidgetsListTest extends DatabaseTestCase
$_GET['idSite'] = 1;
$pluginsManager = Piwik_PluginsManager::getInstance();
- $pluginsToLoad = Piwik_Config::getInstance()->Plugins['Plugins'];
+ $pluginsToLoad = Piwik_Config::getInstance()->Plugins['Plugins'];
$pluginsManager->loadPlugins($pluginsToLoad);
Piwik_WidgetsList::_reset();
@@ -84,12 +84,12 @@ class WidgetsListTest extends DatabaseTestCase
// check that the goal widget was added
$numberOfWidgets = array(
- 'Goals_Goals' => 2,
+ 'Goals_Goals' => 2,
);
foreach ($numberOfWidgets AS $category => $widgetCount) {
- $expected = count($widgets[$category]);
- $this->assertEquals($widgetCount, count($widgets[$category]));
+ $expected = count($widgets[$category]);
+ $this->assertEquals($widgetCount, count($widgets[$category]));
}
}
@@ -111,7 +111,7 @@ class WidgetsListTest extends DatabaseTestCase
$_GET['idSite'] = 1;
$pluginsManager = Piwik_PluginsManager::getInstance();
- $pluginsToLoad = Piwik_Config::getInstance()->Plugins['Plugins'];
+ $pluginsToLoad = Piwik_Config::getInstance()->Plugins['Plugins'];
$pluginsManager->loadPlugins($pluginsToLoad);
Piwik_WidgetsList::_reset();
@@ -123,8 +123,8 @@ class WidgetsListTest extends DatabaseTestCase
// check if each category has the right number of widgets
$numberOfWidgets = array(
- 'Goals_Goals' => 2,
- 'Goals_Ecommerce' => 5,
+ 'Goals_Goals' => 2,
+ 'Goals_Ecommerce' => 5,
);
foreach ($numberOfWidgets AS $category => $widgetCount) {
diff --git a/tests/PHPUnit/Core/RankingQueryTest.php b/tests/PHPUnit/Core/RankingQueryTest.php
index af7ee9a587..833efbfd0d 100644
--- a/tests/PHPUnit/Core/RankingQueryTest.php
+++ b/tests/PHPUnit/Core/RankingQueryTest.php
@@ -8,22 +8,22 @@
class RankingQueryTest extends PHPUnit_Framework_TestCase
{
-
+
/**
* @group Core
* @group RankingQuery
*/
public function testBasic()
{
- $query = new Piwik_RankingQuery();
- $query->addLabelColumn('label');
- $query->addColumn('column');
- $query->addColumn('columnSum', 'sum');
- $query->setLimit(10);
-
- $innerQuery = "SELECT label, column, columnSum FROM myTable";
-
- $expected = "
+ $query = new Piwik_RankingQuery();
+ $query->addLabelColumn('label');
+ $query->addColumn('column');
+ $query->addColumn('columnSum', 'sum');
+ $query->setLimit(10);
+
+ $innerQuery = "SELECT label, column, columnSum FROM myTable";
+
+ $expected = "
SELECT
CASE
WHEN counter = 11 THEN 'Others'
@@ -46,23 +46,23 @@ class RankingQueryTest extends PHPUnit_Framework_TestCase
) AS withCounter
GROUP BY counter
";
-
- $this->checkQuery($query, $innerQuery, $expected);
- }
-
- /**
- * @group Core
- * @group RankingQuery
- */
- public function testExcludeRows()
- {
- $query = new Piwik_RankingQuery(20);
- $query->addLabelColumn('label');
- $query->setColumnToMarkExcludedRows('exclude_marker');
-
- $innerQuery = "SELECT label, 1 AS exclude_marker FROM myTable";
-
- $expected = "
+
+ $this->checkQuery($query, $innerQuery, $expected);
+ }
+
+ /**
+ * @group Core
+ * @group RankingQuery
+ */
+ public function testExcludeRows()
+ {
+ $query = new Piwik_RankingQuery(20);
+ $query->addLabelColumn('label');
+ $query->setColumnToMarkExcludedRows('exclude_marker');
+
+ $innerQuery = "SELECT label, 1 AS exclude_marker FROM myTable";
+
+ $expected = "
SELECT
CASE
WHEN counter = 21 THEN 'Others'
@@ -84,23 +84,23 @@ class RankingQueryTest extends PHPUnit_Framework_TestCase
) AS withCounter
GROUP BY counter
";
-
- $this->checkQuery($query, $innerQuery, $expected);
- }
-
- /**
- * @group Core
- * @group RankingQuery
- */
- public function testPartitionResult()
- {
- $query = new Piwik_RankingQuery(1000);
- $query->addLabelColumn('label');
- $query->partitionResultIntoMultipleGroups('partition', array(1, 2, 3));
-
- $innerQuery = "SELECT label, partition FROM myTable";
-
- $expected = "
+
+ $this->checkQuery($query, $innerQuery, $expected);
+ }
+
+ /**
+ * @group Core
+ * @group RankingQuery
+ */
+ public function testPartitionResult()
+ {
+ $query = new Piwik_RankingQuery(1000);
+ $query->addLabelColumn('label');
+ $query->partitionResultIntoMultipleGroups('partition', array(1, 2, 3));
+
+ $innerQuery = "SELECT label, partition FROM myTable";
+
+ $expected = "
SELECT
CASE
WHEN counter = 1001 THEN 'Others'
@@ -128,24 +128,24 @@ class RankingQueryTest extends PHPUnit_Framework_TestCase
) AS withCounter
GROUP BY counter, `partition`
";
-
- $this->checkQuery($query, $innerQuery, $expected);
- }
-
- /**
- * @param Piwik_RankingQuery $rankingQuery
- * @param string $innerQuerySql
- * @param string $expected
- */
- private function checkQuery($rankingQuery, $innerQuerySql, $expected)
- {
- $query = $rankingQuery->generateQuery($innerQuerySql);
-
- $queryNoWhitespace = preg_replace("/\s+/", "", $query);
- $expectedNoWhitespace = preg_replace("/\s+/", "", $expected);
-
- $message = 'Unexpected query: '.$query;
- $this->assertEquals($queryNoWhitespace, $expectedNoWhitespace, $message);
- }
-
+
+ $this->checkQuery($query, $innerQuery, $expected);
+ }
+
+ /**
+ * @param Piwik_RankingQuery $rankingQuery
+ * @param string $innerQuerySql
+ * @param string $expected
+ */
+ private function checkQuery($rankingQuery, $innerQuerySql, $expected)
+ {
+ $query = $rankingQuery->generateQuery($innerQuerySql);
+
+ $queryNoWhitespace = preg_replace("/\s+/", "", $query);
+ $expectedNoWhitespace = preg_replace("/\s+/", "", $expected);
+
+ $message = 'Unexpected query: ' . $query;
+ $this->assertEquals($queryNoWhitespace, $expectedNoWhitespace, $message);
+ }
+
}
diff --git a/tests/PHPUnit/Core/ReleaseCheckListTest.php b/tests/PHPUnit/Core/ReleaseCheckListTest.php
index d0d9a75a5d..a14ed292f7 100644
--- a/tests/PHPUnit/Core/ReleaseCheckListTest.php
+++ b/tests/PHPUnit/Core/ReleaseCheckListTest.php
@@ -40,11 +40,10 @@ class ReleaseCheckListTest extends PHPUnit_Framework_TestCase
$section = key($key);
$optionName = current($key);
$value = null;
- if(isset($this->globalConfig[$section][$optionName]))
- {
+ if (isset($this->globalConfig[$section][$optionName])) {
$value = $this->globalConfig[$section][$optionName];
}
- $this->assertEquals($valueExpected, $value, "$section -> $optionName was '".var_export($value, true) ."', expected '".var_export($valueExpected,true)."'");
+ $this->assertEquals($valueExpected, $value, "$section -> $optionName was '" . var_export($value, true) . "', expected '" . var_export($valueExpected, true) . "'");
}
/**
@@ -55,10 +54,9 @@ class ReleaseCheckListTest extends PHPUnit_Framework_TestCase
{
$patternFailIfFound = '{debug}';
$files = Piwik::globr(PIWIK_INCLUDE_PATH . '/plugins', '*.tpl');
- foreach($files as $file)
- {
+ foreach ($files as $file) {
$content = file_get_contents($file);
- $this->assertFalse(strpos($content, $patternFailIfFound), 'found in '.$file);
+ $this->assertFalse(strpos($content, $patternFailIfFound), 'found in ' . $file);
}
}
@@ -69,15 +67,13 @@ class ReleaseCheckListTest extends PHPUnit_Framework_TestCase
public function testCheckThatGivenPluginsAreDisabledByDefault()
{
$pluginsShouldBeDisabled = array(
- 'AnonymizeIP',
- 'DBStats',
- 'SecurityInfo',
- 'VisitorGenerator',
+ 'AnonymizeIP',
+ 'DBStats',
+ 'SecurityInfo',
+ 'VisitorGenerator',
);
- foreach($pluginsShouldBeDisabled as $pluginName)
- {
- if(in_array($pluginName, $this->globalConfig['Plugins']['Plugins']))
- {
+ foreach ($pluginsShouldBeDisabled as $pluginName) {
+ if (in_array($pluginName, $this->globalConfig['Plugins']['Plugins'])) {
throw new Exception("Plugin $pluginName is enabled by default but shouldn't.");
}
}
@@ -102,7 +98,7 @@ class ReleaseCheckListTest extends PHPUnit_Framework_TestCase
public function testPiwikTrackerDebugIsOff()
{
$this->assertTrue(!isset($GLOBALS['PIWIK_TRACKER_DEBUG']));
-
+
$oldGet = $_GET;
$_GET = array('idsite' => 1);
@@ -110,7 +106,7 @@ class ReleaseCheckListTest extends PHPUnit_Framework_TestCase
ob_start();
include PIWIK_PATH_TEST_TO_ROOT . "/piwik.php";
ob_end_clean();
-
+
$_GET = $oldGet;
$this->assertTrue($GLOBALS['PIWIK_TRACKER_DEBUG'] === false);
@@ -125,13 +121,13 @@ class ReleaseCheckListTest extends PHPUnit_Framework_TestCase
Piwik::createConfigObject();
Piwik_Config::getInstance()->setTestEnvironment();
- $jqueryJs = file_get_contents( PIWIK_DOCUMENT_ROOT . '/libs/jquery/jquery.js', false, NULL, 0, 512 );
- $this->assertTrue( (boolean)preg_match('/jQuery (?:JavaScript Library )?v?([0-9.]+)/', $jqueryJs, $matches) );
- $this->assertEquals( Piwik_Config::getInstance()->General['jquery_version'], $matches[1] );
+ $jqueryJs = file_get_contents(PIWIK_DOCUMENT_ROOT . '/libs/jquery/jquery.js', false, NULL, 0, 512);
+ $this->assertTrue((boolean)preg_match('/jQuery (?:JavaScript Library )?v?([0-9.]+)/', $jqueryJs, $matches));
+ $this->assertEquals(Piwik_Config::getInstance()->General['jquery_version'], $matches[1]);
- $jqueryuiJs = file_get_contents( PIWIK_DOCUMENT_ROOT . '/libs/jquery/jquery-ui.js', false, NULL, 0, 512 );
- $this->assertTrue( (boolean)preg_match('/jQuery UI (?:- v)?([0-9.]+)/', $jqueryuiJs, $matches) );
- $this->assertEquals( Piwik_Config::getInstance()->General['jqueryui_version'], $matches[1] );
+ $jqueryuiJs = file_get_contents(PIWIK_DOCUMENT_ROOT . '/libs/jquery/jquery-ui.js', false, NULL, 0, 512);
+ $this->assertTrue((boolean)preg_match('/jQuery UI (?:- v)?([0-9.]+)/', $jqueryuiJs, $matches));
+ $this->assertEquals(Piwik_Config::getInstance()->General['jqueryui_version'], $matches[1]);
}
@@ -141,46 +137,40 @@ class ReleaseCheckListTest extends PHPUnit_Framework_TestCase
*/
public function testSvnEolStyle()
{
- if(Piwik_Common::isWindows()) {
+ if (Piwik_Common::isWindows()) {
// SVN native does not make this work on windows
return;
}
- foreach(Piwik::globr(PIWIK_DOCUMENT_ROOT, '*') as $file)
- {
+ foreach (Piwik::globr(PIWIK_DOCUMENT_ROOT, '*') as $file) {
// skip files in these folders
- if(strpos($file, '/.git/') !== false ||
+ if (strpos($file, '/.git/') !== false ||
strpos($file, '/documentation/') !== false ||
strpos($file, '/tests/') !== false ||
strpos($file, '/lang/') !== false ||
strpos($file, 'yuicompressor') !== false ||
- strpos($file, '/tmp/') !== false)
- {
+ strpos($file, '/tmp/') !== false
+ ) {
continue;
}
// skip files with these file extensions
- if(preg_match('/\.(bmp|fdf|gif|deflate|gz|ico|jar|jpg|p12|pdf|png|rar|swf|vsd|z|zip|ttf|so|dat|eps)$/', $file))
- {
+ if (preg_match('/\.(bmp|fdf|gif|deflate|gz|ico|jar|jpg|p12|pdf|png|rar|swf|vsd|z|zip|ttf|so|dat|eps)$/', $file)) {
continue;
}
- if(!is_dir($file))
- {
+ if (!is_dir($file)) {
$contents = file_get_contents($file);
// expect CRLF
- if(preg_match('/\.(bat|ps1)$/', $file))
- {
+ if (preg_match('/\.(bat|ps1)$/', $file)) {
$contents = str_replace("\r\n", '', $contents);
- $this->assertTrue(strpos($contents, "\n") === false, 'Incorrect line endings in '.$file);
- }
- else
- {
- // expect native
- $hasWindowsEOL = strpos($contents, "\r\n");
+ $this->assertTrue(strpos($contents, "\n") === false, 'Incorrect line endings in ' . $file);
+ } else {
+ // expect native
+ $hasWindowsEOL = strpos($contents, "\r\n");
- // overwrite translations files with incorrect line endings
- $this->assertTrue($hasWindowsEOL === false, 'Incorrect line endings \r\n found in '.$file);
+ // overwrite translations files with incorrect line endings
+ $this->assertTrue($hasWindowsEOL === false, 'Incorrect line endings \r\n found in ' . $file);
}
}
}
@@ -195,11 +185,11 @@ class ReleaseCheckListTest extends PHPUnit_Framework_TestCase
// check source against Snort rule 8443
// @see http://dev.piwik.org/trac/ticket/2203
$pattern = '/\x5b\x5c{2}.*\x5c{2}[\x22\x27]/';
- $contents = file_get_contents( PIWIK_DOCUMENT_ROOT . '/js/piwik.js' );
+ $contents = file_get_contents(PIWIK_DOCUMENT_ROOT . '/js/piwik.js');
- $this->assertTrue( preg_match($pattern, $contents) == 0 );
+ $this->assertTrue(preg_match($pattern, $contents) == 0);
- $contents = file_get_contents( PIWIK_DOCUMENT_ROOT . '/piwik.js' );
- $this->assertTrue( preg_match($pattern, $contents) == 0 );
+ $contents = file_get_contents(PIWIK_DOCUMENT_ROOT . '/piwik.js');
+ $this->assertTrue(preg_match($pattern, $contents) == 0);
}
}
diff --git a/tests/PHPUnit/Core/ScheduledTaskTest.php b/tests/PHPUnit/Core/ScheduledTaskTest.php
index 69b4329650..b58c4df6fa 100644
--- a/tests/PHPUnit/Core/ScheduledTaskTest.php
+++ b/tests/PHPUnit/Core/ScheduledTaskTest.php
@@ -9,37 +9,37 @@ require_once PIWIK_INCLUDE_PATH . '/plugins/PDFReports/PDFReports.php';
class ScheduledTaskTest extends PHPUnit_Framework_TestCase
{
- /**
- * @group Core
- * @group ScheduledTask
- */
- public function testGetClassName()
- {
- $scheduledTask = new Piwik_ScheduledTask ( new Piwik_PDFReports(), null, null, null );
- $this->assertEquals('Piwik_PDFReports', $scheduledTask->getClassName());
- }
+ /**
+ * @group Core
+ * @group ScheduledTask
+ */
+ public function testGetClassName()
+ {
+ $scheduledTask = new Piwik_ScheduledTask (new Piwik_PDFReports(), null, null, null);
+ $this->assertEquals('Piwik_PDFReports', $scheduledTask->getClassName());
+ }
- /**
- * Dataprovider for testGetTaskName
- */
- public function getTaskNameTestCases()
- {
- return array(
- array('Piwik_CoreAdminHome.purgeOutdatedArchives', 'Piwik_CoreAdminHome', 'purgeOutdatedArchives', null),
- array('Piwik_CoreAdminHome.purgeOutdatedArchives_previous30', 'Piwik_CoreAdminHome', 'purgeOutdatedArchives', 'previous30'),
- array('Piwik_PDFReports.weeklySchedule', 'Piwik_PDFReports', 'weeklySchedule', null),
- array('Piwik_PDFReports.weeklySchedule_1', 'Piwik_PDFReports', 'weeklySchedule', 1),
- );
- }
+ /**
+ * Dataprovider for testGetTaskName
+ */
+ public function getTaskNameTestCases()
+ {
+ return array(
+ array('Piwik_CoreAdminHome.purgeOutdatedArchives', 'Piwik_CoreAdminHome', 'purgeOutdatedArchives', null),
+ array('Piwik_CoreAdminHome.purgeOutdatedArchives_previous30', 'Piwik_CoreAdminHome', 'purgeOutdatedArchives', 'previous30'),
+ array('Piwik_PDFReports.weeklySchedule', 'Piwik_PDFReports', 'weeklySchedule', null),
+ array('Piwik_PDFReports.weeklySchedule_1', 'Piwik_PDFReports', 'weeklySchedule', 1),
+ );
+ }
- /**
- * @group Core
- * @group ScheduledTask
- * @dataProvider getTaskNameTestCases
- */
- public function testGetTaskName($expectedTaskName, $className, $methodName, $methodParameter)
- {
- $this->assertEquals($expectedTaskName, Piwik_ScheduledTask::getTaskName($className, $methodName, $methodParameter));
- }
+ /**
+ * @group Core
+ * @group ScheduledTask
+ * @dataProvider getTaskNameTestCases
+ */
+ public function testGetTaskName($expectedTaskName, $className, $methodName, $methodParameter)
+ {
+ $this->assertEquals($expectedTaskName, Piwik_ScheduledTask::getTaskName($className, $methodName, $methodParameter));
+ }
}
diff --git a/tests/PHPUnit/Core/ScheduledTime/DailyTest.php b/tests/PHPUnit/Core/ScheduledTime/DailyTest.php
index 6fabb515a8..982e19cd12 100644
--- a/tests/PHPUnit/Core/ScheduledTime/DailyTest.php
+++ b/tests/PHPUnit/Core/ScheduledTime/DailyTest.php
@@ -16,13 +16,13 @@ class ScheduledTime_DailyTest extends PHPUnit_Framework_TestCase
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
- self::$_JANUARY_01_1971_09_00_00 = mktime(9,00,00,1,1,1971);
- self::$_JANUARY_01_1971_09_10_00 = mktime(9,10,00,1,1,1971);
- self::$_JANUARY_01_1971_12_10_00 = mktime(12,10,00,1,1,1971);
- self::$_JANUARY_02_1971_00_00_00 = mktime(0,00,00,1,2,1971);
- self::$_JANUARY_02_1971_09_00_00 = mktime(9,00,00,1,2,1971);
+ self::$_JANUARY_01_1971_09_00_00 = mktime(9, 00, 00, 1, 1, 1971);
+ self::$_JANUARY_01_1971_09_10_00 = mktime(9, 10, 00, 1, 1, 1971);
+ self::$_JANUARY_01_1971_12_10_00 = mktime(12, 10, 00, 1, 1, 1971);
+ self::$_JANUARY_02_1971_00_00_00 = mktime(0, 00, 00, 1, 2, 1971);
+ self::$_JANUARY_02_1971_09_00_00 = mktime(9, 00, 00, 1, 2, 1971);
}
-
+
/**
* Tests invalid call to setHour on Piwik_ScheduledTime_Daily
* @group Core
@@ -31,8 +31,7 @@ class ScheduledTime_DailyTest extends PHPUnit_Framework_TestCase
*/
public function testSetHourScheduledTimeDailyNegative()
{
- try
- {
+ try {
$dailySchedule = new Piwik_ScheduledTime_Daily();
$dailySchedule->setHour(-1);
@@ -58,7 +57,7 @@ class ScheduledTime_DailyTest extends PHPUnit_Framework_TestCase
}
$this->fail('Expected exception not raised');
}
-
+
/**
* Tests forbidden call to setDay on Piwik_ScheduledTime_Daily
* @group Core
@@ -75,7 +74,7 @@ class ScheduledTime_DailyTest extends PHPUnit_Framework_TestCase
}
$this->fail('Expected exception not raised');
}
-
+
/**
* Tests getRescheduledTime on Piwik_ScheduledTime_Daily with unspecified hour
* @group Core
@@ -96,8 +95,8 @@ class ScheduledTime_DailyTest extends PHPUnit_Framework_TestCase
*/
$mock = $this->getMock('Piwik_ScheduledTime_Daily', array('getTime'));
$mock->expects($this->any())
- ->method('getTime')
- ->will($this->returnValue(self::$_JANUARY_01_1971_09_10_00));
+ ->method('getTime')
+ ->will($this->returnValue(self::$_JANUARY_01_1971_09_10_00));
$this->assertEquals(self::$_JANUARY_02_1971_00_00_00, $mock->getRescheduledTime());
}
@@ -121,8 +120,8 @@ class ScheduledTime_DailyTest extends PHPUnit_Framework_TestCase
*/
$mock = $this->getMock('Piwik_ScheduledTime_Daily', array('getTime'));
$mock->expects($this->any())
- ->method('getTime')
- ->will($this->returnValue(self::$_JANUARY_01_1971_09_00_00));
+ ->method('getTime')
+ ->will($this->returnValue(self::$_JANUARY_01_1971_09_00_00));
$mock->setHour(9);
$this->assertEquals(self::$_JANUARY_02_1971_09_00_00, $mock->getRescheduledTime());
@@ -138,8 +137,8 @@ class ScheduledTime_DailyTest extends PHPUnit_Framework_TestCase
*/
$mock = $this->getMock('Piwik_ScheduledTime_Daily', array('getTime'));
$mock->expects($this->any())
- ->method('getTime')
- ->will($this->returnValue(self::$_JANUARY_01_1971_12_10_00));
+ ->method('getTime')
+ ->will($this->returnValue(self::$_JANUARY_01_1971_12_10_00));
$mock->setHour(9);
$this->assertEquals(self::$_JANUARY_02_1971_09_00_00, $mock->getRescheduledTime());
@@ -155,8 +154,8 @@ class ScheduledTime_DailyTest extends PHPUnit_Framework_TestCase
*/
$mock = $this->getMock('Piwik_ScheduledTime_Daily', array('getTime'));
$mock->expects($this->any())
- ->method('getTime')
- ->will($this->returnValue(self::$_JANUARY_01_1971_12_10_00));
+ ->method('getTime')
+ ->will($this->returnValue(self::$_JANUARY_01_1971_12_10_00));
$mock->setHour(0);
$this->assertEquals(self::$_JANUARY_02_1971_00_00_00, $mock->getRescheduledTime());
}
diff --git a/tests/PHPUnit/Core/ScheduledTime/HourlyTest.php b/tests/PHPUnit/Core/ScheduledTime/HourlyTest.php
index c50bb6a7c5..b0c808fe5e 100644
--- a/tests/PHPUnit/Core/ScheduledTime/HourlyTest.php
+++ b/tests/PHPUnit/Core/ScheduledTime/HourlyTest.php
@@ -14,11 +14,11 @@ class ScheduledTime_HourlyTest extends PHPUnit_Framework_TestCase
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
- self::$_JANUARY_01_1971_09_00_00 = mktime(9,00,00,1,1,1971);
- self::$_JANUARY_01_1971_09_10_00 = mktime(9,10,00,1,1,1971);
- self::$_JANUARY_01_1971_10_00_00 = mktime(10,00,00,1,1,1971);
+ self::$_JANUARY_01_1971_09_00_00 = mktime(9, 00, 00, 1, 1, 1971);
+ self::$_JANUARY_01_1971_09_10_00 = mktime(9, 10, 00, 1, 1, 1971);
+ self::$_JANUARY_01_1971_10_00_00 = mktime(10, 00, 00, 1, 1, 1971);
}
-
+
/**
* Tests forbidden call to setHour on Piwik_ScheduledTime_Hourly
* @group Core
@@ -52,7 +52,7 @@ class ScheduledTime_HourlyTest extends PHPUnit_Framework_TestCase
}
$this->fail('Expected exception not raised');
}
-
+
/**
* Tests getRescheduledTime on Piwik_ScheduledTime_Hourly
* @group Core
@@ -72,8 +72,8 @@ class ScheduledTime_HourlyTest extends PHPUnit_Framework_TestCase
*/
$mock = $this->getMock('Piwik_ScheduledTime_Hourly', array('getTime'));
$mock->expects($this->any())
- ->method('getTime')
- ->will($this->returnValue(self::$_JANUARY_01_1971_09_00_00));
+ ->method('getTime')
+ ->will($this->returnValue(self::$_JANUARY_01_1971_09_00_00));
$this->assertEquals(self::$_JANUARY_01_1971_10_00_00, $mock->getRescheduledTime());
/*
@@ -87,8 +87,8 @@ class ScheduledTime_HourlyTest extends PHPUnit_Framework_TestCase
*/
$mock = $this->getMock('Piwik_ScheduledTime_Hourly', array('getTime'));
$mock->expects($this->any())
- ->method('getTime')
- ->will($this->returnValue(self::$_JANUARY_01_1971_09_10_00));
+ ->method('getTime')
+ ->will($this->returnValue(self::$_JANUARY_01_1971_09_10_00));
$this->assertEquals(self::$_JANUARY_01_1971_10_00_00, $mock->getRescheduledTime());
}
}
diff --git a/tests/PHPUnit/Core/ScheduledTime/MonthlyTest.php b/tests/PHPUnit/Core/ScheduledTime/MonthlyTest.php
index d24f957062..8bab11da43 100644
--- a/tests/PHPUnit/Core/ScheduledTime/MonthlyTest.php
+++ b/tests/PHPUnit/Core/ScheduledTime/MonthlyTest.php
@@ -20,15 +20,15 @@ class ScheduledTime_MonthlyTest extends PHPUnit_Framework_TestCase
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
- self::$_JANUARY_01_1971_09_00_00 = mktime(9,00,00,1,1,1971);
- self::$_JANUARY_02_1971_09_00_00 = mktime(9,00,00,1,2,1971);
- self::$_JANUARY_05_1971_09_00_00 = mktime(9,00,00,1,5,1971);
- self::$_JANUARY_15_1971_09_00_00 = mktime(9,00,00,1,15,1971);
- self::$_FEBRUARY_01_1971_00_00_00 = mktime(0,00,00,2,1,1971);
- self::$_FEBRUARY_02_1971_00_00_00 = mktime(0,00,00,2,2,1971);
- self::$_FEBRUARY_03_1971_09_00_00 = mktime(0,00,00,2,3,1971);
- self::$_FEBRUARY_21_1971_09_00_00 = mktime(0,00,00,2,21,1971);
- self::$_FEBRUARY_28_1971_00_00_00 = mktime(0,00,00,2,28,1971);
+ self::$_JANUARY_01_1971_09_00_00 = mktime(9, 00, 00, 1, 1, 1971);
+ self::$_JANUARY_02_1971_09_00_00 = mktime(9, 00, 00, 1, 2, 1971);
+ self::$_JANUARY_05_1971_09_00_00 = mktime(9, 00, 00, 1, 5, 1971);
+ self::$_JANUARY_15_1971_09_00_00 = mktime(9, 00, 00, 1, 15, 1971);
+ self::$_FEBRUARY_01_1971_00_00_00 = mktime(0, 00, 00, 2, 1, 1971);
+ self::$_FEBRUARY_02_1971_00_00_00 = mktime(0, 00, 00, 2, 2, 1971);
+ self::$_FEBRUARY_03_1971_09_00_00 = mktime(0, 00, 00, 2, 3, 1971);
+ self::$_FEBRUARY_21_1971_09_00_00 = mktime(0, 00, 00, 2, 21, 1971);
+ self::$_FEBRUARY_28_1971_00_00_00 = mktime(0, 00, 00, 2, 28, 1971);
}
/**
@@ -120,10 +120,10 @@ class ScheduledTime_MonthlyTest extends PHPUnit_Framework_TestCase
*/
$mock = $this->getMock('Piwik_ScheduledTime_Monthly', array('getTime'));
$mock->expects($this->any())
- ->method('getTime')
- ->will($this->returnValue(self::$_JANUARY_01_1971_09_00_00));
+ ->method('getTime')
+ ->will($this->returnValue(self::$_JANUARY_01_1971_09_00_00));
$this->assertEquals(self::$_FEBRUARY_01_1971_00_00_00, $mock->getRescheduledTime());
-
+
/*
* Test 2
*
@@ -137,12 +137,12 @@ class ScheduledTime_MonthlyTest extends PHPUnit_Framework_TestCase
*/
$mock = $this->getMock('Piwik_ScheduledTime_Monthly', array('getTime'));
$mock->expects($this->any())
- ->method('getTime')
- ->will($this->returnValue(self::$_JANUARY_05_1971_09_00_00));
+ ->method('getTime')
+ ->will($this->returnValue(self::$_JANUARY_05_1971_09_00_00));
$this->assertEquals(self::$_FEBRUARY_01_1971_00_00_00, $mock->getRescheduledTime());
}
-
+
/**
* Tests getRescheduledTime on Piwik_ScheduledTime_Monthly with unspecified hour and specified day
* @group Core
@@ -155,8 +155,8 @@ class ScheduledTime_MonthlyTest extends PHPUnit_Framework_TestCase
{
$mock = $this->getMock('Piwik_ScheduledTime_Monthly', array('getTime'));
$mock->expects($this->any())
- ->method('getTime')
- ->will($this->returnValue(self::$$currentTime));
+ ->method('getTime')
+ ->will($this->returnValue(self::$$currentTime));
$mock->setDay($day);
$this->assertEquals(self::$$expected, $mock->getRescheduledTime());
}
@@ -165,7 +165,8 @@ class ScheduledTime_MonthlyTest extends PHPUnit_Framework_TestCase
* DataProvider for testGetRescheduledTimeMonthlyUnspecifiedHourSpecifiedDay
* @return array
*/
- public function getSpecifiedDayData() {
+ public function getSpecifiedDayData()
+ {
return array(
/*
* Test 1
@@ -214,7 +215,7 @@ class ScheduledTime_MonthlyTest extends PHPUnit_Framework_TestCase
* Expected :
* getRescheduledTime returns Sunday February 28 1971 00:00:00 UTC
*/
- array('_JANUARY_15_1971_09_00_00', 31, '_FEBRUARY_28_1971_00_00_00')
+ array('_JANUARY_15_1971_09_00_00', 31, '_FEBRUARY_28_1971_00_00_00')
);
}
@@ -227,8 +228,8 @@ class ScheduledTime_MonthlyTest extends PHPUnit_Framework_TestCase
{
$mock = $this->getMock('Piwik_ScheduledTime_Monthly', array('getTime'));
$mock->expects($this->any())
- ->method('getTime')
- ->will($this->returnValue(self::$_JANUARY_15_1971_09_00_00));
+ ->method('getTime')
+ ->will($this->returnValue(self::$_JANUARY_15_1971_09_00_00));
$mock->setDayOfWeek(3, 0); // first wednesday
$this->assertEquals(self::$_FEBRUARY_03_1971_09_00_00, $mock->getRescheduledTime());
@@ -247,8 +248,8 @@ class ScheduledTime_MonthlyTest extends PHPUnit_Framework_TestCase
{
$mock = $this->getMock('Piwik_ScheduledTime_Monthly', array('getTime'));
$mock->expects($this->any())
- ->method('getTime')
- ->will($this->returnValue(self::$_JANUARY_15_1971_09_00_00));
+ ->method('getTime')
+ ->will($this->returnValue(self::$_JANUARY_15_1971_09_00_00));
try {
$mock->setDayOfWeek($day, $week);
} catch (Exception $e) {
@@ -261,7 +262,8 @@ class ScheduledTime_MonthlyTest extends PHPUnit_Framework_TestCase
* DataProvider for testMonthlyDayOfWeekInvalid
* @return array
*/
- public function getInvalidDayOfWeekData() {
+ public function getInvalidDayOfWeekData()
+ {
return array(
array(-4, 0),
array(8, 0),
diff --git a/tests/PHPUnit/Core/ScheduledTime/WeeklyTest.php b/tests/PHPUnit/Core/ScheduledTime/WeeklyTest.php
index b5738fb5c4..6812bc90c0 100644
--- a/tests/PHPUnit/Core/ScheduledTime/WeeklyTest.php
+++ b/tests/PHPUnit/Core/ScheduledTime/WeeklyTest.php
@@ -17,14 +17,14 @@ class ScheduledTime_WeeklyTest extends PHPUnit_Framework_TestCase
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
- self::$_JANUARY_01_1971_09_10_00 = mktime(9,10,00,1,1,1971);
- self::$_JANUARY_04_1971_00_00_00 = mktime(0,00,00,1,4,1971);
- self::$_JANUARY_04_1971_09_00_00 = mktime(9,00,00,1,4,1971);
- self::$_JANUARY_05_1971_09_00_00 = mktime(9,00,00,1,5,1971);
- self::$_JANUARY_11_1971_00_00_00 = mktime(0,00,00,1,11,1971);
- self::$_JANUARY_15_1971_00_00_00 = mktime(0,00,00,1,15,1971);
+ self::$_JANUARY_01_1971_09_10_00 = mktime(9, 10, 00, 1, 1, 1971);
+ self::$_JANUARY_04_1971_00_00_00 = mktime(0, 00, 00, 1, 4, 1971);
+ self::$_JANUARY_04_1971_09_00_00 = mktime(9, 00, 00, 1, 4, 1971);
+ self::$_JANUARY_05_1971_09_00_00 = mktime(9, 00, 00, 1, 5, 1971);
+ self::$_JANUARY_11_1971_00_00_00 = mktime(0, 00, 00, 1, 11, 1971);
+ self::$_JANUARY_15_1971_00_00_00 = mktime(0, 00, 00, 1, 15, 1971);
}
-
+
/**
* Tests invalid call to setHour on Piwik_ScheduledTime_Weekly
* @group Core
@@ -58,7 +58,7 @@ class ScheduledTime_WeeklyTest extends PHPUnit_Framework_TestCase
}
$this->fail('Expected exception not raised');
}
-
+
/**
* Tests invalid call to setDay on Piwik_ScheduledTime_Weekly
* @group Core
@@ -114,11 +114,11 @@ class ScheduledTime_WeeklyTest extends PHPUnit_Framework_TestCase
*/
$mock = $this->getMock('Piwik_ScheduledTime_Weekly', array('getTime'));
$mock->expects($this->any())
- ->method('getTime')
- ->will($this->returnValue(self::$_JANUARY_01_1971_09_10_00));
+ ->method('getTime')
+ ->will($this->returnValue(self::$_JANUARY_01_1971_09_10_00));
$this->assertEquals(self::$_JANUARY_04_1971_00_00_00, $mock->getRescheduledTime());
}
-
+
/**
* Tests getRescheduledTime on Piwik_ScheduledTime_Weekly with specified hour and unspecified day
* @group Core
@@ -140,8 +140,8 @@ class ScheduledTime_WeeklyTest extends PHPUnit_Framework_TestCase
*/
$mock = $this->getMock('Piwik_ScheduledTime_Weekly', array('getTime'));
$mock->expects($this->any())
- ->method('getTime')
- ->will($this->returnValue(self::$_JANUARY_01_1971_09_10_00));
+ ->method('getTime')
+ ->will($this->returnValue(self::$_JANUARY_01_1971_09_10_00));
$mock->setHour(9);
$this->assertEquals(self::$_JANUARY_04_1971_09_00_00, $mock->getRescheduledTime());
}
@@ -167,11 +167,11 @@ class ScheduledTime_WeeklyTest extends PHPUnit_Framework_TestCase
*/
$mock = $this->getMock('Piwik_ScheduledTime_Weekly', array('getTime'));
$mock->expects($this->any())
- ->method('getTime')
- ->will($this->returnValue(self::$_JANUARY_04_1971_09_00_00));
+ ->method('getTime')
+ ->will($this->returnValue(self::$_JANUARY_04_1971_09_00_00));
$mock->setDay(1);
$this->assertEquals(self::$_JANUARY_11_1971_00_00_00, $mock->getRescheduledTime());
-
+
/*
* Test 2
*
@@ -185,8 +185,8 @@ class ScheduledTime_WeeklyTest extends PHPUnit_Framework_TestCase
*/
$mock = $this->getMock('Piwik_ScheduledTime_Weekly', array('getTime'));
$mock->expects($this->any())
- ->method('getTime')
- ->will($this->returnValue(self::$_JANUARY_05_1971_09_00_00));
+ ->method('getTime')
+ ->will($this->returnValue(self::$_JANUARY_05_1971_09_00_00));
$mock->setDay(1);
$this->assertEquals(self::$_JANUARY_11_1971_00_00_00, $mock->getRescheduledTime());
@@ -203,8 +203,8 @@ class ScheduledTime_WeeklyTest extends PHPUnit_Framework_TestCase
*/
$mock = $this->getMock('Piwik_ScheduledTime_Weekly', array('getTime'));
$mock->expects($this->any())
- ->method('getTime')
- ->will($this->returnValue(self::$_JANUARY_04_1971_09_00_00));
+ ->method('getTime')
+ ->will($this->returnValue(self::$_JANUARY_04_1971_09_00_00));
$mock->setDay(5);
$this->assertEquals(self::$_JANUARY_15_1971_00_00_00, $mock->getRescheduledTime());
}
diff --git a/tests/PHPUnit/Core/SegmentExpressionTest.php b/tests/PHPUnit/Core/SegmentExpressionTest.php
index 62f87ee421..ea53e5d049 100644
--- a/tests/PHPUnit/Core/SegmentExpressionTest.php
+++ b/tests/PHPUnit/Core/SegmentExpressionTest.php
@@ -60,7 +60,7 @@ class SegmentExpressionTest extends PHPUnit_Framework_TestCase
return array(
array('A==B%', array('where' => " A = ? ", 'bind' => array('B%'))),
array('ABCDEF====B===', array('where' => " ABCDEF = ? ", 'bind' => array('==B==='))),
- array('A===B;CDEF!=C!=', array('where' => " A = ? AND CDEF <> ? ", 'bind' => array('=B', 'C!=' ))),
+ array('A===B;CDEF!=C!=', array('where' => " A = ? AND CDEF <> ? ", 'bind' => array('=B', 'C!='))),
array('A==B,C==D', array('where' => " (A = ? OR C = ? )", 'bind' => array('B', 'D'))),
array('A!=B;C==D', array('where' => " A <> ? AND C = ? ", 'bind' => array('B', 'D'))),
array('A!=B;C==D,E!=Hello World!=', array('where' => " A <> ? AND (C = ? OR E <> ? )", 'bind' => array('B', 'D', 'Hello World!='))),
@@ -70,7 +70,7 @@ class SegmentExpressionTest extends PHPUnit_Framework_TestCase
array('A<=B', array('where' => " A <= ? ", 'bind' => array('B'))),
array('A>=B', array('where' => " A >= ? ", 'bind' => array('B'))),
array('ABCDEF>=>=>=B===', array('where' => " ABCDEF >= ? ", 'bind' => array('>=>=B==='))),
- array('A>=<=B;CDEF>G;H>=I;J<K;L<=M', array('where' => " A >= ? AND CDEF > ? AND H >= ? AND J < ? AND L <= ? ", 'bind' => array('<=B', 'G','I','K','M' ))),
+ array('A>=<=B;CDEF>G;H>=I;J<K;L<=M', array('where' => " A >= ? AND CDEF > ? AND H >= ? AND J < ? AND L <= ? ", 'bind' => array('<=B', 'G', 'I', 'K', 'M'))),
array('A>=B;C>=D,E<w_ow great!', array('where' => " A >= ? AND (C >= ? OR E < ? )", 'bind' => array('B', 'D', 'w_ow great!'))),
array('A=@B_', array('where' => " A LIKE ? ", 'bind' => array('%B\_%'))),
diff --git a/tests/PHPUnit/Core/SegmentTest.php b/tests/PHPUnit/Core/SegmentTest.php
index 4b9249597b..2d021ea65c 100644
--- a/tests/PHPUnit/Core/SegmentTest.php
+++ b/tests/PHPUnit/Core/SegmentTest.php
@@ -15,10 +15,10 @@ class SegmentTest extends PHPUnit_Framework_TestCase
$pseudoMockAccess = new FakeAccess;
FakeAccess::$superUser = true;
Zend_Registry::set('access', $pseudoMockAccess);
-
+
// Load and install plugins
$pluginsManager = Piwik_PluginsManager::getInstance();
- $pluginsManager->loadPlugins( Piwik_Config::getInstance()->Plugins['Plugins'] );
+ $pluginsManager->loadPlugins(Piwik_Config::getInstance()->Plugins['Plugins']);
}
public function tearDown()
@@ -29,8 +29,8 @@ class SegmentTest extends PHPUnit_Framework_TestCase
protected function _filterWhitsSpaces($valueToFilter)
{
- if(is_array($valueToFilter)) {
- foreach($valueToFilter AS $key => $value) {
+ if (is_array($valueToFilter)) {
+ foreach ($valueToFilter AS $key => $value) {
$valueToFilter[$key] = $this->_filterWhitsSpaces($value);
}
return $valueToFilter;
@@ -46,23 +46,23 @@ class SegmentTest extends PHPUnit_Framework_TestCase
// Normal segment
array('country==France', array(
'where' => ' log_visit.location_country = ? ',
- 'bind' => array('France'))),
+ 'bind' => array('France'))),
// unescape the comma please
array('country==a\,==', array(
'where' => ' log_visit.location_country = ? ',
- 'bind' => array('a,=='))),
+ 'bind' => array('a,=='))),
// AND, with 2 values rewrites
array('country==a;visitorType!=returning;visitorType==new', array(
'where' => ' log_visit.location_country = ? AND log_visit.visitor_returning <> ? AND log_visit.visitor_returning = ? ',
- 'bind' => array('a', '1', '0'))),
+ 'bind' => array('a', '1', '0'))),
// OR, with 2 value rewrites
array('referrerType==search,referrerType==direct', array(
- 'where'=>' (log_visit.referer_type = ? OR log_visit.referer_type = ? )',
- 'bind' => array(Piwik_Common::REFERER_TYPE_SEARCH_ENGINE,
- Piwik_Common::REFERER_TYPE_DIRECT_ENTRY))),
+ 'where' => ' (log_visit.referer_type = ? OR log_visit.referer_type = ? )',
+ 'bind' => array(Piwik_Common::REFERER_TYPE_SEARCH_ENGINE,
+ Piwik_Common::REFERER_TYPE_DIRECT_ENTRY))),
);
}
@@ -77,13 +77,13 @@ class SegmentTest extends PHPUnit_Framework_TestCase
$from = 'log_visit';
$expected = array(
- 'sql' => '
+ 'sql' => '
SELECT
log_visit.idvisit
FROM
- '.Piwik_Common::prefixTable('log_visit').' AS log_visit
+ ' . Piwik_Common::prefixTable('log_visit') . ' AS log_visit
WHERE
- '.$expected['where'],
+ ' . $expected['where'],
'bind' => $expected['bind']
);
@@ -98,7 +98,7 @@ class SegmentTest extends PHPUnit_Framework_TestCase
$this->assertEquals(32, strlen($segment->getHash()));
}
-
+
/**
* @group Core
* @group Segment
@@ -109,27 +109,27 @@ class SegmentTest extends PHPUnit_Framework_TestCase
$from = 'log_visit';
$where = 'idsite = ?';
$bind = array(1);
-
+
$segment = 'customVariableName1==Test;visitorType==new';
$segment = new Piwik_Segment($segment, $idSites = array());
-
+
$query = $segment->getSelectQuery($select, $from, $where, $bind);
-
+
$expected = array(
- "sql" => "
+ "sql" => "
SELECT
*
FROM
- ".Piwik_Common::prefixTable('log_visit')." AS log_visit
+ " . Piwik_Common::prefixTable('log_visit') . " AS log_visit
WHERE
( idsite = ? )
AND
( log_visit.custom_var_k1 = ? AND log_visit.visitor_returning = ? )",
"bind" => array(1, 'Test', 0));
-
+
$this->assertEquals($this->_filterWhitsSpaces($expected), $this->_filterWhitsSpaces($query));
}
-
+
/**
* @group Core
* @group Segment
@@ -140,25 +140,25 @@ class SegmentTest extends PHPUnit_Framework_TestCase
$from = 'log_link_visit_action';
$where = 'log_link_visit_action.idvisit = ?';
$bind = array(1);
-
+
$segment = 'customVariablePageName1==Test;visitorType==new';
$segment = new Piwik_Segment($segment, $idSites = array());
-
+
$query = $segment->getSelectQuery($select, $from, $where, $bind);
-
+
$expected = array(
- "sql" => "
+ "sql" => "
SELECT
*
FROM
- ".Piwik_Common::prefixTable('log_link_visit_action')." AS log_link_visit_action
- LEFT JOIN ".Piwik_Common::prefixTable('log_visit')." AS log_visit ON log_visit.idvisit = log_link_visit_action.idvisit
+ " . Piwik_Common::prefixTable('log_link_visit_action') . " AS log_link_visit_action
+ LEFT JOIN " . Piwik_Common::prefixTable('log_visit') . " AS log_visit ON log_visit.idvisit = log_link_visit_action.idvisit
WHERE
( log_link_visit_action.idvisit = ? )
AND
( log_link_visit_action.custom_var_k1 = ? AND log_visit.visitor_returning = ? )",
"bind" => array(1, 'Test', 0));
-
+
$this->assertEquals($this->_filterWhitsSpaces($expected), $this->_filterWhitsSpaces($query));
}
@@ -172,14 +172,14 @@ class SegmentTest extends PHPUnit_Framework_TestCase
$from = 'log_visit';
$where = 'log_visit.idvisit = ?';
$bind = array(1);
-
+
$segment = 'customVariablePageName1==Test;visitorType==new';
$segment = new Piwik_Segment($segment, $idSites = array());
-
+
$query = $segment->getSelectQuery($select, $from, $where, $bind);
-
+
$expected = array(
- "sql" => "
+ "sql" => "
SELECT
sum(log_inner.visit_total_actions) as nb_actions, max(log_inner.visit_total_actions) as max_actions, sum(log_inner.visit_total_time) as sum_visit_length
FROM
@@ -188,8 +188,8 @@ class SegmentTest extends PHPUnit_Framework_TestCase
log_visit.visit_total_actions,
log_visit.visit_total_time
FROM
- ".Piwik_Common::prefixTable('log_visit')." AS log_visit
- LEFT JOIN ".Piwik_Common::prefixTable('log_link_visit_action')." AS log_link_visit_action ON log_link_visit_action.idvisit = log_visit.idvisit
+ " . Piwik_Common::prefixTable('log_visit') . " AS log_visit
+ LEFT JOIN " . Piwik_Common::prefixTable('log_link_visit_action') . " AS log_link_visit_action ON log_link_visit_action.idvisit = log_visit.idvisit
WHERE
( log_visit.idvisit = ? )
AND
@@ -197,10 +197,10 @@ class SegmentTest extends PHPUnit_Framework_TestCase
GROUP BY log_visit.idvisit
) AS log_inner",
"bind" => array(1, 'Test', 0));
-
+
$this->assertEquals($this->_filterWhitsSpaces($expected), $this->_filterWhitsSpaces($query));
}
-
+
/**
* @group Core
* @group Segment
@@ -211,28 +211,28 @@ class SegmentTest extends PHPUnit_Framework_TestCase
$from = 'log_link_visit_action';
$where = 'log_link_visit_action.idvisit = ?';
$bind = array(1);
-
+
$segment = 'customVariablePageName1==Test;visitConvertedGoalId==1;customVariablePageName2==Test2';
$segment = new Piwik_Segment($segment, $idSites = array());
-
+
$query = $segment->getSelectQuery($select, $from, $where, $bind);
-
+
$expected = array(
- "sql" => "
+ "sql" => "
SELECT
*
FROM
- ".Piwik_Common::prefixTable('log_link_visit_action')." AS log_link_visit_action
- LEFT JOIN ".Piwik_Common::prefixTable('log_conversion')." AS log_conversion ON log_conversion.idlink_va = log_link_visit_action.idlink_va AND log_conversion.idsite = log_link_visit_action.idsite
+ " . Piwik_Common::prefixTable('log_link_visit_action') . " AS log_link_visit_action
+ LEFT JOIN " . Piwik_Common::prefixTable('log_conversion') . " AS log_conversion ON log_conversion.idlink_va = log_link_visit_action.idlink_va AND log_conversion.idsite = log_link_visit_action.idsite
WHERE
( log_link_visit_action.idvisit = ? )
AND
( log_link_visit_action.custom_var_k1 = ? AND log_conversion.idgoal = ? AND log_link_visit_action.custom_var_k2 = ? )",
"bind" => array(1, 'Test', 1, 'Test2'));
-
+
$this->assertEquals($this->_filterWhitsSpaces($expected), $this->_filterWhitsSpaces($query));
}
-
+
/**
* @group Core
* @group Segment
@@ -243,28 +243,28 @@ class SegmentTest extends PHPUnit_Framework_TestCase
$from = 'log_conversion';
$where = 'log_conversion.idvisit = ?';
$bind = array(1);
-
+
$segment = 'visitConvertedGoalId!=2;customVariablePageName1==Test;visitConvertedGoalId==1';
$segment = new Piwik_Segment($segment, $idSites = array());
-
+
$query = $segment->getSelectQuery($select, $from, $where, $bind);
-
+
$expected = array(
- "sql" => "
+ "sql" => "
SELECT
*
FROM
- ".Piwik_Common::prefixTable('log_conversion')." AS log_conversion
- LEFT JOIN ".Piwik_Common::prefixTable('log_link_visit_action')." AS log_link_visit_action ON log_conversion.idlink_va = log_link_visit_action.idlink_va
+ " . Piwik_Common::prefixTable('log_conversion') . " AS log_conversion
+ LEFT JOIN " . Piwik_Common::prefixTable('log_link_visit_action') . " AS log_link_visit_action ON log_conversion.idlink_va = log_link_visit_action.idlink_va
WHERE
( log_conversion.idvisit = ? )
AND
( log_conversion.idgoal <> ? AND log_link_visit_action.custom_var_k1 = ? AND log_conversion.idgoal = ? )",
"bind" => array(1, 2, 'Test', 1));
-
+
$this->assertEquals($this->_filterWhitsSpaces($expected), $this->_filterWhitsSpaces($query));
}
-
+
/**
* @group Core
* @group Segment
@@ -275,14 +275,14 @@ class SegmentTest extends PHPUnit_Framework_TestCase
$from = 'log_visit';
$where = 'log_visit.idvisit = ?';
$bind = array(1);
-
+
$segment = 'visitConvertedGoalId==1';
$segment = new Piwik_Segment($segment, $idSites = array());
-
+
$query = $segment->getSelectQuery($select, $from, $where, $bind);
-
+
$expected = array(
- "sql" => "
+ "sql" => "
SELECT
log_inner.*
FROM
@@ -290,8 +290,8 @@ class SegmentTest extends PHPUnit_Framework_TestCase
SELECT
log_visit.*
FROM
- ".Piwik_Common::prefixTable('log_visit')." AS log_visit
- LEFT JOIN ".Piwik_Common::prefixTable('log_conversion')." AS log_conversion ON log_conversion.idvisit = log_visit.idvisit
+ " . Piwik_Common::prefixTable('log_visit') . " AS log_visit
+ LEFT JOIN " . Piwik_Common::prefixTable('log_conversion') . " AS log_conversion ON log_conversion.idvisit = log_visit.idvisit
WHERE
( log_visit.idvisit = ? )
AND
@@ -299,10 +299,10 @@ class SegmentTest extends PHPUnit_Framework_TestCase
GROUP BY log_visit.idvisit
) AS log_inner",
"bind" => array(1, 1));
-
+
$this->assertEquals($this->_filterWhitsSpaces($expected), $this->_filterWhitsSpaces($query));
}
-
+
/**
* @group Core
* @group Segemnt
@@ -313,27 +313,27 @@ class SegmentTest extends PHPUnit_Framework_TestCase
$from = 'log_conversion';
$where = 'log_conversion.idvisit = ?';
$bind = array(1);
-
+
$segment = 'visitConvertedGoalId==1';
$segment = new Piwik_Segment($segment, $idSites = array());
-
+
$query = $segment->getSelectQuery($select, $from, $where, $bind);
-
+
$expected = array(
- "sql" => "
+ "sql" => "
SELECT
log_conversion.*
FROM
- ".Piwik_Common::prefixTable('log_conversion')." AS log_conversion
+ " . Piwik_Common::prefixTable('log_conversion') . " AS log_conversion
WHERE
( log_conversion.idvisit = ? )
AND
( log_conversion.idgoal = ? )",
"bind" => array(1, 1));
-
+
$this->assertEquals($this->_filterWhitsSpaces($expected), $this->_filterWhitsSpaces($query));
}
-
+
/**
* @group Core
* @group Segment
@@ -344,32 +344,32 @@ class SegmentTest extends PHPUnit_Framework_TestCase
$from = 'log_conversion';
$where = 'log_conversion.idvisit = ?';
$bind = array(1);
-
+
$segment = 'visitConvertedGoalId==1,visitServerHour==12';
$segment = new Piwik_Segment($segment, $idSites = array());
-
+
$query = $segment->getSelectQuery($select, $from, $where, $bind);
-
+
$expected = array(
- "sql" => "
+ "sql" => "
SELECT
*
FROM
- ".Piwik_Common::prefixTable('log_conversion')." AS log_conversion
- LEFT JOIN ".Piwik_Common::prefixTable('log_visit')." AS log_visit ON log_conversion.idvisit = log_visit.idvisit
+ " . Piwik_Common::prefixTable('log_conversion') . " AS log_conversion
+ LEFT JOIN " . Piwik_Common::prefixTable('log_visit') . " AS log_visit ON log_conversion.idvisit = log_visit.idvisit
WHERE
( log_conversion.idvisit = ? )
AND
( (log_conversion.idgoal = ? OR HOUR(log_visit.visit_last_action_time) = ? ))",
"bind" => array(1, 1, 12));
-
+
$this->assertEquals($this->_filterWhitsSpaces($expected), $this->_filterWhitsSpaces($query));
}
-
+
/**
* visit is joined on action, then conversion is joined
* make sure that conversion is joined on action not visit
- *
+ *
* @group Core
* @group Segment
*/
@@ -379,31 +379,31 @@ class SegmentTest extends PHPUnit_Framework_TestCase
$from = 'log_link_visit_action';
$where = false;
$bind = array();
-
+
$segment = 'visitServerHour==12;visitConvertedGoalId==1';
$segment = new Piwik_Segment($segment, $idSites = array());
-
+
$query = $segment->getSelectQuery($select, $from, $where, $bind);
-
+
$expected = array(
- "sql" => "
+ "sql" => "
SELECT
*
FROM
- ".Piwik_Common::prefixTable('log_link_visit_action')." AS log_link_visit_action
- LEFT JOIN ".Piwik_Common::prefixTable('log_visit')." AS log_visit ON log_visit.idvisit = log_link_visit_action.idvisit
- LEFT JOIN ".Piwik_Common::prefixTable('log_conversion')." AS log_conversion ON log_conversion.idlink_va = log_link_visit_action.idlink_va AND log_conversion.idsite = log_link_visit_action.idsite
+ " . Piwik_Common::prefixTable('log_link_visit_action') . " AS log_link_visit_action
+ LEFT JOIN " . Piwik_Common::prefixTable('log_visit') . " AS log_visit ON log_visit.idvisit = log_link_visit_action.idvisit
+ LEFT JOIN " . Piwik_Common::prefixTable('log_conversion') . " AS log_conversion ON log_conversion.idlink_va = log_link_visit_action.idlink_va AND log_conversion.idsite = log_link_visit_action.idsite
WHERE
HOUR(log_visit.visit_last_action_time) = ? AND log_conversion.idgoal = ? ",
"bind" => array(12, 1));
-
+
$this->assertEquals($this->_filterWhitsSpaces($expected), $this->_filterWhitsSpaces($query));
}
-
+
/**
* join conversion on visit, then actions
* make sure actions are joined before conversions
- *
+ *
* @group Core
* @group Segment
*/
@@ -413,14 +413,14 @@ class SegmentTest extends PHPUnit_Framework_TestCase
$from = 'log_visit';
$where = false;
$bind = array();
-
+
$segment = 'visitConvertedGoalId==1;visitServerHour==12;customVariablePageName1==Test';
$segment = new Piwik_Segment($segment, $idSites = array());
-
+
$query = $segment->getSelectQuery($select, $from, $where, $bind);
-
+
$expected = array(
- "sql" => "
+ "sql" => "
SELECT
log_inner.*
FROM
@@ -428,15 +428,15 @@ class SegmentTest extends PHPUnit_Framework_TestCase
SELECT
log_visit.*
FROM
- ".Piwik_Common::prefixTable('log_visit')." AS log_visit
- LEFT JOIN ".Piwik_Common::prefixTable('log_link_visit_action')." AS log_link_visit_action ON log_link_visit_action.idvisit = log_visit.idvisit
- LEFT JOIN ".Piwik_Common::prefixTable('log_conversion')." AS log_conversion ON log_conversion.idlink_va = log_link_visit_action.idlink_va AND log_conversion.idsite = log_link_visit_action.idsite
+ " . Piwik_Common::prefixTable('log_visit') . " AS log_visit
+ LEFT JOIN " . Piwik_Common::prefixTable('log_link_visit_action') . " AS log_link_visit_action ON log_link_visit_action.idvisit = log_visit.idvisit
+ LEFT JOIN " . Piwik_Common::prefixTable('log_conversion') . " AS log_conversion ON log_conversion.idlink_va = log_link_visit_action.idlink_va AND log_conversion.idsite = log_link_visit_action.idsite
WHERE
log_conversion.idgoal = ? AND HOUR(log_visit.visit_last_action_time) = ? AND log_link_visit_action.custom_var_k1 = ?
GROUP BY log_visit.idvisit
) AS log_inner",
"bind" => array(1, 12, 'Test'));
-
+
$this->assertEquals($this->_filterWhitsSpaces($expected), $this->_filterWhitsSpaces($query));
}
@@ -451,6 +451,7 @@ class SegmentTest extends PHPUnit_Framework_TestCase
array('A=B')
);
}
+
/**
* @group Core
* @group Segment
diff --git a/tests/PHPUnit/Core/ServeStaticFileTest.php b/tests/PHPUnit/Core/ServeStaticFileTest.php
index 8e70d46cc5..253526f3ca 100644
--- a/tests/PHPUnit/Core/ServeStaticFileTest.php
+++ b/tests/PHPUnit/Core/ServeStaticFileTest.php
@@ -388,8 +388,8 @@ class Test_Piwik_ServeStaticFile extends PHPUnit_Framework_TestCase
*/
private function getStaticSrvUrl()
{
- $url = Test_Piwik_BaseFixture::getRootUrl();
- $url .= '/tests/resources/';
+ $url = Test_Piwik_BaseFixture::getRootUrl();
+ $url .= '/tests/resources/';
return $url . "staticFileServer.php?" . FILE_MODE_REQUEST_VAR . "=" . STATIC_SERVER_MODE .
"&" . SRV_MODE_REQUEST_VAR . "=";
diff --git a/tests/PHPUnit/Core/SqlTest.php b/tests/PHPUnit/Core/SqlTest.php
index 48c64b2cf5..14aebbf22c 100755
--- a/tests/PHPUnit/Core/SqlTest.php
+++ b/tests/PHPUnit/Core/SqlTest.php
@@ -7,37 +7,37 @@
*/
class SqlTest extends DatabaseTestCase
{
- public function setUp()
- {
- parent::setUp();
-
- // create two myisam tables
- Piwik_Exec("CREATE TABLE table1 (a INT) ENGINE=MYISAM");
- Piwik_Exec("CREATE TABLE table2 (b INT) ENGINE=MYISAM");
-
- // create two innodb tables
- Piwik_Exec("CREATE TABLE table3 (c INT) ENGINE=InnoDB");
- Piwik_Exec("CREATE TABLE table4 (d INT) ENGINE=InnoDB");
- }
-
- public function tearDown()
- {
- parent::tearDown();
- }
-
+ public function setUp()
+ {
+ parent::setUp();
+
+ // create two myisam tables
+ Piwik_Exec("CREATE TABLE table1 (a INT) ENGINE=MYISAM");
+ Piwik_Exec("CREATE TABLE table2 (b INT) ENGINE=MYISAM");
+
+ // create two innodb tables
+ Piwik_Exec("CREATE TABLE table3 (c INT) ENGINE=InnoDB");
+ Piwik_Exec("CREATE TABLE table4 (d INT) ENGINE=InnoDB");
+ }
+
+ public function tearDown()
+ {
+ parent::tearDown();
+ }
+
/**
* @group Core
* @group Unzip
*/
public function testOptimize()
{
- // make sure optimizing myisam tables works
- $this->assertTrue(Piwik_OptimizeTables(array('table1', 'table2')) !== false);
-
- // make sure optimizing both myisam & innodb results in optimizations
- $this->assertTrue(Piwik_OptimizeTables(array('table1', 'table2', 'table3', 'table4')) !== false);
-
- // make sure innodb tables are skipped
- $this->assertTrue(Piwik_OptimizeTables(array('table3', 'table4')) === false);
+ // make sure optimizing myisam tables works
+ $this->assertTrue(Piwik_OptimizeTables(array('table1', 'table2')) !== false);
+
+ // make sure optimizing both myisam & innodb results in optimizations
+ $this->assertTrue(Piwik_OptimizeTables(array('table1', 'table2', 'table3', 'table4')) !== false);
+
+ // make sure innodb tables are skipped
+ $this->assertTrue(Piwik_OptimizeTables(array('table3', 'table4')) === false);
}
}
diff --git a/tests/PHPUnit/Core/TablePartitioningTest.php b/tests/PHPUnit/Core/TablePartitioningTest.php
index b6f89574a6..9626b7aceb 100644
--- a/tests/PHPUnit/Core/TablePartitioningTest.php
+++ b/tests/PHPUnit/Core/TablePartitioningTest.php
@@ -22,7 +22,7 @@ class TablePartitioningTest extends DatabaseTestCase
}
$this->fail('Expected exception not raised');
}
-
+
/**
* test table absent => create
* @group Core
@@ -30,22 +30,22 @@ class TablePartitioningTest extends DatabaseTestCase
*/
public function testNoTable()
{
- $tableName ='archive_numeric';
+ $tableName = 'archive_numeric';
$p = new Piwik_TablePartitioning_Monthly($tableName);
$timestamp = strtotime("10 September 2000");
$suffixShouldBe = "_2000_09";
$prefixTables = Piwik_Config::getInstance()->database['tables_prefix'];
- $tablename = $prefixTables.$tableName.$suffixShouldBe;
-
- $p->setTimestamp( $timestamp );
-
+ $tablename = $prefixTables . $tableName . $suffixShouldBe;
+
+ $p->setTimestamp($timestamp);
+
$allTablesInstalled = Piwik::getTablesInstalled($forceReload = true);
-
+
$this->assertContains($tablename, $allTablesInstalled);
$this->assertEquals($tablename, $p->getTableName());
$this->assertEquals($tablename, (string)$p->__toString());
}
-
+
/**
* test monthly
* @group Core
@@ -53,21 +53,21 @@ class TablePartitioningTest extends DatabaseTestCase
*/
public function testMonthlyPartition()
{
- $tableName ='archive_numeric';
+ $tableName = 'archive_numeric';
$p = new Piwik_TablePartitioning_Monthly($tableName);
$timestamp = strtotime("10 September 2000");
$suffixShouldBe = "_2000_09";
$prefixTables = Piwik_Config::getInstance()->database['tables_prefix'];
- $tablename = $prefixTables.$tableName.$suffixShouldBe;
-
- $p->setTimestamp( $timestamp );
-
- $allTablesInstalled = Piwik::getTablesInstalled( $forceReload = true );
+ $tablename = $prefixTables . $tableName . $suffixShouldBe;
+
+ $p->setTimestamp($timestamp);
+
+ $allTablesInstalled = Piwik::getTablesInstalled($forceReload = true);
$this->assertContains($tablename, $allTablesInstalled);
$this->assertEquals($tablename, $p->getTableName());
$this->assertEquals($tablename, (string)$p->__toString());
}
-
+
/**
* test daily
* @group Core
@@ -75,15 +75,15 @@ class TablePartitioningTest extends DatabaseTestCase
*/
public function testDailyPartition()
{
- $tableName ='archive_numeric';
+ $tableName = 'archive_numeric';
$p = new Piwik_TablePartitioning_Daily($tableName);
$timestamp = strtotime("10 September 2000");
$suffixShouldBe = "_2000_09_10";
$prefixTables = Piwik_Config::getInstance()->database['tables_prefix'];
- $tablename = $prefixTables.$tableName.$suffixShouldBe;
-
- $p->setTimestamp( $timestamp );
-
+ $tablename = $prefixTables . $tableName . $suffixShouldBe;
+
+ $p->setTimestamp($timestamp);
+
$allTablesInstalled = Piwik::getTablesInstalled();
$this->assertContains($tablename, $allTablesInstalled);
$this->assertEquals($tablename, $p->getTableName());
diff --git a/tests/PHPUnit/Core/TaskSchedulerTest.php b/tests/PHPUnit/Core/TaskSchedulerTest.php
index 81341055d2..a774666e5a 100644
--- a/tests/PHPUnit/Core/TaskSchedulerTest.php
+++ b/tests/PHPUnit/Core/TaskSchedulerTest.php
@@ -7,312 +7,317 @@
*/
class TaskSchedulerTest extends PHPUnit_Framework_TestCase
{
- private static function getTestTimetable()
- {
- return array(
- 'Piwik_CoreAdminHome.purgeOutdatedArchives' => 1355529607,
- 'Piwik_PrivacyManager.deleteReportData_1' => 1322229607,
- );
- }
-
- /**
- * Dataprovider for testGetTimetableFromOptionValue
- */
- public function getTimetableFromOptionValueTestCases()
- {
- return array(
-
- // invalid option values should return a fresh array
- array(array(), false),
- array(array(), null),
- array(array(), 1),
- array(array(), ''),
- array(array(), 'test'),
-
- // valid serialized array
- array(
- array(
- 'Piwik_CoreAdminHome.purgeOutdatedArchives' => 1355529607,
- 'Piwik_PrivacyManager.deleteReportData' => 1355529607,
- ),
- 'a:2:{s:41:"Piwik_CoreAdminHome.purgeOutdatedArchives";i:1355529607;s:37:"Piwik_PrivacyManager.deleteReportData";i:1355529607;}'
- ),
- );
- }
-
- /**
- * @group Core
- * @group TaskScheduler
- * @dataProvider getTimetableFromOptionValueTestCases
- */
- public function testGetTimetableFromOptionValue($expectedTimetable, $option)
- {
- $getTimetableFromOptionValue = new ReflectionMethod(
- 'Piwik_TaskScheduler', 'getTimetableFromOptionValue'
+ private static function getTestTimetable()
+ {
+ return array(
+ 'Piwik_CoreAdminHome.purgeOutdatedArchives' => 1355529607,
+ 'Piwik_PrivacyManager.deleteReportData_1' => 1322229607,
+ );
+ }
+
+ /**
+ * Dataprovider for testGetTimetableFromOptionValue
+ */
+ public function getTimetableFromOptionValueTestCases()
+ {
+ return array(
+
+ // invalid option values should return a fresh array
+ array(array(), false),
+ array(array(), null),
+ array(array(), 1),
+ array(array(), ''),
+ array(array(), 'test'),
+
+ // valid serialized array
+ array(
+ array(
+ 'Piwik_CoreAdminHome.purgeOutdatedArchives' => 1355529607,
+ 'Piwik_PrivacyManager.deleteReportData' => 1355529607,
+ ),
+ 'a:2:{s:41:"Piwik_CoreAdminHome.purgeOutdatedArchives";i:1355529607;s:37:"Piwik_PrivacyManager.deleteReportData";i:1355529607;}'
+ ),
+ );
+ }
+
+ /**
+ * @group Core
+ * @group TaskScheduler
+ * @dataProvider getTimetableFromOptionValueTestCases
+ */
+ public function testGetTimetableFromOptionValue($expectedTimetable, $option)
+ {
+ $getTimetableFromOptionValue = new ReflectionMethod(
+ 'Piwik_TaskScheduler', 'getTimetableFromOptionValue'
);
$getTimetableFromOptionValue->setAccessible(TRUE);
$this->assertEquals($expectedTimetable, $getTimetableFromOptionValue->invoke(new Piwik_TaskScheduler(), $option));
- }
-
- /**
- * Dataprovider for testTaskHasBeenScheduledOnce
- */
- public function taskHasBeenScheduledOnceTestCases()
- {
- $timetable = self::getTestTimetable();
-
- return array(
- array(true, 'Piwik_CoreAdminHome.purgeOutdatedArchives', $timetable),
- array(true, 'Piwik_PrivacyManager.deleteReportData_1', $timetable),
- array(false, 'Piwik_PDFReports.weeklySchedule"', $timetable)
- );
- }
-
- /**
- * @group Core
- * @group TaskScheduler
- * @dataProvider taskHasBeenScheduledOnceTestCases
- */
- public function testTaskHasBeenScheduledOnce($expectedDecision, $taskName, $timetable)
- {
- $taskHasBeenScheduledOnce = new ReflectionMethod(
- 'Piwik_TaskScheduler', 'taskHasBeenScheduledOnce'
- );
- $taskHasBeenScheduledOnce->setAccessible(TRUE);
-
- $this->assertEquals($expectedDecision, $taskHasBeenScheduledOnce->invoke(new Piwik_TaskScheduler(), $taskName, $timetable));
- }
-
- /**
- * Dataprovider for testGetScheduledTimeForMethod
- */
- public function getScheduledTimeForMethodTestCases()
- {
- $timetable = serialize(self::getTestTimetable());
-
- return array(
- array(1355529607, 'Piwik_CoreAdminHome', 'purgeOutdatedArchives', null, $timetable),
- array(1322229607, 'Piwik_PrivacyManager', 'deleteReportData', 1, $timetable),
- array(false, 'Piwik_PDFReports', 'weeklySchedule', null, $timetable)
- );
- }
-
- /**
- * @group Core
- * @group TaskScheduler
- * @dataProvider getScheduledTimeForMethodTestCases
- */
- public function testGetScheduledTimeForMethod($expectedTime, $className, $methodName, $methodParameter, $timetable)
- {
- self::stubPiwikOption($timetable);
-
- $this->assertEquals($expectedTime, Piwik_TaskScheduler::getScheduledTimeForMethod($className, $methodName, $methodParameter));
-
- self::resetPiwikOption();
- }
-
- /**
- * Dataprovider for testTaskShouldBeExecuted
- */
- public function taskShouldBeExecutedTestCases()
- {
- $timetable = self::getTestTimetable();
-
- // set a date in the future (should not run)
- $timetable['Piwik_CoreAdminHome.purgeOutdatedArchives'] = time() + 60000;
-
- // set now (should run)
- $timetable['Piwik_PrivacyManager.deleteReportData_1'] = time();
-
- return array(
- array(false, 'Piwik_CoreAdminHome.purgeOutdatedArchives', $timetable),
- array(true, 'Piwik_PrivacyManager.deleteReportData_1', $timetable),
- array(false, 'Piwik_PDFReports.weeklySchedule"', $timetable)
- );
- }
-
- /**
- * @group Core
- * @group TaskScheduler
- * @dataProvider taskShouldBeExecutedTestCases
- */
- public function testTaskShouldBeExecuted($expectedDecision, $taskName, $timetable)
- {
- $taskShouldBeExecuted = new ReflectionMethod(
- 'Piwik_TaskScheduler', 'taskShouldBeExecuted'
- );
- $taskShouldBeExecuted->setAccessible(TRUE);
-
- $this->assertEquals($expectedDecision, $taskShouldBeExecuted->invoke(new Piwik_TaskScheduler(), $taskName, $timetable));
- }
-
- /**
- * Dataprovider for testExecuteTask
- */
- public function executeTaskTestCases()
- {
- return array(
- array('scheduledTaskOne', null),
- array('scheduledTaskTwo', 'parameterValue'),
- array('scheduledTaskTwo', 1),
- );
- }
-
- /**
- * @group Core
- * @group TaskScheduler
- * @dataProvider executeTaskTestCases
- */
- public function testExecuteTask($methodName, $parameterValue)
- {
- // assert the scheduled method is executed once with the correct parameter
- $mock = $this->getMock('TaskSchedulerTest', array($methodName));
- $mock->expects($this->once())->method($methodName)->with($this->equalTo($parameterValue));
-
- $executeTask = new ReflectionMethod('Piwik_TaskScheduler', 'executeTask');
- $executeTask->setAccessible(TRUE);
-
- $this->assertNotEmpty($executeTask->invoke(
- new Piwik_TaskScheduler(),
- new Piwik_ScheduledTask ($mock, $methodName, $parameterValue, new Piwik_ScheduledTime_Daily())
- ));
- }
-
- /**
- * Dataprovider for testRunTasks
- */
- public function testRunTasksTestCases()
- {
- $systemTime = time();
-
- $dailySchedule = $this->getMock('Piwik_ScheduledTime_Daily', array('getTime'));
- $dailySchedule->expects($this->any())
- ->method('getTime')
- ->will($this->returnValue($systemTime));
-
- $scheduledTaskOne = new Piwik_ScheduledTask ($this, 'scheduledTaskOne', null, $dailySchedule);
- $scheduledTaskTwo = new Piwik_ScheduledTask ($this, 'scheduledTaskTwo', 1, $dailySchedule);
- $scheduledTaskThree = new Piwik_ScheduledTask ($this, 'scheduledTaskThree', null, $dailySchedule);
-
- $caseOneExpectedTable = array(
- 'TaskSchedulerTest.scheduledTaskOne' => $scheduledTaskOne->getRescheduledTime(),
- 'TaskSchedulerTest.scheduledTaskTwo_1' => $systemTime + 60000,
- 'TaskSchedulerTest.scheduledTaskThree' => $scheduledTaskThree->getRescheduledTime(),
- );
-
- $caseTwoTimetableBeforeExecution = $caseOneExpectedTable;
- $caseTwoTimetableBeforeExecution['TaskSchedulerTest.scheduledTaskThree'] = $systemTime; // simulate elapsed time between case 1 and 2
-
- return array(
-
- // case 1) contains :
- // - scheduledTaskOne: already scheduled before, should be executed and rescheduled
- // - scheduledTaskTwo: already scheduled before, should not be executed and therefore not rescheduled
- // - scheduledTaskThree: not already scheduled before, should be scheduled but not executed
- array(
- $caseOneExpectedTable,
-
- // methods that should be executed
- array(
- 'TaskSchedulerTest.scheduledTaskOne'
- ),
-
- // timetable before task execution
- array(
- 'TaskSchedulerTest.scheduledTaskOne' => $systemTime,
- 'TaskSchedulerTest.scheduledTaskTwo_1' => $systemTime + 60000,
- ),
- // configured tasks
- array(
- $scheduledTaskOne,
- $scheduledTaskTwo,
- $scheduledTaskThree,
- )
- ),
-
- // case 2) follows case 1) with :
- // - scheduledTaskOne: already scheduled before, should not be executed and therefore not rescheduled
- // - scheduledTaskTwo: not configured for execution anymore, should be removed from the timetable
- // - scheduledTaskThree: already scheduled before, should be executed and rescheduled
- array(
- // expected timetable
- array(
- 'TaskSchedulerTest.scheduledTaskOne' => $scheduledTaskOne->getRescheduledTime(),
- 'TaskSchedulerTest.scheduledTaskThree' => $scheduledTaskThree->getRescheduledTime()
- ),
-
- // methods that should be executed
- array(
- 'TaskSchedulerTest.scheduledTaskThree'
- ),
-
- // timetable before task execution
- $caseTwoTimetableBeforeExecution,
-
- // configured tasks
- array(
- $scheduledTaskOne,
+ }
+
+ /**
+ * Dataprovider for testTaskHasBeenScheduledOnce
+ */
+ public function taskHasBeenScheduledOnceTestCases()
+ {
+ $timetable = self::getTestTimetable();
+
+ return array(
+ array(true, 'Piwik_CoreAdminHome.purgeOutdatedArchives', $timetable),
+ array(true, 'Piwik_PrivacyManager.deleteReportData_1', $timetable),
+ array(false, 'Piwik_PDFReports.weeklySchedule"', $timetable)
+ );
+ }
+
+ /**
+ * @group Core
+ * @group TaskScheduler
+ * @dataProvider taskHasBeenScheduledOnceTestCases
+ */
+ public function testTaskHasBeenScheduledOnce($expectedDecision, $taskName, $timetable)
+ {
+ $taskHasBeenScheduledOnce = new ReflectionMethod(
+ 'Piwik_TaskScheduler', 'taskHasBeenScheduledOnce'
+ );
+ $taskHasBeenScheduledOnce->setAccessible(TRUE);
+
+ $this->assertEquals($expectedDecision, $taskHasBeenScheduledOnce->invoke(new Piwik_TaskScheduler(), $taskName, $timetable));
+ }
+
+ /**
+ * Dataprovider for testGetScheduledTimeForMethod
+ */
+ public function getScheduledTimeForMethodTestCases()
+ {
+ $timetable = serialize(self::getTestTimetable());
+
+ return array(
+ array(1355529607, 'Piwik_CoreAdminHome', 'purgeOutdatedArchives', null, $timetable),
+ array(1322229607, 'Piwik_PrivacyManager', 'deleteReportData', 1, $timetable),
+ array(false, 'Piwik_PDFReports', 'weeklySchedule', null, $timetable)
+ );
+ }
+
+ /**
+ * @group Core
+ * @group TaskScheduler
+ * @dataProvider getScheduledTimeForMethodTestCases
+ */
+ public function testGetScheduledTimeForMethod($expectedTime, $className, $methodName, $methodParameter, $timetable)
+ {
+ self::stubPiwikOption($timetable);
+
+ $this->assertEquals($expectedTime, Piwik_TaskScheduler::getScheduledTimeForMethod($className, $methodName, $methodParameter));
+
+ self::resetPiwikOption();
+ }
+
+ /**
+ * Dataprovider for testTaskShouldBeExecuted
+ */
+ public function taskShouldBeExecutedTestCases()
+ {
+ $timetable = self::getTestTimetable();
+
+ // set a date in the future (should not run)
+ $timetable['Piwik_CoreAdminHome.purgeOutdatedArchives'] = time() + 60000;
+
+ // set now (should run)
+ $timetable['Piwik_PrivacyManager.deleteReportData_1'] = time();
+
+ return array(
+ array(false, 'Piwik_CoreAdminHome.purgeOutdatedArchives', $timetable),
+ array(true, 'Piwik_PrivacyManager.deleteReportData_1', $timetable),
+ array(false, 'Piwik_PDFReports.weeklySchedule"', $timetable)
+ );
+ }
+
+ /**
+ * @group Core
+ * @group TaskScheduler
+ * @dataProvider taskShouldBeExecutedTestCases
+ */
+ public function testTaskShouldBeExecuted($expectedDecision, $taskName, $timetable)
+ {
+ $taskShouldBeExecuted = new ReflectionMethod(
+ 'Piwik_TaskScheduler', 'taskShouldBeExecuted'
+ );
+ $taskShouldBeExecuted->setAccessible(TRUE);
+
+ $this->assertEquals($expectedDecision, $taskShouldBeExecuted->invoke(new Piwik_TaskScheduler(), $taskName, $timetable));
+ }
+
+ /**
+ * Dataprovider for testExecuteTask
+ */
+ public function executeTaskTestCases()
+ {
+ return array(
+ array('scheduledTaskOne', null),
+ array('scheduledTaskTwo', 'parameterValue'),
+ array('scheduledTaskTwo', 1),
+ );
+ }
+
+ /**
+ * @group Core
+ * @group TaskScheduler
+ * @dataProvider executeTaskTestCases
+ */
+ public function testExecuteTask($methodName, $parameterValue)
+ {
+ // assert the scheduled method is executed once with the correct parameter
+ $mock = $this->getMock('TaskSchedulerTest', array($methodName));
+ $mock->expects($this->once())->method($methodName)->with($this->equalTo($parameterValue));
+
+ $executeTask = new ReflectionMethod('Piwik_TaskScheduler', 'executeTask');
+ $executeTask->setAccessible(TRUE);
+
+ $this->assertNotEmpty($executeTask->invoke(
+ new Piwik_TaskScheduler(),
+ new Piwik_ScheduledTask ($mock, $methodName, $parameterValue, new Piwik_ScheduledTime_Daily())
+ ));
+ }
+
+ /**
+ * Dataprovider for testRunTasks
+ */
+ public function testRunTasksTestCases()
+ {
+ $systemTime = time();
+
+ $dailySchedule = $this->getMock('Piwik_ScheduledTime_Daily', array('getTime'));
+ $dailySchedule->expects($this->any())
+ ->method('getTime')
+ ->will($this->returnValue($systemTime));
+
+ $scheduledTaskOne = new Piwik_ScheduledTask ($this, 'scheduledTaskOne', null, $dailySchedule);
+ $scheduledTaskTwo = new Piwik_ScheduledTask ($this, 'scheduledTaskTwo', 1, $dailySchedule);
+ $scheduledTaskThree = new Piwik_ScheduledTask ($this, 'scheduledTaskThree', null, $dailySchedule);
+
+ $caseOneExpectedTable = array(
+ 'TaskSchedulerTest.scheduledTaskOne' => $scheduledTaskOne->getRescheduledTime(),
+ 'TaskSchedulerTest.scheduledTaskTwo_1' => $systemTime + 60000,
+ 'TaskSchedulerTest.scheduledTaskThree' => $scheduledTaskThree->getRescheduledTime(),
+ );
+
+ $caseTwoTimetableBeforeExecution = $caseOneExpectedTable;
+ $caseTwoTimetableBeforeExecution['TaskSchedulerTest.scheduledTaskThree'] = $systemTime; // simulate elapsed time between case 1 and 2
+
+ return array(
+
+ // case 1) contains :
+ // - scheduledTaskOne: already scheduled before, should be executed and rescheduled
+ // - scheduledTaskTwo: already scheduled before, should not be executed and therefore not rescheduled
+ // - scheduledTaskThree: not already scheduled before, should be scheduled but not executed
+ array(
+ $caseOneExpectedTable,
+
+ // methods that should be executed
+ array(
+ 'TaskSchedulerTest.scheduledTaskOne'
+ ),
+
+ // timetable before task execution
+ array(
+ 'TaskSchedulerTest.scheduledTaskOne' => $systemTime,
+ 'TaskSchedulerTest.scheduledTaskTwo_1' => $systemTime + 60000,
+ ),
+ // configured tasks
+ array(
+ $scheduledTaskOne,
+ $scheduledTaskTwo,
+ $scheduledTaskThree,
+ )
+ ),
+
+ // case 2) follows case 1) with :
+ // - scheduledTaskOne: already scheduled before, should not be executed and therefore not rescheduled
+ // - scheduledTaskTwo: not configured for execution anymore, should be removed from the timetable
+ // - scheduledTaskThree: already scheduled before, should be executed and rescheduled
+ array(
+ // expected timetable
+ array(
+ 'TaskSchedulerTest.scheduledTaskOne' => $scheduledTaskOne->getRescheduledTime(),
+ 'TaskSchedulerTest.scheduledTaskThree' => $scheduledTaskThree->getRescheduledTime()
+ ),
+
+ // methods that should be executed
+ array(
+ 'TaskSchedulerTest.scheduledTaskThree'
+ ),
+
+ // timetable before task execution
+ $caseTwoTimetableBeforeExecution,
+
+ // configured tasks
+ array(
+ $scheduledTaskOne,
// $scheduledTaskTwo, Not configured anymore (ie. not returned after Piwik_TaskScheduler::GET_TASKS_EVENT is issued)
- $scheduledTaskThree,
- )
- ),
- );
- }
-
- public function scheduledTaskOne() { } // nothing to do
- public function scheduledTaskTwo($param) { } // nothing to do
- public function scheduledTaskThree() { } // nothing to do
-
- /**
- * @group Core
- * @group TaskScheduler
- * @dataProvider testRunTasksTestCases
- */
- public function testRunTasks($expectedTimetable, $expectedExecutedTasks, $timetableBeforeTaskExecution, $configuredTasks)
- {
- // stub the event dispatcher so we can control the returned event notification
- Piwik_PluginsManager::getInstance()->dispatcher = new MockEventDispatcher($configuredTasks);
-
- // stub the piwik option object to control the returned option value
- self::stubPiwikOption(serialize($timetableBeforeTaskExecution));
-
- // execute tasks
- $executionResults = Piwik_TaskScheduler::runTasks();
-
- // assert methods are executed
- $executedTasks = array();
- foreach($executionResults as $executionResult)
- {
- $executedTasks[] = $executionResult['task'];
- $this->assertNotEmpty($executionResult['output']);
- }
- $this->assertEquals($expectedExecutedTasks, $executedTasks);
-
- // assert the timetable is correctly updated
- $getTimetableFromOptionTable = new ReflectionMethod('Piwik_TaskScheduler', 'getTimetableFromOptionTable');
- $getTimetableFromOptionTable->setAccessible(TRUE);
- $this->assertEquals($expectedTimetable, $getTimetableFromOptionTable->invoke(new Piwik_TaskScheduler()));
-
- // restore event dispatcher & piwik options
- Piwik_PluginsManager::getInstance()->dispatcher = Event_Dispatcher::getInstance();
- self::resetPiwikOption();
- }
-
- private static function stubPiwikOption($timetable)
- {
- self::getReflectedPiwikOptionInstance()->setValue(new MockPiwikOption($timetable));
- }
-
- private static function resetPiwikOption()
- {
- self::getReflectedPiwikOptionInstance()->setValue(null);
- }
-
- private static function getReflectedPiwikOptionInstance()
- {
- $piwikOptionInstance = new ReflectionProperty('Piwik_Option', 'instance');
- $piwikOptionInstance->setAccessible(true);
- return $piwikOptionInstance;
- }
+ $scheduledTaskThree,
+ )
+ ),
+ );
+ }
+
+ public function scheduledTaskOne()
+ {
+ } // nothing to do
+ public function scheduledTaskTwo($param)
+ {
+ } // nothing to do
+ public function scheduledTaskThree()
+ {
+ } // nothing to do
+
+ /**
+ * @group Core
+ * @group TaskScheduler
+ * @dataProvider testRunTasksTestCases
+ */
+ public function testRunTasks($expectedTimetable, $expectedExecutedTasks, $timetableBeforeTaskExecution, $configuredTasks)
+ {
+ // stub the event dispatcher so we can control the returned event notification
+ Piwik_PluginsManager::getInstance()->dispatcher = new MockEventDispatcher($configuredTasks);
+
+ // stub the piwik option object to control the returned option value
+ self::stubPiwikOption(serialize($timetableBeforeTaskExecution));
+
+ // execute tasks
+ $executionResults = Piwik_TaskScheduler::runTasks();
+
+ // assert methods are executed
+ $executedTasks = array();
+ foreach ($executionResults as $executionResult) {
+ $executedTasks[] = $executionResult['task'];
+ $this->assertNotEmpty($executionResult['output']);
+ }
+ $this->assertEquals($expectedExecutedTasks, $executedTasks);
+
+ // assert the timetable is correctly updated
+ $getTimetableFromOptionTable = new ReflectionMethod('Piwik_TaskScheduler', 'getTimetableFromOptionTable');
+ $getTimetableFromOptionTable->setAccessible(TRUE);
+ $this->assertEquals($expectedTimetable, $getTimetableFromOptionTable->invoke(new Piwik_TaskScheduler()));
+
+ // restore event dispatcher & piwik options
+ Piwik_PluginsManager::getInstance()->dispatcher = Event_Dispatcher::getInstance();
+ self::resetPiwikOption();
+ }
+
+ private static function stubPiwikOption($timetable)
+ {
+ self::getReflectedPiwikOptionInstance()->setValue(new MockPiwikOption($timetable));
+ }
+
+ private static function resetPiwikOption()
+ {
+ self::getReflectedPiwikOptionInstance()->setValue(null);
+ }
+
+ private static function getReflectedPiwikOptionInstance()
+ {
+ $piwikOptionInstance = new ReflectionProperty('Piwik_Option', 'instance');
+ $piwikOptionInstance->setAccessible(true);
+ return $piwikOptionInstance;
+ }
}
diff --git a/tests/PHPUnit/Core/Tracker/ActionTest.php b/tests/PHPUnit/Core/Tracker/ActionTest.php
index 3e661c8611..f6cb3321de 100644
--- a/tests/PHPUnit/Core/Tracker/ActionTest.php
+++ b/tests/PHPUnit/Core/Tracker/ActionTest.php
@@ -14,7 +14,7 @@ class Tracker_ActionTest extends DatabaseTestCase
$config = Piwik_Config::getInstance();
$config->clear();
$config->setTestEnvironment($userFile, false);
-
+
Piwik_PluginsManager::getInstance()->loadPlugins(array('SitesManager'));
}
@@ -24,79 +24,79 @@ class Tracker_ActionTest extends DatabaseTestCase
FakeAccess::$superUser = true;
Zend_Registry::set('access', $pseudoMockAccess);
}
-
+
public function getTestUrls()
{
$campaignNameParam = 'test_campaign_name';
$campaignKwdParam = 'test_piwik_kwd';
-
+
$urls = array(
// a wrongly formatted url (parse_url returns false)
array('http:////wrongurl',
- array(false,
- false)),
-
+ array(false,
+ false)),
+
// a URL with all components
array('http://username:password@hostname:80/path?phpSESSID=value#anchor',
- array('http://username:password@hostname:80/path#anchor',
- 'http://username:password@hostname:80/path#anchor')),
-
+ array('http://username:password@hostname:80/path#anchor',
+ 'http://username:password@hostname:80/path#anchor')),
+
// a standard url with excluded campaign parameters
- array('http://a.com/index?p1=v1&'.$campaignNameParam.'=Adwords-CPC&'.$campaignKwdParam.'=My killer keyword',
- array('http://a.com/index?p1=v1',
- 'http://a.com/index?p1=v1')),
+ array('http://a.com/index?p1=v1&' . $campaignNameParam . '=Adwords-CPC&' . $campaignKwdParam . '=My killer keyword',
+ array('http://a.com/index?p1=v1',
+ 'http://a.com/index?p1=v1')),
// a standard url with excluded campaign parameters, GA style
array('http://a.com/index?p1=v1&utm_campaign=Adwords-CPC&utm_term=My killer keyword',
- array('http://a.com/index?p1=v1',
- 'http://a.com/index?p1=v1')),
-
+ array('http://a.com/index?p1=v1',
+ 'http://a.com/index?p1=v1')),
+
// testing with capital parameter
array('http://a.com/index?p1=v1&P2=v2&p3=v3',
- array('http://a.com/index?p1=v1&P2=v2&p3=v3',
- 'http://a.com/index?p1=v1&p3=v3')),
-
+ array('http://a.com/index?p1=v1&P2=v2&p3=v3',
+ 'http://a.com/index?p1=v1&p3=v3')),
+
// testing with array []
array('http://a.com/index?p1=v1&p2[]=v;2a&p2[]=v2b&p2[]=v2c&p3=v3&p4=v4',
- array('http://a.com/index?p1=v1&p2[]=v;2a&p2[]=v2b&p2[]=v2c&p3=v3&p4=v4',
- 'http://a.com/index?p1=v1&p3=v3')),
+ array('http://a.com/index?p1=v1&p2[]=v;2a&p2[]=v2b&p2[]=v2c&p3=v3&p4=v4',
+ 'http://a.com/index?p1=v1&p3=v3')),
// testing with missing value
array('http://a.com/index?p1=v1&p2=&p3=v3&p4',
- array('http://a.com/index?p1=v1&p2=&p3=v3&p4',
- 'http://a.com/index?p1=v1&p3=v3')),
+ array('http://a.com/index?p1=v1&p2=&p3=v3&p4',
+ 'http://a.com/index?p1=v1&p3=v3')),
array('http://a.com/index?p1&p2=v2&p3=v3&p4',
- array('http://a.com/index?p1&p2=v2&p3=v3&p4',
- 'http://a.com/index?p1&p3=v3')),
+ array('http://a.com/index?p1&p2=v2&p3=v3&p4',
+ 'http://a.com/index?p1&p3=v3')),
// testing with extra &&
array('http://a.com/index?p1=v1&&p2=v;2&p3=v%3b3&p4=v4&&',
- array('http://a.com/index?p1=v1&p2=v;2&p3=v%3b3&p4=v4',
- 'http://a.com/index?p1=v1&p3=v%3b3')),
+ array('http://a.com/index?p1=v1&p2=v;2&p3=v%3b3&p4=v4',
+ 'http://a.com/index?p1=v1&p3=v%3b3')),
// encode entities
array('http://a.com/index?p1=v1&p2%5B%5D=v2&p3=v3&p4=v4',
- array('http://a.com/index?p1=v1&p2[]=v2&p3=v3&p4=v4',
- 'http://a.com/index?p1=v1&p3=v3')),
+ array('http://a.com/index?p1=v1&p2[]=v2&p3=v3&p4=v4',
+ 'http://a.com/index?p1=v1&p3=v3')),
array('http://a.com/index?var%5Bvalue%5D%5Bdate%5D=01.01.2012',
- array('http://a.com/index?var[value][date]=01.01.2012',
- 'http://a.com/index')),
+ array('http://a.com/index?var[value][date]=01.01.2012',
+ 'http://a.com/index')),
// matrix parameters
array('http://a.com/index;jsessionid=value;p1=v1;p2=v2',
- array('http://a.com/index?p1=v1&p2=v2',
- 'http://a.com/index?p1=v1')),
+ array('http://a.com/index?p1=v1&p2=v2',
+ 'http://a.com/index?p1=v1')),
array('http://a.com/index;jsessionid=value?p1=v1&p2=v2',
- array('http://a.com/index?p1=v1&p2=v2',
- 'http://a.com/index?p1=v1')),
+ array('http://a.com/index?p1=v1&p2=v2',
+ 'http://a.com/index?p1=v1')),
);
-
+
return $urls;
}
-
+
/**
* No excluded query parameters specified, apart from the standard "session" parameters, always excluded
- *
+ *
* @group Core
* @group Tracker
* @group Tracker_Action
@@ -105,37 +105,37 @@ class Tracker_ActionTest extends DatabaseTestCase
public function testExcludeQueryParametersNone($url, $filteredUrl)
{
$this->setUpRootAccess();
- $idSite = Piwik_SitesManager_API::getInstance()->addSite("site1",array('http://example.org'),$ecommerce=0,
- $siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null,
- $excludedIps = '', $excludedQueryParameters='', $timezone = null, $currency = null,
- $group = null, $startDate = null, $excludedUserAgents = null, $keepURLFragments = 1);
+ $idSite = Piwik_SitesManager_API::getInstance()->addSite("site1", array('http://example.org'), $ecommerce = 0,
+ $siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null,
+ $excludedIps = '', $excludedQueryParameters = '', $timezone = null, $currency = null,
+ $group = null, $startDate = null, $excludedUserAgents = null, $keepURLFragments = 1);
$this->assertEquals($filteredUrl[0], Piwik_Tracker_Action::excludeQueryParametersFromUrl($url, $idSite));
}
- public function getTestUrlsHashtag()
- {
+ public function getTestUrlsHashtag()
+ {
$urls = array(
- // URL, Expected URL
- array('wrongurl/#', 'http://wrongurl/'),
- array('wrongurl/#t', 'http://wrongurl/#t'),
- array('wrongurl/#test', 'http://wrongurl/#test'),
- array('wrongurl/#test=1', 'http://wrongurl/#test=1'),
- array('wrongurl/#test=1#', 'http://wrongurl/#test=1'),
+ // URL, Expected URL
+ array('wrongurl/#', 'http://wrongurl/'),
+ array('wrongurl/#t', 'http://wrongurl/#t'),
+ array('wrongurl/#test', 'http://wrongurl/#test'),
+ array('wrongurl/#test=1', 'http://wrongurl/#test=1'),
+ array('wrongurl/#test=1#', 'http://wrongurl/#test=1'),
);
- return $urls;
- }
+ return $urls;
+ }
- /**
- * Test removing hash tag
- * @group Core
- * @group Tracker
- * @group Tracker_Action
- * @dataProvider getTestUrlsHashtag
- */
- public function testRemoveTrailingHashtag($url, $expectedUrl)
- {
- $this->assertEquals( Piwik_Tracker_Action::reconstructNormalizedUrl($url, Piwik_Tracker_Action::$urlPrefixMap['http://']), $expectedUrl);
- }
+ /**
+ * Test removing hash tag
+ * @group Core
+ * @group Tracker
+ * @group Tracker_Action
+ * @dataProvider getTestUrlsHashtag
+ */
+ public function testRemoveTrailingHashtag($url, $expectedUrl)
+ {
+ $this->assertEquals(Piwik_Tracker_Action::reconstructNormalizedUrl($url, Piwik_Tracker_Action::$urlPrefixMap['http://']), $expectedUrl);
+ }
/**
@@ -149,13 +149,13 @@ class Tracker_ActionTest extends DatabaseTestCase
{
$excludedQueryParameters = 'p4, p2, var[value][date]';
$this->setUpRootAccess();
- $idSite = Piwik_SitesManager_API::getInstance()->addSite("site1",array('http://example.org'),$ecommerce=0,
- $siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null,
- $excludedIps = '', $excludedQueryParameters, $timezone = null, $currency = null,
- $group = null, $startDate = null, $excludedUserAgents = null, $keepURLFragments = 1);
+ $idSite = Piwik_SitesManager_API::getInstance()->addSite("site1", array('http://example.org'), $ecommerce = 0,
+ $siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null,
+ $excludedIps = '', $excludedQueryParameters, $timezone = null, $currency = null,
+ $group = null, $startDate = null, $excludedUserAgents = null, $keepURLFragments = 1);
$this->assertEquals($filteredUrl[1], Piwik_Tracker_Action::excludeQueryParametersFromUrl($url, $idSite));
}
-
+
/**
* Testing with some website specific and some global excluded query parameters
* @group Core
@@ -169,16 +169,17 @@ class Tracker_ActionTest extends DatabaseTestCase
$excludedQueryParameters = 'P2,var[value][date]';
$excludedGlobalParameters = 'blabla, P4';
$this->setUpRootAccess();
- $idSite = Piwik_SitesManager_API::getInstance()->addSite("site1",array('http://example.org'),$ecommerce=0,
- $siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null,
- $excludedIps = '', $excludedQueryParameters, $timezone = null, $currency = null,
- $group = null, $startDate = null, $excludedUserAgents = null, $keepURLFragments = 1);
+ $idSite = Piwik_SitesManager_API::getInstance()->addSite("site1", array('http://example.org'), $ecommerce = 0,
+ $siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null,
+ $excludedIps = '', $excludedQueryParameters, $timezone = null, $currency = null,
+ $group = null, $startDate = null, $excludedUserAgents = null, $keepURLFragments = 1);
Piwik_SitesManager_API::getInstance()->setGlobalExcludedQueryParameters($excludedGlobalParameters);
$this->assertEquals($filteredUrl[1], Piwik_Tracker_Action::excludeQueryParametersFromUrl($url, $idSite));
}
-
-
- public function getExtractUrlData() {
+
+
+ public function getExtractUrlData()
+ {
return array(
// outlinks
array(
@@ -214,7 +215,7 @@ class Tracker_ActionTest extends DatabaseTestCase
array(
'request' => array('download' => 'http://example.org/*$test.zip'),
'expected' => array('name' => null,
- 'url' => 'http://example.org/*$test.zip',
+ 'url' => 'http://example.org/*$test.zip',
'type' => Piwik_Tracker_Action::TYPE_DOWNLOAD),
),
@@ -222,132 +223,132 @@ class Tracker_ActionTest extends DatabaseTestCase
array(
'request' => array('download' => 'http://example.org/*$test.zip', 'action_name' => 'Download test.zip'),
'expected' => array('name' => 'Download test.zip',
- 'url' => 'http://example.org/*$test.zip',
+ 'url' => 'http://example.org/*$test.zip',
'type' => Piwik_Tracker_Action::TYPE_DOWNLOAD),
),
-
+
// keep the case and multiple / in urls
array(
'request' => array('download' => 'http://example.org/CATEGORY/test///test.pdf'),
'expected' => array('name' => null,
- 'url' => 'http://example.org/CATEGORY/test///test.pdf',
+ 'url' => 'http://example.org/CATEGORY/test///test.pdf',
'type' => Piwik_Tracker_Action::TYPE_DOWNLOAD),
),
-
+
// page view
array(
'request' => array('url' => 'http://example.org/'),
'expected' => array('name' => null,
- 'url' => 'http://example.org/',
+ 'url' => 'http://example.org/',
'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
),
array(
'request' => array('url' => 'http://example.org/', 'action_name' => 'Example.org Website'),
'expected' => array('name' => 'Example.org Website',
- 'url' => 'http://example.org/',
+ 'url' => 'http://example.org/',
'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
),
array(
'request' => array('url' => 'http://example.org/CATEGORY/'),
'expected' => array('name' => null,
- 'url' => 'http://example.org/CATEGORY/',
+ 'url' => 'http://example.org/CATEGORY/',
'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
),
array(
'request' => array('url' => 'http://example.org/CATEGORY/TEST', 'action_name' => 'Example.org / Category / test /'),
'expected' => array('name' => 'Example.org/Category/test',
- 'url' => 'http://example.org/CATEGORY/TEST',
+ 'url' => 'http://example.org/CATEGORY/TEST',
'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
),
array(
'request' => array('url' => 'http://example.org/?2,123'),
'expected' => array('name' => null,
- 'url' => 'http://example.org/?2,123',
+ 'url' => 'http://example.org/?2,123',
'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
),
// empty request
array(
'request' => array(),
- 'expected' => array('name' => null, 'url' => '',
+ 'expected' => array('name' => null, 'url' => '',
'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
),
array(
'request' => array('name' => null, 'url' => "\n"),
- 'expected' => array('name' => null, 'url' => '',
+ 'expected' => array('name' => null, 'url' => '',
'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
),
array(
- 'request' => array('url' => 'http://example.org/category/',
+ 'request' => array('url' => 'http://example.org/category/',
'action_name' => 'custom name with/one delimiter/two delimiters/'),
'expected' => array('name' => 'custom name with/one delimiter/two delimiters',
- 'url' => 'http://example.org/category/',
+ 'url' => 'http://example.org/category/',
'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
),
array(
- 'request' => array('url' => 'http://example.org/category/',
+ 'request' => array('url' => 'http://example.org/category/',
'action_name' => 'http://custom action name look like url/'),
'expected' => array('name' => 'http:/custom action name look like url',
- 'url' => 'http://example.org/category/',
+ 'url' => 'http://example.org/category/',
'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
),
// testing: delete tab, trimmed, not strtolowered
- array(
+ array(
'request' => array('url' => "http://example.org/category/test///test wOw "),
'expected' => array('name' => null,
- 'url' => 'http://example.org/category/test///test wOw',
+ 'url' => 'http://example.org/category/test///test wOw',
'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
),
// testing: inclusion of zero values in action name
array(
'request' => array('url' => "http://example.org/category/1/0/t/test"),
'expected' => array('name' => null,
- 'url' => 'http://example.org/category/1/0/t/test',
+ 'url' => 'http://example.org/category/1/0/t/test',
'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
),
// testing: action name ("Test &hellip;") - expect decoding of some html entities
array(
- 'request' => array('url' => 'http://example.org/ACTION/URL',
+ 'request' => array('url' => 'http://example.org/ACTION/URL',
'action_name' => "Test &hellip;"),
'expected' => array('name' => 'Test …',
- 'url' => 'http://example.org/ACTION/URL',
+ 'url' => 'http://example.org/ACTION/URL',
'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
),
// testing: action name ("Special &amp; chars") - expect no conversion of html special chars
array(
- 'request' => array('url' => 'http://example.org/ACTION/URL',
+ 'request' => array('url' => 'http://example.org/ACTION/URL',
'action_name' => "Special &amp; chars"),
'expected' => array('name' => 'Special &amp; chars',
- 'url' => 'http://example.org/ACTION/URL',
+ 'url' => 'http://example.org/ACTION/URL',
'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
),
// testing: action name ("Tést") - handle wide character
array(
- 'request' => array('url' => 'http://example.org/ACTION/URL',
+ 'request' => array('url' => 'http://example.org/ACTION/URL',
'action_name' => "Tést"),
'expected' => array('name' => 'Tést',
- 'url' => 'http://example.org/ACTION/URL',
+ 'url' => 'http://example.org/ACTION/URL',
'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
),
// testing: action name ("Tést") - handle UTF-8 byte sequence
array(
- 'request' => array('url' => 'http://example.org/ACTION/URL',
+ 'request' => array('url' => 'http://example.org/ACTION/URL',
'action_name' => "T\xc3\xa9st"),
'expected' => array('name' => 'Tést',
- 'url' => 'http://example.org/ACTION/URL',
+ 'url' => 'http://example.org/ACTION/URL',
'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
),
// testing: action name ("Tést") - invalid UTF-8 (e.g., ISO-8859-1) is not handled
array(
- 'request' => array('url' => 'http://example.org/ACTION/URL',
+ 'request' => array('url' => 'http://example.org/ACTION/URL',
'action_name' => "T\xe9st"),
'expected' => array('name' => version_compare(PHP_VERSION, '5.2.5') === -1 ? 'T\xe9st' : 'Tést',
- 'url' => 'http://example.org/ACTION/URL',
+ 'url' => 'http://example.org/ACTION/URL',
'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
),
);
}
-
+
/**
* @dataProvider getExtractUrlData
* @group Core
@@ -356,11 +357,11 @@ class Tracker_ActionTest extends DatabaseTestCase
*/
public function testExtractUrlAndActionNameFromRequest($request, $expected)
{
- $this->setUpRootAccess();
- $idSite = Piwik_SitesManager_API::getInstance()->addSite("site1",array('http://example.org'));
- $action = new Test_Piwik_TrackerAction_extractUrlAndActionNameFromRequest();
- $action->setRequest($request);
- $action->setIdSite($idSite);
+ $this->setUpRootAccess();
+ $idSite = Piwik_SitesManager_API::getInstance()->addSite("site1", array('http://example.org'));
+ $action = new Test_Piwik_TrackerAction_extractUrlAndActionNameFromRequest();
+ $action->setRequest($request);
+ $action->setIdSite($idSite);
$this->assertEquals($action->public_extractUrlAndActionNameFromRequest(), $expected);
}
}
diff --git a/tests/PHPUnit/Core/Tracker/VisitTest.php b/tests/PHPUnit/Core/Tracker/VisitTest.php
index a56f1d27a2..0a262b9fc6 100644
--- a/tests/PHPUnit/Core/Tracker/VisitTest.php
+++ b/tests/PHPUnit/Core/Tracker/VisitTest.php
@@ -15,7 +15,7 @@ class Tracker_VisitTest extends DatabaseTestCase
$pseudoMockAccess = new FakeAccess;
FakeAccess::$superUser = true;
Zend_Registry::set('access', $pseudoMockAccess);
-
+
Piwik_PluginsManager::getInstance()->loadPlugins(array('SitesManager'));
}
@@ -26,41 +26,41 @@ class Tracker_VisitTest extends DatabaseTestCase
{
return array(
array('12.12.12.12', array(
- '12.12.12.12' => true,
- '12.12.12.11' => false,
- '12.12.12.13' => false,
- '0.0.0.0' => false,
+ '12.12.12.12' => true,
+ '12.12.12.11' => false,
+ '12.12.12.13' => false,
+ '0.0.0.0' => false,
'255.255.255.255' => false
)),
array('12.12.12.12/32', array(
- '12.12.12.12' => true,
- '12.12.12.11' => false,
- '12.12.12.13' => false,
- '0.0.0.0' => false,
+ '12.12.12.12' => true,
+ '12.12.12.11' => false,
+ '12.12.12.13' => false,
+ '0.0.0.0' => false,
'255.255.255.255' => false
)),
array('12.12.12.*', array(
- '12.12.12.0' => true,
- '12.12.12.255' => true,
- '12.12.12.12' => true,
- '12.12.11.255' => false,
- '12.12.13.0' => false,
- '0.0.0.0' => false,
+ '12.12.12.0' => true,
+ '12.12.12.255' => true,
+ '12.12.12.12' => true,
+ '12.12.11.255' => false,
+ '12.12.13.0' => false,
+ '0.0.0.0' => false,
'255.255.255.255' => false,
)),
array('12.12.12.0/24', array(
- '12.12.12.0' => true,
- '12.12.12.255' => true,
- '12.12.12.12' => true,
- '12.12.11.255' => false,
- '12.12.13.0' => false,
- '0.0.0.0' => false,
+ '12.12.12.0' => true,
+ '12.12.12.255' => true,
+ '12.12.12.12' => true,
+ '12.12.11.255' => false,
+ '12.12.13.0' => false,
+ '0.0.0.0' => false,
'255.255.255.255' => false,
)),
// add some ipv6 addresses!
);
}
-
+
/**
* @group Core
* @group Tracker
@@ -70,76 +70,75 @@ class Tracker_VisitTest extends DatabaseTestCase
public function testIsVisitorIpExcluded($excludedIp, $tests)
{
$visit = new Test_Piwik_TrackerVisit_public();
- $idsite = Piwik_SitesManager_API::getInstance()->addSite("name","http://piwik.net/",$ecommerce=0,
- $siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null, $excludedIp);
+ $idsite = Piwik_SitesManager_API::getInstance()->addSite("name", "http://piwik.net/", $ecommerce = 0,
+ $siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null, $excludedIp);
$visit->setRequest(array('idsite' => $idsite));
// test that IPs within the range, or the given IP, are excluded
- foreach($tests as $ip => $expected)
- {
+ foreach ($tests as $ip => $expected) {
$testIpIsExcluded = Piwik_IP::P2N($ip);
$this->assertSame($expected, $visit->public_isVisitorIpExcluded($testIpIsExcluded));
}
}
-
+
/**
* Dataprovider for testIsVisitorUserAgentExcluded.
*/
public function getExcludedUserAgentTestData()
{
- return array(
- array('', array(
- 'whatever' => false,
- '' => false,
- 'nlksdjfsldkjfsa' => false,
- )),
- array('mozilla', array(
- 'this has mozilla in it' => true,
- 'this doesn\'t' => false,
- 'partial presence: mozi' => false,
- )),
- array('cHrOmE,notinthere,&^%', array(
- 'chrome is here' => true,
- 'CHROME is here' => true,
- '12&^%345' => true,
- 'sfasdf' => false,
- )),
- );
+ return array(
+ array('', array(
+ 'whatever' => false,
+ '' => false,
+ 'nlksdjfsldkjfsa' => false,
+ )),
+ array('mozilla', array(
+ 'this has mozilla in it' => true,
+ 'this doesn\'t' => false,
+ 'partial presence: mozi' => false,
+ )),
+ array('cHrOmE,notinthere,&^%', array(
+ 'chrome is here' => true,
+ 'CHROME is here' => true,
+ '12&^%345' => true,
+ 'sfasdf' => false,
+ )),
+ );
+ }
+
+ /**
+ * @group Core
+ * @group Tracker
+ * @group Tracker_Visit
+ * @dataProvider getExcludedUserAgentTestData
+ */
+ public function testIsVisitorUserAgentExcluded($excludedUserAgent, $tests)
+ {
+ Piwik_SitesManager_API::getInstance()->setSiteSpecificUserAgentExcludeEnabled(true);
+
+ $visit = new Test_Piwik_TrackerVisit_public();
+ $idsite = Piwik_SitesManager_API::getInstance()->addSite("name", "http://piwik.net/", $ecommerce = 0,
+ $siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null, $excludedIp = null,
+ $excludedQueryParameters = null, $timezone = null, $currency = null, $group = null, $startDate = null,
+ $excludedUserAgent);
+ $visit->setRequest(array('idsite' => $idsite));
+
+ // test that user agents that contain excluded user agent strings are excluded
+ foreach ($tests as $ua => $expected) {
+ $this->assertSame($expected, $visit->public_isUserAgentExcluded($ua), "Result if isUserAgentExcluded('$ua') was not " . ($expected ? 'true' : 'false') . ".");
+ }
}
-
- /**
- * @group Core
- * @group Tracker
- * @group Tracker_Visit
- * @dataProvider getExcludedUserAgentTestData
- */
- public function testIsVisitorUserAgentExcluded($excludedUserAgent, $tests)
- {
- Piwik_SitesManager_API::getInstance()->setSiteSpecificUserAgentExcludeEnabled(true);
-
- $visit = new Test_Piwik_TrackerVisit_public();
- $idsite = Piwik_SitesManager_API::getInstance()->addSite("name","http://piwik.net/",$ecommerce=0,
- $siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null, $excludedIp=null,
- $excludedQueryParameters = null, $timezone = null, $currency = null, $group = null, $startDate = null,
- $excludedUserAgent);
- $visit->setRequest(array('idsite' => $idsite));
-
- // test that user agents that contain excluded user agent strings are excluded
- foreach ($tests as $ua => $expected)
- {
- $this->assertSame($expected, $visit->public_isUserAgentExcluded($ua), "Result if isUserAgentExcluded('$ua') was not ".($expected?'true':'false').".");
- }
- }
}
-class Test_Piwik_TrackerVisit_public extends Piwik_Tracker_Visit {
- public function public_isVisitorIpExcluded( $ip )
- {
- return $this->isVisitorIpExcluded($ip);
- }
-
- public function public_isUserAgentExcluded( $ua )
- {
- return $this->isUserAgentExcluded($ua);
- }
+class Test_Piwik_TrackerVisit_public extends Piwik_Tracker_Visit
+{
+ public function public_isVisitorIpExcluded($ip)
+ {
+ return $this->isVisitorIpExcluded($ip);
+ }
+
+ public function public_isUserAgentExcluded($ua)
+ {
+ return $this->isUserAgentExcluded($ua);
+ }
}
diff --git a/tests/PHPUnit/Core/TranslationWriterTest.php b/tests/PHPUnit/Core/TranslationWriterTest.php
index be5c90f93a..27a4fa597a 100644
--- a/tests/PHPUnit/Core/TranslationWriterTest.php
+++ b/tests/PHPUnit/Core/TranslationWriterTest.php
@@ -62,8 +62,7 @@ class TranslationWriterTest extends PHPUnit_Framework_TestCase
*/
public function testQuote($data, $expected)
{
- if(Piwik_Common::isWindows() && $data == "\n")
- {
+ if (Piwik_Common::isWindows() && $data == "\n") {
return;
}
$this->assertEquals($expected, Piwik_TranslationWriter::quote($data));
@@ -82,7 +81,7 @@ class TranslationWriterTest extends PHPUnit_Framework_TestCase
}
$this->fail('Expected exception not raised');
}
-
+
/**
* @group Core
* @group TranslationWriter
@@ -96,7 +95,7 @@ class TranslationWriterTest extends PHPUnit_Framework_TestCase
}
$this->fail('Expected exception not raised');
}
-
+
/**
* @group Core
* @group TranslationWriter
@@ -124,7 +123,7 @@ class TranslationWriterTest extends PHPUnit_Framework_TestCase
}
$this->fail('Expected exception not raised');
}
-
+
/**
* @group Core
* @group TranslationWriter
@@ -151,9 +150,9 @@ class TranslationWriterTest extends PHPUnit_Framework_TestCase
$translations = array(
'General_Locale' => 'en_CA.UTF-8',
- 'General_Id' => 'Id',
- 'Goals_Goals' => 'Goals',
- 'Plugin_Body' => "Message\nBody",
+ 'General_Id' => 'Id',
+ 'Goals_Goals' => 'Goals',
+ 'Plugin_Body' => "Message\nBody",
);
@unlink($path);
@@ -163,7 +162,7 @@ class TranslationWriterTest extends PHPUnit_Framework_TestCase
$contents = file_get_contents($path);
$expected = "<?php\n\$translations = array(\n\t'General_Locale' => 'en_CA.UTF-8',\n\t'General_Id' => 'Id',\n\t'Goals_Goals' => 'Goals',\n\n\t// FOR REVIEW\n\t'Plugin_Body' => 'Message\nBody',\n);\n";
- if(Piwik_Common::isWindows()) $expected = str_replace("\r\n", "\n", $expected);
+ if (Piwik_Common::isWindows()) $expected = str_replace("\r\n", "\n", $expected);
$this->assertEquals($expected, $contents);
}
}
diff --git a/tests/PHPUnit/Core/UnzipTest.php b/tests/PHPUnit/Core/UnzipTest.php
index 40706a19df..8ec666dd79 100644
--- a/tests/PHPUnit/Core/UnzipTest.php
+++ b/tests/PHPUnit/Core/UnzipTest.php
@@ -16,10 +16,9 @@ class UnzipTest extends PHPUnit_Framework_TestCase
clearstatcache();
$extractDir = PIWIK_USER_PATH . '/tmp/latest/';
$test = 'relative';
- $filename = dirname(__FILE__) . '/Unzip/'.$test.'.zip';
+ $filename = dirname(__FILE__) . '/Unzip/' . $test . '.zip';
- if(class_exists('ZipArchive', false))
- {
+ if (class_exists('ZipArchive', false)) {
$unzip = Piwik_Unzip::factory('ZipArchive', $filename);
$res = $unzip->extract($extractDir);
$this->assertEquals(1, count($res));
@@ -63,10 +62,9 @@ class UnzipTest extends PHPUnit_Framework_TestCase
clearstatcache();
$extractDir = PIWIK_USER_PATH . '/tmp/latest/';
$test = 'zaatt';
- $filename = dirname(__FILE__) . '/Unzip/'.$test.'.zip';
+ $filename = dirname(__FILE__) . '/Unzip/' . $test . '.zip';
- if(class_exists('ZipArchive', false))
- {
+ if (class_exists('ZipArchive', false)) {
$unzip = new Piwik_Unzip_ZipArchive($filename);
$res = $unzip->extract($extractDir);
$this->assertEquals(0, $res);
@@ -96,10 +94,9 @@ class UnzipTest extends PHPUnit_Framework_TestCase
clearstatcache();
$extractDir = PIWIK_USER_PATH . '/tmp/latest/';
$test = 'zaabs';
- $filename = dirname(__FILE__) . '/Unzip/'.$test.'.zip';
+ $filename = dirname(__FILE__) . '/Unzip/' . $test . '.zip';
- if(class_exists('ZipArchive', false))
- {
+ if (class_exists('ZipArchive', false)) {
$unzip = new Piwik_Unzip_ZipArchive($filename);
$res = $unzip->extract($extractDir);
$this->assertEquals(0, $res);
@@ -177,48 +174,48 @@ class UnzipTest extends PHPUnit_Framework_TestCase
$this->assertContains('PCLZIP_ERR_MISSING_FILE', $unzip->errorInfo());
}
- /**
- * @group Core
- * @group Unzip
- */
- public function testGzipFile()
- {
- $extractDir = PIWIK_USER_PATH . '/tmp/latest/';
- $extractFile = $extractDir.'testgz.txt';
- $filename = dirname(__FILE__).'/Unzip/test.gz';
-
- $unzip = new Piwik_Unzip_Gzip($filename);
- $res = $unzip->extract($extractFile);
- $this->assertTrue($res);
-
- $this->assertFileContentsEquals('TESTSTRING', $extractFile);
- }
-
- /**
- * @group Core
- * @group Unzip
- */
- public function testTarGzFile()
- {
- $extractDir = PIWIK_USER_PATH.'/tmp/latest/';
- $filename = dirname(__FILE__).'/Unzip/test.tar.gz';
-
- $unzip = new Piwik_Unzip_Tar($filename, 'gz');
- $res = $unzip->extract($extractDir);
- $this->assertTrue($res);
-
- $this->assertFileContentsEquals('TESTDATA', $extractDir.'tarout1.txt');
- $this->assertFileContentsEquals('MORETESTDATA', $extractDir.'tardir/tarout2.txt');
- }
-
- private function assertFileContentsEquals( $expectedContent, $path )
- {
- $this->assertTrue(file_exists($path));
-
- $fd = fopen($path, 'rb');
- $actualContent = fread($fd, filesize($path));
- fclose($fd);
-
- $this->assertEquals($expectedContent, $actualContent);
- }
+ /**
+ * @group Core
+ * @group Unzip
+ */
+ public function testGzipFile()
+ {
+ $extractDir = PIWIK_USER_PATH . '/tmp/latest/';
+ $extractFile = $extractDir . 'testgz.txt';
+ $filename = dirname(__FILE__) . '/Unzip/test.gz';
+
+ $unzip = new Piwik_Unzip_Gzip($filename);
+ $res = $unzip->extract($extractFile);
+ $this->assertTrue($res);
+
+ $this->assertFileContentsEquals('TESTSTRING', $extractFile);
+ }
+
+ /**
+ * @group Core
+ * @group Unzip
+ */
+ public function testTarGzFile()
+ {
+ $extractDir = PIWIK_USER_PATH . '/tmp/latest/';
+ $filename = dirname(__FILE__) . '/Unzip/test.tar.gz';
+
+ $unzip = new Piwik_Unzip_Tar($filename, 'gz');
+ $res = $unzip->extract($extractDir);
+ $this->assertTrue($res);
+
+ $this->assertFileContentsEquals('TESTDATA', $extractDir . 'tarout1.txt');
+ $this->assertFileContentsEquals('MORETESTDATA', $extractDir . 'tardir/tarout2.txt');
+ }
+
+ private function assertFileContentsEquals($expectedContent, $path)
+ {
+ $this->assertTrue(file_exists($path));
+
+ $fd = fopen($path, 'rb');
+ $actualContent = fread($fd, filesize($path));
+ fclose($fd);
+
+ $this->assertEquals($expectedContent, $actualContent);
+ }
}
diff --git a/tests/PHPUnit/Core/UpdaterTest.php b/tests/PHPUnit/Core/UpdaterTest.php
index f177c52de2..546a9891b6 100644
--- a/tests/PHPUnit/Core/UpdaterTest.php
+++ b/tests/PHPUnit/Core/UpdaterTest.php
@@ -5,7 +5,7 @@
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
-class UpdaterTest extends DatabaseTestCase
+class UpdaterTest extends DatabaseTestCase
{
/**
* @group Core
@@ -36,11 +36,11 @@ class UpdaterTest extends DatabaseTestCase
$this->assertEquals(1, count($componentsWithUpdateFile));
$updateFiles = $componentsWithUpdateFile['testpluginUpdates'];
$this->assertEquals(2, count($updateFiles));
-
+
$path = PIWIK_INCLUDE_PATH . '/tests/resources/Updater/testpluginUpdates/';
$expectedInOrder = array(
$path . '0.1beta2.php' => '0.1beta2',
- $path . '0.1.php' => '0.1'
+ $path . '0.1.php' => '0.1'
);
$this->assertEquals($expectedInOrder, array_map("basename", $updateFiles));
}
@@ -54,13 +54,13 @@ class UpdaterTest extends DatabaseTestCase
$updater = new Piwik_Updater();
$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');
-
+
$updater->recordComponentSuccessfullyUpdated('core', '0.1');
$updater->addComponentToCheck('core', '0.3');
-
+
$componentsWithUpdateFile = $updater->getComponentsWithUpdateFile();
$this->assertEquals(2, count($componentsWithUpdateFile));
reset($componentsWithUpdateFile);
diff --git a/tests/PHPUnit/Core/UrlTest.php b/tests/PHPUnit/Core/UrlTest.php
index 27cacd9d4f..114adb365b 100644
--- a/tests/PHPUnit/Core/UrlTest.php
+++ b/tests/PHPUnit/Core/UrlTest.php
@@ -13,16 +13,15 @@ class UrlTest extends PHPUnit_Framework_TestCase
*/
public function testAllMethods()
{
- $this->assertEquals(Piwik_Url::getCurrentQueryStringWithParametersModified(array()),Piwik_Url::getCurrentQueryString() );
+ $this->assertEquals(Piwik_Url::getCurrentQueryStringWithParametersModified(array()), Piwik_Url::getCurrentQueryString());
$this->assertEquals(Piwik_Url::getCurrentUrl(), Piwik_Url::getCurrentUrlWithoutQueryString());
- $this->assertEquals(Piwik_Url::getCurrentUrl(), Piwik_Url::getCurrentScheme() . '://' . Piwik_Url::getCurrentHost() . Piwik_Url::getCurrentScriptName() );
-
+ $this->assertEquals(Piwik_Url::getCurrentUrl(), Piwik_Url::getCurrentScheme() . '://' . Piwik_Url::getCurrentHost() . Piwik_Url::getCurrentScriptName());
+
$_SERVER['QUERY_STRING'] = 'q=test';
-
+
$parameters = array_keys(Piwik_Url::getArrayFromCurrentQueryString());
$parametersNameToValue = array();
- foreach($parameters as $name)
- {
+ foreach ($parameters as $name) {
$parametersNameToValue[$name] = null;
}
$this->assertEquals('', Piwik_Url::getCurrentQueryStringWithParametersModified($parametersNameToValue));
@@ -31,7 +30,8 @@ class UrlTest extends PHPUnit_Framework_TestCase
/**
* Dataprovider for testGetCurrentHost()
*/
- public function getCurrentHosts() {
+ public function getCurrentHosts()
+ {
return array(
array('localhost IPv4', array('127.0.0.1', null, null, null, '127.0.0.1')),
array('localhost IPv6', array('[::1]', null, null, null, '[::1]')),
@@ -62,10 +62,10 @@ class UrlTest extends PHPUnit_Framework_TestCase
{
$_SERVER['HTTP_HOST'] = $test[0];
$_SERVER['HTTP_X_FORWARDED_HOST'] = $test[1];
- Piwik_Config::getInstance()->General['proxy_host_headers'] = array( $test[2] );
- Piwik_Config::getInstance()->General['proxy_ips'] = array( $test[3] );
+ Piwik_Config::getInstance()->General['proxy_host_headers'] = array($test[2]);
+ Piwik_Config::getInstance()->General['proxy_ips'] = array($test[3]);
Piwik_Config::getInstance()->General['enable_trusted_host_check'] = 0;
- $this->assertEquals( $test[4], Piwik_Url::getCurrentHost(), $description );
+ $this->assertEquals($test[4], Piwik_Url::getCurrentHost(), $description);
}
/**
@@ -123,7 +123,7 @@ class UrlTest extends PHPUnit_Framework_TestCase
array('www.example.com', 'http://www.example.com/path/', '/path/', 'http://crsf.example.com/path/', false),
);
}
-
+
/**
* @dataProvider getLocalUrls
* @group Core
@@ -137,13 +137,14 @@ class UrlTest extends PHPUnit_Framework_TestCase
Piwik_Config::getInstance()->General['enable_trusted_host_check'] = 1;
Piwik_Config::getInstance()->General['trusted_hosts'] = array($httphost);
$urlToTest = $testurl;
- $this->assertEquals( $result, Piwik_Url::isLocalUrl($urlToTest) );
+ $this->assertEquals($result, Piwik_Url::isLocalUrl($urlToTest));
}
/**
* Dataprovider for testGetCurrentUrlWithoutFilename
*/
- public function getCurrentUrlWithoutFilename() {
+ public function getCurrentUrlWithoutFilename()
+ {
return array(
array('http://example.com/', false, 'example.com', '/'),
array('https://example.org/', true, 'example.org', '/'),
@@ -161,8 +162,7 @@ class UrlTest extends PHPUnit_Framework_TestCase
{
$names = array('PATH_INFO', 'REQUEST_URI', 'SCRIPT_NAME', 'SCRIPT_FILENAME', 'argv', 'HTTPS', 'HTTP_HOST', 'QUERY_STRING', 'HTTP_REFERER');
- foreach($names as $name)
- {
+ foreach ($names as $name) {
unset($_SERVER[$name]);
}
@@ -176,7 +176,7 @@ class UrlTest extends PHPUnit_Framework_TestCase
$_SERVER['HTTP_HOST'] = $host;
Piwik_Config::getInstance()->General['trusted_hosts'] = array($host);
-
+
$url = Piwik_Url::getCurrentUrlWithoutFilename();
$this->assertEquals($expected, $url);
}
@@ -189,8 +189,7 @@ class UrlTest extends PHPUnit_Framework_TestCase
{
$names = array('PATH_INFO', 'REQUEST_URI', 'SCRIPT_NAME', 'SCRIPT_FILENAME', 'argv', 'HTTPS', 'HTTP_HOST', 'QUERY_STRING', 'HTTP_REFERER');
- foreach($names as $name)
- {
+ foreach ($names as $name) {
unset($_SERVER[$name]);
}
@@ -204,8 +203,7 @@ class UrlTest extends PHPUnit_Framework_TestCase
array('/path/index.php', '/path/index.php/route/3/?module=Fu&action=Bar#Hash', '/route/3/'),
);
- foreach($tests as $test)
- {
+ foreach ($tests as $test) {
list($expected, $uri, $pathInfo) = $test;
$_SERVER['REQUEST_URI'] = $uri;
@@ -247,7 +245,7 @@ class UrlTest extends PHPUnit_Framework_TestCase
*/
public function testIsValidHost($expected, $host, $trustedHosts, $description)
{
- Piwik_Config::getInstance()->General['enable_trusted_host_check'] = 1;
+ Piwik_Config::getInstance()->General['enable_trusted_host_check'] = 1;
Piwik_Config::getInstance()->General['trusted_hosts'] = $trustedHosts;
$this->assertEquals($expected, Piwik_Url::isValidHost($host), $description);
}
diff --git a/tests/PHPUnit/DatabaseTestCase.php b/tests/PHPUnit/DatabaseTestCase.php
index 760962e1d5..2b0627f251 100644
--- a/tests/PHPUnit/DatabaseTestCase.php
+++ b/tests/PHPUnit/DatabaseTestCase.php
@@ -8,10 +8,10 @@
/**
* Tests extending DatabaseTestCase are much slower to run: the setUp will
* create all Piwik tables in a freshly empty test database.
- *
- * This allows each test method to start from a clean DB and setup initial state to
+ *
+ * This allows each test method to start from a clean DB and setup initial state to
* then test it.
- *
+ *
*/
class DatabaseTestCase extends PHPUnit_Framework_TestCase
{
@@ -39,12 +39,12 @@ class DatabaseTestCase extends PHPUnit_Framework_TestCase
Piwik::createTables();
Piwik::createLogObject();
- Piwik_PluginsManager::getInstance()->loadPlugins(array());
+ Piwik_PluginsManager::getInstance()->loadPlugins(array());
- } catch(Exception $e) {
- $this->fail("TEST INITIALIZATION FAILED: " .$e->getMessage());
+ } catch (Exception $e) {
+ $this->fail("TEST INITIALIZATION FAILED: " . $e->getMessage());
}
-
+
include "DataFiles/SearchEngines.php";
include "DataFiles/Languages.php";
include "DataFiles/Countries.php";
@@ -60,11 +60,12 @@ class DatabaseTestCase extends PHPUnit_Framework_TestCase
parent::tearDown();
try {
$plugins = Piwik_PluginsManager::getInstance()->getLoadedPlugins();
- foreach($plugins AS $plugin) {
+ foreach ($plugins AS $plugin) {
$plugin->uninstall();
}
Piwik_PluginsManager::getInstance()->unloadPlugins();
- } catch (Exception $e) {}
+ } catch (Exception $e) {
+ }
Piwik::dropDatabase();
Piwik_DataTable_Manager::getInstance()->deleteAll();
Piwik_Option::getInstance()->clearCache();
diff --git a/tests/PHPUnit/FakeAccess.php b/tests/PHPUnit/FakeAccess.php
index 032cbfc3c4..3d8f0710a4 100644
--- a/tests/PHPUnit/FakeAccess.php
+++ b/tests/PHPUnit/FakeAccess.php
@@ -17,10 +17,10 @@ class FakeAccess
public function __construct()
{
- self::$superUser = false;
+ self::$superUser = false;
self::$idSitesAdmin = array();
- self::$idSitesView = array();
- self::$identity = 'superUserLogin';
+ self::$idSitesView = array();
+ self::$identity = 'superUserLogin';
}
public static function setIdSitesAdmin($ids)
@@ -28,82 +28,68 @@ class FakeAccess
self::$superUser = false;
self::$idSitesAdmin = $ids;
}
+
public static function setIdSitesView($ids)
{
self::$superUser = false;
self::$idSitesView = $ids;
}
-
+
public static function checkUserIsSuperUser()
{
- if(!self::$superUser)
- {
+ if (!self::$superUser) {
throw new Exception("checkUserIsSuperUser Fake exception // string not to be tested");
}
}
-
+
public static function setSuperUser($bool = true)
{
self::$superUser = $bool;
}
public static function reloadAccess()
- {}
+ {
+ }
- public static function checkUserHasAdminAccess( $idSites )
+ public static function checkUserHasAdminAccess($idSites)
{
- if(!self::$superUser)
- {
- $websitesAccess=self::$idSitesAdmin;
- }
- else
- {
- $websitesAccess=Piwik_SitesManager_API::getInstance()->getAllSitesId();
+ if (!self::$superUser) {
+ $websitesAccess = self::$idSitesAdmin;
+ } else {
+ $websitesAccess = Piwik_SitesManager_API::getInstance()->getAllSitesId();
}
-
+
$idSites = Piwik_Site::getIdSitesFromIdSitesString($idSites);
- foreach($idSites as $idsite)
- {
- if(!in_array($idsite, $websitesAccess))
- {
+ foreach ($idSites as $idsite) {
+ if (!in_array($idsite, $websitesAccess)) {
throw new Exception("checkUserHasAdminAccess Fake exception // string not to be tested");
}
}
}
-
+
//means at least view access
- public static function checkUserHasViewAccess( $idSites )
+ public static function checkUserHasViewAccess($idSites)
{
- if(!self::$superUser)
- {
- $websitesAccess=array_merge(self::$idSitesView,self::$idSitesAdmin);
- }
- else
- {
- $websitesAccess=Piwik_SitesManager_API::getInstance()->getAllSitesId();
+ if (!self::$superUser) {
+ $websitesAccess = array_merge(self::$idSitesView, self::$idSitesAdmin);
+ } else {
+ $websitesAccess = Piwik_SitesManager_API::getInstance()->getAllSitesId();
}
-
- if(!is_array($idSites))
- {
- if($idSites == 'all')
- {
- $idSites = Piwik_SitesManager_API::getInstance()->getAllSitesId();
- }
- else
- {
- $idSites = explode(',', $idSites);
- }
+
+ if (!is_array($idSites)) {
+ if ($idSites == 'all') {
+ $idSites = Piwik_SitesManager_API::getInstance()->getAllSitesId();
+ } else {
+ $idSites = explode(',', $idSites);
+ }
}
-
- if (empty($websitesAccess))
- {
- throw new Exception("checkUserHasViewAccess Fake exception // string not to be tested");
+
+ if (empty($websitesAccess)) {
+ throw new Exception("checkUserHasViewAccess Fake exception // string not to be tested");
}
-
- foreach($idSites as $idsite)
- {
- if(!in_array($idsite, $websitesAccess))
- {
+
+ foreach ($idSites as $idsite) {
+ if (!in_array($idsite, $websitesAccess)) {
throw new Exception("checkUserHasViewAccess Fake exception // string not to be tested");
}
}
@@ -111,15 +97,11 @@ class FakeAccess
public static function checkUserHasSomeViewAccess()
{
- if(!self::$superUser)
- {
- if( count(self::$idSitesView) == 0 )
- {
+ if (!self::$superUser) {
+ if (count(self::$idSitesView) == 0) {
throw new Exception("checkUserHasSomeViewAccess Fake exception // string not to be tested");
}
- }
- else
- {
+ } else {
return;
}
}
@@ -127,47 +109,41 @@ class FakeAccess
//means at least view access
public static function checkUserHasSomeAdminAccess()
{
- if(!self::$superUser)
- {
- if( count(self::$idSitesAdmin) == 0 )
- {
+ if (!self::$superUser) {
+ if (count(self::$idSitesAdmin) == 0) {
throw new Exception("checkUserHasSomeAdminAccess Fake exception // string not to be tested");
}
- }
- else
- {
+ } else {
return; //super user has some admin rights
}
}
-
+
public static function getLogin()
{
return self::$identity;
}
-
+
public static function getSitesIdWithAdminAccess()
{
- if(self::$superUser)
- {
+ if (self::$superUser) {
return Piwik_SitesManager_API::getInstance()->getAllSitesId();
}
- return self::$idSitesAdmin;
+ return self::$idSitesAdmin;
}
-
+
public static function getSitesIdWithViewAccess()
{
- if(self::$superUser)
- {
+ if (self::$superUser) {
return Piwik_SitesManager_API::getInstance()->getAllSitesId();
}
- return self::$idSitesView;
+ return self::$idSitesView;
}
+
public static function getSitesIdWithAtLeastViewAccess()
{
- if(self::$superUser)
- {
+ if (self::$superUser) {
return Piwik_SitesManager_API::getInstance()->getAllSitesId();
}
- return array_merge(self::$idSitesView,self::$idSitesAdmin);
+ return array_merge(self::$idSitesView, self::$idSitesAdmin);
}
}
diff --git a/tests/PHPUnit/Fixtures/FewVisitsWithSetVisitorId.php b/tests/PHPUnit/Fixtures/FewVisitsWithSetVisitorId.php
index 0f394ad92e..3768205fc6 100644
--- a/tests/PHPUnit/Fixtures/FewVisitsWithSetVisitorId.php
+++ b/tests/PHPUnit/Fixtures/FewVisitsWithSetVisitorId.php
@@ -11,20 +11,20 @@
*/
class Test_Piwik_Fixture_FewVisitsWithSetVisitorId extends Test_Piwik_BaseFixture
{
- public $idSite = 1;
+ public $idSite = 1;
public $dateTime = '2010-03-06 11:22:33';
-
+
public function setUp()
{
$this->setUpWebsitesAndGoals();
$this->trackVisits();
}
-
+
public function tearDown()
{
- // empty
+ // empty
}
-
+
private function setUpWebsitesAndGoals()
{
// tests run in UTC, the Tracker in UTC
@@ -34,8 +34,8 @@ class Test_Piwik_Fixture_FewVisitsWithSetVisitorId extends Test_Piwik_BaseFixtur
private function trackVisits()
{
$dateTime = $this->dateTime;
- $idSite = $this->idSite;
-
+ $idSite = $this->idSite;
+
$t = self::getTracker($idSite, $dateTime, $defaultInit = true);
// First, some basic tests
@@ -67,19 +67,19 @@ class Test_Piwik_Fixture_FewVisitsWithSetVisitorId extends Test_Piwik_BaseFixtur
try {
$t->setVisitorId('test');
$this->fail('should throw');
- } catch(Exception $e) {
+ } catch (Exception $e) {
//OK
}
try {
$t->setVisitorId('61e8');
$this->fail('should throw');
- } catch(Exception $e) {
+ } catch (Exception $e) {
//OK
}
try {
$t->setVisitorId('61e8cc2d51fea26dabcabcabc');
$this->fail('should throw');
- } catch(Exception $e) {
+ } catch (Exception $e) {
//OK
}
}
diff --git a/tests/PHPUnit/Fixtures/InvalidVisits.php b/tests/PHPUnit/Fixtures/InvalidVisits.php
index f7d7a004d6..a424f05c6d 100644
--- a/tests/PHPUnit/Fixtures/InvalidVisits.php
+++ b/tests/PHPUnit/Fixtures/InvalidVisits.php
@@ -12,20 +12,20 @@
*/
class Test_Piwik_Fixture_InvalidVisits extends Test_Piwik_BaseFixture
{
- public $idSite = 1;
- public $dateTime = '2009-01-04 00:11:42';
-
- public $trackInvalidRequests = true;
+ public $idSite = 1;
+ public $dateTime = '2009-01-04 00:11:42';
- public function setUp()
- {
+ public $trackInvalidRequests = true;
+
+ public function setUp()
+ {
$this->setUpWebsitesAndGoals();
$this->trackVisits();
}
-
+
public function tearDown()
{
- // empty
+ // empty
}
private function setUpWebsitesAndGoals()
@@ -35,20 +35,19 @@ class Test_Piwik_Fixture_InvalidVisits extends Test_Piwik_BaseFixture
private function trackVisits()
{
- if (!$this->trackInvalidRequests)
- {
- return;
- }
-
+ if (!$this->trackInvalidRequests) {
+ return;
+ }
+
$dateTime = $this->dateTime;
- $idSite = $this->idSite;
-
+ $idSite = $this->idSite;
+
Piwik_SitesManager_API::getInstance()->setSiteSpecificUserAgentExcludeEnabled(true);
Piwik_SitesManager_API::getInstance()->setGlobalExcludedUserAgents('globalexcludeduseragent');
// Trigger empty request
$trackerUrl = self::getTrackerUrl();
- $response = Piwik_Http::fetchRemoteFile($trackerUrl);
+ $response = Piwik_Http::fetchRemoteFile($trackerUrl);
self::assertTrue(strpos($response, 'is a free open source web') !== false, 'Piwik empty request response not correct: ' . $response);
$t = self::getTracker($idSite, $dateTime, $defaultInit = true);
@@ -60,8 +59,8 @@ class Test_Piwik_Fixture_InvalidVisits extends Test_Piwik_BaseFixture
// Test IP Exclusion works with or without IP exclusion
foreach (array(false, true) as $enable) {
$excludedIp = '154.1.12.34';
- Piwik_SitesManager_API::getInstance()->updateSite($idSite, 'new site name', $url = array('http://site.com'), $ecommerce = 0, $ss = 1, $ss_kwd = '', $ss_cat = '', $excludedIp . ',1.2.3.4', $excludedQueryParameters = null, $timezone = null, $currency = null, $group = null, $startDate = null, $excludedUserAgents = 'excludeduseragentstring');
-
+ Piwik_SitesManager_API::getInstance()->updateSite($idSite, 'new site name', $url = array('http://site.com'), $ecommerce = 0, $ss = 1, $ss_kwd = '', $ss_cat = '', $excludedIp . ',1.2.3.4', $excludedQueryParameters = null, $timezone = null, $currency = null, $group = null, $startDate = null, $excludedUserAgents = 'excludeduseragentstring');
+
// Enable IP Anonymization
$t->DEBUG_APPEND_URL = '&forceIpAnonymization=' . (int)$enable;
@@ -69,7 +68,7 @@ class Test_Piwik_Fixture_InvalidVisits extends Test_Piwik_BaseFixture
$t->setUserAgent('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 (.NET CLR 3.5.30729) (excludeduseragentstring)');
$t->setIp('211.1.2.3');
self::checkResponse($t->doTrackPageView('visit from excluded User Agent'));
-
+
// test w/ global excluded User Agent
$t->setUserAgent('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 (.NET CLR 3.5.30729) (globalexcludeduseragent)');
$t->setIp('211.1.2.3');
@@ -79,7 +78,7 @@ class Test_Piwik_Fixture_InvalidVisits extends Test_Piwik_BaseFixture
$t->setUserAgent('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 (.NET CLR 3.5.30729)'); // restore normal user agent
$t->setIp($excludedIp);
self::checkResponse($t->doTrackPageView('visit from IP excluded'));
-
+
// test with global list of excluded IPs
$excludedIpBis = '145.5.3.4';
Piwik_SitesManager_API::getInstance()->setGlobalExcludedIps($excludedIpBis);
diff --git a/tests/PHPUnit/Fixtures/ManySitesImportedLogs.php b/tests/PHPUnit/Fixtures/ManySitesImportedLogs.php
index de486be2b2..276cb761ef 100644
--- a/tests/PHPUnit/Fixtures/ManySitesImportedLogs.php
+++ b/tests/PHPUnit/Fixtures/ManySitesImportedLogs.php
@@ -2,7 +2,7 @@
/**
* Piwik - Open source web analytics
*
- * @link http://piwik.org
+ * @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
@@ -11,160 +11,157 @@
*/
class Test_Piwik_Fixture_ManySitesImportedLogs extends Test_Piwik_BaseFixture
{
- public $dateTime = '2010-03-06 11:22:33';
- public $idSite = 1;
- public $idSite2 = 2;
- public $idGoal = 1;
-
- public function setUp()
- {
+ public $dateTime = '2010-03-06 11:22:33';
+ public $idSite = 1;
+ public $idSite2 = 2;
+ public $idGoal = 1;
+
+ public function setUp()
+ {
$this->setUpWebsitesAndGoals();
- self::downloadGeoIpDbs();
-
- Piwik_UserCountry_LocationProvider::$providers = null;
- Piwik_UserCountry_LocationProvider_GeoIp::$geoIPDatabaseDir = 'tests/lib/geoip-files';
- Piwik_UserCountry_LocationProvider::setCurrentProvider('geoip_php');
-
+ self::downloadGeoIpDbs();
+
+ Piwik_UserCountry_LocationProvider::$providers = null;
+ Piwik_UserCountry_LocationProvider_GeoIp::$geoIPDatabaseDir = 'tests/lib/geoip-files';
+ Piwik_UserCountry_LocationProvider::setCurrentProvider('geoip_php');
+
$this->trackVisits();
- }
-
- public function tearDown()
- {
- Piwik_UserCountry_LocationProvider::$providers = null;
- Piwik_UserCountry_LocationProvider_GeoIp::$geoIPDatabaseDir = 'tests/lib/geoip-files';
- Piwik_UserCountry_LocationProvider::setCurrentProvider('default');
- }
-
+ }
+
+ public function tearDown()
+ {
+ Piwik_UserCountry_LocationProvider::$providers = null;
+ Piwik_UserCountry_LocationProvider_GeoIp::$geoIPDatabaseDir = 'tests/lib/geoip-files';
+ Piwik_UserCountry_LocationProvider::setCurrentProvider('default');
+ }
+
public function setUpWebsitesAndGoals()
{
- // for conversion testing
- self::createWebsite($this->dateTime);
- Piwik_Goals_API::getInstance()->addGoal($this->idSite, 'all', 'url', 'http', 'contains', false, 5);
- self::createWebsite($this->dateTime, $ecommerce = 0, $siteName = 'Piwik test two',
- $siteUrl = 'http://example-site-two.com');
+ // for conversion testing
+ self::createWebsite($this->dateTime);
+ Piwik_Goals_API::getInstance()->addGoal($this->idSite, 'all', 'url', 'http', 'contains', false, 5);
+ self::createWebsite($this->dateTime, $ecommerce = 0, $siteName = 'Piwik test two',
+ $siteUrl = 'http://example-site-two.com');
}
-
+
private function trackVisits()
{
- $this->logVisitsWithStaticResolver();
- $this->logVisitsWithAllEnabled();
- $this->replayLogFile();
- $this->logCustomFormat();
+ $this->logVisitsWithStaticResolver();
+ $this->logVisitsWithAllEnabled();
+ $this->replayLogFile();
+ $this->logCustomFormat();
+ }
+
+ /**
+ * Logs a couple visits for Aug 9, Aug 10, Aug 11 of 2012, for site we create.
+ */
+ private function logVisitsWithStaticResolver()
+ {
+ $logFile = PIWIK_INCLUDE_PATH . '/tests/resources/fake_logs.log'; # log file
+
+ $opts = array('--idsite' => $this->idSite,
+ '--token-auth' => self::getTokenAuth(),
+ '--recorders' => '4',
+ '--recorder-max-payload-size' => '2');
+
+ self::executeLogImporter($logFile, $opts);
+ }
+
+ /**
+ * Logs a couple visits for the site we created and two new sites that do not
+ * exist yet. Visits are from Aug 12, 13 & 14 of 2012.
+ */
+ public function logVisitsWithDynamicResolver()
+ {
+ $logFile = PIWIK_INCLUDE_PATH . '/tests/resources/fake_logs_dynamic.log'; # log file
+
+ $opts = array('--add-sites-new-hosts' => false,
+ '--token-auth' => self::getTokenAuth(),
+ '--recorders' => '4',
+ '--recorder-max-payload-size' => '1');
+
+ self::executeLogImporter($logFile, $opts);
+ }
+
+ /**
+ * Logs a couple visits for the site we created w/ all log importer options
+ * enabled. Visits are for Aug 11 of 2012.
+ */
+ private function logVisitsWithAllEnabled()
+ {
+ $logFile = PIWIK_INCLUDE_PATH . '/tests/resources/fake_logs_enable_all.log';
+
+ $opts = array('--idsite' => $this->idSite,
+ '--token-auth' => self::getTokenAuth(),
+ '--recorders' => '4',
+ '--recorder-max-payload-size' => '2',
+ '--enable-static' => false,
+ '--enable-bots' => false,
+ '--enable-http-errors' => false,
+ '--enable-http-redirects' => false,
+ '--enable-reverse-dns' => false);
+
+ self::executeLogImporter($logFile, $opts);
+ }
+
+ /**
+ * Logs a couple visit using log entries that are tracking requests to a piwik.php file.
+ * Adds two visits to idSite=1 and two to non-existant sites.
+ */
+ private function replayLogFile()
+ {
+ $logFile = PIWIK_INCLUDE_PATH . '/tests/resources/fake_logs_replay.log';
+
+ $opts = array('--token-auth' => self::getTokenAuth(),
+ '--recorders' => '4',
+ '--recorder-max-payload-size' => '2',
+ '--replay-tracking' => false);
+
+ self::executeLogImporter($logFile, $opts);
+ }
+
+ /**
+ * Imports a log file in custom format that contains generation time
+ */
+ private function logCustomFormat()
+ {
+ $logFile = PIWIK_INCLUDE_PATH . '/tests/resources/fake_logs_custom.log';
+
+ $opts = array('--idsite' => $this->idSite,
+ '--token-auth' => self::getTokenAuth(),
+ '--log-format-regex' => '(?P<ip>\S+) - - \[(?P<date>.*?) (?P<timezone>.*?)\] (?P<status>\S+) '
+ . '\"\S+ (?P<path>.*?) \S+\" (?P<generation_time_micro>\S+)');
+
+ self::executeLogImporter($logFile, $opts);
}
- /**
- * Logs a couple visits for Aug 9, Aug 10, Aug 11 of 2012, for site we create.
- */
- private function logVisitsWithStaticResolver()
+ private static function executeLogImporter($logFile, $options)
{
- $logFile = PIWIK_INCLUDE_PATH.'/tests/resources/fake_logs.log'; # log file
-
- $opts = array('--idsite' => $this->idSite,
- '--token-auth' => self::getTokenAuth(),
- '--recorders' => '4',
- '--recorder-max-payload-size' => '2');
-
- self::executeLogImporter($logFile, $opts);
- }
-
- /**
- * Logs a couple visits for the site we created and two new sites that do not
- * exist yet. Visits are from Aug 12, 13 & 14 of 2012.
- */
- public function logVisitsWithDynamicResolver()
- {
- $logFile = PIWIK_INCLUDE_PATH.'/tests/resources/fake_logs_dynamic.log'; # log file
-
- $opts = array('--add-sites-new-hosts' => false,
- '--token-auth' => self::getTokenAuth(),
- '--recorders' => '4',
- '--recorder-max-payload-size' => '1');
-
- self::executeLogImporter($logFile, $opts);
- }
-
- /**
- * Logs a couple visits for the site we created w/ all log importer options
- * enabled. Visits are for Aug 11 of 2012.
- */
- private function logVisitsWithAllEnabled()
- {
- $logFile = PIWIK_INCLUDE_PATH.'/tests/resources/fake_logs_enable_all.log';
-
- $opts = array('--idsite' => $this->idSite,
- '--token-auth' => self::getTokenAuth(),
- '--recorders' => '4',
- '--recorder-max-payload-size' => '2',
- '--enable-static' => false,
- '--enable-bots' => false,
- '--enable-http-errors' => false,
- '--enable-http-redirects' => false,
- '--enable-reverse-dns' => false);
-
- self::executeLogImporter($logFile, $opts);
- }
-
- /**
- * Logs a couple visit using log entries that are tracking requests to a piwik.php file.
- * Adds two visits to idSite=1 and two to non-existant sites.
- */
- private function replayLogFile()
- {
- $logFile = PIWIK_INCLUDE_PATH.'/tests/resources/fake_logs_replay.log';
-
- $opts = array('--token-auth' => self::getTokenAuth(),
- '--recorders' => '4',
- '--recorder-max-payload-size' => '2',
- '--replay-tracking' => false);
-
- self::executeLogImporter($logFile, $opts);
- }
-
- /**
- * Imports a log file in custom format that contains generation time
- */
- private function logCustomFormat()
- {
- $logFile = PIWIK_INCLUDE_PATH.'/tests/resources/fake_logs_custom.log';
-
- $opts = array('--idsite' => $this->idSite,
- '--token-auth' => self::getTokenAuth(),
- '--log-format-regex' => '(?P<ip>\S+) - - \[(?P<date>.*?) (?P<timezone>.*?)\] (?P<status>\S+) '
- . '\"\S+ (?P<path>.*?) \S+\" (?P<generation_time_micro>\S+)');
-
- self::executeLogImporter($logFile, $opts);
- }
-
- private static function executeLogImporter( $logFile, $options )
- {
- $python = Piwik_Common::isWindows() ? "C:\Python27\python.exe" : 'python';
-
- // create the command
- $cmd = $python
- . ' "'.PIWIK_INCLUDE_PATH.'/misc/log-analytics/import_logs.py" ' # script loc
- . '-ddd ' // debug
- . '--url="'.self::getRootUrl().'tests/PHPUnit/proxy/" ' # proxy so that piwik uses test config files
- ;
-
- foreach ($options as $name => $value)
- {
- $cmd .= $name;
- if ($value !== false)
- {
- $cmd .= '="'.$value.'"';
- }
- $cmd .= ' ';
- }
-
- $cmd .= '"'.$logFile.'" 2>&1';
-
- // run the command
- exec($cmd, $output, $result);
- if ($result !== 0)
- {
- throw new Exception("log importer failed: ".implode("\n", $output)."\n\ncommand used: $cmd");
- }
-
- return $output;
+ $python = Piwik_Common::isWindows() ? "C:\Python27\python.exe" : 'python';
+
+ // create the command
+ $cmd = $python
+ . ' "' . PIWIK_INCLUDE_PATH . '/misc/log-analytics/import_logs.py" ' # script loc
+ . '-ddd ' // debug
+ . '--url="' . self::getRootUrl() . 'tests/PHPUnit/proxy/" ' # proxy so that piwik uses test config files
+ ;
+
+ foreach ($options as $name => $value) {
+ $cmd .= $name;
+ if ($value !== false) {
+ $cmd .= '="' . $value . '"';
+ }
+ $cmd .= ' ';
+ }
+
+ $cmd .= '"' . $logFile . '" 2>&1';
+
+ // run the command
+ exec($cmd, $output, $result);
+ if ($result !== 0) {
+ throw new Exception("log importer failed: " . implode("\n", $output) . "\n\ncommand used: $cmd");
+ }
+
+ return $output;
}
}
diff --git a/tests/PHPUnit/Fixtures/ManyVisitsWithGeoIP.php b/tests/PHPUnit/Fixtures/ManyVisitsWithGeoIP.php
index 4aa03d8f6a..33f2f7006c 100644
--- a/tests/PHPUnit/Fixtures/ManyVisitsWithGeoIP.php
+++ b/tests/PHPUnit/Fixtures/ManyVisitsWithGeoIP.php
@@ -2,7 +2,7 @@
/**
* Piwik - Open source web analytics
*
- * @link http://piwik.org
+ * @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
@@ -14,176 +14,166 @@ require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/MockLocationProvider.php';
*/
class Test_Piwik_Fixture_ManyVisitsWithGeoIP extends Test_Piwik_BaseFixture
{
- const GEOIP_IMPL_TO_TEST = 'geoip_php';
-
- public $idSite = 1;
- public $dateTime = '2010-01-03 11:22:33';
-
- public $ips = array(
- '194.57.91.215', // in Besançon, FR (unicode city name)
- '::ffff:137.82.130.49', // in British Columbia (mapped ipv4)
- '137.82.130.0', // anonymization tests
- '137.82.0.0',
- '2001:db8:85a3:0:0:8a2e:370:7334', // ipv6 (geoip lookup not supported)
- '113.62.1.1', // in Lhasa, Tibet
- '151.100.101.92', // in Rome, Italy (using country DB, so only Italy will show)
- '103.29.196.229', // in Indonesia (Bali), (only Indonesia will show up)
- );
-
- public function setUp()
- {
- $this->setUpWebsitesAndGoals();
- self::downloadGeoIpDbs();
-
- $this->setMockLocationProvider();
- $this->trackVisits(9, false);
-
- $this->setLocationProvider('GeoIPCity.dat');
- $this->trackVisits(2, true, $useLocal = false);
- $this->trackVisits(4, true, $useLocal = false, $doBulk = true);
-
- $this->setLocationProvider('GeoIP.dat');
- $this->trackVisits(2, true);
-
- $this->trackOtherVisits();
-
- $this->setLocationProvider('GeoIPCity.dat');
- }
-
- public function tearDown()
- {
- $this->unsetLocationProvider();
- }
-
- private function setUpWebsitesAndGoals()
- {
- self::createWebsite($this->dateTime, 0, "Site 1");
+ const GEOIP_IMPL_TO_TEST = 'geoip_php';
+
+ public $idSite = 1;
+ public $dateTime = '2010-01-03 11:22:33';
+
+ public $ips = array(
+ '194.57.91.215', // in Besançon, FR (unicode city name)
+ '::ffff:137.82.130.49', // in British Columbia (mapped ipv4)
+ '137.82.130.0', // anonymization tests
+ '137.82.0.0',
+ '2001:db8:85a3:0:0:8a2e:370:7334', // ipv6 (geoip lookup not supported)
+ '113.62.1.1', // in Lhasa, Tibet
+ '151.100.101.92', // in Rome, Italy (using country DB, so only Italy will show)
+ '103.29.196.229', // in Indonesia (Bali), (only Indonesia will show up)
+ );
+
+ public function setUp()
+ {
+ $this->setUpWebsitesAndGoals();
+ self::downloadGeoIpDbs();
+
+ $this->setMockLocationProvider();
+ $this->trackVisits(9, false);
+
+ $this->setLocationProvider('GeoIPCity.dat');
+ $this->trackVisits(2, true, $useLocal = false);
+ $this->trackVisits(4, true, $useLocal = false, $doBulk = true);
+
+ $this->setLocationProvider('GeoIP.dat');
+ $this->trackVisits(2, true);
+
+ $this->trackOtherVisits();
+
+ $this->setLocationProvider('GeoIPCity.dat');
+ }
+
+ public function tearDown()
+ {
+ $this->unsetLocationProvider();
+ }
+
+ private function setUpWebsitesAndGoals()
+ {
+ self::createWebsite($this->dateTime, 0, "Site 1");
Piwik_Goals_API::getInstance()->addGoal($this->idSite, 'all', 'url', 'http', 'contains', false, 5);
- }
-
- private function trackVisits( $visitorCount, $setIp = false, $useLocal = true, $doBulk = false )
- {
- $dateTime = $this->dateTime;
- $idSite = $this->idSite;
-
- // use local tracker so mock location provider can be used
- $t = self::getTracker($idSite, $dateTime, $defaultInit = true, $useLocal);
- if ($doBulk)
- {
- $t->enableBulkTracking();
- $t->setTokenAuth(self::getTokenAuth());
- }
- for ($i = 0; $i != $visitorCount; ++$i)
- {
- $t->setNewVisitorId();
- if ($setIp)
- {
- $t->setIp(current($this->ips));
- next($this->ips);
- }
- else
- {
- $t->setIp("1.2.4.$i");
- }
-
- // first visit
- $date = Piwik_Date::factory($dateTime)->addDay($i);
- $t->setForceVisitDateTime($date->getDatetime());
- $t->setUrl("http://piwik.net/grue/lair");
- $r = $t->doTrackPageView('It\'s pitch black...');
- if (!$doBulk)
- {
- self::checkResponse($r);
- }
-
- // second visit
- $date = $date->addHour(1);
- $t->setForceVisitDateTime($date->getDatetime());
- $t->setUrl("http://piwik.net/space/quest/iv");
- $r = $t->doTrackPageView("Space Quest XII");
- if (!$doBulk)
- {
- self::checkResponse($r);
- }
- }
- if ($doBulk)
- {
- self::checkResponse($t->doBulkTrack());
- }
- }
-
- private function trackOtherVisits()
- {
- $dateTime = $this->dateTime;
- $idSite = $this->idSite;
-
- $t = self::getTracker($idSite, $dateTime, $defaultInit = true);
- $t->setTokenAuth(self::getTokenAuth());
- $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addDay(20)->getDatetime());
- $t->setIp('194.57.91.215');
- $t->setCountry('us');
- $t->setRegion('CA');
- $t->setCity('not a city');
- $t->setLatitude(1);
- $t->setLongitude(2);
- $t->setUrl("http://piwik.net/grue/lair");
- self::checkResponse($t->doTrackPageView('It\'s pitch black...'));
- }
-
- private function setLocationProvider( $file )
- {
- Piwik_UserCountry_LocationProvider_GeoIp::$dbNames['loc'] = array($file);
- Piwik_UserCountry_LocationProvider_GeoIp::$geoIPDatabaseDir = 'tests/lib/geoip-files';
- Piwik_UserCountry_LocationProvider::$providers = null;
- Piwik_UserCountry_LocationProvider::setCurrentProvider(self::GEOIP_IMPL_TO_TEST);
-
- if (Piwik_UserCountry_LocationProvider::getCurrentProviderId() !== self::GEOIP_IMPL_TO_TEST)
- {
- throw new Exception("Failed to set the current location provider to '".self::GEOIP_IMPL_TO_TEST."'.");
- }
-
- $possibleFiles = Piwik_UserCountry_LocationProvider_GeoIp::$dbNames['loc'];
- if (Piwik_UserCountry_LocationProvider_GeoIp::getPathToGeoIpDatabase($possibleFiles) === false)
- {
- throw new Exception("The GeoIP location provider cannot find the '$file' file! Tests will fail.");
- }
- }
-
- private function setMockLocationProvider()
- {
- Piwik_UserCountry_LocationProvider::$providers = null;
- Piwik_UserCountry_LocationProvider::setCurrentProvider('mock_provider');
- MockLocationProvider::$locations = array(
- self::makeLocation('Stratford-upon-Avon', 'P3', 'gb', 123.456, 21.321), // template location
-
- // same region, different city, same country
- self::makeLocation('Nuneaton and Bedworth', 'P3', 'gb'),
-
- // same region, city & country (different lat/long)
- self::makeLocation('Stratford-upon-Avon', 'P3', 'gb', 124.456, 22.231),
-
- // same country, different region & city
- self::makeLocation('London', 'H9', 'gb'),
-
- // same country, different region, same city
- self::makeLocation('Stratford-upon-Avon', 'G5', 'gb'),
-
- // different country, diff region, same city
- self::makeLocation('Stratford-upon-Avon', '66', 'ru'),
-
- // different country, diff region (same as last), different city
- self::makeLocation('Hluboká nad Vltavou', '66', 'ru'),
-
- // different country, diff region (same as last), same city
- self::makeLocation('Stratford-upon-Avon', '66', 'mk'),
-
- // unknown location
- self::makeLocation(null, null, null),
- );
- }
-
- private function unsetLocationProvider()
- {
- Piwik_UserCountry_LocationProvider::setCurrentProvider('default');
- }
+ }
+
+ private function trackVisits($visitorCount, $setIp = false, $useLocal = true, $doBulk = false)
+ {
+ $dateTime = $this->dateTime;
+ $idSite = $this->idSite;
+
+ // use local tracker so mock location provider can be used
+ $t = self::getTracker($idSite, $dateTime, $defaultInit = true, $useLocal);
+ if ($doBulk) {
+ $t->enableBulkTracking();
+ $t->setTokenAuth(self::getTokenAuth());
+ }
+ for ($i = 0; $i != $visitorCount; ++$i) {
+ $t->setNewVisitorId();
+ if ($setIp) {
+ $t->setIp(current($this->ips));
+ next($this->ips);
+ } else {
+ $t->setIp("1.2.4.$i");
+ }
+
+ // first visit
+ $date = Piwik_Date::factory($dateTime)->addDay($i);
+ $t->setForceVisitDateTime($date->getDatetime());
+ $t->setUrl("http://piwik.net/grue/lair");
+ $r = $t->doTrackPageView('It\'s pitch black...');
+ if (!$doBulk) {
+ self::checkResponse($r);
+ }
+
+ // second visit
+ $date = $date->addHour(1);
+ $t->setForceVisitDateTime($date->getDatetime());
+ $t->setUrl("http://piwik.net/space/quest/iv");
+ $r = $t->doTrackPageView("Space Quest XII");
+ if (!$doBulk) {
+ self::checkResponse($r);
+ }
+ }
+ if ($doBulk) {
+ self::checkResponse($t->doBulkTrack());
+ }
+ }
+
+ private function trackOtherVisits()
+ {
+ $dateTime = $this->dateTime;
+ $idSite = $this->idSite;
+
+ $t = self::getTracker($idSite, $dateTime, $defaultInit = true);
+ $t->setTokenAuth(self::getTokenAuth());
+ $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addDay(20)->getDatetime());
+ $t->setIp('194.57.91.215');
+ $t->setCountry('us');
+ $t->setRegion('CA');
+ $t->setCity('not a city');
+ $t->setLatitude(1);
+ $t->setLongitude(2);
+ $t->setUrl("http://piwik.net/grue/lair");
+ self::checkResponse($t->doTrackPageView('It\'s pitch black...'));
+ }
+
+ private function setLocationProvider($file)
+ {
+ Piwik_UserCountry_LocationProvider_GeoIp::$dbNames['loc'] = array($file);
+ Piwik_UserCountry_LocationProvider_GeoIp::$geoIPDatabaseDir = 'tests/lib/geoip-files';
+ Piwik_UserCountry_LocationProvider::$providers = null;
+ Piwik_UserCountry_LocationProvider::setCurrentProvider(self::GEOIP_IMPL_TO_TEST);
+
+ if (Piwik_UserCountry_LocationProvider::getCurrentProviderId() !== self::GEOIP_IMPL_TO_TEST) {
+ throw new Exception("Failed to set the current location provider to '" . self::GEOIP_IMPL_TO_TEST . "'.");
+ }
+
+ $possibleFiles = Piwik_UserCountry_LocationProvider_GeoIp::$dbNames['loc'];
+ if (Piwik_UserCountry_LocationProvider_GeoIp::getPathToGeoIpDatabase($possibleFiles) === false) {
+ throw new Exception("The GeoIP location provider cannot find the '$file' file! Tests will fail.");
+ }
+ }
+
+ private function setMockLocationProvider()
+ {
+ Piwik_UserCountry_LocationProvider::$providers = null;
+ Piwik_UserCountry_LocationProvider::setCurrentProvider('mock_provider');
+ MockLocationProvider::$locations = array(
+ self::makeLocation('Stratford-upon-Avon', 'P3', 'gb', 123.456, 21.321), // template location
+
+ // same region, different city, same country
+ self::makeLocation('Nuneaton and Bedworth', 'P3', 'gb'),
+
+ // same region, city & country (different lat/long)
+ self::makeLocation('Stratford-upon-Avon', 'P3', 'gb', 124.456, 22.231),
+
+ // same country, different region & city
+ self::makeLocation('London', 'H9', 'gb'),
+
+ // same country, different region, same city
+ self::makeLocation('Stratford-upon-Avon', 'G5', 'gb'),
+
+ // different country, diff region, same city
+ self::makeLocation('Stratford-upon-Avon', '66', 'ru'),
+
+ // different country, diff region (same as last), different city
+ self::makeLocation('Hluboká nad Vltavou', '66', 'ru'),
+
+ // different country, diff region (same as last), same city
+ self::makeLocation('Stratford-upon-Avon', '66', 'mk'),
+
+ // unknown location
+ self::makeLocation(null, null, null),
+ );
+ }
+
+ private function unsetLocationProvider()
+ {
+ Piwik_UserCountry_LocationProvider::setCurrentProvider('default');
+ }
}
diff --git a/tests/PHPUnit/Fixtures/ManyVisitsWithMockLocationProvider.php b/tests/PHPUnit/Fixtures/ManyVisitsWithMockLocationProvider.php
index ea116f545a..6c8d2a2834 100644
--- a/tests/PHPUnit/Fixtures/ManyVisitsWithMockLocationProvider.php
+++ b/tests/PHPUnit/Fixtures/ManyVisitsWithMockLocationProvider.php
@@ -13,197 +13,185 @@ require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/MockLocationProvider.php';
*/
class Test_Piwik_Fixture_ManyVisitsWithMockLocationProvider extends Test_Piwik_BaseFixture
{
- public $idSite = 1;
- public $dateTime = '2010-01-03 01:22:33';
-
- public function setUp()
- {
- $this->setUpWebsitesAndGoals();
- $this->setMockLocationProvider();
- $this->trackVisits();
- }
-
- public function tearDown()
- {
- $this->unsetMockLocationProvider();
- }
-
- private function setUpWebsitesAndGoals()
- {
- self::createWebsite($this->dateTime);
- }
-
- private function trackVisits()
- {
- $linuxFirefoxA = "Mozilla/5.0 (X11; Linux i686; rv:6.0) Gecko/20100101 Firefox/6.0";
- $win7FirefoxA = "Mozilla/5.0 (Windows; U; Windows NT 6.1; fr; rv:1.9.1.6) Gecko/20100101 Firefox/6.0";
- $win7ChromeA = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/532.0 (KHTML, like Gecko) Chrome/3.0.195.38 Safari/532.0";
- $linuxChromeA = "Mozilla/5.0 (X11; Linux i686; rv:6.0) AppleWebKit/532.0 (KHTML, like Gecko) Chrome/3.0.195.38 Safari/532.0";
- $linuxSafariA = "Mozilla/5.0 (X11; U; Linux x86_64; en-us) AppleWebKit/531.2+ (KHTML, like Gecko) Version/5.0 Safari/531.2+";
- $iPadSafariA = "Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/531.2+ (KHTML, like Gecko) Version/5.0 Safari/531.2+";
- $iPadFirefoxB = "Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) Gecko/20100101 Firefox/14.0.1";
- $androidFirefoxB = "Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) Gecko/20100101 Firefox/14.0.1";
- $androidChromeB = "Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/22.0.1207.1 Safari/537.1";
- $androidIEA = "Mozilla/5.0 (compatible; MSIE 10.6; Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K; Trident/5.0; InfoPath.2; SLCC1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 2.0.50727) 3gpp-gba UNTRUSTED/1.0";
- $iPhoneOperaA = "Opera/9.80 (iPod; U; CPU iPhone OS 4_3_3 like Mac OS X; ja-jp) Presto/2.9.181 Version/12.00";
- $win8IEB = "Mozilla/5.0 (compatible; MSIE 10.0; Windows 8; Trident/5.0)";
- $winVistaIEB = "Mozilla/5.0 (compatible; MSIE 10.0; Windows Vista; Trident/5.0)";
- $osxOperaB = "Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; fr) Presto/2.9.168 Version/11.52";
- $userAgents = array(
- $linuxFirefoxA, $linuxFirefoxA, $win7FirefoxA, $win7ChromeA, $linuxChromeA, $linuxSafariA,
- $iPadSafariA, $iPadFirefoxB, $androidFirefoxB, $androidChromeB, $androidIEA, $iPhoneOperaA,
- $win8IEB, $winVistaIEB, $osxOperaB
- );
-
- $resolutions = array(
- "1920x1080", "1920x1080", "1920x1080", "1920x1080", "1366x768", "1366x768", "1366x768",
- "1280x1024", "1280x1024", "1280x1024", "1680x1050", "1680x1050", "1024x768", "800x600",
- "320x480"
- );
-
- $referrers = array(
- // website referrers (8)
- 'http://whatever0.com/0', 'http://whatever0.com/0', 'http://whatever0.com/1', 'http://whatever0.com/2',
- 'http://whatever1.com/0', 'http://whatever.com1/1', 'http://whatever1.com/2', 'http://whatever3.com/3',
-
- // search engines w/ keyword (12)
- 'http://www.google.com/search?q=this+search+term',
- 'http://www.google.com/search?q=that+search+term',
- 'http://search.yahoo.com/search?p=this+search+term',
- 'http://search.yahoo.com/search?p=that+search+term',
- 'http://www.ask.com/web?q=this+search+term',
- 'http://www.bing.com/search?q=search+term+1',
- 'http://search.babylon.com/?q=search+term+2',
- 'http://alexa.com/search?q=search+term+2',
- 'http://www.google.com/search?q=search+term+3',
- 'http://search.yahoo.com/search?p=search+term+4',
- 'http://www.ask.com/web?q=search+term+3',
- 'http://www.bing.com/search?q=search+term+4',
- );
-
- $customVars = array(
- 'name' => array('thing0', 'thing1', 'thing2', 'thing3', 'thing4', 'thing5', 'thing6', 'thing7',
- 'thing8', 'thing9', 'thing10', 'thing11', 'thing12', 'thing13', 'thing14',
- 'thing15', 'thing16', 'thing17', 'thing18', 'thing19'),
- 'rating' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 20),
- 'tweeted' => array('y', 'n', 'm', 'n', 'y', 'n', 'y', 'n', 'y', 'n', 'y', 'n', 'y', 'n', 'y', 'n',
- 'm', 'n', 'm', 'n'),
- 'liked' => array('yes', 'y', 'y', 'no', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y',
- 'y', 'y', 'no', 'n'),
- );
- $downloadCustomVars = array(
- 'size' => array(1024, 1024, 1024, 2048, 2048, 3072, 3072, 3072, 3072, 4096, 4096, 4096,
- 512, 512, 256, 128, 64, 32, 48, 48)
- );
-
- $visitorCounter = 0;
- $t = self::getTracker($this->idSite, $this->dateTime, $defaultInit = true, $useLocal = true);
-
- // track regular actions
- $this->trackActions($t, $visitorCounter, 'pageview', $userAgents, $resolutions, $referrers, $customVars);
-
- // track downloads
- $this->trackActions($t, $visitorCounter, 'download', $userAgents, $resolutions, null, $downloadCustomVars);
-
- // track outlinks
- $this->trackActions($t, $visitorCounter, 'outlink', $userAgents, $resolutions);
- }
-
- private function trackActions($t, &$visitorCounter, $actionType, $userAgents, $resolutions,
- $referrers = null, $customVars = null)
- {
- for ($i = 0; $i != 5; ++$i, ++$visitorCounter)
- {
- $visitDate = Piwik_Date::factory($this->dateTime);
-
- $t->setNewVisitorId();
- $t->setIp("156.5.3.$visitorCounter");
-
- $t->setUserAgent($userAgents[$visitorCounter]);
- list($w, $h) = explode('x', $resolutions[$visitorCounter]);
- $t->setResolution((int)$w, (int)$h);
-
- // one visit to root url
- $t->setUrl("http://piwik.net/$visitorCounter/");
- $t->setUrlReferrer(null);
- $t->setForceVisitDateTime($visitDate->getDatetime());
- $this->trackAction($t, $actionType, $visitorCounter, null);
-
- for ($j = 0; $j != 4; ++$j)
- {
- // NOTE: to test referers w/o creating too many visits, we don't actually track 4 actions, but
- // 4 separate visits
- $actionDate = $visitDate->addHour($j + 1);
-
- $actionIdx = $i * 4 + $j;
- $actionNum = $visitorCounter * 4 + $j;
-
- $t->setUrl("http://piwik.net/$visitorCounter/$actionNum");
- $t->setForceVisitDateTime($actionDate->getDatetime());
-
- if (!is_null($referrers))
- {
- $t->setUrlReferrer($referrers[$actionIdx]);
- }
- else
- {
- $t->setUrlReferrer(null);
- }
-
- if (!is_null($customVars))
- {
- $k = 1;
- foreach ($customVars as $name => $values)
- {
- $value = $values[$actionIdx];
- $t->setCustomVariable($k, $name, $value, $scope = 'page');
-
- ++$k;
- }
- }
-
- $this->trackAction($t, $actionType, $visitorCounter, $actionNum);
- }
- }
- }
-
- private function trackAction($t, $actionType, $visitorCounter, $actionNum)
- {
- if ($actionType == 'pageview')
- {
- self::checkResponse($t->doTrackPageView(
- is_null($actionNum) ? "title_$visitorCounter" : "title_$visitorCounter / title_$actionNum"));
- }
- else if ($actionType == 'download')
- {
- $root = is_null($actionNum) ? "http://cloudsite$visitorCounter.com"
- : "http://cloudsite$visitorCounter.com/$actionNum";
-
- self::checkResponse($t->doTrackAction("$root/download", 'download'));
- }
- else if ($actionType == 'outlink')
- {
- self::checkResponse($t->doTrackAction(is_null($actionNum) ? "http://othersite$visitorCounter.com/"
- : "http://othersite$visitorCounter.com/$actionNum/", 'link'));
- }
- }
-
- private function setMockLocationProvider()
- {
- Piwik_UserCountry_LocationProvider::setCurrentProvider('mock_provider');
- MockLocationProvider::$locations = array(
- self::makeLocation('Toronto', 'ON', 'CA'),
-
- self::makeLocation('Nice', 'B8', 'FR'),
-
- self::makeLocation('Melbourne', '07', 'AU'),
-
- self::makeLocation('Yokohama', '19', 'JP'),
- );
- }
-
- private function unsetMockLocationProvider()
- {
- Piwik_UserCountry_LocationProvider::setCurrentProvider('default');
- }
+ public $idSite = 1;
+ public $dateTime = '2010-01-03 01:22:33';
+
+ public function setUp()
+ {
+ $this->setUpWebsitesAndGoals();
+ $this->setMockLocationProvider();
+ $this->trackVisits();
+ }
+
+ public function tearDown()
+ {
+ $this->unsetMockLocationProvider();
+ }
+
+ private function setUpWebsitesAndGoals()
+ {
+ self::createWebsite($this->dateTime);
+ }
+
+ private function trackVisits()
+ {
+ $linuxFirefoxA = "Mozilla/5.0 (X11; Linux i686; rv:6.0) Gecko/20100101 Firefox/6.0";
+ $win7FirefoxA = "Mozilla/5.0 (Windows; U; Windows NT 6.1; fr; rv:1.9.1.6) Gecko/20100101 Firefox/6.0";
+ $win7ChromeA = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/532.0 (KHTML, like Gecko) Chrome/3.0.195.38 Safari/532.0";
+ $linuxChromeA = "Mozilla/5.0 (X11; Linux i686; rv:6.0) AppleWebKit/532.0 (KHTML, like Gecko) Chrome/3.0.195.38 Safari/532.0";
+ $linuxSafariA = "Mozilla/5.0 (X11; U; Linux x86_64; en-us) AppleWebKit/531.2+ (KHTML, like Gecko) Version/5.0 Safari/531.2+";
+ $iPadSafariA = "Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/531.2+ (KHTML, like Gecko) Version/5.0 Safari/531.2+";
+ $iPadFirefoxB = "Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) Gecko/20100101 Firefox/14.0.1";
+ $androidFirefoxB = "Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) Gecko/20100101 Firefox/14.0.1";
+ $androidChromeB = "Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/22.0.1207.1 Safari/537.1";
+ $androidIEA = "Mozilla/5.0 (compatible; MSIE 10.6; Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K; Trident/5.0; InfoPath.2; SLCC1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 2.0.50727) 3gpp-gba UNTRUSTED/1.0";
+ $iPhoneOperaA = "Opera/9.80 (iPod; U; CPU iPhone OS 4_3_3 like Mac OS X; ja-jp) Presto/2.9.181 Version/12.00";
+ $win8IEB = "Mozilla/5.0 (compatible; MSIE 10.0; Windows 8; Trident/5.0)";
+ $winVistaIEB = "Mozilla/5.0 (compatible; MSIE 10.0; Windows Vista; Trident/5.0)";
+ $osxOperaB = "Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; fr) Presto/2.9.168 Version/11.52";
+ $userAgents = array(
+ $linuxFirefoxA, $linuxFirefoxA, $win7FirefoxA, $win7ChromeA, $linuxChromeA, $linuxSafariA,
+ $iPadSafariA, $iPadFirefoxB, $androidFirefoxB, $androidChromeB, $androidIEA, $iPhoneOperaA,
+ $win8IEB, $winVistaIEB, $osxOperaB
+ );
+
+ $resolutions = array(
+ "1920x1080", "1920x1080", "1920x1080", "1920x1080", "1366x768", "1366x768", "1366x768",
+ "1280x1024", "1280x1024", "1280x1024", "1680x1050", "1680x1050", "1024x768", "800x600",
+ "320x480"
+ );
+
+ $referrers = array(
+ // website referrers (8)
+ 'http://whatever0.com/0', 'http://whatever0.com/0', 'http://whatever0.com/1', 'http://whatever0.com/2',
+ 'http://whatever1.com/0', 'http://whatever.com1/1', 'http://whatever1.com/2', 'http://whatever3.com/3',
+
+ // search engines w/ keyword (12)
+ 'http://www.google.com/search?q=this+search+term',
+ 'http://www.google.com/search?q=that+search+term',
+ 'http://search.yahoo.com/search?p=this+search+term',
+ 'http://search.yahoo.com/search?p=that+search+term',
+ 'http://www.ask.com/web?q=this+search+term',
+ 'http://www.bing.com/search?q=search+term+1',
+ 'http://search.babylon.com/?q=search+term+2',
+ 'http://alexa.com/search?q=search+term+2',
+ 'http://www.google.com/search?q=search+term+3',
+ 'http://search.yahoo.com/search?p=search+term+4',
+ 'http://www.ask.com/web?q=search+term+3',
+ 'http://www.bing.com/search?q=search+term+4',
+ );
+
+ $customVars = array(
+ 'name' => array('thing0', 'thing1', 'thing2', 'thing3', 'thing4', 'thing5', 'thing6', 'thing7',
+ 'thing8', 'thing9', 'thing10', 'thing11', 'thing12', 'thing13', 'thing14',
+ 'thing15', 'thing16', 'thing17', 'thing18', 'thing19'),
+ 'rating' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 20),
+ 'tweeted' => array('y', 'n', 'm', 'n', 'y', 'n', 'y', 'n', 'y', 'n', 'y', 'n', 'y', 'n', 'y', 'n',
+ 'm', 'n', 'm', 'n'),
+ 'liked' => array('yes', 'y', 'y', 'no', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y',
+ 'y', 'y', 'no', 'n'),
+ );
+ $downloadCustomVars = array(
+ 'size' => array(1024, 1024, 1024, 2048, 2048, 3072, 3072, 3072, 3072, 4096, 4096, 4096,
+ 512, 512, 256, 128, 64, 32, 48, 48)
+ );
+
+ $visitorCounter = 0;
+ $t = self::getTracker($this->idSite, $this->dateTime, $defaultInit = true, $useLocal = true);
+
+ // track regular actions
+ $this->trackActions($t, $visitorCounter, 'pageview', $userAgents, $resolutions, $referrers, $customVars);
+
+ // track downloads
+ $this->trackActions($t, $visitorCounter, 'download', $userAgents, $resolutions, null, $downloadCustomVars);
+
+ // track outlinks
+ $this->trackActions($t, $visitorCounter, 'outlink', $userAgents, $resolutions);
+ }
+
+ private function trackActions($t, &$visitorCounter, $actionType, $userAgents, $resolutions,
+ $referrers = null, $customVars = null)
+ {
+ for ($i = 0; $i != 5; ++$i, ++$visitorCounter) {
+ $visitDate = Piwik_Date::factory($this->dateTime);
+
+ $t->setNewVisitorId();
+ $t->setIp("156.5.3.$visitorCounter");
+
+ $t->setUserAgent($userAgents[$visitorCounter]);
+ list($w, $h) = explode('x', $resolutions[$visitorCounter]);
+ $t->setResolution((int)$w, (int)$h);
+
+ // one visit to root url
+ $t->setUrl("http://piwik.net/$visitorCounter/");
+ $t->setUrlReferrer(null);
+ $t->setForceVisitDateTime($visitDate->getDatetime());
+ $this->trackAction($t, $actionType, $visitorCounter, null);
+
+ for ($j = 0; $j != 4; ++$j) {
+ // NOTE: to test referers w/o creating too many visits, we don't actually track 4 actions, but
+ // 4 separate visits
+ $actionDate = $visitDate->addHour($j + 1);
+
+ $actionIdx = $i * 4 + $j;
+ $actionNum = $visitorCounter * 4 + $j;
+
+ $t->setUrl("http://piwik.net/$visitorCounter/$actionNum");
+ $t->setForceVisitDateTime($actionDate->getDatetime());
+
+ if (!is_null($referrers)) {
+ $t->setUrlReferrer($referrers[$actionIdx]);
+ } else {
+ $t->setUrlReferrer(null);
+ }
+
+ if (!is_null($customVars)) {
+ $k = 1;
+ foreach ($customVars as $name => $values) {
+ $value = $values[$actionIdx];
+ $t->setCustomVariable($k, $name, $value, $scope = 'page');
+
+ ++$k;
+ }
+ }
+
+ $this->trackAction($t, $actionType, $visitorCounter, $actionNum);
+ }
+ }
+ }
+
+ private function trackAction($t, $actionType, $visitorCounter, $actionNum)
+ {
+ if ($actionType == 'pageview') {
+ self::checkResponse($t->doTrackPageView(
+ is_null($actionNum) ? "title_$visitorCounter" : "title_$visitorCounter / title_$actionNum"));
+ } else if ($actionType == 'download') {
+ $root = is_null($actionNum) ? "http://cloudsite$visitorCounter.com"
+ : "http://cloudsite$visitorCounter.com/$actionNum";
+
+ self::checkResponse($t->doTrackAction("$root/download", 'download'));
+ } else if ($actionType == 'outlink') {
+ self::checkResponse($t->doTrackAction(is_null($actionNum) ? "http://othersite$visitorCounter.com/"
+ : "http://othersite$visitorCounter.com/$actionNum/", 'link'));
+ }
+ }
+
+ private function setMockLocationProvider()
+ {
+ Piwik_UserCountry_LocationProvider::setCurrentProvider('mock_provider');
+ MockLocationProvider::$locations = array(
+ self::makeLocation('Toronto', 'ON', 'CA'),
+
+ self::makeLocation('Nice', 'B8', 'FR'),
+
+ self::makeLocation('Melbourne', '07', 'AU'),
+
+ self::makeLocation('Yokohama', '19', 'JP'),
+ );
+ }
+
+ private function unsetMockLocationProvider()
+ {
+ Piwik_UserCountry_LocationProvider::setCurrentProvider('default');
+ }
}
diff --git a/tests/PHPUnit/Fixtures/ManyVisitsWithSubDirReferrersAndCustomVars.php b/tests/PHPUnit/Fixtures/ManyVisitsWithSubDirReferrersAndCustomVars.php
index b3782cce0f..44f19e6664 100644
--- a/tests/PHPUnit/Fixtures/ManyVisitsWithSubDirReferrersAndCustomVars.php
+++ b/tests/PHPUnit/Fixtures/ManyVisitsWithSubDirReferrersAndCustomVars.php
@@ -4,7 +4,8 @@
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
- */#
+ */
+#
/**
* Adds one site and tracks 13 visits all with custom variables and referrer URLs
@@ -13,19 +14,19 @@
class Test_Piwik_Fixture_ManyVisitsWithSubDirReferrersAndCustomVars extends Test_Piwik_BaseFixture
{
public $dateTime = '2010-03-06 11:22:33';
- public $idSite = 1;
-
+ public $idSite = 1;
+
public function setUp()
{
- $this->setUpWebsitesAndGoals();
- $this->trackVisits();
+ $this->setUpWebsitesAndGoals();
+ $this->trackVisits();
}
-
+
public function tearDown()
{
- // empty
+ // empty
}
-
+
private function setUpWebsitesAndGoals()
{
self::createWebsite($this->dateTime);
@@ -34,18 +35,18 @@ class Test_Piwik_Fixture_ManyVisitsWithSubDirReferrersAndCustomVars extends Test
private function trackVisits()
{
$dateTime = $this->dateTime;
- $idSite = $this->idSite;
+ $idSite = $this->idSite;
for ($referrerSite = 1; $referrerSite < 4; $referrerSite++) {
for ($referrerPage = 1; $referrerPage < 3; $referrerPage++) {
$offset = $referrerSite * 3 + $referrerPage;
- $t = self::getTracker($idSite, Piwik_Date::factory($dateTime)->addHour($offset)->getDatetime());
+ $t = self::getTracker($idSite, Piwik_Date::factory($dateTime)->addHour($offset)->getDatetime());
$t->setUrlReferrer('http://www.referrer' . $referrerSite . '.com/sub/dir/page' . $referrerPage . '.html');
$t->setCustomVariable(1, 'CustomVarVisit', 'CustomVarValue' . $referrerPage, 'visit');
for ($page = 0; $page < 3; $page++) {
$t->setUrl('http://example.org/dir' . $referrerSite . '/sub/dir/page' . $page . '.html');
$t->setCustomVariable(1, 'CustomVarPage', 'CustomVarValue' . $page, 'page');
- $t->setGenerationTime($referrerPage * $referrerSite * ($page + 1) * 100);
+ $t->setGenerationTime($referrerPage * $referrerSite * ($page + 1) * 100);
self::checkResponse($t->doTrackPageView('title'));
}
}
diff --git a/tests/PHPUnit/Fixtures/OneVisitSeveralPageViews.php b/tests/PHPUnit/Fixtures/OneVisitSeveralPageViews.php
index 14d523159b..3a3bd00ba2 100644
--- a/tests/PHPUnit/Fixtures/OneVisitSeveralPageViews.php
+++ b/tests/PHPUnit/Fixtures/OneVisitSeveralPageViews.php
@@ -12,19 +12,19 @@
class Test_Piwik_Fixture_OneVisitSeveralPageViews extends Test_Piwik_BaseFixture
{
public $dateTime = '2010-03-06 11:22:33';
- public $idSite = 1;
-
+ public $idSite = 1;
+
public function setUp()
{
$this->setUpWebsitesAndGoals();
$this->trackVisits();
}
-
+
public function tearDown()
{
- // empty
+ // empty
}
-
+
private function setUpWebsitesAndGoals()
{
self::createWebsite($this->dateTime);
@@ -33,37 +33,37 @@ class Test_Piwik_Fixture_OneVisitSeveralPageViews extends Test_Piwik_BaseFixture
private function trackVisits()
{
$dateTime = $this->dateTime;
- $idSite = $this->idSite;
- $t = self::getTracker($idSite, $dateTime, $defaultInit = true, $useThirdPartyCookie = 1);
+ $idSite = $this->idSite;
+ $t = self::getTracker($idSite, $dateTime, $defaultInit = true, $useThirdPartyCookie = 1);
$t->setUrlReferrer('http://www.google.com.vn/url?sa=t&rct=j&q=%3C%3E%26%5C%22the%20pdo%20extension%20is%20required%20for%20this%20adapter%20but%20the%20extension%20is%20not%20loaded&source=web&cd=4&ved=0FjAD&url=http%3A%2F%2Fforum.piwik.org%2Fread.php%3F2%2C1011&ei=y-HHAQ&usg=AFQjCN2-nt5_GgDeg&cad=rja');
$t->setUrl('http://example.org/%C3%A9%C3%A9%C3%A9%22%27...%20%3Cthis%20is%20cool%3E!');
- $t->setGenerationTime(523);
+ $t->setGenerationTime(523);
self::checkResponse($t->doTrackPageView('incredible title! <>,;'));
$t->setUrl('http://example.org/dir/file.php?foo=bar&foo2=bar');
$t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.2)->getDatetime());
- $t->setGenerationTime(123);
+ $t->setGenerationTime(123);
self::checkResponse($t->doTrackPageView('incredible title! <>,;'));
$t->setUrl('http://example.org/dir/file.php?foo=bar&foo2=bar2');
$t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.3)->getDatetime());
- $t->setGenerationTime(153);
+ $t->setGenerationTime(153);
self::checkResponse($t->doTrackPageView('incredible parent title! <>,; / subtitle <>,;'));
$t->setUrl('http://example.org/dir2/file.php?foo=bar&foo2=bar');
$t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.4)->getDatetime());
- $t->setGenerationTime(1233);
+ $t->setGenerationTime(1233);
self::checkResponse($t->doTrackPageView('incredible title! <>,;'));
$t->setUrl('http://example.org/dir2/sub/0/file.php');
$t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.4)->getDatetime());
- $t->setGenerationTime(837);
+ $t->setGenerationTime(837);
self::checkResponse($t->doTrackPageView('incredible title! <>,;'));
$t->setUrl('http://example.org/0');
$t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.4)->getDatetime());
- $t->setGenerationTime(635);
+ $t->setGenerationTime(635);
self::checkResponse($t->doTrackPageView('I am URL zero!'));
}
diff --git a/tests/PHPUnit/Fixtures/OneVisitWithAbnormalPageviewUrls.php b/tests/PHPUnit/Fixtures/OneVisitWithAbnormalPageviewUrls.php
index 439433cefe..ac67e3cb0f 100644
--- a/tests/PHPUnit/Fixtures/OneVisitWithAbnormalPageviewUrls.php
+++ b/tests/PHPUnit/Fixtures/OneVisitWithAbnormalPageviewUrls.php
@@ -13,19 +13,19 @@
class Test_Piwik_Fixture_OneVisitWithAbnormalPageviewUrls extends Test_Piwik_BaseFixture
{
public $dateTime = '2010-03-06 11:22:33';
- public $idSite = 1;
-
+ public $idSite = 1;
+
public function setUp()
{
- $this->setUpWebsitesAndGoals();
- $this->trackVisits();
+ $this->setUpWebsitesAndGoals();
+ $this->trackVisits();
}
-
+
public function tearDown()
{
- // empty
+ // empty
}
-
+
private function setUpWebsitesAndGoals()
{
self::createWebsite($this->dateTime);
@@ -34,8 +34,8 @@ class Test_Piwik_Fixture_OneVisitWithAbnormalPageviewUrls extends Test_Piwik_Bas
private function trackVisits()
{
$dateTime = $this->dateTime;
- $idSite = $this->idSite;
- $t = self::getTracker($idSite, $dateTime, $defaultInit = true, $useThirdPartyCookie = 1);
+ $idSite = $this->idSite;
+ $t = self::getTracker($idSite, $dateTime, $defaultInit = true, $useThirdPartyCookie = 1);
$t->setUrlReferrer('http://www.google.com/search?q=piwik');
$t->setUrl('http://example.org/foo/bar.html');
diff --git a/tests/PHPUnit/Fixtures/OneVisitorTwoVisits.php b/tests/PHPUnit/Fixtures/OneVisitorTwoVisits.php
index 3177a41c3f..bba9bdcd54 100644
--- a/tests/PHPUnit/Fixtures/OneVisitorTwoVisits.php
+++ b/tests/PHPUnit/Fixtures/OneVisitorTwoVisits.php
@@ -11,44 +11,42 @@
*/
class Test_Piwik_Fixture_OneVisitorTwoVisits extends Test_Piwik_BaseFixture
{
- public $idSite = 1;
- public $dateTime = '2010-03-06 11:22:33';
-
+ public $idSite = 1;
+ public $dateTime = '2010-03-06 11:22:33';
+
public $useThirdPartyCookies = false;
public $useSiteSearch = false;
public $excludeMozilla = false;
-
- public function setUp()
- {
- $this->setUpWebsitesAndGoals();
- $this->trackVisits();
- }
-
- public function tearDown()
- {
- // empty
- }
-
- private function setUpWebsitesAndGoals()
- {
- self::createWebsite($this->dateTime);
- }
-
- private function trackVisits()
- {
+
+ public function setUp()
+ {
+ $this->setUpWebsitesAndGoals();
+ $this->trackVisits();
+ }
+
+ public function tearDown()
+ {
+ // empty
+ }
+
+ private function setUpWebsitesAndGoals()
+ {
+ self::createWebsite($this->dateTime);
+ }
+
+ private function trackVisits()
+ {
$dateTime = $this->dateTime;
- $idSite = $this->idSite;
+ $idSite = $this->idSite;
- if ($this->excludeMozilla)
- {
- Piwik_SitesManager_API::getInstance()->setSiteSpecificUserAgentExcludeEnabled(false);
+ if ($this->excludeMozilla) {
+ Piwik_SitesManager_API::getInstance()->setSiteSpecificUserAgentExcludeEnabled(false);
}
-
+
$t = self::getTracker($idSite, $dateTime, $defaultInit = true);
-
- if ($this->useThirdPartyCookies)
- {
- $t->DEBUG_APPEND_URL = '&forceUseThirdPartyCookie=1';
+
+ if ($this->useThirdPartyCookies) {
+ $t->DEBUG_APPEND_URL = '&forceUseThirdPartyCookie=1';
}
$t->disableCookieSupport();
@@ -58,21 +56,21 @@ class Test_Piwik_Fixture_OneVisitorTwoVisits extends Test_Piwik_BaseFixture
// testing URL excluded parameters
$parameterToExclude = 'excluded_parameter';
Piwik_SitesManager_API::getInstance()->updateSite(
- $idSite,
- 'new name',
- $url = array('http://site.com'),
- $ecommerce = 0,
- $siteSearch = $this->useSiteSearch ? 1 : 0,
- $searchKeywordParameters = $this->useSiteSearch ? '' : null,
- $searchCategoryParameters = $this->useSiteSearch ? 'notparam' : null,
- $excludedIps = null,
- $parameterToExclude . ',anotherParameter',
- $timezone = null,
- $currency = null,
- $group = null,
- $startDate = null,
- // test that visit won't be excluded since site-specific exclude is not enabled
- $excludedUserAgents = $this->excludeMozilla ? 'mozilla' : null
+ $idSite,
+ 'new name',
+ $url = array('http://site.com'),
+ $ecommerce = 0,
+ $siteSearch = $this->useSiteSearch ? 1 : 0,
+ $searchKeywordParameters = $this->useSiteSearch ? '' : null,
+ $searchCategoryParameters = $this->useSiteSearch ? 'notparam' : null,
+ $excludedIps = null,
+ $parameterToExclude . ',anotherParameter',
+ $timezone = null,
+ $currency = null,
+ $group = null,
+ $startDate = null,
+ // test that visit won't be excluded since site-specific exclude is not enabled
+ $excludedUserAgents = $this->excludeMozilla ? 'mozilla' : null
);
// Record 1st page view
@@ -113,26 +111,23 @@ class Test_Piwik_Fixture_OneVisitorTwoVisits extends Test_Piwik_BaseFixture
self::checkResponse($t->doTrackGoal($idGoal, $revenue = 42));
$t->setBrowserLanguage('fr');
-
- if ($this->useSiteSearch)
- {
- // Site Search request
- $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.42)->getDatetime());
- $t->setUrl('http://example.org/index.htm?q=Banks Own The World');
- self::checkResponse($t->doTrackPageView('Site Search request'));
-
- // Final page view (after 27 min)
- $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.45)->getDatetime());
- $t->setUrl('http://example.org/index.htm');
- self::checkResponse($t->doTrackPageView('Looking at homepage after site search...'));
+
+ if ($this->useSiteSearch) {
+ // Site Search request
+ $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.42)->getDatetime());
+ $t->setUrl('http://example.org/index.htm?q=Banks Own The World');
+ self::checkResponse($t->doTrackPageView('Site Search request'));
+
+ // Final page view (after 27 min)
+ $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.45)->getDatetime());
+ $t->setUrl('http://example.org/index.htm');
+ self::checkResponse($t->doTrackPageView('Looking at homepage after site search...'));
+ } else {
+ // Final page view (after 27 min)
+ $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.45)->getDatetime());
+ $t->setUrl('http://example.org/index.htm#ignoredFragment#');
+ self::checkResponse($t->doTrackPageView('Looking at homepage (again)...'));
}
- else
- {
- // Final page view (after 27 min)
- $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.45)->getDatetime());
- $t->setUrl('http://example.org/index.htm#ignoredFragment#');
- self::checkResponse($t->doTrackPageView('Looking at homepage (again)...'));
- }
// -
// End of first visit: 24min
@@ -152,5 +147,5 @@ class Test_Piwik_Fixture_OneVisitorTwoVisits extends Test_Piwik_BaseFixture
self::checkResponse($t->doTrackPageView('Checkout/Purchasing...'));
// -
// End of second visit
- }
+ }
}
diff --git a/tests/PHPUnit/Fixtures/SomeVisitsAllConversions.php b/tests/PHPUnit/Fixtures/SomeVisitsAllConversions.php
index 72b3b8d1c9..670bc635df 100644
--- a/tests/PHPUnit/Fixtures/SomeVisitsAllConversions.php
+++ b/tests/PHPUnit/Fixtures/SomeVisitsAllConversions.php
@@ -15,16 +15,16 @@ class Piwik_Test_Fixture_SomeVisitsAllConversions extends Test_Piwik_BaseFixture
public $idSite = 1;
public $idGoal_OneConversionPerVisit = 1;
public $idGoal_MultipleConversionPerVisit = 2;
-
+
public function setUp()
{
$this->setUpWebsitesAndGoals();
$this->trackVisits();
}
-
+
public function tearDown()
{
- // empty
+ // empty
}
private function setUpWebsitesAndGoals()
@@ -33,22 +33,22 @@ class Piwik_Test_Fixture_SomeVisitsAllConversions extends Test_Piwik_BaseFixture
// First, a goal that is only recorded once per visit
Piwik_Goals_API::getInstance()->addGoal(
- $this->idSite, 'triggered js ONCE', 'title', 'Thank you', 'contains', $caseSensitive = false,
- $revenue = 10, $allowMultipleConversions = false
- );
+ $this->idSite, 'triggered js ONCE', 'title', 'Thank you', 'contains', $caseSensitive = false,
+ $revenue = 10, $allowMultipleConversions = false
+ );
// Second, a goal allowing multiple conversions
Piwik_Goals_API::getInstance()->addGoal(
- $this->idSite, 'triggered js MULTIPLE ALLOWED', 'manually', '', '', $caseSensitive = false,
- $revenue = 10, $allowMultipleConversions = true
- );
+ $this->idSite, 'triggered js MULTIPLE ALLOWED', 'manually', '', '', $caseSensitive = false,
+ $revenue = 10, $allowMultipleConversions = true
+ );
}
private function trackVisits()
{
- $dateTime = $this->dateTime;
- $idSite = $this->idSite;
- $idGoal_OneConversionPerVisit = $this->idGoal_OneConversionPerVisit;
+ $dateTime = $this->dateTime;
+ $idSite = $this->idSite;
+ $idGoal_OneConversionPerVisit = $this->idGoal_OneConversionPerVisit;
$idGoal_MultipleConversionPerVisit = $this->idGoal_MultipleConversionPerVisit;
$t = self::getTracker($idSite, $dateTime, $defaultInit = true);
@@ -68,7 +68,7 @@ class Piwik_Test_Fixture_SomeVisitsAllConversions extends Test_Piwik_BaseFixture
// Update & set to not allow multiple
$goals = Piwik_Goals_API::getInstance()->getGoals($idSite);
- $goal = $goals[$idGoal_OneConversionPerVisit];
+ $goal = $goals[$idGoal_OneConversionPerVisit];
self::assertTrue($goal['allow_multiple'] == 0);
Piwik_Goals_API::getInstance()->updateGoal($idSite, $idGoal_OneConversionPerVisit, $goal['name'], @$goal['match_attribute'], @$goal['pattern'], @$goal['pattern_type'], @$goal['case_sensitive'], $goal['revenue'], $goal['allow_multiple'] = 1);
self::assertTrue($goal['allow_multiple'] == 1);
diff --git a/tests/PHPUnit/Fixtures/SomeVisitsCustomVariablesCampaignsNotHeuristics.php b/tests/PHPUnit/Fixtures/SomeVisitsCustomVariablesCampaignsNotHeuristics.php
index 4ccbdf624a..a3752ad05c 100644
--- a/tests/PHPUnit/Fixtures/SomeVisitsCustomVariablesCampaignsNotHeuristics.php
+++ b/tests/PHPUnit/Fixtures/SomeVisitsCustomVariablesCampaignsNotHeuristics.php
@@ -15,18 +15,18 @@ class Test_Piwik_Fixture_SomeVisitsCustomVariablesCampaignsNotHeuristics extends
public $dateTime = '2009-01-04 00:11:42';
public $idSite = 1;
public $idGoal = 1;
-
+
public function setUp()
{
$this->setUpWebsitesAndGoals();
$this->trackVisits();
}
-
+
public function tearDown()
{
- // empty
+ // empty
}
-
+
private function setUpWebsitesAndGoals()
{
self::createWebsite($this->dateTime);
@@ -36,8 +36,8 @@ class Test_Piwik_Fixture_SomeVisitsCustomVariablesCampaignsNotHeuristics extends
private function trackVisits()
{
$dateTime = $this->dateTime;
- $idSite = $this->idSite;
- $idGoal = $this->idGoal;
+ $idSite = $this->idSite;
+ $idGoal = $this->idGoal;
$t = self::getTracker($idSite, $dateTime, $defaultInit = true);
@@ -49,8 +49,8 @@ class Test_Piwik_Fixture_SomeVisitsCustomVariablesCampaignsNotHeuristics extends
self::assertTrue(strlen($visitorId) == 16);
// test setting/getting the first party cookie via the PHP Tracking Client
- $_COOKIE['_pk_id_1_1fff'] = 'ca0afe7b6b692ff5.1302307497.1.1302307497.1302307497';
- $_COOKIE['_pk_ref_1_1fff'] = '["YEAH","RIGHT!",1302307497,"http://referrer.example.org/page/sub?query=test&test2=test3"]';
+ $_COOKIE['_pk_id_1_1fff'] = 'ca0afe7b6b692ff5.1302307497.1.1302307497.1302307497';
+ $_COOKIE['_pk_ref_1_1fff'] = '["YEAH","RIGHT!",1302307497,"http://referrer.example.org/page/sub?query=test&test2=test3"]';
$_COOKIE['_pk_cvar_1_1fff'] = '{"1":["VAR 1 set, var 2 not set","yes"],"3":["var 3 set","yes!!!!"]}';
self::assertEquals('ca0afe7b6b692ff5', $t->getVisitorId());
self::assertEquals($t->getAttributionInfo(), $_COOKIE['_pk_ref_1_1fff']);
@@ -95,24 +95,24 @@ class Test_Piwik_Fixture_SomeVisitsCustomVariablesCampaignsNotHeuristics extends
$t4->setUrl('http://example.org/index.html?utm_campaign=GA+Campaign');
self::checkResponse($t4->doTrackPageView('first page'));
- // No campaign keyword specified, will use the referrer hostname
+ // No campaign keyword specified, will use the referrer hostname
$t4->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(4)->getDatetime());
$t4->setUrlReferrer('http://thing1.com/a/b/c.html?a=b&d=c');
$t4->setUrl('http://example.org/index.html?utm_campaign=GA+Campaign');
self::checkResponse($t4->doTrackPageView('second page'));
- // Test with Google adsense type URL:
- $adsenseRefererUrl = 'http://googleads.g.doubleclick.net/pagead/ads?client=ca-pub-12345&output=html&h=280&slotname=123&w=336&lmt=1359388321&202&url=http%3A%2F%2Fwww.adsense-publisher-website.org%2F&dt=123&bpp=13&shv=r22&jsv=1565606614&correlator=ss&ga_vid=aaa&ga_sid=1359435122&ga_hid=1801871121&ga_fc=0&u_tz=780&u_his=4&u_java=1&u_h=900&u_w=1600&u_ah=876&u_aw=1551&u_cd=24&u_nplug=4&u_nmime=5&dff=georgia&dfs=16&adx=33&ady=201&biw=1551&bih=792&oid=3&fu=0&ifi=1&dtd=608&p=http%3A//www.adsense-publisher-website.com';
- $t4->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(5)->getDatetime());
- $t4->setUrlReferrer($adsenseRefererUrl);
- $t4->setUrl('http://example.org/index.html?utm_campaign=Adsense campaign');
- self::checkResponse($t4->doTrackPageView('second page'));
-
- // Test with google Adwords URL
- $adwordsUrl = 'http://www.google.co.nz/aclk?sa=L&ai=uYmFyiZgAf0oO0J&num=3&sig=EpOCR4xQ&ved=ENEM&adurl=http://pixel.everesttech.net/3163/cq%3Fev_sid%3D3%26ev_cmpid%3D33%26ev_ln%3Dused%2520wii%2520consoles%26ev_crx%528386%26ev_mt%3Db%26ev_n%3Dg%26ev_ltx%3D%26ev_pl%3D%26ev_pos%3D1s2%26url%3Dhttp%253A//au.shopping.com/used%2520wii%2520consoles/products%253Flinkin_id%253D8077872&rct=j&q=nintendo+consoles+second+hand';
- $t4->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(6)->getDatetime());
- $t4->setUrlReferrer($adwordsUrl);
- $t4->setUrl('http://example.org/index.html?utm_campaign=Adwords campaign');
- self::checkResponse($t4->doTrackPageView('second page'));
+ // Test with Google adsense type URL:
+ $adsenseRefererUrl = 'http://googleads.g.doubleclick.net/pagead/ads?client=ca-pub-12345&output=html&h=280&slotname=123&w=336&lmt=1359388321&202&url=http%3A%2F%2Fwww.adsense-publisher-website.org%2F&dt=123&bpp=13&shv=r22&jsv=1565606614&correlator=ss&ga_vid=aaa&ga_sid=1359435122&ga_hid=1801871121&ga_fc=0&u_tz=780&u_his=4&u_java=1&u_h=900&u_w=1600&u_ah=876&u_aw=1551&u_cd=24&u_nplug=4&u_nmime=5&dff=georgia&dfs=16&adx=33&ady=201&biw=1551&bih=792&oid=3&fu=0&ifi=1&dtd=608&p=http%3A//www.adsense-publisher-website.com';
+ $t4->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(5)->getDatetime());
+ $t4->setUrlReferrer($adsenseRefererUrl);
+ $t4->setUrl('http://example.org/index.html?utm_campaign=Adsense campaign');
+ self::checkResponse($t4->doTrackPageView('second page'));
+
+ // Test with google Adwords URL
+ $adwordsUrl = 'http://www.google.co.nz/aclk?sa=L&ai=uYmFyiZgAf0oO0J&num=3&sig=EpOCR4xQ&ved=ENEM&adurl=http://pixel.everesttech.net/3163/cq%3Fev_sid%3D3%26ev_cmpid%3D33%26ev_ln%3Dused%2520wii%2520consoles%26ev_crx%528386%26ev_mt%3Db%26ev_n%3Dg%26ev_ltx%3D%26ev_pl%3D%26ev_pos%3D1s2%26url%3Dhttp%253A//au.shopping.com/used%2520wii%2520consoles/products%253Flinkin_id%253D8077872&rct=j&q=nintendo+consoles+second+hand';
+ $t4->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(6)->getDatetime());
+ $t4->setUrlReferrer($adwordsUrl);
+ $t4->setUrl('http://example.org/index.html?utm_campaign=Adwords campaign');
+ self::checkResponse($t4->doTrackPageView('second page'));
}
}
diff --git a/tests/PHPUnit/Fixtures/SomeVisitsManyPageviewsWithTransitions.php b/tests/PHPUnit/Fixtures/SomeVisitsManyPageviewsWithTransitions.php
index dc7ea10572..ed793bb0bc 100644
--- a/tests/PHPUnit/Fixtures/SomeVisitsManyPageviewsWithTransitions.php
+++ b/tests/PHPUnit/Fixtures/SomeVisitsManyPageviewsWithTransitions.php
@@ -12,80 +12,82 @@
*/
class Test_Piwik_Fixture_SomeVisitsManyPageviewsWithTransitions extends Test_Piwik_BaseFixture
{
- public $dateTime = '2010-03-06 11:22:33';
- public $idSite = 1;
-
- private $prefixCounter = 0;
-
- public function setUp()
- {
- $this->setUpWebsitesAndGoals();
- $this->trackVisits();
- }
-
- public function tearDown()
- {
- // empty
- }
+ public $dateTime = '2010-03-06 11:22:33';
+ public $idSite = 1;
- private function setUpWebsitesAndGoals()
- {
- self::createWebsite($this->dateTime);
- }
+ private $prefixCounter = 0;
- private function trackVisits()
- {
- $visit1 = $this->createVisit(1);
- $visit1->setUrlReferrer('http://www.google.com.vn/url?sa=t&rct=j&q=%3C%3E%26%5C%22the%20pdo%20extension%20is%20required%20for%20this%20adapter%20but%20the%20extension%20is%20not%20loaded&source=web&cd=4&ved=0FjAD&url=http%3A%2F%2Fforum.piwik.org%2Fread.php%3F2%2C1011&ei=y-HHAQ&usg=AFQjCN2-nt5_GgDeg&cad=rja');
- $this->trackPageView($visit1, 0, 'page/one.html');
- $this->trackPageView($visit1, 0.1, 'sub/dir/page2.html');
- $this->trackPageView($visit1, 0.2, 'page/one.html');
- $this->trackPageView($visit1, 0.3, 'the/third_page.html?foo=bar');
- $this->trackPageView($visit1, 0.4, 'page/one.html');
- $this->trackPageView($visit1, 0.5, 'the/third_page.html?foo=bar');
- $this->trackPageView($visit1, 0.6, 'page/one.html');
- $this->trackPageView($visit1, 0.7, 'the/third_page.html?foo=baz#anchor1');
- $this->trackPageView($visit1, 0.8, 'page/one.html');
- $this->trackPageView($visit1, 0.9, 'page/one.html');
- $this->trackPageView($visit1, 1.0, 'the/third_page.html?foo=baz#anchor2');
- $this->trackPageView($visit1, 1.1, 'page/one.html');
- $this->trackPageView($visit1, 1.2, 'page3.html');
-
- $visit2 = $this->createVisit(2);
- $visit2->setUrlReferrer('http://www.external.com.vn/referrerPage-notCounted.html');
- $this->trackPageView($visit2, 0, 'sub/dir/page2.html');
- $this->trackPageView($visit2, 0.1, 'the/third_page.html?foo=bar');
- $this->trackPageView($visit2, 0.2, 'page/one.html');
- $this->trackPageView($visit2, 0.3, 'the/third_page.html?foo=baz#anchor1');
-
- $visit3 = $this->createVisit(3);
- $visit3->setUrlReferrer('http://www.external.com.vn/referrerPage-counted.html');
- $this->trackPageView($visit3, 0.1, 'page/one.html');
- $this->trackPageView($visit3, 0.2, 'sub/dir/page2.html');
- $this->trackPageView($visit3, 0.3, 'page/one.html');
-
- $visit4 = $this->createVisit(4);
- $this->trackPageView($visit4, 0, 'page/one.html?pk_campaign=TestCampaign&pk_kwd=TestKeyword');
-
- $visit5 = $this->createVisit(5);
- $this->trackPageView($visit5, 0, 'page/one.html');
- }
-
- private function createVisit($id) {
- $visit = self::getTracker($this->idSite, $this->dateTime, $defaultInit = true);
- $visit->setIp('156.5.3.'.$id);
- return $visit;
- }
-
- private function trackPageView($visit, $timeOffset, $path) {
- // rotate protocol and www to make sure it doesn't matter
- $prefixes = array('http://', 'http://www.', 'https://', 'https://');
- $prefix = $prefixes[$this->prefixCounter];
- $this->prefixCounter = ($this->prefixCounter + 1) % 4;
-
- /** @var $visit PiwikTracker */
- $visit->setUrl($prefix.'example.org/'.$path);
- $visit->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour($timeOffset)->getDatetime());
- self::checkResponse($visit->doTrackPageView('page title'));
- }
+ public function setUp()
+ {
+ $this->setUpWebsitesAndGoals();
+ $this->trackVisits();
+ }
+
+ public function tearDown()
+ {
+ // empty
+ }
+
+ private function setUpWebsitesAndGoals()
+ {
+ self::createWebsite($this->dateTime);
+ }
+
+ private function trackVisits()
+ {
+ $visit1 = $this->createVisit(1);
+ $visit1->setUrlReferrer('http://www.google.com.vn/url?sa=t&rct=j&q=%3C%3E%26%5C%22the%20pdo%20extension%20is%20required%20for%20this%20adapter%20but%20the%20extension%20is%20not%20loaded&source=web&cd=4&ved=0FjAD&url=http%3A%2F%2Fforum.piwik.org%2Fread.php%3F2%2C1011&ei=y-HHAQ&usg=AFQjCN2-nt5_GgDeg&cad=rja');
+ $this->trackPageView($visit1, 0, 'page/one.html');
+ $this->trackPageView($visit1, 0.1, 'sub/dir/page2.html');
+ $this->trackPageView($visit1, 0.2, 'page/one.html');
+ $this->trackPageView($visit1, 0.3, 'the/third_page.html?foo=bar');
+ $this->trackPageView($visit1, 0.4, 'page/one.html');
+ $this->trackPageView($visit1, 0.5, 'the/third_page.html?foo=bar');
+ $this->trackPageView($visit1, 0.6, 'page/one.html');
+ $this->trackPageView($visit1, 0.7, 'the/third_page.html?foo=baz#anchor1');
+ $this->trackPageView($visit1, 0.8, 'page/one.html');
+ $this->trackPageView($visit1, 0.9, 'page/one.html');
+ $this->trackPageView($visit1, 1.0, 'the/third_page.html?foo=baz#anchor2');
+ $this->trackPageView($visit1, 1.1, 'page/one.html');
+ $this->trackPageView($visit1, 1.2, 'page3.html');
+
+ $visit2 = $this->createVisit(2);
+ $visit2->setUrlReferrer('http://www.external.com.vn/referrerPage-notCounted.html');
+ $this->trackPageView($visit2, 0, 'sub/dir/page2.html');
+ $this->trackPageView($visit2, 0.1, 'the/third_page.html?foo=bar');
+ $this->trackPageView($visit2, 0.2, 'page/one.html');
+ $this->trackPageView($visit2, 0.3, 'the/third_page.html?foo=baz#anchor1');
+
+ $visit3 = $this->createVisit(3);
+ $visit3->setUrlReferrer('http://www.external.com.vn/referrerPage-counted.html');
+ $this->trackPageView($visit3, 0.1, 'page/one.html');
+ $this->trackPageView($visit3, 0.2, 'sub/dir/page2.html');
+ $this->trackPageView($visit3, 0.3, 'page/one.html');
+
+ $visit4 = $this->createVisit(4);
+ $this->trackPageView($visit4, 0, 'page/one.html?pk_campaign=TestCampaign&pk_kwd=TestKeyword');
+
+ $visit5 = $this->createVisit(5);
+ $this->trackPageView($visit5, 0, 'page/one.html');
+ }
+
+ private function createVisit($id)
+ {
+ $visit = self::getTracker($this->idSite, $this->dateTime, $defaultInit = true);
+ $visit->setIp('156.5.3.' . $id);
+ return $visit;
+ }
+
+ private function trackPageView($visit, $timeOffset, $path)
+ {
+ // rotate protocol and www to make sure it doesn't matter
+ $prefixes = array('http://', 'http://www.', 'https://', 'https://');
+ $prefix = $prefixes[$this->prefixCounter];
+ $this->prefixCounter = ($this->prefixCounter + 1) % 4;
+
+ /** @var $visit PiwikTracker */
+ $visit->setUrl($prefix . 'example.org/' . $path);
+ $visit->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour($timeOffset)->getDatetime());
+ self::checkResponse($visit->doTrackPageView('page title'));
+ }
}
diff --git a/tests/PHPUnit/Fixtures/SomeVisitsWithLongUrls.php b/tests/PHPUnit/Fixtures/SomeVisitsWithLongUrls.php
index d0335f45db..9eb839ad53 100644
--- a/tests/PHPUnit/Fixtures/SomeVisitsWithLongUrls.php
+++ b/tests/PHPUnit/Fixtures/SomeVisitsWithLongUrls.php
@@ -13,19 +13,19 @@
class Test_Piwik_Fixture_SomeVisitsWithLongUrls extends Test_Piwik_BaseFixture
{
public $dateTime = '2010-03-06 01:22:33';
- public $idSite = 1;
-
+ public $idSite = 1;
+
public function setUp()
{
- $this->setUpWebsitesAndGoals();
- $this->trackVisits();
+ $this->setUpWebsitesAndGoals();
+ $this->trackVisits();
}
-
+
public function tearDown()
{
- // empty
+ // empty
}
-
+
private function setUpWebsitesAndGoals()
{
self::createWebsite($this->dateTime);
@@ -35,7 +35,7 @@ class Test_Piwik_Fixture_SomeVisitsWithLongUrls extends Test_Piwik_BaseFixture
{
// tests run in UTC, the Tracker in UTC
$dateTime = $this->dateTime;
- $idSite = $this->idSite;
+ $idSite = $this->idSite;
// Visit 1: keyword and few URLs
$t = self::getTracker($idSite, $dateTime, $defaultInit = true, $useThirdPartyCookie = 1);
diff --git a/tests/PHPUnit/Fixtures/SomeVisitsWithNonUnicodePageTitles.php b/tests/PHPUnit/Fixtures/SomeVisitsWithNonUnicodePageTitles.php
index b87111433b..b0dac3c1a8 100644
--- a/tests/PHPUnit/Fixtures/SomeVisitsWithNonUnicodePageTitles.php
+++ b/tests/PHPUnit/Fixtures/SomeVisitsWithNonUnicodePageTitles.php
@@ -2,7 +2,7 @@
/**
* Piwik - Open source web analytics
*
- * @link http://piwik.org
+ * @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
@@ -11,87 +11,87 @@
*/
class Test_Piwik_Fixture_SomeVisitsWithNonUnicodePageTitles extends Test_Piwik_BaseFixture
{
- public $idSite1 = 1;
- public $dateTime = '2010-01-03 11:22:33';
-
- public function setUp()
- {
- $this->setUpWebsites();
- $this->trackVisits();
- }
-
- public function tearDown()
- {
- // empty
- }
+ public $idSite1 = 1;
+ public $dateTime = '2010-01-03 11:22:33';
- /**
- * One site with custom search parameters,
- * One site using default search parameters,
- * One site with disabled site search
- */
- private function setUpWebsites()
- {
- Piwik_SitesManager_API::getInstance()->setGlobalSearchParameters($searchKeywordParameters='gkwd', $searchCategoryParameters='gcat');
- self::createWebsite(Piwik_Date::factory($this->dateTime)->getDatetime(), 0, "Site 1 - Site search", $siteurl=false, $search=1, $searchKwd='q,mykwd,p', $searchCat='cats' );
- }
+ public function setUp()
+ {
+ $this->setUpWebsites();
+ $this->trackVisits();
+ }
- private function trackVisits()
- {
- $idSite1 = $this->idSite1;
- $dateTime = $this->dateTime;
-
- self::assertTrue(function_exists('mb_check_encoding'), ' check mb_check_encoding ');
- self::assertTrue(function_exists('mb_convert_encoding'), ' check mb_convert_encoding ');
+ public function tearDown()
+ {
+ // empty
+ }
- // Visitor site1
- $visitor = self::getTracker($idSite1, $dateTime, $defaultInit = true);
-
- // Test w/ iso-8859-15
- $visitor->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.3)->getDatetime());
- $visitor->setUrlReferrer('http://anothersite.com/whatever.html?whatever=Ato%FC');
- // Also testing that the value is encoded when passed as an array
- $visitor->setUrl('http://example.org/index.htm?random=param&mykwd[]=Search 2%FC&test&cats= Search Kategory &search_count=INCORRECT!');
- $visitor->setPageCharset('iso-8859-15');
- self::checkResponse($visitor->doTrackPageView('Site Search results'));
- $visitor->setPageCharset('');
-
- // Test w/ windows-1251
- $visitor = self::getTracker($idSite1, $dateTime, $defaultInit = true);
- $visitor->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.3)->getDatetime());
- $visitor->setUrlReferrer('http://anothersite.com/whatever.html?txt=%EC%E5%F8%EA%EE%E2%FB%E5');
- $visitor->setUrl('http://example.org/page/index.htm?whatever=%EC%E5%F8%EA%EE%E2%FB%E5');
- $visitor->setPageCharset('windows-1251');
- self::checkResponse($visitor->doTrackPageView('Page title is always UTF-8'));
+ /**
+ * One site with custom search parameters,
+ * One site using default search parameters,
+ * One site with disabled site search
+ */
+ private function setUpWebsites()
+ {
+ Piwik_SitesManager_API::getInstance()->setGlobalSearchParameters($searchKeywordParameters = 'gkwd', $searchCategoryParameters = 'gcat');
+ self::createWebsite(Piwik_Date::factory($this->dateTime)->getDatetime(), 0, "Site 1 - Site search", $siteurl = false, $search = 1, $searchKwd = 'q,mykwd,p', $searchCat = 'cats');
+ }
- $visitor->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.4)->getDatetime());
- $nonUnicodeKeyword = '%EC%E5%F8%EA%EE%E2%FB%E5';
- $visitor->setUrl('http://example.org/page/index.htm?q='.$nonUnicodeKeyword);
- $visitor->setPageCharset('windows-1251');
- self::checkResponse($visitor->doTrackPageView('Site Search'));
+ private function trackVisits()
+ {
+ $idSite1 = $this->idSite1;
+ $dateTime = $this->dateTime;
+ self::assertTrue(function_exists('mb_check_encoding'), ' check mb_check_encoding ');
+ self::assertTrue(function_exists('mb_convert_encoding'), ' check mb_convert_encoding ');
- // Test URL with non unicode Site Search keyword
- $visitor->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.5)->getDatetime());
- //TESTS: on jenkins somehow the "<-was here" was cut off so removing this test case and simply append the wrong keyword
+ // Visitor site1
+ $visitor = self::getTracker($idSite1, $dateTime, $defaultInit = true);
+
+ // Test w/ iso-8859-15
+ $visitor->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.3)->getDatetime());
+ $visitor->setUrlReferrer('http://anothersite.com/whatever.html?whatever=Ato%FC');
+ // Also testing that the value is encoded when passed as an array
+ $visitor->setUrl('http://example.org/index.htm?random=param&mykwd[]=Search 2%FC&test&cats= Search Kategory &search_count=INCORRECT!');
+ $visitor->setPageCharset('iso-8859-15');
+ self::checkResponse($visitor->doTrackPageView('Site Search results'));
+ $visitor->setPageCharset('');
+
+ // Test w/ windows-1251
+ $visitor = self::getTracker($idSite1, $dateTime, $defaultInit = true);
+ $visitor->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.3)->getDatetime());
+ $visitor->setUrlReferrer('http://anothersite.com/whatever.html?txt=%EC%E5%F8%EA%EE%E2%FB%E5');
+ $visitor->setUrl('http://example.org/page/index.htm?whatever=%EC%E5%F8%EA%EE%E2%FB%E5');
+ $visitor->setPageCharset('windows-1251');
+ self::checkResponse($visitor->doTrackPageView('Page title is always UTF-8'));
+
+ $visitor->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.4)->getDatetime());
+ $nonUnicodeKeyword = '%EC%E5%F8%EA%EE%E2%FB%E5';
+ $visitor->setUrl('http://example.org/page/index.htm?q=' . $nonUnicodeKeyword);
+ $visitor->setPageCharset('windows-1251');
+ self::checkResponse($visitor->doTrackPageView('Site Search'));
+
+
+ // Test URL with non unicode Site Search keyword
+ $visitor->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.5)->getDatetime());
+ //TESTS: on jenkins somehow the "<-was here" was cut off so removing this test case and simply append the wrong keyword
// $visitor->setUrl('http://example.org/page/index.htm?q=non unicode keyword %EC%E5%F8%EAe%EE%E2%FBf%E5 <-was here');
- $visitor->setUrl('http://example.org/page/index.htm?q=non unicode keyword %EC%E5%F8%EA%EE%E2%FB%E5');
- $visitor->setPageCharset('utf-8');
- self::checkResponse($visitor->doTrackPageView('Site Search'));
+ $visitor->setUrl('http://example.org/page/index.htm?q=non unicode keyword %EC%E5%F8%EA%EE%E2%FB%E5');
+ $visitor->setPageCharset('utf-8');
+ self::checkResponse($visitor->doTrackPageView('Site Search'));
- $visitor->setPageCharset('');
- $visitor->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.5)->getDatetime());
- $visitor->setUrl('http://example.org/exit-page');
- self::checkResponse($visitor->doTrackPageView('Page title is always UTF-8'));
+ $visitor->setPageCharset('');
+ $visitor->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.5)->getDatetime());
+ $visitor->setUrl('http://example.org/exit-page');
+ self::checkResponse($visitor->doTrackPageView('Page title is always UTF-8'));
- // Test set invalid page char set
- $visitor = self::getTracker($idSite1, $dateTime, $defaultInit = true);
- $visitor->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(1)->getDatetime());
- $visitor->setUrlReferrer('http://anothersite.com/whatever.html');
- $visitor->setUrl('http://example.org/index.htm?random=param&mykwd=a+keyword&test&cats= Search Kategory &search_count=INCORRECT!');
- $visitor->setPageCharset('GTF-42'); // galactic transformation format
- self::checkResponse($visitor->doTrackPageView('Site Search results'));
- $visitor->setPageCharset('');
- }
+ // Test set invalid page char set
+ $visitor = self::getTracker($idSite1, $dateTime, $defaultInit = true);
+ $visitor->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(1)->getDatetime());
+ $visitor->setUrlReferrer('http://anothersite.com/whatever.html');
+ $visitor->setUrl('http://example.org/index.htm?random=param&mykwd=a+keyword&test&cats= Search Kategory &search_count=INCORRECT!');
+ $visitor->setPageCharset('GTF-42'); // galactic transformation format
+ self::checkResponse($visitor->doTrackPageView('Site Search results'));
+ $visitor->setPageCharset('');
+ }
}
diff --git a/tests/PHPUnit/Fixtures/ThreeGoalsOnePageview.php b/tests/PHPUnit/Fixtures/ThreeGoalsOnePageview.php
index 2e95f196d1..7f055f4de6 100644
--- a/tests/PHPUnit/Fixtures/ThreeGoalsOnePageview.php
+++ b/tests/PHPUnit/Fixtures/ThreeGoalsOnePageview.php
@@ -13,38 +13,38 @@
class Test_Piwik_Fixture_ThreeGoalsOnePageview extends Test_Piwik_BaseFixture
{
public $dateTime = '2009-01-04 00:11:42';
- public $idSite = 1;
- public $idGoal = 1;
- public $idGoal2 = 2;
- public $idGoal3 = 3;
-
- public function setUp()
- {
- $this->setUpWebsitesAndGoals();
- $this->trackVisits();
- }
-
- public function tearDown()
- {
- // empty
- }
+ public $idSite = 1;
+ public $idGoal = 1;
+ public $idGoal2 = 2;
+ public $idGoal3 = 3;
+
+ public function setUp()
+ {
+ $this->setUpWebsitesAndGoals();
+ $this->trackVisits();
+ }
+
+ public function tearDown()
+ {
+ // empty
+ }
private function setUpWebsitesAndGoals()
{
self::createWebsite($this->dateTime, $ecommerce = 1);
Piwik_Goals_API::getInstance()->addGoal(
- $this->idSite, 'Goal 1 - Thank you', 'title', 'Thank you', 'contains', $caseSensitive = false,
- $revenue = 10, $allowMultipleConversions = 1
- );
-
+ $this->idSite, 'Goal 1 - Thank you', 'title', 'Thank you', 'contains', $caseSensitive = false,
+ $revenue = 10, $allowMultipleConversions = 1
+ );
+
Piwik_Goals_API::getInstance()->addGoal(
- $this->idSite, 'Goal 2 - Hello', 'url', 'hellow', 'contains', $caseSensitive = false,
- $revenue = 10, $allowMultipleConversions = 0
- );
-
+ $this->idSite, 'Goal 2 - Hello', 'url', 'hellow', 'contains', $caseSensitive = false,
+ $revenue = 10, $allowMultipleConversions = 0
+ );
+
Piwik_Goals_API::getInstance()->addGoal($this->idSite, 'triggered js', 'manually', '', '');
}
-
+
private function trackVisits()
{
$t = self::getTracker($this->idSite, $this->dateTime, $defaultInit = true);
diff --git a/tests/PHPUnit/Fixtures/ThreeSitesWithManyVisitsWithSiteSearch.php b/tests/PHPUnit/Fixtures/ThreeSitesWithManyVisitsWithSiteSearch.php
index 8f02a2d875..ac93543b42 100644
--- a/tests/PHPUnit/Fixtures/ThreeSitesWithManyVisitsWithSiteSearch.php
+++ b/tests/PHPUnit/Fixtures/ThreeSitesWithManyVisitsWithSiteSearch.php
@@ -12,180 +12,180 @@
*/
class Test_Piwik_Fixture_ThreeSitesWithManyVisitsWithSiteSearch extends Test_Piwik_BaseFixture
{
- public $idSite1 = 1;
- public $idSite2 = 2;
- public $idSite3 = 3;
+ public $idSite1 = 1;
+ public $idSite2 = 2;
+ public $idSite3 = 3;
public $dateTime = '2010-01-03 11:22:33';
-
+
public function setUp()
{
self::setUpWebsites();
self::trackVisits();
}
-
+
public function tearDown()
{
- // empty
+ // empty
}
-
- /**
- * One site with custom search parameters,
- * One site using default search parameters,
- * One site with disabled site search
- */
- protected function setUpWebsites()
+
+ /**
+ * One site with custom search parameters,
+ * One site using default search parameters,
+ * One site with disabled site search
+ */
+ protected function setUpWebsites()
{
- Piwik_SitesManager_API::getInstance()->setGlobalSearchParameters($searchKeywordParameters='gkwd', $searchCategoryParameters='gcat');
- self::createWebsite(Piwik_Date::factory($this->dateTime)->subHour(200)->getDatetime(), 0, "Site 1 - Site search", $siteurl=false, $search=1, $searchKwd='q,mykwd,p', $searchCat='cats' );
- self::createWebsite(Piwik_Date::factory($this->dateTime)->subHour(400)->getDatetime(), 0, "Site 2 - Site search use default", $siteurl = false, $search=1, $searchKwd='', $searchCat='' );
- self::createWebsite(Piwik_Date::factory($this->dateTime)->subHour(600)->getDatetime(), 0, "Site 3 - No site search", $siteurl = false, $search=0);
+ Piwik_SitesManager_API::getInstance()->setGlobalSearchParameters($searchKeywordParameters = 'gkwd', $searchCategoryParameters = 'gcat');
+ self::createWebsite(Piwik_Date::factory($this->dateTime)->subHour(200)->getDatetime(), 0, "Site 1 - Site search", $siteurl = false, $search = 1, $searchKwd = 'q,mykwd,p', $searchCat = 'cats');
+ self::createWebsite(Piwik_Date::factory($this->dateTime)->subHour(400)->getDatetime(), 0, "Site 2 - Site search use default", $siteurl = false, $search = 1, $searchKwd = '', $searchCat = '');
+ self::createWebsite(Piwik_Date::factory($this->dateTime)->subHour(600)->getDatetime(), 0, "Site 3 - No site search", $siteurl = false, $search = 0);
}
protected function trackVisits()
{
- $this->recordVisitorsSite1();
- $this->recordVisitorSite2();
- $this->recordVisitorSite3();
+ $this->recordVisitorsSite1();
+ $this->recordVisitorSite2();
+ $this->recordVisitorSite3();
+ }
+
+ protected function recordVisitorsSite1()
+ {
+ // -
+ // Visitor site1
+ $visitor = self::getTracker($this->idSite1, $this->dateTime, $defaultInit = true);
+
+ $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(0.2)->getDatetime());
+ $visitor->setUrl('http://example.org/index.htm?q=Search 1 ');
+ self::checkResponse($visitor->doTrackPageView('Site Search results'));
+
+ // Normal page view
+ $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(0.22)->getDatetime());
+ $visitor->setUrl('http://example.org/index.htm');
+ self::checkResponse($visitor->doTrackPageView('Im just a page'));
+
+ // IS_FOLLOWING_SEARCH: Not this time
+ $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(0.23)->getDatetime());
+ $visitor->setUrl('http://example.org/index.htm?random=PAGEVIEW, NOT SEARCH&mykwd=&IS_FOLLOWING_SEARCH ONCE');
+ self::checkResponse($visitor->doTrackPageView('This is a pageview, not a Search - IS_FOLLOWING_SEARCH ONCE'));
+
+ $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(0.25)->getDatetime());
+ $visitor->setUrl('http://example.org/index.htm?standard=query&but=also#hash&q=' . urlencode('Search 1'));
+ self::checkResponse($visitor->doTrackPageView('Site Search results - URL Fragment'));
+
+ $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(0.26)->getDatetime());
+ $visitor->setUrl('http://example.org/index.htm#q=Search 1&search_count=10');
+ self::checkResponse($visitor->doTrackPageView('Site Search results - URL Fragment'));
+
+ // &search_count=0 so it's a "No Result" keyword, but it will not appear in the report, because it also has other seraches with results
+ // and the archiving does a MAX()
+ $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(0.27)->getDatetime());
+ $visitor->setUrl('http://example.org/index.htm?hello=world#q=Search 1&search_count=0');
+ self::checkResponse($visitor->doTrackPageView('Site Search results - URL Fragment'));
+
+ // Testing with non urlencoded values
+ $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(0.3)->getDatetime());
+ // ALso testing that array[] notation is detected
+ $visitor->setUrl('http://example.org/index.htm?random=param&mykwd[]=Search 2&test&cats= Search Category &search_count=INCORRECT!');
+ self::checkResponse($visitor->doTrackPageView('Site Search results'));
+
+ // Testing with urlencoded values
+ $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(0.32)->getDatetime());
+ // Also testing with random case 'myKwd'
+ $visitor->setUrl('http://example.org/index.htm?random=param&myKwd=Search 1&test&cats=' . urlencode(' Search Category ') . ' &search_count=0');
+ self::checkResponse($visitor->doTrackPageView('Site Search results'));
+
+ // IS_FOLLOWING_SEARCH: Yes
+ $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(0.35)->getDatetime());
+ $visitor->setUrl('http://example.org/index.htm?random=PAGEVIEW, NOT SEARCH&mykwd=&IS_FOLLOWING_SEARCH ONCE');
+ self::checkResponse($visitor->doTrackPageView('This is a pageview, not a Search - IS_FOLLOWING_SEARCH ONCE'));
+
+ $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(0.4)->getDatetime());
+ $visitor->setUrl('http://example.org/index.htm?gkwd=SHOULD be a PageView, NOT a search');
+ self::checkResponse($visitor->doTrackPageView('Pageview, not search'));
+
+ $visitor->setUrl('http://example.org/hello?THIS IS A SITE SEARCH TRACKING API, NOT PAGEVIEW!');
+
+ $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(24.41)->getDatetime());
+ self::checkResponse($visitor->doTrackSiteSearch("Keyword - Tracking API"));
+
+ $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(24.42)->getDatetime());
+ self::checkResponse($visitor->doTrackSiteSearch("Keyword - Tracking API", "Category", $count = 5));
+
+ $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(24.43)->getDatetime());
+ self::checkResponse($visitor->doTrackSiteSearch("No Result Keyword!", "Bad No Result Category :(", $count = 0));
+
+ // Keyword in iso-8859-15 charset with funny character
+ $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(24.5)->getDatetime());
+ $visitor->setPageCharset('iso-8859-15');
+ $visitor->setUrl('http://example.org/index.htm?q=Final%20t%FCte%20Keyword%20Searched%20for%20now&search_count=10');
+ self::checkResponse($visitor->doTrackPageView(false));
+
+ // -
+ // Visitor BIS
+ $visitorB = self::getTracker($this->idSite1, $this->dateTime, $defaultInit = true);
+ $visitorB->setIp('156.66.6.66');
+ $visitorB->setResolution(1600, 1000);
+
+ $visitorB->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(2.26)->getDatetime());
+ $visitorB->setUrl('http://example.org/index.htm#q=' . urlencode('No Result Keyword!') . '&search_count=0');
+ self::checkResponse($visitorB->doTrackPageView('Site Search results - URL Fragment'));
+
+ $visitorB->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(2.27)->getDatetime());
+ $visitorB->setUrl('http://example.org/index.htm?hello=world#q=Search 1&search_count=10');
+ self::checkResponse($visitorB->doTrackPageView('Site Search results - URL Fragment'));
+
+ $visitorB->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(2.3)->getDatetime());
+ $visitorB->setUrl('http://example.org/index.htm?random=param&mykwd=Search 2&test&cats= Search Category &search_count=10');
+ self::checkResponse($visitorB->doTrackPageView('Site Search results'));
+ }
+
+ protected function recordVisitorSite3()
+ { // -
+ // Third new visitor on Idsite 3
+ $visitor = self::getTracker($this->idSite3, $this->dateTime, $defaultInit = true);
+ $visitor->setResolution(1801, 1301);
+
+ $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(0.2)->getDatetime());
+ $visitor->setUrl('http://example.org/index.htm?q=Search 1&IsPageView=1');
+ $visitor->setCustomVariable(1, 'test cvar name', 'test cvar value');
+ self::checkResponse($visitor->doTrackPageView('IsPageView'));
+
+ $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(0.35)->getDatetime());
+ $visitor->setUrl('http://example.org/index.htm?gkwd=test not a keyword&gcat=Cat not but not keyword, so this is not search');
+ self::checkResponse($visitor->doTrackPageView('This is a pageview, not a Search'));
+
+ // Testing UTF8 Title & URL
+ $crazyTitle = '%2C%20%C3%8Dslenska%2C%20Italiano%2C%20%E6%97%A5%E6%9C%AC%E8%AA%9E%2C%20%E1%83%A5%E1%83%90%E1%83%A0%E1%83%97%E1%83%A3%E1%83%9A%E1%83%98%2C%20%ED%95%9C%EA%B5%AD%EC%96%B4%2C%20Lietuvi%C5%B3%2C%20Latvie%C5%A1u%2C%20Norsk%20(bokm%C3%A5l)%2C%20Nederlands%2C%20Norsk%20(nynorsk)%2C%20Polski%2C%20Portugu%C3%AAs%20brasileiro%2C%20Portugu%C3%AAs%2C%20Rom%C3%A2n%C4%83%2C%20%D0%A0%D1%83%D1%81%D1%81%D0%BA%D0%B8%D0%B9%2C%20Slovensky%2C%20Sloven%C5%A1%C4%8Dina%2C%20Shqip%2C%20Srpski%2C%20Svenska%2C%20%E0%B0%A4%E0%B1%86%E0%B0%B2%E0%B1%81%E0%B0%97%E0%B1%81%2C%20%E0%B8%A0%E0%B8%B2%E0%B8%A9%E0%B8%B2%E0%B9%84%E0%B8%97%E0%B8%A2%2C%20T%C3%BCrk%C3%A7e%2C%20%D0%A3%D0%BA%D1%80%D0%B0%D1%97%D0%BD%D1%81%D1%8C%D0%BA%D0%B0%2C%20%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87%2C%20%E7%B9%81%E9%AB%94%E4%B8%AD%E6%96%87.';
+ $visitor->setUrl('http://example.org/index.htm?' . $crazyTitle);
+ self::checkResponse($visitor->doTrackPageView('Pageview: ' . $crazyTitle));
}
- protected function recordVisitorsSite1()
- {
- // -
- // Visitor site1
- $visitor = self::getTracker($this->idSite1, $this->dateTime, $defaultInit = true);
-
- $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(0.2)->getDatetime());
- $visitor->setUrl('http://example.org/index.htm?q=Search 1 ');
- self::checkResponse($visitor->doTrackPageView('Site Search results'));
-
- // Normal page view
- $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(0.22)->getDatetime());
- $visitor->setUrl('http://example.org/index.htm');
- self::checkResponse($visitor->doTrackPageView('Im just a page'));
-
- // IS_FOLLOWING_SEARCH: Not this time
- $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(0.23)->getDatetime());
- $visitor->setUrl('http://example.org/index.htm?random=PAGEVIEW, NOT SEARCH&mykwd=&IS_FOLLOWING_SEARCH ONCE');
- self::checkResponse($visitor->doTrackPageView('This is a pageview, not a Search - IS_FOLLOWING_SEARCH ONCE'));
-
- $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(0.25)->getDatetime());
- $visitor->setUrl('http://example.org/index.htm?standard=query&but=also#hash&q='.urlencode('Search 1'));
- self::checkResponse($visitor->doTrackPageView('Site Search results - URL Fragment'));
-
- $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(0.26)->getDatetime());
- $visitor->setUrl('http://example.org/index.htm#q=Search 1&search_count=10');
- self::checkResponse($visitor->doTrackPageView('Site Search results - URL Fragment'));
-
- // &search_count=0 so it's a "No Result" keyword, but it will not appear in the report, because it also has other seraches with results
- // and the archiving does a MAX()
- $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(0.27)->getDatetime());
- $visitor->setUrl('http://example.org/index.htm?hello=world#q=Search 1&search_count=0');
- self::checkResponse($visitor->doTrackPageView('Site Search results - URL Fragment'));
-
- // Testing with non urlencoded values
- $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(0.3)->getDatetime());
- // ALso testing that array[] notation is detected
- $visitor->setUrl('http://example.org/index.htm?random=param&mykwd[]=Search 2&test&cats= Search Category &search_count=INCORRECT!');
- self::checkResponse($visitor->doTrackPageView('Site Search results'));
-
- // Testing with urlencoded values
- $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(0.32)->getDatetime());
- // Also testing with random case 'myKwd'
- $visitor->setUrl('http://example.org/index.htm?random=param&myKwd=Search 1&test&cats='.urlencode(' Search Category '). ' &search_count=0');
- self::checkResponse($visitor->doTrackPageView('Site Search results'));
-
- // IS_FOLLOWING_SEARCH: Yes
- $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(0.35)->getDatetime());
- $visitor->setUrl('http://example.org/index.htm?random=PAGEVIEW, NOT SEARCH&mykwd=&IS_FOLLOWING_SEARCH ONCE');
- self::checkResponse($visitor->doTrackPageView('This is a pageview, not a Search - IS_FOLLOWING_SEARCH ONCE'));
-
- $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(0.4)->getDatetime());
- $visitor->setUrl('http://example.org/index.htm?gkwd=SHOULD be a PageView, NOT a search');
- self::checkResponse($visitor->doTrackPageView('Pageview, not search'));
-
- $visitor->setUrl('http://example.org/hello?THIS IS A SITE SEARCH TRACKING API, NOT PAGEVIEW!');
-
- $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(24.41)->getDatetime());
- self::checkResponse($visitor->doTrackSiteSearch("Keyword - Tracking API"));
-
- $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(24.42)->getDatetime());
- self::checkResponse($visitor->doTrackSiteSearch("Keyword - Tracking API", "Category", $count = 5));
-
- $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(24.43)->getDatetime());
- self::checkResponse($visitor->doTrackSiteSearch("No Result Keyword!", "Bad No Result Category :(", $count = 0));
-
- // Keyword in iso-8859-15 charset with funny character
- $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(24.5)->getDatetime());
- $visitor->setPageCharset('iso-8859-15');
- $visitor->setUrl('http://example.org/index.htm?q=Final%20t%FCte%20Keyword%20Searched%20for%20now&search_count=10');
- self::checkResponse($visitor->doTrackPageView(false));
-
- // -
- // Visitor BIS
- $visitorB = self::getTracker($this->idSite1, $this->dateTime, $defaultInit = true);
- $visitorB->setIp('156.66.6.66');
- $visitorB->setResolution(1600, 1000);
-
- $visitorB->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(2.26)->getDatetime());
- $visitorB->setUrl('http://example.org/index.htm#q=' . urlencode('No Result Keyword!') . '&search_count=0');
- self::checkResponse($visitorB->doTrackPageView('Site Search results - URL Fragment'));
-
- $visitorB->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(2.27)->getDatetime());
- $visitorB->setUrl('http://example.org/index.htm?hello=world#q=Search 1&search_count=10');
- self::checkResponse($visitorB->doTrackPageView('Site Search results - URL Fragment'));
-
- $visitorB->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(2.3)->getDatetime());
- $visitorB->setUrl('http://example.org/index.htm?random=param&mykwd=Search 2&test&cats= Search Category &search_count=10');
- self::checkResponse($visitorB->doTrackPageView('Site Search results'));
- }
-
- protected function recordVisitorSite3()
- { // -
- // Third new visitor on Idsite 3
- $visitor = self::getTracker($this->idSite3, $this->dateTime, $defaultInit = true);
- $visitor->setResolution(1801, 1301);
-
- $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(0.2)->getDatetime());
- $visitor->setUrl('http://example.org/index.htm?q=Search 1&IsPageView=1');
- $visitor->setCustomVariable(1, 'test cvar name', 'test cvar value');
- self::checkResponse($visitor->doTrackPageView('IsPageView'));
-
- $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(0.35)->getDatetime());
- $visitor->setUrl('http://example.org/index.htm?gkwd=test not a keyword&gcat=Cat not but not keyword, so this is not search');
- self::checkResponse($visitor->doTrackPageView('This is a pageview, not a Search'));
-
- // Testing UTF8 Title & URL
- $crazyTitle = '%2C%20%C3%8Dslenska%2C%20Italiano%2C%20%E6%97%A5%E6%9C%AC%E8%AA%9E%2C%20%E1%83%A5%E1%83%90%E1%83%A0%E1%83%97%E1%83%A3%E1%83%9A%E1%83%98%2C%20%ED%95%9C%EA%B5%AD%EC%96%B4%2C%20Lietuvi%C5%B3%2C%20Latvie%C5%A1u%2C%20Norsk%20(bokm%C3%A5l)%2C%20Nederlands%2C%20Norsk%20(nynorsk)%2C%20Polski%2C%20Portugu%C3%AAs%20brasileiro%2C%20Portugu%C3%AAs%2C%20Rom%C3%A2n%C4%83%2C%20%D0%A0%D1%83%D1%81%D1%81%D0%BA%D0%B8%D0%B9%2C%20Slovensky%2C%20Sloven%C5%A1%C4%8Dina%2C%20Shqip%2C%20Srpski%2C%20Svenska%2C%20%E0%B0%A4%E0%B1%86%E0%B0%B2%E0%B1%81%E0%B0%97%E0%B1%81%2C%20%E0%B8%A0%E0%B8%B2%E0%B8%A9%E0%B8%B2%E0%B9%84%E0%B8%97%E0%B8%A2%2C%20T%C3%BCrk%C3%A7e%2C%20%D0%A3%D0%BA%D1%80%D0%B0%D1%97%D0%BD%D1%81%D1%8C%D0%BA%D0%B0%2C%20%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87%2C%20%E7%B9%81%E9%AB%94%E4%B8%AD%E6%96%87.';
- $visitor->setUrl('http://example.org/index.htm?' . $crazyTitle);
- self::checkResponse($visitor->doTrackPageView('Pageview: ' . $crazyTitle));
- }
-
- protected function recordVisitorSite2()
- {
- $visitor = self::getTracker($this->idSite2, $this->dateTime, $defaultInit = true);
- $visitor->setResolution(801, 301);
-
- $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(0.2)->getDatetime());
- $visitor->setUrl('http://example.org/index.htm?q=Search 1&IsPageView=1');
- self::checkResponse($visitor->doTrackPageView('IsPageView'));
-
- $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(0.35)->getDatetime());
- $visitor->setUrl('http://example.org/index.htm?random=PAGEVIEW, NOT SEARCH&gcat=Cat not but not keyword, so this is not search');
- self::checkResponse($visitor->doTrackPageView('This is a pageview, not a Search'));
-
- $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(0.4)->getDatetime());
- $visitor->setUrl('http://example.org/index.htm?gkwd=SHOULD be a Search with no result!&search_count=0');
- self::checkResponse($visitor->doTrackPageView('This is a Search'));
-
- // Testing UTF8 keywords
- $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(0.45)->getDatetime());
- $crazySearchTerm = 'You%20can%20use%20Piwik%20in%3A%20%E1%8A%A0%E1%88%9B%E1%88%AD%E1%8A%9B%2C%20%D8%A7%D9%84%D8%B9%D8%B1%D8%A8%D9%8A%D8%A9%2C%20%D0%91%D0%B5%D0%BB%D0%B0%D1%80%D1%83%D1%81%D0%BA%D0%B0%D1%8F%2C%20%D0%91%D1%8A%D0%BB%D0%B3%D0%B0%D1%80%D1%81%D0%BA%D0%B8%2C%20Catal%C3%A0%2C%20%C4%8Cesky%2C%20Dansk%2C%20Deutsch%2C%20%CE%95%CE%BB%CE%BB%CE%B7%CE%BD%CE%B9%CE%BA%CE%AC%2C%20English%2C%20Espa%C3%B1ol%2C%20Eesti%20keel%2C%20Euskara%2C%20%D9%81%D8%A7%D8%B1%D8%B3%DB%8C%2C%20Suomi%2C%20Fran%C3%A7ais%2C%20Galego%2C%20%D7%A2%D7%91%D7%A8%D7%99%D7%AA%2C%20Magyar%2C%20Bahasa%20Indonesia%2C%20%C3%8Dslenska%2C%20Italiano%2C%20%E6%97%A5%E6%9C%AC%E8%AA%9E%2C%20%E1%83%A5%E1%83%90%E1%83%A0%E1%83%97%E1%83%A3%E1%83%9A%E1%83%98%2C%20%ED%95%9C%EA%B5%AD%EC%96%B4%2C%20Lietuvi%C5%B3%2C%20Latvie%C5%A1u%2C%20Norsk%20(bokm%C3%A5l)%2C%20Nederlands%2C%20Norsk%20(nynorsk)%2C%20Polski%2C%20Portugu%C3%AAs%20brasileiro%2C%20Portugu%C3%AAs%2C%20Rom%C3%A2n%C4%83%2C%20%D0%A0%D1%83%D1%81%D1%81%D0%BA%D0%B8%D0%B9%2C%20Slovensky%2C%20Sloven%C5%A1%C4%8Dina%2C%20Shqip%2C%20Srpski%2C%20Svenska%2C%20%E0%B0%A4%E0%B1%86%E0%B0%B2%E0%B1%81%E0%B0%97%E0%B1%81%2C%20%E0%B8%A0%E0%B8%B2%E0%B8%A9%E0%B8%B2%E0%B9%84%E0%B8%97%E0%B8%A2%2C%20T%C3%BCrk%C3%A7e%2C%20%D0%A3%D0%BA%D1%80%D0%B0%D1%97%D0%BD%D1%81%D1%8C%D0%BA%D0%B0%2C%20%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87%2C%20%E7%B9%81%E9%AB%94%E4%B8%AD%E6%96%87.';
- $visitor->setUrl('http://example.org/index.htm?gkwd=' . $crazySearchTerm . '&gcat=' . $crazySearchTerm . '&search_count=1');
- self::checkResponse($visitor->doTrackPageView('Site Search with 1 result'));
-
- $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(0.5)->getDatetime());
- self::checkResponse($visitor->doTrackSiteSearch("No Result Keyword!", "Bad No Result Category bis :(", $count = 0));
- return array($defaultInit, $visitor);
- }
+ protected function recordVisitorSite2()
+ {
+ $visitor = self::getTracker($this->idSite2, $this->dateTime, $defaultInit = true);
+ $visitor->setResolution(801, 301);
+
+ $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(0.2)->getDatetime());
+ $visitor->setUrl('http://example.org/index.htm?q=Search 1&IsPageView=1');
+ self::checkResponse($visitor->doTrackPageView('IsPageView'));
+
+ $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(0.35)->getDatetime());
+ $visitor->setUrl('http://example.org/index.htm?random=PAGEVIEW, NOT SEARCH&gcat=Cat not but not keyword, so this is not search');
+ self::checkResponse($visitor->doTrackPageView('This is a pageview, not a Search'));
+
+ $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(0.4)->getDatetime());
+ $visitor->setUrl('http://example.org/index.htm?gkwd=SHOULD be a Search with no result!&search_count=0');
+ self::checkResponse($visitor->doTrackPageView('This is a Search'));
+
+ // Testing UTF8 keywords
+ $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(0.45)->getDatetime());
+ $crazySearchTerm = 'You%20can%20use%20Piwik%20in%3A%20%E1%8A%A0%E1%88%9B%E1%88%AD%E1%8A%9B%2C%20%D8%A7%D9%84%D8%B9%D8%B1%D8%A8%D9%8A%D8%A9%2C%20%D0%91%D0%B5%D0%BB%D0%B0%D1%80%D1%83%D1%81%D0%BA%D0%B0%D1%8F%2C%20%D0%91%D1%8A%D0%BB%D0%B3%D0%B0%D1%80%D1%81%D0%BA%D0%B8%2C%20Catal%C3%A0%2C%20%C4%8Cesky%2C%20Dansk%2C%20Deutsch%2C%20%CE%95%CE%BB%CE%BB%CE%B7%CE%BD%CE%B9%CE%BA%CE%AC%2C%20English%2C%20Espa%C3%B1ol%2C%20Eesti%20keel%2C%20Euskara%2C%20%D9%81%D8%A7%D8%B1%D8%B3%DB%8C%2C%20Suomi%2C%20Fran%C3%A7ais%2C%20Galego%2C%20%D7%A2%D7%91%D7%A8%D7%99%D7%AA%2C%20Magyar%2C%20Bahasa%20Indonesia%2C%20%C3%8Dslenska%2C%20Italiano%2C%20%E6%97%A5%E6%9C%AC%E8%AA%9E%2C%20%E1%83%A5%E1%83%90%E1%83%A0%E1%83%97%E1%83%A3%E1%83%9A%E1%83%98%2C%20%ED%95%9C%EA%B5%AD%EC%96%B4%2C%20Lietuvi%C5%B3%2C%20Latvie%C5%A1u%2C%20Norsk%20(bokm%C3%A5l)%2C%20Nederlands%2C%20Norsk%20(nynorsk)%2C%20Polski%2C%20Portugu%C3%AAs%20brasileiro%2C%20Portugu%C3%AAs%2C%20Rom%C3%A2n%C4%83%2C%20%D0%A0%D1%83%D1%81%D1%81%D0%BA%D0%B8%D0%B9%2C%20Slovensky%2C%20Sloven%C5%A1%C4%8Dina%2C%20Shqip%2C%20Srpski%2C%20Svenska%2C%20%E0%B0%A4%E0%B1%86%E0%B0%B2%E0%B1%81%E0%B0%97%E0%B1%81%2C%20%E0%B8%A0%E0%B8%B2%E0%B8%A9%E0%B8%B2%E0%B9%84%E0%B8%97%E0%B8%A2%2C%20T%C3%BCrk%C3%A7e%2C%20%D0%A3%D0%BA%D1%80%D0%B0%D1%97%D0%BD%D1%81%D1%8C%D0%BA%D0%B0%2C%20%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87%2C%20%E7%B9%81%E9%AB%94%E4%B8%AD%E6%96%87.';
+ $visitor->setUrl('http://example.org/index.htm?gkwd=' . $crazySearchTerm . '&gcat=' . $crazySearchTerm . '&search_count=1');
+ self::checkResponse($visitor->doTrackPageView('Site Search with 1 result'));
+
+ $visitor->setForceVisitDateTime(Piwik_Date::factory($this->dateTime)->addHour(0.5)->getDatetime());
+ self::checkResponse($visitor->doTrackSiteSearch("No Result Keyword!", "Bad No Result Category bis :(", $count = 0));
+ return array($defaultInit, $visitor);
+ }
}
diff --git a/tests/PHPUnit/Fixtures/TwoSitesEcommerceOrderWithItems.php b/tests/PHPUnit/Fixtures/TwoSitesEcommerceOrderWithItems.php
index 543b2e29f4..2000580da8 100644
--- a/tests/PHPUnit/Fixtures/TwoSitesEcommerceOrderWithItems.php
+++ b/tests/PHPUnit/Fixtures/TwoSitesEcommerceOrderWithItems.php
@@ -11,44 +11,44 @@
*/
class Test_Piwik_Fixture_TwoSitesEcommerceOrderWithItems extends Test_Piwik_BaseFixture
{
- public $dateTime = '2011-04-05 00:11:42';
- public $idSite = 1;
- public $idSite2 = 2;
+ public $dateTime = '2011-04-05 00:11:42';
+ public $idSite = 1;
+ public $idSite2 = 2;
public $idGoalStandard = 1;
-
+
public function setUp()
{
$this->setUpWebsitesAndGoals();
- self::setUpScheduledReports($this->idSite);
+ self::setUpScheduledReports($this->idSite);
$this->trackVisits();
}
-
+
public function tearDown()
{
- // empty
+ // empty
}
-
+
private function setUpWebsitesAndGoals()
{
self::createWebsite($this->dateTime, $ecommerce = 1);
self::createWebsite($this->dateTime);
Piwik_Goals_API::getInstance()->addGoal(
- $this->idSite, 'title match, triggered ONCE', 'title', 'incredible', 'contains',
- $caseSensitive = false, $revenue = 10, $allowMultipleConversions = true
- );
+ $this->idSite, 'title match, triggered ONCE', 'title', 'incredible', 'contains',
+ $caseSensitive = false, $revenue = 10, $allowMultipleConversions = true
+ );
}
private function trackVisits()
{
$dateTime = $this->dateTime;
- $idSite = $this->idSite;
- $idSite2 = $this->idSite2;
+ $idSite = $this->idSite;
+ $idSite2 = $this->idSite2;
$t = self::getTracker($idSite, $dateTime, $defaultInit = true);
// VISIT NO 1
$t->setUrl('http://example.org/index.htm');
$category = 'Electronics & Cameras';
- $price = 1111.11111;
+ $price = 1111.11111;
// VIEW product page
$t->setEcommerceView('SKU2', 'PRODUCT name', $category, $price);
@@ -118,7 +118,7 @@ class Test_Piwik_Fixture_TwoSitesEcommerceOrderWithItems extends Test_Piwik_Base
// This is a frequent use case: ecommerce shops tracking the order from backoffice
// without passing the custom variable 1st party cookie along since it's not known by back office
$visitorCustomVarSave = $t->visitorCustomVar;
- $t->visitorCustomVar = false;
+ $t->visitorCustomVar = false;
self::checkResponse($t->doTrackEcommerceOrder($orderId = '1037nsjusu4s3894', $grandTotal = 2000, $subTotal = 1500, $tax = 400, $shipping = 100, $discount = 0));
$t->visitorCustomVar = $visitorCustomVarSave;
diff --git a/tests/PHPUnit/Fixtures/TwoSitesManyVisitsOverSeveralDaysWithSearchEngineReferrers.php b/tests/PHPUnit/Fixtures/TwoSitesManyVisitsOverSeveralDaysWithSearchEngineReferrers.php
index f03a086390..faf3d45696 100644
--- a/tests/PHPUnit/Fixtures/TwoSitesManyVisitsOverSeveralDaysWithSearchEngineReferrers.php
+++ b/tests/PHPUnit/Fixtures/TwoSitesManyVisitsOverSeveralDaysWithSearchEngineReferrers.php
@@ -20,79 +20,78 @@ class Test_Piwik_Fixture_TwoSitesManyVisitsOverSeveralDaysWithSearchEngineReferr
'peace "," not war', // testing a keyword containing ,
'justice )(&^#%$ NOT corruption!',
);
-
+
public function setUp()
{
$this->setUpWebsitesAndGoals();
$this->trackVisits();
}
-
+
public function tearDown()
{
- // empty
+ // empty
}
private function setUpWebsitesAndGoals()
{
- $siteCreated = '2010-02-01 11:22:33';
-
+ $siteCreated = '2010-02-01 11:22:33';
+
self::createWebsite($siteCreated);
- Piwik_Goals_API::getInstance()->addGoal($this->idSite, 'triggered php', 'manually', '', '');
- Piwik_Goals_API::getInstance()->addGoal(
- $this->idSite, 'another triggered php', 'manually', '', '', false, false, true);
-
- self::createWebsite($siteCreated);
- }
+ Piwik_Goals_API::getInstance()->addGoal($this->idSite, 'triggered php', 'manually', '', '');
+ Piwik_Goals_API::getInstance()->addGoal(
+ $this->idSite, 'another triggered php', 'manually', '', '', false, false, true);
+
+ self::createWebsite($siteCreated);
+ }
private function trackVisits()
{
$dateTime = $this->today;
- $idSite = $this->idSite;
- $idSite2 = $this->idSite2;
-
+ $idSite = $this->idSite;
+ $idSite2 = $this->idSite2;
+
$mozillaUserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; fr; rv:1.9.1.6) Gecko/20100101 Firefox/6.0";
$operaUserAgent = "Opera/9.80 (iPod; U; CPU iPhone OS 4_3_3 like Mac OS X; ja-jp) Presto/2.9.181 Version/12.00";
- $t = self::getTracker($idSite, $dateTime, $defaultInit = true);
- $t->setTokenAuth(self::getTokenAuth());
- $t->enableBulkTracking();
- for ($daysIntoPast = 30; $daysIntoPast >= 0; $daysIntoPast--)
- {
+ $t = self::getTracker($idSite, $dateTime, $defaultInit = true);
+ $t->setTokenAuth(self::getTokenAuth());
+ $t->enableBulkTracking();
+ for ($daysIntoPast = 30; $daysIntoPast >= 0; $daysIntoPast--) {
// Visit 1: referrer website + test page views
$visitDateTime = Piwik_Date::factory($dateTime)->subDay($daysIntoPast)->getDatetime();
-
+
$t->setNewVisitorId();
$t->setIdSite($idSite);
$t->setUserAgent($mozillaUserAgent);
-
+
$t->setUrlReferrer('http://www.referrer' . ($daysIntoPast % 5) . '.com/theReferrerPage' . ($daysIntoPast % 2) . '.html');
$t->setUrl('http://example.org/my/dir/page' . ($daysIntoPast % 4) . '?foo=bar&baz=bar');
$t->setForceVisitDateTime($visitDateTime);
- $t->setGenerationTime($daysIntoPast * 100 + 100);
+ $t->setGenerationTime($daysIntoPast * 100 + 100);
self::assertTrue($t->doTrackPageView('incredible title ' . ($daysIntoPast % 3)));
- // Trigger goal n°1 once
- self::assertTrue($t->doTrackGoal(1));
+ // Trigger goal n°1 once
+ self::assertTrue($t->doTrackGoal(1));
- // Trigger goal n°2 twice
- self::assertTrue($t->doTrackGoal(2));
- $t->setForceVisitDateTime(Piwik_Date::factory($visitDateTime)->addHour(0.1)->getDatetime());
- self::assertTrue($t->doTrackGoal(2));
+ // Trigger goal n°2 twice
+ self::assertTrue($t->doTrackGoal(2));
+ $t->setForceVisitDateTime(Piwik_Date::factory($visitDateTime)->addHour(0.1)->getDatetime());
+ self::assertTrue($t->doTrackGoal(2));
// VISIT 2: search engine
$t->setForceVisitDateTime(Piwik_Date::factory($visitDateTime)->addHour(3)->getDatetime());
$t->setUrlReferrer('http://google.com/search?q=' . urlencode($this->keywords[$daysIntoPast % 3]));
- $t->setGenerationTime($daysIntoPast * 100 + 200);
+ $t->setGenerationTime($daysIntoPast * 100 + 200);
self::assertTrue($t->doTrackPageView('not an incredible title '));
-
+
// VISIT 1 for idSite = 2
$t->setIdSite($idSite2);
$t->setNewVisitorId();
$t->setUserAgent($daysIntoPast % 2 == 0 ? $mozillaUserAgent : $operaUserAgent);
-
+
$t->setForceVisitDateTime($visitDateTime);
$t->setUrl('http://example.org/');
- $t->setGenerationTime($daysIntoPast * 100 + 300);
+ $t->setGenerationTime($daysIntoPast * 100 + 300);
self::assertTrue($t->doTrackPageView('so-so page title'));
}
self::checkResponse($t->doBulkTrack());
diff --git a/tests/PHPUnit/Fixtures/TwoSitesTwoVisitorsDifferentDays.php b/tests/PHPUnit/Fixtures/TwoSitesTwoVisitorsDifferentDays.php
index b5ae0fad67..ccfb6ca509 100644
--- a/tests/PHPUnit/Fixtures/TwoSitesTwoVisitorsDifferentDays.php
+++ b/tests/PHPUnit/Fixtures/TwoSitesTwoVisitorsDifferentDays.php
@@ -16,21 +16,21 @@ class Test_Piwik_Fixture_TwoSitesTwoVisitorsDifferentDays extends Test_Piwik_Bas
public $idGoal1 = 1;
public $idGoal2 = 2;
public $dateTime = '2010-01-03 11:22:33';
-
+
public $allowConversions = false;
-
+
public function setUp()
{
$this->setUpWebsitesAndGoals();
- self::setUpScheduledReports($this->idSite1);
+ self::setUpScheduledReports($this->idSite1);
$this->trackVisits();
}
-
+
public function tearDown()
{
- // empty
+ // empty
}
-
+
private function setUpWebsitesAndGoals()
{
// tests run in UTC, the Tracker in UTC
@@ -43,46 +43,46 @@ class Test_Piwik_Fixture_TwoSitesTwoVisitorsDifferentDays extends Test_Piwik_Bas
Piwik_Goals_API::getInstance()->addGoal($this->idSite1, 'all', 'url', 'http', 'contains', false, 5);
Piwik_Goals_API::getInstance()->addGoal($this->idSite2, 'all', 'url', 'http', 'contains');
}
-
+
Piwik_SitesManager_API::getInstance()->updateSite(
- $this->idSite1, "Site 1", $urls = null, $ecommerce = null, $siteSearch = null,
- $searchKeywordParameters = null, $searchCategoryParameters = null, $excludedIps = null,
- $excludedQueryParameters = null, $timezone = null, $currency = null, $group = null,
- $startDate = null, $excludedUserAgents = null, $keepURLFragments = 2); // KEEP_URL_FRAGMENT_NO No for idSite 1
+ $this->idSite1, "Site 1", $urls = null, $ecommerce = null, $siteSearch = null,
+ $searchKeywordParameters = null, $searchCategoryParameters = null, $excludedIps = null,
+ $excludedQueryParameters = null, $timezone = null, $currency = null, $group = null,
+ $startDate = null, $excludedUserAgents = null, $keepURLFragments = 2); // KEEP_URL_FRAGMENT_NO No for idSite 1
Piwik_SitesManager_API::getInstance()->updateSite(
- $this->idSite2, "Site 2", $urls = null, $ecommerce = null, $siteSearch = null,
- $searchKeywordParameters = null, $searchCategoryParameters = null, $excludedIps = null,
- $excludedQueryParameters = null, $timezone = null, $currency = null, $group = null,
- $startDate = null, $excludedUserAgents = null, $keepURLFragments = 1); // KEEP_URL_FRAGMENT_YES Yes for idSite 2
+ $this->idSite2, "Site 2", $urls = null, $ecommerce = null, $siteSearch = null,
+ $searchKeywordParameters = null, $searchCategoryParameters = null, $excludedIps = null,
+ $excludedQueryParameters = null, $timezone = null, $currency = null, $group = null,
+ $startDate = null, $excludedUserAgents = null, $keepURLFragments = 1); // KEEP_URL_FRAGMENT_YES Yes for idSite 2
}
private function trackVisits()
{
$dateTime = $this->dateTime;
- $idSite = $this->idSite1;
- $idSite2 = $this->idSite2;
+ $idSite = $this->idSite1;
+ $idSite2 = $this->idSite2;
// -
// First visitor on Idsite 1: two page views
$datetimeSpanOverTwoDays = '2010-01-03 23:55:00';
- $visitorA = self::getTracker($idSite, $datetimeSpanOverTwoDays, $defaultInit = true);
+ $visitorA = self::getTracker($idSite, $datetimeSpanOverTwoDays, $defaultInit = true);
$visitorA->setUrlReferrer('http://referer.com/page.htm?param=valuewith some spaces');
$visitorA->setUrl('http://example.org/index.htm#ignoredFragment');
$visitorA->DEBUG_APPEND_URL = '&_idts=' . Piwik_Date::factory($datetimeSpanOverTwoDays)->getTimestamp();
- $visitorA->setGenerationTime(123);
+ $visitorA->setGenerationTime(123);
self::checkResponse($visitorA->doTrackPageView('first page view'));
$visitorA->setForceVisitDateTime(Piwik_Date::factory($datetimeSpanOverTwoDays)->addHour(0.1)->getDatetime());
// testing with empty URL and empty page title
$visitorA->setUrl(' ');
- $visitorA->setGenerationTime(223);
+ $visitorA->setGenerationTime(223);
self::checkResponse($visitorA->doTrackPageView(' '));
// -
// Second new visitor on Idsite 1: one page view
$visitorB = self::getTracker($idSite, $dateTime, $defaultInit = true);
$visitorB->enableBulkTracking();
- $visitorB->setTokenAuth(self::getTokenAuth());
+ $visitorB->setTokenAuth(self::getTokenAuth());
$visitorB->setIp('100.52.156.83');
$visitorB->setResolution(800, 300);
$visitorB->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(1)->getDatetime());
@@ -90,7 +90,7 @@ class Test_Piwik_Fixture_TwoSitesTwoVisitorsDifferentDays extends Test_Piwik_Bas
$visitorB->setUserAgent('Opera/9.63 (Windows NT 5.1; U; en) Presto/2.1.1');
$visitorB->setUrl('http://example.org/products');
$visitorB->DEBUG_APPEND_URL = '&_idts=' . Piwik_Date::factory($dateTime)->addHour(1)->getTimestamp();
- $visitorB->setGenerationTime(153);
+ $visitorB->setGenerationTime(153);
self::assertTrue($visitorB->doTrackPageView('first page view'));
// -
@@ -102,12 +102,12 @@ class Test_Piwik_Fixture_TwoSitesTwoVisitorsDifferentDays extends Test_Piwik_Bas
$visitorB->setUrlReferrer('http://referer.com/Other_Page.htm');
$visitorB->setUrl('http://example.org/index.htm');
- $visitorB->setGenerationTime(323);
+ $visitorB->setGenerationTime(323);
self::assertTrue($visitorB->doTrackPageView('second visitor/two days later/a new visit'));
// Second page view 6 minutes later
$visitorB->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(48)->addHour(0.1)->getDatetime());
$visitorB->setUrl('http://example.org/thankyou');
- $visitorB->setGenerationTime(173);
+ $visitorB->setGenerationTime(173);
self::assertTrue($visitorB->doTrackPageView('second visitor/two days later/second page view'));
// testing a strange combination causing an error in r3767
@@ -118,7 +118,7 @@ class Test_Piwik_Fixture_TwoSitesTwoVisitorsDifferentDays extends Test_Piwik_Bas
// Actions.getPageTitle tested with this title
$visitorB->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(48)->addHour(0.25)->getDatetime());
- $visitorB->setGenerationTime(452);
+ $visitorB->setGenerationTime(452);
self::assertTrue($visitorB->doTrackPageView('Checkout / Purchasing...'));
self::checkResponse($visitorB->doBulkTrack());
@@ -129,12 +129,12 @@ class Test_Piwik_Fixture_TwoSitesTwoVisitorsDifferentDays extends Test_Piwik_Bas
$visitorAsite2->setUrlReferrer('http://only-homepage-referer.com/');
$visitorAsite2->setUrl('http://example2.com/home#notIgnoredFragment#');
$visitorAsite2->DEBUG_APPEND_URL = '&_idts=' . Piwik_Date::factory($dateTime)->addHour(24)->getTimestamp();
- $visitorAsite2->setGenerationTime(193);
+ $visitorAsite2->setGenerationTime(193);
self::checkResponse($visitorAsite2->doTrackPageView('Website 2 page view'));
// test with invalid URL
$visitorAsite2->setUrl('this is invalid url');
// and an empty title
- $visitorAsite2->setGenerationTime(203);
+ $visitorAsite2->setGenerationTime(203);
self::checkResponse($visitorAsite2->doTrackPageView(''));
}
}
diff --git a/tests/PHPUnit/Fixtures/TwoSitesVisitsInPast.php b/tests/PHPUnit/Fixtures/TwoSitesVisitsInPast.php
index 2584eb8b46..d476bb7933 100644
--- a/tests/PHPUnit/Fixtures/TwoSitesVisitsInPast.php
+++ b/tests/PHPUnit/Fixtures/TwoSitesVisitsInPast.php
@@ -18,17 +18,17 @@ class Test_Piwik_Fixture_TwoSitesVisitsInPast extends Test_Piwik_BaseFixture
public $idSite = 1;
public $idSite2 = 2;
- public function setUp()
- {
+ public function setUp()
+ {
$this->setUpWebsitesAndGoals();
$this->trackVisits();
- }
-
- public function tearDown()
- {
- // empty
- }
-
+ }
+
+ public function tearDown()
+ {
+ // empty
+ }
+
public function setUpWebsitesAndGoals()
{
self::createWebsite($this->dateTimeFirstDateWebsite1);
diff --git a/tests/PHPUnit/Fixtures/TwoSitesWithAnnotations.php b/tests/PHPUnit/Fixtures/TwoSitesWithAnnotations.php
index 19d03b78e5..af5efd26be 100644
--- a/tests/PHPUnit/Fixtures/TwoSitesWithAnnotations.php
+++ b/tests/PHPUnit/Fixtures/TwoSitesWithAnnotations.php
@@ -11,61 +11,60 @@
*/
class Test_Piwik_Fixture_TwoSitesWithAnnotations extends Test_Piwik_BaseFixture
{
- public $dateTime = '2011-01-01 00:11:42';
- public $idSite1 = 1;
- public $idSite2 = 2;
-
- public function setUp()
- {
- $this->setUpWebsitesAndGoals();
- $this->addAnnotations();
- }
-
- public function tearDown()
- {
- // empty
- }
-
- private function addAnnotations()
- {
- // create fake access for fake username
- $access = new FakeAccess();
- FakeAccess::$superUser = true;
- Zend_Registry::set('access', $access);
-
- // add two annotations per week for three months, starring every third annotation
- // first month in 2011, second two in 2012
- $count = 0;
- $dateStart = Piwik_Date::factory('2011-12-01');
- $dateEnd = Piwik_Date::factory('2012-03-01');
- while ($dateStart->getTimestamp() < $dateEnd->getTimestamp())
- {
- $starred = $count % 3 == 0 ? 1 : 0;
- $site1Text = "$count: Site 1 annotation for ".$dateStart->toString();
- $site2Text = "$count: Site 2 annotation for ".$dateStart->toString();
-
- Piwik_Annotations_API::getInstance()->add($this->idSite1, $dateStart->toString(), $site1Text, $starred);
- Piwik_Annotations_API::getInstance()->add($this->idSite2, $dateStart->toString(), $site2Text, $starred);
-
- $nextDay = $dateStart->addDay(1);
- ++$count;
-
- $starred = $count % 3 == 0 ? 1 : 0;
- $site1Text = "$count: Site 1 annotation for ".$nextDay->toString();
- $site2Text = "$count: Site 2 annotation for ".$nextDay->toString();
-
- Piwik_Annotations_API::getInstance()->add($this->idSite1, $nextDay->toString(), $site1Text, $starred);
- Piwik_Annotations_API::getInstance()->add($this->idSite2, $nextDay->toString(), $site2Text, $starred);
-
- $dateStart = $dateStart->addPeriod(1, 'WEEK');
- ++$count;
- }
- }
-
- private function setUpWebsitesAndGoals()
- {
- // add two websites
- self::createWebsite($this->dateTime, $ecommerce = 1);
- self::createWebsite($this->dateTime, $ecommerce = 1);
- }
+ public $dateTime = '2011-01-01 00:11:42';
+ public $idSite1 = 1;
+ public $idSite2 = 2;
+
+ public function setUp()
+ {
+ $this->setUpWebsitesAndGoals();
+ $this->addAnnotations();
+ }
+
+ public function tearDown()
+ {
+ // empty
+ }
+
+ private function addAnnotations()
+ {
+ // create fake access for fake username
+ $access = new FakeAccess();
+ FakeAccess::$superUser = true;
+ Zend_Registry::set('access', $access);
+
+ // add two annotations per week for three months, starring every third annotation
+ // first month in 2011, second two in 2012
+ $count = 0;
+ $dateStart = Piwik_Date::factory('2011-12-01');
+ $dateEnd = Piwik_Date::factory('2012-03-01');
+ while ($dateStart->getTimestamp() < $dateEnd->getTimestamp()) {
+ $starred = $count % 3 == 0 ? 1 : 0;
+ $site1Text = "$count: Site 1 annotation for " . $dateStart->toString();
+ $site2Text = "$count: Site 2 annotation for " . $dateStart->toString();
+
+ Piwik_Annotations_API::getInstance()->add($this->idSite1, $dateStart->toString(), $site1Text, $starred);
+ Piwik_Annotations_API::getInstance()->add($this->idSite2, $dateStart->toString(), $site2Text, $starred);
+
+ $nextDay = $dateStart->addDay(1);
+ ++$count;
+
+ $starred = $count % 3 == 0 ? 1 : 0;
+ $site1Text = "$count: Site 1 annotation for " . $nextDay->toString();
+ $site2Text = "$count: Site 2 annotation for " . $nextDay->toString();
+
+ Piwik_Annotations_API::getInstance()->add($this->idSite1, $nextDay->toString(), $site1Text, $starred);
+ Piwik_Annotations_API::getInstance()->add($this->idSite2, $nextDay->toString(), $site2Text, $starred);
+
+ $dateStart = $dateStart->addPeriod(1, 'WEEK');
+ ++$count;
+ }
+ }
+
+ private function setUpWebsitesAndGoals()
+ {
+ // add two websites
+ self::createWebsite($this->dateTime, $ecommerce = 1);
+ self::createWebsite($this->dateTime, $ecommerce = 1);
+ }
}
diff --git a/tests/PHPUnit/Fixtures/TwoVisitsNoKeywordWithBot.php b/tests/PHPUnit/Fixtures/TwoVisitsNoKeywordWithBot.php
index afb73d687d..a0cf6d8128 100644
--- a/tests/PHPUnit/Fixtures/TwoVisitsNoKeywordWithBot.php
+++ b/tests/PHPUnit/Fixtures/TwoVisitsNoKeywordWithBot.php
@@ -13,19 +13,19 @@
class Test_Piwik_Fixture_TwoVisitsNoKeywordWithBot extends Test_Piwik_BaseFixture
{
public $dateTime = '2010-03-06 11:22:33';
- public $idSite = 1;
-
+ public $idSite = 1;
+
public function setUp()
{
$this->setUpWebsitesAndGoals();
$this->trackVisits();
}
-
+
public function tearDown()
{
- // empty
+ // empty
}
-
+
private function setUpWebsitesAndGoals()
{
self::createWebsite($this->dateTime);
@@ -35,8 +35,8 @@ class Test_Piwik_Fixture_TwoVisitsNoKeywordWithBot extends Test_Piwik_BaseFixtur
{
// tests run in UTC, the Tracker in UTC
$dateTime = $this->dateTime;
- $idSite = $this->idSite;
- $t = self::getTracker($idSite, $dateTime, $defaultInit = true, $useThirdPartyCookie = 1);
+ $idSite = $this->idSite;
+ $t = self::getTracker($idSite, $dateTime, $defaultInit = true, $useThirdPartyCookie = 1);
// Also testing to record this as a bot while specifically allowing bots
$t->setUserAgent('Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)');
@@ -56,7 +56,7 @@ class Test_Piwik_Fixture_TwoVisitsNoKeywordWithBot extends Test_Piwik_BaseFixtur
$t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(2)->getDatetime());
$t->setUrlReferrer('http://www.google.com.vn/url?sa=t&rct=j&q=%3C%3E%26%5C%22the%20pdo%20extension%20is%20required%20for%20this%20adapter%20but%20the%20extension%20is%20not%20loaded&source=web&cd=4&ved=0FjAD&url=http%3A%2F%2Fforum.piwik.org%2Fread.php%3F2%2C1011&ei=y-HHAQ&usg=AFQjCN2-nt5_GgDeg&cad=rja');
- // Test with empty title, that the output of Live is valid
+ // Test with empty title, that the output of Live is valid
self::checkResponse($t->doTrackPageView(''));
}
diff --git a/tests/PHPUnit/Fixtures/TwoVisitsWithCustomVariables.php b/tests/PHPUnit/Fixtures/TwoVisitsWithCustomVariables.php
index 12aa1b6213..070d266ecf 100644
--- a/tests/PHPUnit/Fixtures/TwoVisitsWithCustomVariables.php
+++ b/tests/PHPUnit/Fixtures/TwoVisitsWithCustomVariables.php
@@ -11,29 +11,29 @@
*/
class Test_Piwik_Fixture_TwoVisitsWithCustomVariables extends Test_Piwik_BaseFixture
{
- public $dateTime = '2010-01-03 11:22:33';
- public $idSite = 1;
- public $idGoal1 = 1;
- public $idGoal2 = 2;
+ public $dateTime = '2010-01-03 11:22:33';
+ public $idSite = 1;
+ public $idGoal1 = 1;
+ public $idGoal2 = 2;
public $visitorId = '61e8cc2d51fea26d';
- public $useEscapedQuotes = true;
+ public $useEscapedQuotes = true;
public $doExtraQuoteTests = true;
- public $resolutionWidthToUse = 1111;
- public $resolutionHeightToUse = 222;
-
- public function setUp()
- {
- $this->setUpWebsitesAndGoals();
- $this->trackVisits();
- }
-
- public function tearDown()
- {
- // empty
- }
-
+ public $resolutionWidthToUse = 1111;
+ public $resolutionHeightToUse = 222;
+
+ public function setUp()
+ {
+ $this->setUpWebsitesAndGoals();
+ $this->trackVisits();
+ }
+
+ public function tearDown()
+ {
+ // empty
+ }
+
private function setUpWebsitesAndGoals()
{
// tests run in UTC, the Tracker in UTC
@@ -45,9 +45,9 @@ class Test_Piwik_Fixture_TwoVisitsWithCustomVariables extends Test_Piwik_BaseFix
private function trackVisits()
{
$dateTime = $this->dateTime;
- $idSite = $this->idSite;
- $idGoal = $this->idGoal1;
- $idGoal2 = $this->idGoal2;
+ $idSite = $this->idSite;
+ $idGoal = $this->idGoal1;
+ $idGoal2 = $this->idGoal2;
$visitorA = self::getTracker($this->idSite, $this->dateTime, $defaultInit = true);
// Used to test actual referer + keyword position in Live!
@@ -105,9 +105,8 @@ class Test_Piwik_Fixture_TwoVisitsWithCustomVariables extends Test_Piwik_BaseFix
// -
// Second new visitor on Idsite 1: one page view
$visitorB = self::getTracker($idSite, $dateTime, $defaultInit = true);
- if (!empty($this->visitorId))
- {
- $visitorB->setVisitorId($this->visitorId);
+ if (!empty($this->visitorId)) {
+ $visitorB->setVisitorId($this->visitorId);
}
$visitorB->setUrlReferrer('');
diff --git a/tests/PHPUnit/Fixtures/VisitsOverSeveralDays.php b/tests/PHPUnit/Fixtures/VisitsOverSeveralDays.php
index ded57b1057..e53db1ace5 100644
--- a/tests/PHPUnit/Fixtures/VisitsOverSeveralDays.php
+++ b/tests/PHPUnit/Fixtures/VisitsOverSeveralDays.php
@@ -7,7 +7,7 @@
*/
/**
- * Adds one website and tracks several visits from one visitor on
+ * Adds one website and tracks several visits from one visitor on
* different days that span about a month apart.
*/
class Test_Piwik_Fixture_VisitsOverSeveralDays extends Test_Piwik_BaseFixture
@@ -19,45 +19,45 @@ class Test_Piwik_Fixture_VisitsOverSeveralDays extends Test_Piwik_BaseFixture
'2011-01-15 01:00:00',
'2011-01-16 01:00:00',
);
-
- public $idSite = 1;
- public $idSite2 = 2;
-
+
+ public $idSite = 1;
+ public $idSite2 = 2;
+
// one per visit
public $referrerUrls = array(
- 'http://facebook.com/whatever',
- 'http://www.facebook.com/another/path',
- 'http://fb.me/?q=sdlfjs&n=slfjsd',
- 'http://twitter.com/whatever2',
- 'http://www.twitter.com/index?a=2334',
- 'http://t.co/id/?y=dsfs',
- 'http://www.flickr.com',
- 'http://xanga.com',
- 'http://skyrock.com',
- 'http://mixi.jp',
+ 'http://facebook.com/whatever',
+ 'http://www.facebook.com/another/path',
+ 'http://fb.me/?q=sdlfjs&n=slfjsd',
+ 'http://twitter.com/whatever2',
+ 'http://www.twitter.com/index?a=2334',
+ 'http://t.co/id/?y=dsfs',
+ 'http://www.flickr.com',
+ 'http://xanga.com',
+ 'http://skyrock.com',
+ 'http://mixi.jp',
);
-
+
public function setUp()
{
$this->setUpWebsitesAndGoals();
$this->trackVisits();
}
-
+
public function tearDown()
{
- // empty
+ // empty
}
-
+
private function setUpWebsitesAndGoals()
{
- self::createWebsite($this->dateTimes[0], $ecommerce = 0, $siteName = 'Site AAAAAA');
- self::createWebsite($this->dateTimes[0], $ecommerce = 0, $siteName = 'SITE BBbbBB');
+ self::createWebsite($this->dateTimes[0], $ecommerce = 0, $siteName = 'Site AAAAAA');
+ self::createWebsite($this->dateTimes[0], $ecommerce = 0, $siteName = 'SITE BBbbBB');
}
private function trackVisits()
{
$dateTimes = $this->dateTimes;
- $idSite = $this->idSite;
+ $idSite = $this->idSite;
$i = 0;
$ridx = 0;
@@ -85,14 +85,14 @@ class Test_Piwik_Fixture_VisitsOverSeveralDays extends Test_Piwik_BaseFixture
self::checkResponse($visitor->doTrackPageView('ou pas'));
- if($i <= 3 ) {
+ if ($i <= 3) {
- $visitor = self::getTracker($this->idSite2, $dateTime, $defaultInit = true);
- $visitor->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.1)->getDatetime());
- $visitor->setUrl('http://example.org/homepage');
- $visitor->setUrlReferrer($this->referrerUrls[$ridx-1]);
- self::checkResponse($visitor->doTrackPageView('Second website'));
- }
+ $visitor = self::getTracker($this->idSite2, $dateTime, $defaultInit = true);
+ $visitor->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.1)->getDatetime());
+ $visitor->setUrl('http://example.org/homepage');
+ $visitor->setUrlReferrer($this->referrerUrls[$ridx - 1]);
+ self::checkResponse($visitor->doTrackPageView('Second website'));
+ }
}
}
}
diff --git a/tests/PHPUnit/Integration/AnnotationsTest.php b/tests/PHPUnit/Integration/AnnotationsTest.php
index 112732731c..256f401eaa 100755
--- a/tests/PHPUnit/Integration/AnnotationsTest.php
+++ b/tests/PHPUnit/Integration/AnnotationsTest.php
@@ -8,355 +8,319 @@
class AnnotationsTest extends IntegrationTestCase
{
- public static $fixture = null;
-
- public function getOutputPrefix()
- {
- return 'annotations';
- }
-
- public function getApiForTesting()
- {
- $idSite1 = self::$fixture->idSite1;
- $idSite2 = self::$fixture->idSite2;
-
- return array(
-
- // get
- array('Annotations.get', array('idSite' => $idSite1,
- 'date' => '2012-01-01',
- 'periods' => 'day',
- 'otherRequestParameters' => array('idNote' => 1))),
-
- // getAll
- array('Annotations.getAll', array('idSite' => $idSite1,
- 'date' => '2011-12-01',
- 'periods' => array('day', 'week', 'month'))),
- array('Annotations.getAll', array('idSite' => $idSite1,
- 'date' => '2012-01-01',
- 'periods' => array('year'))),
- array('Annotations.getAll', array('idSite' => $idSite1,
- 'date' => '2012-03-01',
- 'periods' => array('week'),
- 'otherRequestParameters' => array('lastN' => 6),
- 'testSuffix' => '_lastN')),
- array('Annotations.getAll', array('idSite' => $idSite1,
- 'date' => '2012-01-15,2012-02-15',
- 'periods' => array('range'),
- 'otherRequestParameters' => array('lastN' => 6),
- 'testSuffix' => '_range')),
- array('Annotations.getAll', array('idSite' => 'all',
- 'date' => '2012-01-01',
- 'periods' => array('month'),
- 'testSuffix' => '_multipleSites')),
-
- // getAnnotationCountForDates
- array('Annotations.getAnnotationCountForDates', array('idSite' => $idSite1,
- 'date' => '2011-12-01',
- 'periods' => array('day', 'week', 'month'))),
- array('Annotations.getAnnotationCountForDates', array('idSite' => $idSite1,
- 'date' => '2012-01-01',
- 'periods' => array('year'))),
- array('Annotations.getAnnotationCountForDates', array('idSite' => $idSite1,
- 'date' => '2012-03-01',
- 'periods' => array('week'),
- 'otherRequestParameters' => array('lastN' => 6),
- 'testSuffix' => '_lastN')),
- array('Annotations.getAnnotationCountForDates', array('idSite' => $idSite1,
- 'date' => '2012-01-15,2012-02-15',
- 'periods' => array('range'),
- 'otherRequestParameters' => array('lastN' => 6),
- 'testSuffix' => '_range')),
- array('Annotations.getAnnotationCountForDates', array('idSite' => 'all',
- 'date' => '2012-01-01',
- 'periods' => array('month'),
- 'testSuffix' => '_multipleSites')),
- );
- }
-
- /**
- * @dataProvider getApiForTesting
- * @group Integration
- * @group Annotations
- */
- public function testApi($api, $params)
- {
- $this->runApiTests($api, $params);
- }
-
- /**
- * @group Integration
- * @group Annotations
- */
- public function testAddMultipleSitesFail()
- {
- try
- {
- Piwik_Annotations_API::getInstance()->add("1,2,3", "2012-01-01", "whatever");
- $this->fail("add should fail when given multiple sites in idSite");
- }
- catch (Exception $ex)
- {
- // pass
- }
- }
-
- /**
- * @group Integration
- * @group Annotations
- */
- public function testAddInvalidDateFail()
- {
- try
- {
- Piwik_Annotations_API::getInstance()->add(self::$fixture->idSite1, "invaliddate", "whatever");
- $this->fail("add should fail when given invalid date");
- }
- catch (Exception $ex)
- {
- // pass
- }
- }
-
- /**
- * @group Integration
- * @group Annotations
- */
- public function testSaveMultipleSitesFail()
- {
- try
- {
- Piwik_Annotations_API::getInstance()->save("1,2,3", 0);
- $this->fail("save should fail when given multiple sites");
- }
- catch (Exception $ex)
- {
- // pass
- }
- }
-
- /**
- * @group Integration
- * @group Annotations
- */
- public function testSaveInvalidDateFail()
- {
- try
- {
- Piwik_Annotations_API::getInstance()->save(self::$fixture->idSite1, 0, "invaliddate");
- $this->fail("save should fail when given an invalid date");
- }
- catch (Exception $ex)
- {
- // pass
- }
- }
-
- /**
- * @group Integration
- * @group Annotations
- */
- public function testSaveInvalidNoteIdFail()
- {
- try
- {
- Piwik_Annotations_API::getInstance()->save(self::$fixture->idSite1, -1);
- $this->fail("save should fail when given an invalid note id");
- }
- catch (Exception $ex)
- {
- // pass
- }
- }
-
- /**
- * @group Integration
- * @group Annotations
- */
- public function testDeleteMultipleSitesFail()
- {
- try
- {
- Piwik_Annotations_API::getInstance()->delete("1,2,3", 0);
- $this->fail("delete should fail when given multiple site IDs");
- }
- catch (Exception $ex)
- {
- // pass
- }
- }
-
- /**
- * @group Integration
- * @group Annotations
- */
- public function testDeleteInvalidNoteIdFail()
- {
- try
- {
- Piwik_Annotations_API::getInstance()->delete(self::$fixture->idSite1, -1);
- $this->fail("delete should fail when given an invalid site ID");
- }
- catch (Exception $ex)
- {
- // pass
- }
- }
-
- /**
- * @group Integration
- * @group Annotations
- */
- public function testGetMultipleSitesFail()
- {
- try
- {
- Piwik_Annotations_API::getInstance()->get("1,2,3", 0);
- $this->fail("get should fail when given multiple site IDs");
- }
- catch (Exception $ex)
- {
- // pass
- }
- }
-
- /**
- * @group Integration
- * @group Annotations
- */
- public function testGetInvalidNoteIdFail()
- {
- try
- {
- Piwik_Annotations_API::getInstance()->get(self::$fixture->idSite1, -1);
- $this->fail("get should fail when given an invalid note ID");
- }
- catch (Exception $ex)
- {
- // pass
- }
- }
-
- /**
- * @group Integration
- * @group Annotations
- */
- public function testSaveSuccess()
- {
- Piwik_Annotations_API::getInstance()->save(
- self::$fixture->idSite1, 0, $date = '2011-04-01', $note = 'new note text', $starred = 1);
-
- $expectedAnnotation = array(
- 'date' => '2011-04-01',
- 'note' => 'new note text',
- 'starred' => 1,
- 'user' => 'superUserLogin',
- 'idNote' => 0,
- 'canEditOrDelete' => true
- );
- $this->assertEquals($expectedAnnotation, Piwik_Annotations_API::getInstance()->get(self::$fixture->idSite1, 0));
- }
-
- /**
- * @group Integration
- * @group Annotations
- */
- public function testSaveNoChangesSuccess()
- {
- Piwik_Annotations_API::getInstance()->save(self::$fixture->idSite1, 1);
-
- $expectedAnnotation = array(
- 'date' => '2011-12-02',
- 'note' => '1: Site 1 annotation for 2011-12-02',
- 'starred' => 0,
- 'user' => 'superUserLogin',
- 'idNote' => 1,
- 'canEditOrDelete' => true
- );
- $this->assertEquals($expectedAnnotation, Piwik_Annotations_API::getInstance()->get(self::$fixture->idSite1, 1));
- }
-
- /**
- * @group Integration
- * @group Annotations
- */
- public function testDeleteSuccess()
- {
- Piwik_Annotations_API::getInstance()->delete(self::$fixture->idSite1, 1);
-
- try
- {
- Piwik_Annotations_API::getInstance()->get(self::$fixture->idSite1, 1);
- $this->fail("failed to delete annotation");
- }
- catch (Exception $ex)
- {
- // pass
- }
- }
-
- public function getPermissionsFailData()
- {
- return array(
- // getAll
- array(false, false, "module=API&method=Annotations.getAll&idSite=1&date=2012-01-01&period=year", true, "getAll should throw if user does not have view access"),
-
- // get
- array(false, false, "module=API&method=Annotations.get&idSite=1&idNote=0", true, "get should throw if user does not have view access"),
-
- // getAnnotationCountForDates
- array(false, false, "module=API&method=Annotations.getAnnotationCountForDates&idSite=1&date=2012-01-01&period=year", true, "getAnnotationCountForDates should throw if user does not have view access"),
-
- // add
- array(false, false, "module=API&method=Annotations.add&idSite=1&date=2011-02-01&note=whatever", true, "add should throw if user does not have view access"),
- array(false, true, "module=API&method=Annotations.add&idSite=1&date=2011-02-01&note=whatever2", false, "add should not throw if user has view access"),
- array(true, true, "module=API&method=Annotations.add&idSite=1&date=2011-02-01&note=whatever3", false, "add should not throw if user has admin access"),
-
- // save
- array(false, false, "module=API&method=Annotations.save&idSite=1&idNote=0&date=2011-03-01&note=newnote", true, "save should throw if user does not have view access"),
- array(false, true, "module=API&method=Annotations.save&idSite=1&idNote=0&date=2011-03-01&note=newnote", true, "save should throw if user has view access but did not edit note"),
- array(true, true, "module=API&method=Annotations.save&idSite=1&idNote=0&date=2011-03-01&note=newnote", false, "save should not throw if user has admin access"),
-
- // delete
- array(false, false, "module=API&method=Annotations.delete&idSite=1&idNote=0", true, "delete should throw if user does not have view access"),
- array(false, true, "module=API&method=Annotations.delete&idSite=1&idNote=0", true, "delete should throw if user does not have view access"),
- array(true, true, "module=API&method=Annotations.delete&idSite=1&idNote=0", false, "delete should not throw if user has admin access"),
- );
- }
-
- /**
- * @dataProvider getPermissionsFailData
- * @group Integration
- * @group Annotations
- */
- public function testMethodPermissions( $hasAdminAccess, $hasViewAccess, $request, $checkException, $failMessage )
- {
- // create fake access that denies user access
- $access = new FakeAccess();
- FakeAccess::$superUser = false;
- FakeAccess::$idSitesAdmin = $hasAdminAccess ? array(self::$fixture->idSite1) : array();
- FakeAccess::$idSitesView = $hasViewAccess ? array(self::$fixture->idSite1) : array();
- Zend_Registry::set('access', $access);
-
- if ($checkException)
- {
- try
- {
- $request = new Piwik_API_Request($request);
- $request->process();
- $this->fail($failMessage);
- }
- catch (Exception $ex)
- {
- // pass
- }
- }
- else
- {
- $request = new Piwik_API_Request($request);
- $request->process();
- }
- }
+ public static $fixture = null;
+
+ public function getOutputPrefix()
+ {
+ return 'annotations';
+ }
+
+ public function getApiForTesting()
+ {
+ $idSite1 = self::$fixture->idSite1;
+ $idSite2 = self::$fixture->idSite2;
+
+ return array(
+
+ // get
+ array('Annotations.get', array('idSite' => $idSite1,
+ 'date' => '2012-01-01',
+ 'periods' => 'day',
+ 'otherRequestParameters' => array('idNote' => 1))),
+
+ // getAll
+ array('Annotations.getAll', array('idSite' => $idSite1,
+ 'date' => '2011-12-01',
+ 'periods' => array('day', 'week', 'month'))),
+ array('Annotations.getAll', array('idSite' => $idSite1,
+ 'date' => '2012-01-01',
+ 'periods' => array('year'))),
+ array('Annotations.getAll', array('idSite' => $idSite1,
+ 'date' => '2012-03-01',
+ 'periods' => array('week'),
+ 'otherRequestParameters' => array('lastN' => 6),
+ 'testSuffix' => '_lastN')),
+ array('Annotations.getAll', array('idSite' => $idSite1,
+ 'date' => '2012-01-15,2012-02-15',
+ 'periods' => array('range'),
+ 'otherRequestParameters' => array('lastN' => 6),
+ 'testSuffix' => '_range')),
+ array('Annotations.getAll', array('idSite' => 'all',
+ 'date' => '2012-01-01',
+ 'periods' => array('month'),
+ 'testSuffix' => '_multipleSites')),
+
+ // getAnnotationCountForDates
+ array('Annotations.getAnnotationCountForDates', array('idSite' => $idSite1,
+ 'date' => '2011-12-01',
+ 'periods' => array('day', 'week', 'month'))),
+ array('Annotations.getAnnotationCountForDates', array('idSite' => $idSite1,
+ 'date' => '2012-01-01',
+ 'periods' => array('year'))),
+ array('Annotations.getAnnotationCountForDates', array('idSite' => $idSite1,
+ 'date' => '2012-03-01',
+ 'periods' => array('week'),
+ 'otherRequestParameters' => array('lastN' => 6),
+ 'testSuffix' => '_lastN')),
+ array('Annotations.getAnnotationCountForDates', array('idSite' => $idSite1,
+ 'date' => '2012-01-15,2012-02-15',
+ 'periods' => array('range'),
+ 'otherRequestParameters' => array('lastN' => 6),
+ 'testSuffix' => '_range')),
+ array('Annotations.getAnnotationCountForDates', array('idSite' => 'all',
+ 'date' => '2012-01-01',
+ 'periods' => array('month'),
+ 'testSuffix' => '_multipleSites')),
+ );
+ }
+
+ /**
+ * @dataProvider getApiForTesting
+ * @group Integration
+ * @group Annotations
+ */
+ public function testApi($api, $params)
+ {
+ $this->runApiTests($api, $params);
+ }
+
+ /**
+ * @group Integration
+ * @group Annotations
+ */
+ public function testAddMultipleSitesFail()
+ {
+ try {
+ Piwik_Annotations_API::getInstance()->add("1,2,3", "2012-01-01", "whatever");
+ $this->fail("add should fail when given multiple sites in idSite");
+ } catch (Exception $ex) {
+ // pass
+ }
+ }
+
+ /**
+ * @group Integration
+ * @group Annotations
+ */
+ public function testAddInvalidDateFail()
+ {
+ try {
+ Piwik_Annotations_API::getInstance()->add(self::$fixture->idSite1, "invaliddate", "whatever");
+ $this->fail("add should fail when given invalid date");
+ } catch (Exception $ex) {
+ // pass
+ }
+ }
+
+ /**
+ * @group Integration
+ * @group Annotations
+ */
+ public function testSaveMultipleSitesFail()
+ {
+ try {
+ Piwik_Annotations_API::getInstance()->save("1,2,3", 0);
+ $this->fail("save should fail when given multiple sites");
+ } catch (Exception $ex) {
+ // pass
+ }
+ }
+
+ /**
+ * @group Integration
+ * @group Annotations
+ */
+ public function testSaveInvalidDateFail()
+ {
+ try {
+ Piwik_Annotations_API::getInstance()->save(self::$fixture->idSite1, 0, "invaliddate");
+ $this->fail("save should fail when given an invalid date");
+ } catch (Exception $ex) {
+ // pass
+ }
+ }
+
+ /**
+ * @group Integration
+ * @group Annotations
+ */
+ public function testSaveInvalidNoteIdFail()
+ {
+ try {
+ Piwik_Annotations_API::getInstance()->save(self::$fixture->idSite1, -1);
+ $this->fail("save should fail when given an invalid note id");
+ } catch (Exception $ex) {
+ // pass
+ }
+ }
+
+ /**
+ * @group Integration
+ * @group Annotations
+ */
+ public function testDeleteMultipleSitesFail()
+ {
+ try {
+ Piwik_Annotations_API::getInstance()->delete("1,2,3", 0);
+ $this->fail("delete should fail when given multiple site IDs");
+ } catch (Exception $ex) {
+ // pass
+ }
+ }
+
+ /**
+ * @group Integration
+ * @group Annotations
+ */
+ public function testDeleteInvalidNoteIdFail()
+ {
+ try {
+ Piwik_Annotations_API::getInstance()->delete(self::$fixture->idSite1, -1);
+ $this->fail("delete should fail when given an invalid site ID");
+ } catch (Exception $ex) {
+ // pass
+ }
+ }
+
+ /**
+ * @group Integration
+ * @group Annotations
+ */
+ public function testGetMultipleSitesFail()
+ {
+ try {
+ Piwik_Annotations_API::getInstance()->get("1,2,3", 0);
+ $this->fail("get should fail when given multiple site IDs");
+ } catch (Exception $ex) {
+ // pass
+ }
+ }
+
+ /**
+ * @group Integration
+ * @group Annotations
+ */
+ public function testGetInvalidNoteIdFail()
+ {
+ try {
+ Piwik_Annotations_API::getInstance()->get(self::$fixture->idSite1, -1);
+ $this->fail("get should fail when given an invalid note ID");
+ } catch (Exception $ex) {
+ // pass
+ }
+ }
+
+ /**
+ * @group Integration
+ * @group Annotations
+ */
+ public function testSaveSuccess()
+ {
+ Piwik_Annotations_API::getInstance()->save(
+ self::$fixture->idSite1, 0, $date = '2011-04-01', $note = 'new note text', $starred = 1);
+
+ $expectedAnnotation = array(
+ 'date' => '2011-04-01',
+ 'note' => 'new note text',
+ 'starred' => 1,
+ 'user' => 'superUserLogin',
+ 'idNote' => 0,
+ 'canEditOrDelete' => true
+ );
+ $this->assertEquals($expectedAnnotation, Piwik_Annotations_API::getInstance()->get(self::$fixture->idSite1, 0));
+ }
+
+ /**
+ * @group Integration
+ * @group Annotations
+ */
+ public function testSaveNoChangesSuccess()
+ {
+ Piwik_Annotations_API::getInstance()->save(self::$fixture->idSite1, 1);
+
+ $expectedAnnotation = array(
+ 'date' => '2011-12-02',
+ 'note' => '1: Site 1 annotation for 2011-12-02',
+ 'starred' => 0,
+ 'user' => 'superUserLogin',
+ 'idNote' => 1,
+ 'canEditOrDelete' => true
+ );
+ $this->assertEquals($expectedAnnotation, Piwik_Annotations_API::getInstance()->get(self::$fixture->idSite1, 1));
+ }
+
+ /**
+ * @group Integration
+ * @group Annotations
+ */
+ public function testDeleteSuccess()
+ {
+ Piwik_Annotations_API::getInstance()->delete(self::$fixture->idSite1, 1);
+
+ try {
+ Piwik_Annotations_API::getInstance()->get(self::$fixture->idSite1, 1);
+ $this->fail("failed to delete annotation");
+ } catch (Exception $ex) {
+ // pass
+ }
+ }
+
+ public function getPermissionsFailData()
+ {
+ return array(
+ // getAll
+ array(false, false, "module=API&method=Annotations.getAll&idSite=1&date=2012-01-01&period=year", true, "getAll should throw if user does not have view access"),
+
+ // get
+ array(false, false, "module=API&method=Annotations.get&idSite=1&idNote=0", true, "get should throw if user does not have view access"),
+
+ // getAnnotationCountForDates
+ array(false, false, "module=API&method=Annotations.getAnnotationCountForDates&idSite=1&date=2012-01-01&period=year", true, "getAnnotationCountForDates should throw if user does not have view access"),
+
+ // add
+ array(false, false, "module=API&method=Annotations.add&idSite=1&date=2011-02-01&note=whatever", true, "add should throw if user does not have view access"),
+ array(false, true, "module=API&method=Annotations.add&idSite=1&date=2011-02-01&note=whatever2", false, "add should not throw if user has view access"),
+ array(true, true, "module=API&method=Annotations.add&idSite=1&date=2011-02-01&note=whatever3", false, "add should not throw if user has admin access"),
+
+ // save
+ array(false, false, "module=API&method=Annotations.save&idSite=1&idNote=0&date=2011-03-01&note=newnote", true, "save should throw if user does not have view access"),
+ array(false, true, "module=API&method=Annotations.save&idSite=1&idNote=0&date=2011-03-01&note=newnote", true, "save should throw if user has view access but did not edit note"),
+ array(true, true, "module=API&method=Annotations.save&idSite=1&idNote=0&date=2011-03-01&note=newnote", false, "save should not throw if user has admin access"),
+
+ // delete
+ array(false, false, "module=API&method=Annotations.delete&idSite=1&idNote=0", true, "delete should throw if user does not have view access"),
+ array(false, true, "module=API&method=Annotations.delete&idSite=1&idNote=0", true, "delete should throw if user does not have view access"),
+ array(true, true, "module=API&method=Annotations.delete&idSite=1&idNote=0", false, "delete should not throw if user has admin access"),
+ );
+ }
+
+ /**
+ * @dataProvider getPermissionsFailData
+ * @group Integration
+ * @group Annotations
+ */
+ public function testMethodPermissions($hasAdminAccess, $hasViewAccess, $request, $checkException, $failMessage)
+ {
+ // create fake access that denies user access
+ $access = new FakeAccess();
+ FakeAccess::$superUser = false;
+ FakeAccess::$idSitesAdmin = $hasAdminAccess ? array(self::$fixture->idSite1) : array();
+ FakeAccess::$idSitesView = $hasViewAccess ? array(self::$fixture->idSite1) : array();
+ Zend_Registry::set('access', $access);
+
+ if ($checkException) {
+ try {
+ $request = new Piwik_API_Request($request);
+ $request->process();
+ $this->fail($failMessage);
+ } catch (Exception $ex) {
+ // pass
+ }
+ } else {
+ $request = new Piwik_API_Request($request);
+ $request->process();
+ }
+ }
}
AnnotationsTest::$fixture = new Test_Piwik_Fixture_TwoSitesWithAnnotations();
diff --git a/tests/PHPUnit/Integration/ApiGetReportMetadataTest.php b/tests/PHPUnit/Integration/ApiGetReportMetadataTest.php
index 811e023bf3..cc0f41eede 100755
--- a/tests/PHPUnit/Integration/ApiGetReportMetadataTest.php
+++ b/tests/PHPUnit/Integration/ApiGetReportMetadataTest.php
@@ -7,13 +7,13 @@
*/
/**
- * This tests the output of the API plugin API
+ * This tests the output of the API plugin API
* It will return metadata about all API reports from all plugins
* as well as the data itself, pre-processed and ready to be displayed
*/
class Test_Piwik_Integration_ApiGetReportMetadata extends IntegrationTestCase
{
- public static $fixture = null; // initialized below class definition
+ public static $fixture = null; // initialized below class definition
public function setUp()
{
@@ -40,35 +40,35 @@ class Test_Piwik_Integration_ApiGetReportMetadata extends IntegrationTestCase
public function getApiForTesting()
{
- $idSite = self::$fixture->idSite;
- $dateTime = self::$fixture->dateTime;
-
+ $idSite = self::$fixture->idSite;
+ $dateTime = self::$fixture->dateTime;
+
return array(
array('API', array('idSite' => $idSite, 'date' => $dateTime)),
-
- // test w/ hideMetricsDocs=true
- array('API.getMetadata', array('idSite' => $idSite, 'date' => $dateTime,
- 'apiModule' => 'Actions', 'apiAction' => 'get',
- 'testSuffix' => '_hideMetricsDoc',
- 'otherRequestParameters' => array('hideMetricsDoc' => 1)) ),
- array('API.getProcessedReport', array('idSite' => $idSite, 'date' => $dateTime,
- 'apiModule' => 'Actions', 'apiAction' => 'get',
- 'testSuffix' => '_hideMetricsDoc',
- 'otherRequestParameters' => array('hideMetricsDoc' => 1)) ),
+
+ // test w/ hideMetricsDocs=true
+ array('API.getMetadata', array('idSite' => $idSite, 'date' => $dateTime,
+ 'apiModule' => 'Actions', 'apiAction' => 'get',
+ 'testSuffix' => '_hideMetricsDoc',
+ 'otherRequestParameters' => array('hideMetricsDoc' => 1))),
+ array('API.getProcessedReport', array('idSite' => $idSite, 'date' => $dateTime,
+ 'apiModule' => 'Actions', 'apiAction' => 'get',
+ 'testSuffix' => '_hideMetricsDoc',
+ 'otherRequestParameters' => array('hideMetricsDoc' => 1))),
// Test w/ showRawMetrics=true
- array('API.getProcessedReport', array('idSite' => $idSite, 'date' => $dateTime,
- 'apiModule' => 'UserCountry', 'apiAction' => 'getCountry',
- 'testSuffix' => '_showRawMetrics',
- 'otherRequestParameters' => array('showRawMetrics' => 1)) ),
+ array('API.getProcessedReport', array('idSite' => $idSite, 'date' => $dateTime,
+ 'apiModule' => 'UserCountry', 'apiAction' => 'getCountry',
+ 'testSuffix' => '_showRawMetrics',
+ 'otherRequestParameters' => array('showRawMetrics' => 1))),
// Test w/ showRawMetrics=true
- array('Actions.getPageTitles', array('idSite' => $idSite, 'date' => $dateTime,
- 'testSuffix' => '_pageTitleZeroString') ),
+ array('Actions.getPageTitles', array('idSite' => $idSite, 'date' => $dateTime,
+ 'testSuffix' => '_pageTitleZeroString')),
// test php renderer w/ array data
- array('API.getDefaultMetricTranslations', array('idSite' => $idSite, 'date' => $dateTime,
- 'format' => 'php', 'testSuffix' => '_phpRenderer')),
+ array('API.getDefaultMetricTranslations', array('idSite' => $idSite, 'date' => $dateTime,
+ 'format' => 'php', 'testSuffix' => '_phpRenderer')),
);
}
diff --git a/tests/PHPUnit/Integration/ApiGetReportMetadata_yearTest.php b/tests/PHPUnit/Integration/ApiGetReportMetadata_yearTest.php
index 1921112be2..ff2c413ae4 100755
--- a/tests/PHPUnit/Integration/ApiGetReportMetadata_yearTest.php
+++ b/tests/PHPUnit/Integration/ApiGetReportMetadata_yearTest.php
@@ -7,12 +7,12 @@
*/
/**
- * test the Yearly metadata API response,
- * with no visits, with custom response language
+ * test the Yearly metadata API response,
+ * with no visits, with custom response language
*/
class Test_Piwik_Integration_ApiGetReportMetadata_Year extends IntegrationTestCase
{
- public static $fixture = null; // initialized below class definition
+ public static $fixture = null; // initialized below class definition
public function getApiForTesting()
{
@@ -24,7 +24,7 @@ class Test_Piwik_Integration_ApiGetReportMetadata_Year extends IntegrationTestCa
array('API.getProcessedReport', $params),
// @todo reenable me
//array('API.getReportMetadata', $params),
- //array('LanguagesManager.getTranslationsForLanguage', $params),
+ //array('LanguagesManager.getTranslationsForLanguage', $params),
array('LanguagesManager.getAvailableLanguageNames', $params),
array('SitesManager.getJavascriptTag', $params)
);
diff --git a/tests/PHPUnit/Integration/BlobReportLimitingTest.php b/tests/PHPUnit/Integration/BlobReportLimitingTest.php
index 2db36b32d4..918b177358 100755
--- a/tests/PHPUnit/Integration/BlobReportLimitingTest.php
+++ b/tests/PHPUnit/Integration/BlobReportLimitingTest.php
@@ -14,86 +14,85 @@ require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/MockLocationProvider.php';
*/
class Test_Piwik_Integration_BlobReportLimitingTest extends IntegrationTestCase
{
- public static $fixture = null; // initialized below class definition
-
- public static function setUpBeforeClass()
- {
- self::setUpConfigOptions();
- parent::_setUpBeforeClass($dbName = false, $createEmptyDatabase = true, $createConfig = false);
- parent::setUpFixture(self::$fixture);
- }
+ public static $fixture = null; // initialized below class definition
- public function getApiForTesting()
- {
- // TODO: test Provider plugin? Not sure if it's possible.
- $apiToCall = array(
- 'Actions.getPageUrls', 'Actions.getPageTitles', 'Actions.getDownloads', 'Actions.getOutlinks',
- 'CustomVariables.getCustomVariables',
- 'Referers.getRefererType', 'Referers.getKeywords', 'Referers.getSearchEngines',
- 'Referers.getWebsites', 'Referers.getAll', /* TODO 'Referers.getCampaigns', */
- 'UserSettings.getResolution', 'UserSettings.getConfiguration', 'UserSettings.getOS',
- 'UserSettings.getBrowserVersion',
- 'UserCountry.getRegion', 'UserCountry.getCity',
- );
-
- return array(
- array($apiToCall, array('idSite' => self::$fixture->idSite,
- 'date' => self::$fixture->dateTime,
- 'periods' => array('day')))
- );
- }
-
- /**
- * @dataProvider getApiForTesting
- * @group Integration
- * @group BlobReportLimiting
- */
- public function testApi($api, $params)
- {
- $this->runApiTests($api, $params);
- }
-
- /**
- * @group Integration
- * @group BlobReportLimiting
- */
- public function testApiWithRankingQuery()
- {
- // custom setup
- self::deleteArchiveTables();
- $generalConfig['datatable_archiving_maximum_rows_referers'] = 4;
- $generalConfig['datatable_archiving_maximum_rows_subtable_referers'] = 4;
- $generalConfig['datatable_archiving_maximum_rows_actions'] = 4;
- $generalConfig['datatable_archiving_maximum_rows_subtable_actions'] = 4;
- $generalConfig['datatable_archiving_maximum_rows_standard'] = 4;
- Piwik_Config::getInstance()->General['archiving_ranking_query_row_limit'] = 3;
- Piwik_Actions_ArchivingHelper::reloadConfig();
-
- foreach ($this->getApiForTesting() as $pair)
- {
- list($apiToCall, $params) = $pair;
- $params['testSuffix'] = '_rankingQuery';
-
- $this->runApiTests($apiToCall, $params);
- }
- }
+ public static function setUpBeforeClass()
+ {
+ self::setUpConfigOptions();
+ parent::_setUpBeforeClass($dbName = false, $createEmptyDatabase = true, $createConfig = false);
+ parent::setUpFixture(self::$fixture);
+ }
- public function getOutputPrefix()
- {
- return 'reportLimiting';
- }
-
- protected static function setUpConfigOptions()
- {
- self::createTestConfig();
- $generalConfig =& Piwik_Config::getInstance()->General;
- $generalConfig['datatable_archiving_maximum_rows_referers'] = 3;
- $generalConfig['datatable_archiving_maximum_rows_subtable_referers'] = 2;
- $generalConfig['datatable_archiving_maximum_rows_actions'] = 3;
- $generalConfig['datatable_archiving_maximum_rows_subtable_actions'] = 2;
- $generalConfig['datatable_archiving_maximum_rows_standard'] = 3;
- $generalConfig['archiving_ranking_query_row_limit'] = 50000;
- }
+ public function getApiForTesting()
+ {
+ // TODO: test Provider plugin? Not sure if it's possible.
+ $apiToCall = array(
+ 'Actions.getPageUrls', 'Actions.getPageTitles', 'Actions.getDownloads', 'Actions.getOutlinks',
+ 'CustomVariables.getCustomVariables',
+ 'Referers.getRefererType', 'Referers.getKeywords', 'Referers.getSearchEngines',
+ 'Referers.getWebsites', 'Referers.getAll', /* TODO 'Referers.getCampaigns', */
+ 'UserSettings.getResolution', 'UserSettings.getConfiguration', 'UserSettings.getOS',
+ 'UserSettings.getBrowserVersion',
+ 'UserCountry.getRegion', 'UserCountry.getCity',
+ );
+
+ return array(
+ array($apiToCall, array('idSite' => self::$fixture->idSite,
+ 'date' => self::$fixture->dateTime,
+ 'periods' => array('day')))
+ );
+ }
+
+ /**
+ * @dataProvider getApiForTesting
+ * @group Integration
+ * @group BlobReportLimiting
+ */
+ public function testApi($api, $params)
+ {
+ $this->runApiTests($api, $params);
+ }
+
+ /**
+ * @group Integration
+ * @group BlobReportLimiting
+ */
+ public function testApiWithRankingQuery()
+ {
+ // custom setup
+ self::deleteArchiveTables();
+ $generalConfig['datatable_archiving_maximum_rows_referers'] = 4;
+ $generalConfig['datatable_archiving_maximum_rows_subtable_referers'] = 4;
+ $generalConfig['datatable_archiving_maximum_rows_actions'] = 4;
+ $generalConfig['datatable_archiving_maximum_rows_subtable_actions'] = 4;
+ $generalConfig['datatable_archiving_maximum_rows_standard'] = 4;
+ Piwik_Config::getInstance()->General['archiving_ranking_query_row_limit'] = 3;
+ Piwik_Actions_ArchivingHelper::reloadConfig();
+
+ foreach ($this->getApiForTesting() as $pair) {
+ list($apiToCall, $params) = $pair;
+ $params['testSuffix'] = '_rankingQuery';
+
+ $this->runApiTests($apiToCall, $params);
+ }
+ }
+
+ public function getOutputPrefix()
+ {
+ return 'reportLimiting';
+ }
+
+ protected static function setUpConfigOptions()
+ {
+ self::createTestConfig();
+ $generalConfig =& Piwik_Config::getInstance()->General;
+ $generalConfig['datatable_archiving_maximum_rows_referers'] = 3;
+ $generalConfig['datatable_archiving_maximum_rows_subtable_referers'] = 2;
+ $generalConfig['datatable_archiving_maximum_rows_actions'] = 3;
+ $generalConfig['datatable_archiving_maximum_rows_subtable_actions'] = 2;
+ $generalConfig['datatable_archiving_maximum_rows_standard'] = 3;
+ $generalConfig['archiving_ranking_query_row_limit'] = 50000;
+ }
}
Test_Piwik_Integration_BlobReportLimitingTest::$fixture = new Test_Piwik_Fixture_ManyVisitsWithMockLocationProvider();
diff --git a/tests/PHPUnit/Integration/CsvExportTest.php b/tests/PHPUnit/Integration/CsvExportTest.php
index 44cb1c5e41..737530cced 100755
--- a/tests/PHPUnit/Integration/CsvExportTest.php
+++ b/tests/PHPUnit/Integration/CsvExportTest.php
@@ -11,14 +11,14 @@
*/
class Test_Piwik_Integration_CsvExport extends IntegrationTestCase
{
- public static $fixture = null; // initialized below class definition
+ public static $fixture = null; // initialized below class definition
public function getApiForTesting()
{
- $idSite = self::$fixture->idSite;
- $dateTime = self::$fixture->dateTime;
-
- $apiToCall = array('VisitsSummary.get', 'CustomVariables.getCustomVariables');
+ $idSite = self::$fixture->idSite;
+ $dateTime = self::$fixture->dateTime;
+
+ $apiToCall = array('VisitsSummary.get', 'CustomVariables.getCustomVariables');
$enExtraParam = array('expanded' => 0, 'flat' => 1, 'include_aggregate_rows' => 0, 'translateColumnNames' => 1);
diff --git a/tests/PHPUnit/Integration/EcommerceOrderWithItemsTest.php b/tests/PHPUnit/Integration/EcommerceOrderWithItemsTest.php
index 0bb23213c7..629f9706a3 100755
--- a/tests/PHPUnit/Integration/EcommerceOrderWithItemsTest.php
+++ b/tests/PHPUnit/Integration/EcommerceOrderWithItemsTest.php
@@ -11,16 +11,16 @@
*/
class Test_Piwik_Integration_EcommerceOrderWithItems extends IntegrationTestCase
{
- public static $fixture = null; // initialized below class definition
+ public static $fixture = null; // initialized below class definition
- /**
- * @group Integration
- * @group EcommerceOrderWithItems
- */
- public function testImagesIncludedInTests()
- {
- $this->alertWhenImagesExcludedFromTests();
- }
+ /**
+ * @group Integration
+ * @group EcommerceOrderWithItems
+ */
+ public function testImagesIncludedInTests()
+ {
+ $this->alertWhenImagesExcludedFromTests();
+ }
/**
* @dataProvider getApiForTesting
@@ -34,10 +34,10 @@ class Test_Piwik_Integration_EcommerceOrderWithItems extends IntegrationTestCase
public function getApiForTesting()
{
- $idSite = self::$fixture->idSite;
- $idSite2 = self::$fixture->idSite2;
- $dateTime = self::$fixture->dateTime;
-
+ $idSite = self::$fixture->idSite;
+ $idSite2 = self::$fixture->idSite2;
+ $dateTime = self::$fixture->dateTime;
+
$dayApi = array('VisitsSummary.get', 'VisitTime', 'CustomVariables.getCustomVariables',
'Live.getLastVisitsDetails', 'UserCountry', 'API.getProcessedReport', 'Goals.get',
'Goals.getConversions', 'Goals.getItemsSku', 'Goals.getItemsName', 'Goals.getItemsCategory');
@@ -51,125 +51,125 @@ class Test_Piwik_Integration_EcommerceOrderWithItems extends IntegrationTestCase
// Normal standard goal
return array_merge(array(
- // day tests
- array($dayApi, array('idSite' => $idSite, 'date' => $dateTime, 'periods' => array('day'), 'otherRequestParameters' => array('_leavePiwikCoreVariables' => 1))),
-
- // goals API week tests
- array($goalWeekApi, array('idSite' => $idSite, 'date' => $dateTime, 'periods' => array('week'))),
-
- // abandoned carts tests
- array($goalItemApi, array('idSite' => $idSite, 'date' => $dateTime,
- 'periods' => array('day', 'week'), 'abandonedCarts' => 1,
- 'testSuffix' => '_AbandonedCarts')),
-
- // multiple periods tests
- array($goalItemApi, array('idSite' => $idSite, 'date' => $dateTime, 'periods' => array('day'),
- 'setDateLastN' => true, 'testSuffix' => 'multipleDates')),
-
- // multiple periods & multiple websites tests
- array($goalItemApi, array('idSite' => sprintf("%u,%u", $idSite, $idSite2), 'date' => $dateTime,
- 'periods' => array('day'), 'setDateLastN' => true,
- 'testSuffix' => 'multipleDates_andMultipleWebsites')),
-
- // test metadata products
- array($processedReportApi, array('idSite' => $idSite, 'date' => $dateTime,
- 'periods' => array('day'), 'apiModule' => 'Goals',
- 'apiAction' => 'getItemsSku', 'testSuffix' => '_Metadata_ItemsSku')),
- array($processedReportApi, array('idSite' => $idSite, 'date' => $dateTime,
- 'periods' => array('day'), 'apiModule' => 'Goals',
- 'apiAction' => 'getItemsCategory', 'testSuffix' => '_Metadata_ItemsCategory')),
-
- // test metadata Goals.get for Ecommerce orders & Carts
- array($processedReportApi, array('idSite' => $idSite, 'date' => $dateTime,
- 'periods' => array('day'), 'apiModule' => 'Goals', 'apiAction' => 'get',
- 'idGoal' => Piwik_Archive::LABEL_ECOMMERCE_ORDER,
- 'testSuffix' => '_Metadata_Goals.Get_Order')),
- array($processedReportApi, array('idSite' => $idSite, 'date' => $dateTime,
- 'periods' => array('day'), 'apiModule' => 'Goals', 'apiAction' => 'get',
- 'idGoal' => Piwik_Archive::LABEL_ECOMMERCE_CART,
- 'testSuffix' => '_Metadata_Goals.Get_AbandonedCart')),
-
- // normal standard goal test
- array($processedReportApi, array('idSite' => $idSite, 'date' => $dateTime,
- 'periods' => array('day'), 'apiModule' => 'Goals', 'apiAction' => 'get',
- 'idGoal' => self::$fixture->idGoalStandard,
- 'testSuffix' => '_Metadata_Goals.Get_NormalGoal')),
-
- // non-existant goal test
- array($processedReportApi, array('idSite' => $idSite, 'date' => $dateTime,
- 'periods' => array('day'), 'apiModule' => 'Goals', 'apiAction' => 'get',
- 'idGoal' => 'FAKE IDGOAL',
- 'testSuffix' => '_Metadata_Goals.Get_NotExistingGoal')),
-
- // While we're at it, test for a standard Metadata report with zero entries
- array($processedReportApi, array('idSite' => $idSite, 'date' => $dateTime,
- 'periods' => array('day'), 'apiModule' => 'VisitTime',
- 'apiAction' => 'getVisitInformationPerServerTime',
- 'testSuffix' => '_Metadata_VisitTime.getVisitInformationPerServerTime')),
-
- // Standard non metadata Goals.get
- // test Goals.get with idGoal=ecommerceOrder and ecommerceAbandonedCart
- array('Goals.get', array('idSite' => $idSite, 'date' => $dateTime,
- 'periods' => array('day', 'week'), 'idGoal' => Piwik_Archive::LABEL_ECOMMERCE_CART,
- 'testSuffix' => '_GoalAbandonedCart')),
- array('Goals.get', array('idSite' => $idSite, 'date' => $dateTime,
- 'periods' => array('day', 'week'), 'idGoal' => Piwik_Archive::LABEL_ECOMMERCE_ORDER,
- 'testSuffix' => '_GoalOrder')),
- array('Goals.get', array('idSite' => $idSite, 'date' => $dateTime,
- 'periods' => array('day', 'week'), 'idGoal' => 1, 'testSuffix' => '_GoalMatchTitle')),
- array('Goals.get', array('idSite' => $idSite, 'date' => $dateTime,
- 'periods' => array('day', 'week'), 'idGoal' => '', 'testSuffix' => '_GoalOverall')),
-
- array('VisitsSummary.get', array('idSite' => $idSite, 'date' => $dateTime,
- 'periods' => array('day'), 'segment' => 'visitEcommerceStatus==none',
- 'testSuffix' => '_SegmentNoEcommerce')),
- array('VisitsSummary.get', array('idSite' => $idSite, 'date' => $dateTime,
- 'periods' => array('day'), 'testSuffix' => '_SegmentOrderedSomething',
- 'segment' => 'visitEcommerceStatus==ordered,visitEcommerceStatus==orderedThenAbandonedCart')),
- array('VisitsSummary.get', array('idSite' => $idSite, 'date' => $dateTime,
- 'periods' => array('day'), 'testSuffix' => '_SegmentAbandonedCart',
- 'segment' => 'visitEcommerceStatus==abandonedCart,visitEcommerceStatus==orderedThenAbandonedCart')),
-
- // test segment visitConvertedGoalId
- array('VisitsSummary.get', array('idSite' => $idSite, 'date' => $dateTime,
- 'periods' => array('day', 'week'), 'testSuffix' => '_SegmentConvertedGoalId1',
- 'segment' => "visitConvertedGoalId==".self::$fixture->idGoalStandard)),
- array('VisitsSummary.get', array('idSite' => $idSite, 'date' => $dateTime,
- 'periods' => array('day'), 'testSuffix' => '_SegmentDidNotConvertGoalId1',
- 'segment' => "visitConvertedGoalId!=".self::$fixture->idGoalStandard)),
-
- // test segment visitorType
- array('VisitsSummary.get', array('idSite' => $idSite, 'date' => $dateTime,
- 'periods' => array('week'), 'segment' => 'visitorType==new',
- 'testSuffix' => '_SegmentNewVisitors')),
- array('VisitsSummary.get', array('idSite' => $idSite, 'date' => $dateTime,
- 'periods' => array('week'), 'segment' => 'visitorType==returning',
- 'testSuffix' => '_SegmentReturningVisitors')),
- array('VisitsSummary.get', array('idSite' => $idSite, 'date' => $dateTime,
- 'periods' => array('week'), 'segment' => 'visitorType==returningCustomer',
- 'testSuffix' => '_SegmentReturningCustomers')),
-
- // test segment pageTitle
- array('VisitsSummary.get', array('idSite' => $idSite, 'date' => $dateTime,
- 'periods' => array('day'), 'segment' => 'pageTitle==incredible title!',
- 'testSuffix' => '_SegmentPageTitleMatch')),
-
- // test Live! output is OK also for the visit that just bought something (other visits leave an abandoned cart)
- array('Live.getLastVisitsDetails', array('idSite' => $idSite,
- 'date' => Piwik_Date::factory($dateTime)->addHour(30.65)->getDatetime(),
- 'periods' => array('day'), 'testSuffix' => '_LiveEcommerceStatusOrdered')),
-
- // test API.get method
- array('API.get', array('idSite' => $idSite, 'date' => $dateTime, 'periods' => array('day', 'week'),
- 'otherRequestParameters' => array(
- 'columns' => 'nb_pageviews,nb_visits,avg_time_on_site,nb_visits_converted'),
- 'testSuffix' => '_API_get')),
-
- // Website2
- array($goalWeekApi, array('idSite' => $idSite2, 'date' => $dateTime, 'periods' => array('week'),
- 'testSuffix' => '_Website2')),
-
- ), self::getApiForTestingScheduledReports($dateTime, 'week'));
+ // day tests
+ array($dayApi, array('idSite' => $idSite, 'date' => $dateTime, 'periods' => array('day'), 'otherRequestParameters' => array('_leavePiwikCoreVariables' => 1))),
+
+ // goals API week tests
+ array($goalWeekApi, array('idSite' => $idSite, 'date' => $dateTime, 'periods' => array('week'))),
+
+ // abandoned carts tests
+ array($goalItemApi, array('idSite' => $idSite, 'date' => $dateTime,
+ 'periods' => array('day', 'week'), 'abandonedCarts' => 1,
+ 'testSuffix' => '_AbandonedCarts')),
+
+ // multiple periods tests
+ array($goalItemApi, array('idSite' => $idSite, 'date' => $dateTime, 'periods' => array('day'),
+ 'setDateLastN' => true, 'testSuffix' => 'multipleDates')),
+
+ // multiple periods & multiple websites tests
+ array($goalItemApi, array('idSite' => sprintf("%u,%u", $idSite, $idSite2), 'date' => $dateTime,
+ 'periods' => array('day'), 'setDateLastN' => true,
+ 'testSuffix' => 'multipleDates_andMultipleWebsites')),
+
+ // test metadata products
+ array($processedReportApi, array('idSite' => $idSite, 'date' => $dateTime,
+ 'periods' => array('day'), 'apiModule' => 'Goals',
+ 'apiAction' => 'getItemsSku', 'testSuffix' => '_Metadata_ItemsSku')),
+ array($processedReportApi, array('idSite' => $idSite, 'date' => $dateTime,
+ 'periods' => array('day'), 'apiModule' => 'Goals',
+ 'apiAction' => 'getItemsCategory', 'testSuffix' => '_Metadata_ItemsCategory')),
+
+ // test metadata Goals.get for Ecommerce orders & Carts
+ array($processedReportApi, array('idSite' => $idSite, 'date' => $dateTime,
+ 'periods' => array('day'), 'apiModule' => 'Goals', 'apiAction' => 'get',
+ 'idGoal' => Piwik_Archive::LABEL_ECOMMERCE_ORDER,
+ 'testSuffix' => '_Metadata_Goals.Get_Order')),
+ array($processedReportApi, array('idSite' => $idSite, 'date' => $dateTime,
+ 'periods' => array('day'), 'apiModule' => 'Goals', 'apiAction' => 'get',
+ 'idGoal' => Piwik_Archive::LABEL_ECOMMERCE_CART,
+ 'testSuffix' => '_Metadata_Goals.Get_AbandonedCart')),
+
+ // normal standard goal test
+ array($processedReportApi, array('idSite' => $idSite, 'date' => $dateTime,
+ 'periods' => array('day'), 'apiModule' => 'Goals', 'apiAction' => 'get',
+ 'idGoal' => self::$fixture->idGoalStandard,
+ 'testSuffix' => '_Metadata_Goals.Get_NormalGoal')),
+
+ // non-existant goal test
+ array($processedReportApi, array('idSite' => $idSite, 'date' => $dateTime,
+ 'periods' => array('day'), 'apiModule' => 'Goals', 'apiAction' => 'get',
+ 'idGoal' => 'FAKE IDGOAL',
+ 'testSuffix' => '_Metadata_Goals.Get_NotExistingGoal')),
+
+ // While we're at it, test for a standard Metadata report with zero entries
+ array($processedReportApi, array('idSite' => $idSite, 'date' => $dateTime,
+ 'periods' => array('day'), 'apiModule' => 'VisitTime',
+ 'apiAction' => 'getVisitInformationPerServerTime',
+ 'testSuffix' => '_Metadata_VisitTime.getVisitInformationPerServerTime')),
+
+ // Standard non metadata Goals.get
+ // test Goals.get with idGoal=ecommerceOrder and ecommerceAbandonedCart
+ array('Goals.get', array('idSite' => $idSite, 'date' => $dateTime,
+ 'periods' => array('day', 'week'), 'idGoal' => Piwik_Archive::LABEL_ECOMMERCE_CART,
+ 'testSuffix' => '_GoalAbandonedCart')),
+ array('Goals.get', array('idSite' => $idSite, 'date' => $dateTime,
+ 'periods' => array('day', 'week'), 'idGoal' => Piwik_Archive::LABEL_ECOMMERCE_ORDER,
+ 'testSuffix' => '_GoalOrder')),
+ array('Goals.get', array('idSite' => $idSite, 'date' => $dateTime,
+ 'periods' => array('day', 'week'), 'idGoal' => 1, 'testSuffix' => '_GoalMatchTitle')),
+ array('Goals.get', array('idSite' => $idSite, 'date' => $dateTime,
+ 'periods' => array('day', 'week'), 'idGoal' => '', 'testSuffix' => '_GoalOverall')),
+
+ array('VisitsSummary.get', array('idSite' => $idSite, 'date' => $dateTime,
+ 'periods' => array('day'), 'segment' => 'visitEcommerceStatus==none',
+ 'testSuffix' => '_SegmentNoEcommerce')),
+ array('VisitsSummary.get', array('idSite' => $idSite, 'date' => $dateTime,
+ 'periods' => array('day'), 'testSuffix' => '_SegmentOrderedSomething',
+ 'segment' => 'visitEcommerceStatus==ordered,visitEcommerceStatus==orderedThenAbandonedCart')),
+ array('VisitsSummary.get', array('idSite' => $idSite, 'date' => $dateTime,
+ 'periods' => array('day'), 'testSuffix' => '_SegmentAbandonedCart',
+ 'segment' => 'visitEcommerceStatus==abandonedCart,visitEcommerceStatus==orderedThenAbandonedCart')),
+
+ // test segment visitConvertedGoalId
+ array('VisitsSummary.get', array('idSite' => $idSite, 'date' => $dateTime,
+ 'periods' => array('day', 'week'), 'testSuffix' => '_SegmentConvertedGoalId1',
+ 'segment' => "visitConvertedGoalId==" . self::$fixture->idGoalStandard)),
+ array('VisitsSummary.get', array('idSite' => $idSite, 'date' => $dateTime,
+ 'periods' => array('day'), 'testSuffix' => '_SegmentDidNotConvertGoalId1',
+ 'segment' => "visitConvertedGoalId!=" . self::$fixture->idGoalStandard)),
+
+ // test segment visitorType
+ array('VisitsSummary.get', array('idSite' => $idSite, 'date' => $dateTime,
+ 'periods' => array('week'), 'segment' => 'visitorType==new',
+ 'testSuffix' => '_SegmentNewVisitors')),
+ array('VisitsSummary.get', array('idSite' => $idSite, 'date' => $dateTime,
+ 'periods' => array('week'), 'segment' => 'visitorType==returning',
+ 'testSuffix' => '_SegmentReturningVisitors')),
+ array('VisitsSummary.get', array('idSite' => $idSite, 'date' => $dateTime,
+ 'periods' => array('week'), 'segment' => 'visitorType==returningCustomer',
+ 'testSuffix' => '_SegmentReturningCustomers')),
+
+ // test segment pageTitle
+ array('VisitsSummary.get', array('idSite' => $idSite, 'date' => $dateTime,
+ 'periods' => array('day'), 'segment' => 'pageTitle==incredible title!',
+ 'testSuffix' => '_SegmentPageTitleMatch')),
+
+ // test Live! output is OK also for the visit that just bought something (other visits leave an abandoned cart)
+ array('Live.getLastVisitsDetails', array('idSite' => $idSite,
+ 'date' => Piwik_Date::factory($dateTime)->addHour(30.65)->getDatetime(),
+ 'periods' => array('day'), 'testSuffix' => '_LiveEcommerceStatusOrdered')),
+
+ // test API.get method
+ array('API.get', array('idSite' => $idSite, 'date' => $dateTime, 'periods' => array('day', 'week'),
+ 'otherRequestParameters' => array(
+ 'columns' => 'nb_pageviews,nb_visits,avg_time_on_site,nb_visits_converted'),
+ 'testSuffix' => '_API_get')),
+
+ // Website2
+ array($goalWeekApi, array('idSite' => $idSite2, 'date' => $dateTime, 'periods' => array('week'),
+ 'testSuffix' => '_Website2')),
+
+ ), self::getApiForTestingScheduledReports($dateTime, 'week'));
}
public function getOutputPrefix()
diff --git a/tests/PHPUnit/Integration/FlattenReportsTest.php b/tests/PHPUnit/Integration/FlattenReportsTest.php
index 16d4580267..48ecdad576 100644
--- a/tests/PHPUnit/Integration/FlattenReportsTest.php
+++ b/tests/PHPUnit/Integration/FlattenReportsTest.php
@@ -11,7 +11,7 @@
*/
class Test_Piwik_Integration_FlattenReports extends IntegrationTestCase
{
- public static $fixture = null; // initialized below class definition
+ public static $fixture = null; // initialized below class definition
/**
* @dataProvider getApiForTesting
@@ -25,9 +25,9 @@ class Test_Piwik_Integration_FlattenReports extends IntegrationTestCase
public function getApiForTesting()
{
- $idSite = self::$fixture->idSite;
- $dateTime = self::$fixture->dateTime;
-
+ $idSite = self::$fixture->idSite;
+ $dateTime = self::$fixture->dateTime;
+
$return = array();
// referrers
@@ -78,29 +78,29 @@ class Test_Piwik_Integration_FlattenReports extends IntegrationTestCase
)
));
- // test expanded=1 w/ idSubtable=X
- $return[] = array('Actions.getPageUrls', array('idSite' => $idSite,
- 'date' => $dateTime,
- 'periods' => array('week'),
- 'apiModule' => 'Actions',
- 'apiAction' => 'getPageUrls',
- 'supertableApi' => 'Actions.getPageUrls',
- 'testSuffix' => '_expandedSubtable',
- 'otherRequestParameters' => array('expanded' => '1')));
-
- // test flat=1 w/ filter_pattern_recursive
- $return[] = array('Actions.getPageUrls', array('idSite' => $idSite,
- 'date' => $dateTime,
- 'periods' => array('week'),
- 'apiModule' => 'Actions',
- 'apiAction' => 'getPageUrls',
- 'testSuffix' => '_flatFilterPatternRecursive',
- 'otherRequestParameters' => array(
- 'flat' => '1',
- 'expanded' => '0',
- 'filter_pattern_recursive' => 'dir2/'
- )));
-
+ // test expanded=1 w/ idSubtable=X
+ $return[] = array('Actions.getPageUrls', array('idSite' => $idSite,
+ 'date' => $dateTime,
+ 'periods' => array('week'),
+ 'apiModule' => 'Actions',
+ 'apiAction' => 'getPageUrls',
+ 'supertableApi' => 'Actions.getPageUrls',
+ 'testSuffix' => '_expandedSubtable',
+ 'otherRequestParameters' => array('expanded' => '1')));
+
+ // test flat=1 w/ filter_pattern_recursive
+ $return[] = array('Actions.getPageUrls', array('idSite' => $idSite,
+ 'date' => $dateTime,
+ 'periods' => array('week'),
+ 'apiModule' => 'Actions',
+ 'apiAction' => 'getPageUrls',
+ 'testSuffix' => '_flatFilterPatternRecursive',
+ 'otherRequestParameters' => array(
+ 'flat' => '1',
+ 'expanded' => '0',
+ 'filter_pattern_recursive' => 'dir2/'
+ )));
+
return $return;
}
@@ -111,5 +111,5 @@ class Test_Piwik_Integration_FlattenReports extends IntegrationTestCase
}
Test_Piwik_Integration_FlattenReports::$fixture =
- new Test_Piwik_Fixture_ManyVisitsWithSubDirReferrersAndCustomVars();
+ new Test_Piwik_Fixture_ManyVisitsWithSubDirReferrersAndCustomVars();
diff --git a/tests/PHPUnit/Integration/ImportLogsTest.php b/tests/PHPUnit/Integration/ImportLogsTest.php
index 9801ba4962..1e1027cb54 100755
--- a/tests/PHPUnit/Integration/ImportLogsTest.php
+++ b/tests/PHPUnit/Integration/ImportLogsTest.php
@@ -11,7 +11,7 @@
*/
class Test_Piwik_Integration_ImportLogs extends IntegrationTestCase
{
- public static $fixture = null; // initialized below class definition
+ public static $fixture = null; // initialized below class definition
/**
* @dataProvider getApiForTesting
@@ -25,49 +25,49 @@ class Test_Piwik_Integration_ImportLogs extends IntegrationTestCase
public function getApiForTesting()
{
- return array(
- array('all', array('idSite' => self::$fixture->idSite,
- 'date' => '2012-08-09',
- 'periods' => 'month')),
+ return array(
+ array('all', array('idSite' => self::$fixture->idSite,
+ 'date' => '2012-08-09',
+ 'periods' => 'month')),
- // report generated from custom log format including generation time
- array('Actions.getPageUrls', array('idSite' => self::$fixture->idSite,
- 'date' => '2012-09-30',
- 'periods' => 'day')),
-
- array('VisitsSummary.get', array('idSite' => self::$fixture->idSite2,
- 'date' => '2012-08-09',
- 'periods' => 'month',
- 'testSuffix' => '_siteIdTwo_TrackedUsingLogReplay')),
- );
+ // report generated from custom log format including generation time
+ array('Actions.getPageUrls', array('idSite' => self::$fixture->idSite,
+ 'date' => '2012-09-30',
+ 'periods' => 'day')),
+
+ array('VisitsSummary.get', array('idSite' => self::$fixture->idSite2,
+ 'date' => '2012-08-09',
+ 'periods' => 'month',
+ 'testSuffix' => '_siteIdTwo_TrackedUsingLogReplay')),
+ );
}
-
+
/**
* @group Integration
* @group ImportLogs
*/
public function testDynamicResolverSitesCreated()
{
- self::$fixture->logVisitsWithDynamicResolver();
-
- // reload access so new sites are viewable
- Zend_Registry::get('access')->setSuperUser(true);
-
- // make sure sites aren't created twice
- $piwikDotNet = Piwik_SitesManager_API::getInstance()->getSitesIdFromSiteUrl('http://piwik.net');
- $this->assertEquals(1, count($piwikDotNet));
-
- $anothersiteDotCom = Piwik_SitesManager_API::getInstance()->getSitesIdFromSiteUrl('http://anothersite.com');
- $this->assertEquals(1, count($anothersiteDotCom));
-
- $whateverDotCom = Piwik_SitesManager_API::getInstance()->getSitesIdFromSiteUrl('http://whatever.com');
- $this->assertEquals(1, count($whateverDotCom));
- }
+ self::$fixture->logVisitsWithDynamicResolver();
+
+ // reload access so new sites are viewable
+ Zend_Registry::get('access')->setSuperUser(true);
+
+ // make sure sites aren't created twice
+ $piwikDotNet = Piwik_SitesManager_API::getInstance()->getSitesIdFromSiteUrl('http://piwik.net');
+ $this->assertEquals(1, count($piwikDotNet));
+
+ $anothersiteDotCom = Piwik_SitesManager_API::getInstance()->getSitesIdFromSiteUrl('http://anothersite.com');
+ $this->assertEquals(1, count($anothersiteDotCom));
- public function getOutputPrefix()
- {
- return 'ImportLogs';
- }
+ $whateverDotCom = Piwik_SitesManager_API::getInstance()->getSitesIdFromSiteUrl('http://whatever.com');
+ $this->assertEquals(1, count($whateverDotCom));
+ }
+
+ public function getOutputPrefix()
+ {
+ return 'ImportLogs';
+ }
}
Test_Piwik_Integration_ImportLogs::$fixture = new Test_Piwik_Fixture_ManySitesImportedLogs();
diff --git a/tests/PHPUnit/Integration/LabelFilterTest.php b/tests/PHPUnit/Integration/LabelFilterTest.php
index 44126a963f..0141761bed 100644
--- a/tests/PHPUnit/Integration/LabelFilterTest.php
+++ b/tests/PHPUnit/Integration/LabelFilterTest.php
@@ -12,7 +12,7 @@
*/
class Test_Piwik_Integration_LabelFilter extends IntegrationTestCase
{
- public static $fixture = null; // initialized below class definition
+ public static $fixture = null; // initialized below class definition
/**
* @dataProvider getApiForTesting
@@ -26,19 +26,19 @@ class Test_Piwik_Integration_LabelFilter extends IntegrationTestCase
public function getApiForTesting()
{
- $idSite = self::$fixture->idSite;
- $dateTime = self::$fixture->dateTime;
-
+ $idSite = self::$fixture->idSite;
+ $dateTime = self::$fixture->dateTime;
+
$labelsToTest = array(
- // first level
- 'shouldBeNoData' => 'nonExistent',
- 'dir' => ' dir ',
- '0' => '/0',
+ // first level
+ 'shouldBeNoData' => 'nonExistent',
+ 'dir' => ' dir ',
+ '0' => '/0',
- // TODO the label in the API output is ...&amp;#039;... why does it only work this way?
- 'thisiscool' => '/ééé&quot;&#039;... &lt;this is cool&gt;!',
+ // TODO the label in the API output is ...&amp;#039;... why does it only work this way?
+ 'thisiscool' => '/ééé&quot;&#039;... &lt;this is cool&gt;!',
- // second level
+ // second level
'dirnonExistent' => 'dir>nonExistent',
'dirfilephpfoobarfoo2bar' => 'dir>' . urlencode('/file.php?foo=bar&foo2=bar'),
@@ -59,57 +59,57 @@ class Test_Piwik_Integration_LabelFilter extends IntegrationTestCase
));
}
- $label = 'dir';
- $return[] = array('Actions.getPageUrls', array(
- 'testSuffix' => '_' . $label . '_range',
- 'idSite' => $idSite,
- 'date' => $dateTime,
- 'otherRequestParameters' => array(
- 'date' => '2010-03-06,2010-03-08',
- 'label' => urlencode($label),
- 'expanded' => 0
- )
- ));
-
- $return[] = array('Actions.getPageTitles', array(
- 'testSuffix' => '_titles',
- 'idSite' => $idSite,
- 'date' => $dateTime,
- 'otherRequestParameters' => array(
- // note: title has no blank prefixed here. in the report it has.
- 'label' => urlencode('incredible title! <>,;'),
- 'expanded' => 0
- )
- ));
-
- $return[] = array('Actions.getPageTitles', array(
- 'testSuffix' => '_titlesRecursive',
- 'idSite' => $idSite,
- 'date' => $dateTime,
- 'otherRequestParameters' => array(
- 'label' => urlencode(
- ' ' . // test trimming
- urlencode('incredible parent title! <>,;') .
- '>' .
- urlencode('subtitle <>,;')),
- 'expanded' => 0
- )
- ));
-
- $keyword = '&lt;&gt;&amp;\&quot;the pdo extension is required for this adapter but the extension is not loaded';
- $searchEngineTest = array(
- 'testSuffix' => '_keywords_html',
- 'idSite' => $idSite,
- 'date' => $dateTime,
- 'otherRequestParameters' => array(
- 'label' => urlencode('Google>' . urlencode($keyword)),
- 'expanded' => 0
- )
- );
- $return[] = array('Referers.getSearchEngines', $searchEngineTest);
-
- $searchEngineTest['otherRequestParameters']['label'] = urlencode('Google>' . urlencode(html_entity_decode($keyword)));
- $return[] = array('Referers.getSearchEngines', $searchEngineTest);
+ $label = 'dir';
+ $return[] = array('Actions.getPageUrls', array(
+ 'testSuffix' => '_' . $label . '_range',
+ 'idSite' => $idSite,
+ 'date' => $dateTime,
+ 'otherRequestParameters' => array(
+ 'date' => '2010-03-06,2010-03-08',
+ 'label' => urlencode($label),
+ 'expanded' => 0
+ )
+ ));
+
+ $return[] = array('Actions.getPageTitles', array(
+ 'testSuffix' => '_titles',
+ 'idSite' => $idSite,
+ 'date' => $dateTime,
+ 'otherRequestParameters' => array(
+ // note: title has no blank prefixed here. in the report it has.
+ 'label' => urlencode('incredible title! <>,;'),
+ 'expanded' => 0
+ )
+ ));
+
+ $return[] = array('Actions.getPageTitles', array(
+ 'testSuffix' => '_titlesRecursive',
+ 'idSite' => $idSite,
+ 'date' => $dateTime,
+ 'otherRequestParameters' => array(
+ 'label' => urlencode(
+ ' ' . // test trimming
+ urlencode('incredible parent title! <>,;') .
+ '>' .
+ urlencode('subtitle <>,;')),
+ 'expanded' => 0
+ )
+ ));
+
+ $keyword = '&lt;&gt;&amp;\&quot;the pdo extension is required for this adapter but the extension is not loaded';
+ $searchEngineTest = array(
+ 'testSuffix' => '_keywords_html',
+ 'idSite' => $idSite,
+ 'date' => $dateTime,
+ 'otherRequestParameters' => array(
+ 'label' => urlencode('Google>' . urlencode($keyword)),
+ 'expanded' => 0
+ )
+ );
+ $return[] = array('Referers.getSearchEngines', $searchEngineTest);
+
+ $searchEngineTest['otherRequestParameters']['label'] = urlencode('Google>' . urlencode(html_entity_decode($keyword)));
+ $return[] = array('Referers.getSearchEngines', $searchEngineTest);
return $return;
}
diff --git a/tests/PHPUnit/Integration/ManyVisitorsOneWebsiteTest.php b/tests/PHPUnit/Integration/ManyVisitorsOneWebsiteTest.php
index 0ab4ecab47..677c5c3ff7 100755
--- a/tests/PHPUnit/Integration/ManyVisitorsOneWebsiteTest.php
+++ b/tests/PHPUnit/Integration/ManyVisitorsOneWebsiteTest.php
@@ -2,7 +2,7 @@
/**
* Piwik - Open source web analytics
*
- * @link http://piwik.org
+ * @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
@@ -11,72 +11,72 @@ require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/MockLocationProvider.php';
/**
* Tests w/ 14 visitors w/ 2 visits each.
* Uses geoip location provider to test city/region reports.
- *
+ *
* TODO Test ServerBased GeoIP implementation somehow. (Use X-FORWARDED-FOR?)
* TODO Test PECL implementation somehow. (The PECL module must point to the test dir, not the real one.)
*/
class Test_Piwik_Integration_ManyVisitorsOneWebsiteTest extends IntegrationTestCase
{
- public static $fixture = null; // initialized below class definition
-
- /**
- * @dataProvider getApiForTesting
- * @group Integration
- * @group TwoVisitors_TwoWebsites_DifferentDays_ArchivingDisabled
- */
- public function testApi($api, $params)
- {
- $this->runApiTests($api, $params);
- }
+ public static $fixture = null; // initialized below class definition
+
+ /**
+ * @dataProvider getApiForTesting
+ * @group Integration
+ * @group TwoVisitors_TwoWebsites_DifferentDays_ArchivingDisabled
+ */
+ public function testApi($api, $params)
+ {
+ $this->runApiTests($api, $params);
+ }
+
+ public function getApiForTesting()
+ {
+ $idSite = self::$fixture->idSite;
+ $dateTime = self::$fixture->dateTime;
- public function getApiForTesting()
- {
- $idSite = self::$fixture->idSite;
- $dateTime = self::$fixture->dateTime;
-
- // Note: we must set 'UserCountry.getLocationFromIP' since it's "excluded" by default in setApiNotToCall
- $apiToCall = array('UserCountry');
+ // Note: we must set 'UserCountry.getLocationFromIP' since it's "excluded" by default in setApiNotToCall
+ $apiToCall = array('UserCountry');
- return array(
- array( $apiToCall,
- array( 'idSite' => $idSite,
- 'date' => $dateTime,
- 'periods' => array('month'))),
+ return array(
+ array($apiToCall,
+ array('idSite' => $idSite,
+ 'date' => $dateTime,
+ 'periods' => array('month'))),
- array($apiToCall, array('idSite' => $idSite,
- 'date' => $dateTime,
- 'periods' => array('month'),
- 'testSuffix' => '_segment_region',
- 'segment' => 'region==P3;country==gb')),
+ array($apiToCall, array('idSite' => $idSite,
+ 'date' => $dateTime,
+ 'periods' => array('month'),
+ 'testSuffix' => '_segment_region',
+ 'segment' => 'region==P3;country==gb')),
- array($apiToCall, array('idSite' => $idSite,
- 'date' => $dateTime,
- 'periods' => array('month'),
- 'testSuffix' => '_segment_city',
- 'segment' => 'city==Stratford-upon-Avon;region==P3;country==gb')),
+ array($apiToCall, array('idSite' => $idSite,
+ 'date' => $dateTime,
+ 'periods' => array('month'),
+ 'testSuffix' => '_segment_city',
+ 'segment' => 'city==Stratford-upon-Avon;region==P3;country==gb')),
- array($apiToCall, array('idSite' => $idSite,
- 'date' => $dateTime,
- 'periods' => array('month'),
- 'testSuffix' => '_segment_lat_long',
- 'segment' => 'lat>45;lat<49.3;long>-125;long<-122')),
+ array($apiToCall, array('idSite' => $idSite,
+ 'date' => $dateTime,
+ 'periods' => array('month'),
+ 'testSuffix' => '_segment_lat_long',
+ 'segment' => 'lat>45;lat<49.3;long>-125;long<-122')),
- array('UserCountry.getCountry', array('idSite' => $idSite,
- 'date' => $dateTime,
- 'periods' => array('month'),
- 'testSuffix' => '_segment_continent',
- 'segment' => 'continent==eur')),
+ array('UserCountry.getCountry', array('idSite' => $idSite,
+ 'date' => $dateTime,
+ 'periods' => array('month'),
+ 'testSuffix' => '_segment_continent',
+ 'segment' => 'continent==eur')),
- array(array('UserCountry.getLocationFromIP', 'Live.getLastVisitsDetails'), array(
- 'idSite' => $idSite,
- 'date' => $dateTime,
- 'periods' => array('month'),
- 'otherRequestParameters' => array('ip' => '194.57.91.215')
- )),
- );
- }
+ array(array('UserCountry.getLocationFromIP', 'Live.getLastVisitsDetails'), array(
+ 'idSite' => $idSite,
+ 'date' => $dateTime,
+ 'periods' => array('month'),
+ 'otherRequestParameters' => array('ip' => '194.57.91.215')
+ )),
+ );
+ }
}
Test_Piwik_Integration_ManyVisitorsOneWebsiteTest::$fixture
- = new Test_Piwik_Fixture_ManyVisitsWithGeoIP();
+ = new Test_Piwik_Fixture_ManyVisitsWithGeoIP();
diff --git a/tests/PHPUnit/Integration/NoVisitTest.php b/tests/PHPUnit/Integration/NoVisitTest.php
index c9b5d18238..50cbe20c65 100755
--- a/tests/PHPUnit/Integration/NoVisitTest.php
+++ b/tests/PHPUnit/Integration/NoVisitTest.php
@@ -13,7 +13,7 @@
*/
class Test_Piwik_Integration_NoVisit extends IntegrationTestCase
{
- public static $fixture = null; // initialized below class definition
+ public static $fixture = null; // initialized below class definition
/**
* @dataProvider getApiForTesting
@@ -29,8 +29,8 @@ class Test_Piwik_Integration_NoVisit extends IntegrationTestCase
{
// this will output empty XML result sets as no visit was tracked
return array(
- array('all', array('idSite' => self::$fixture->idSite,
- 'date' => self::$fixture->dateTime)),
+ array('all', array('idSite' => self::$fixture->idSite,
+ 'date' => self::$fixture->dateTime)),
array('all', array('idSite' => self::$fixture->idSite,
'date' => self::$fixture->dateTime,
'periods' => array('day', 'week'),
diff --git a/tests/PHPUnit/Integration/NonUnicodeTest.php b/tests/PHPUnit/Integration/NonUnicodeTest.php
index 995add7567..83628577ed 100755
--- a/tests/PHPUnit/Integration/NonUnicodeTest.php
+++ b/tests/PHPUnit/Integration/NonUnicodeTest.php
@@ -2,7 +2,7 @@
/**
* Piwik - Open source web analytics
*
- * @link http://piwik.org
+ * @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
@@ -12,41 +12,41 @@
*/
class Test_Piwik_Integration_NonUnicodeTest extends IntegrationTestCase
{
- public static $fixture = null; // initialized below class definition
-
- /**
- * @dataProvider getApiForTesting
- * @group Integration
- * @group NonUnicodeTest
- */
- public function testApi($api, $params)
- {
- $this->runApiTests($api, $params);
- }
-
- public function getApiForTesting()
- {
- $apiToCall = array(
- 'Actions.getSiteSearchKeywords',
- 'Actions.getPageTitles',
- 'Actions.getPageUrls',
- 'Referers.getWebsites',
- );
-
- return array(
- array($apiToCall, array('idSite' => self::$fixture->idSite1,
- 'date' => self::$fixture->dateTime,
- 'periods' => 'day'))
- );
- }
-
- public function getOutputPrefix()
- {
- return 'NonUnicode';
- }
+ public static $fixture = null; // initialized below class definition
+
+ /**
+ * @dataProvider getApiForTesting
+ * @group Integration
+ * @group NonUnicodeTest
+ */
+ public function testApi($api, $params)
+ {
+ $this->runApiTests($api, $params);
+ }
+
+ public function getApiForTesting()
+ {
+ $apiToCall = array(
+ 'Actions.getSiteSearchKeywords',
+ 'Actions.getPageTitles',
+ 'Actions.getPageUrls',
+ 'Referers.getWebsites',
+ );
+
+ return array(
+ array($apiToCall, array('idSite' => self::$fixture->idSite1,
+ 'date' => self::$fixture->dateTime,
+ 'periods' => 'day'))
+ );
+ }
+
+ public function getOutputPrefix()
+ {
+ return 'NonUnicode';
+ }
}
Test_Piwik_Integration_NonUnicodeTest::$fixture =
- new Test_Piwik_Fixture_SomeVisitsWithNonUnicodePageTitles();
+ new Test_Piwik_Fixture_SomeVisitsWithNonUnicodePageTitles();
diff --git a/tests/PHPUnit/Integration/OneVisitorOneWebsite_SeveralDaysDateRangeTest.php b/tests/PHPUnit/Integration/OneVisitorOneWebsite_SeveralDaysDateRangeTest.php
index 23f3b114b8..5a96ed8aed 100755
--- a/tests/PHPUnit/Integration/OneVisitorOneWebsite_SeveralDaysDateRangeTest.php
+++ b/tests/PHPUnit/Integration/OneVisitorOneWebsite_SeveralDaysDateRangeTest.php
@@ -15,7 +15,7 @@
*/
class Test_Piwik_Integration_OneVisitorOneWebsite_SeveralDaysDateRange extends IntegrationTestCase
{
- public static $fixture = null; // initialized below class definition
+ public static $fixture = null; // initialized below class definition
/**
* @dataProvider getApiForTesting
@@ -29,59 +29,59 @@ class Test_Piwik_Integration_OneVisitorOneWebsite_SeveralDaysDateRange extends I
public function getApiForTesting()
{
- $idSite = self::$fixture->idSite;
-
+ $idSite = self::$fixture->idSite;
+
return array(
- // FIRST some MultiSites API goodness!
+ // FIRST some MultiSites API goodness!
// range test
- array('MultiSites.getAll', array( 'date' => '2010-12-15,2011-01-15',
- 'periods' => array('range')
- // Testing without &pattern= so should return all sites
- )),
+ array('MultiSites.getAll', array('date' => '2010-12-15,2011-01-15',
+ 'periods' => array('range')
+ // Testing without &pattern= so should return all sites
+ )),
// test several dates (tests use of IndexedByDate w/ 'date1,date2,etc.')
- array('MultiSites.getAll', array('date' => '2010-12-15',
- 'periods' => array('day'),
- 'testSuffix' => '_IndexedByDate',
- // Testing the pattern to getAll restrict websites using name matching
+ array('MultiSites.getAll', array('date' => '2010-12-15',
+ 'periods' => array('day'),
+ 'testSuffix' => '_IndexedByDate',
+ // Testing the pattern to getAll restrict websites using name matching
'otherRequestParameters' => array('pattern' => 'aAa')
)),
- // test getOne call used in MobileMessaging SMS reports
- array('MultiSites.getOne', array( 'date' => '2010-12-15,2011-01-15',
- 'periods' => array('range'),
- 'idSite' => $idSite,
- // Testing without &pattern= so should return all sites
- )),
+ // test getOne call used in MobileMessaging SMS reports
+ array('MultiSites.getOne', array('date' => '2010-12-15,2011-01-15',
+ 'periods' => array('range'),
+ 'idSite' => $idSite,
+ // Testing without &pattern= so should return all sites
+ )),
+
+ // test that multiple periods are not supported
+ array('MultiSites.getAll', array('date' => '2010-12-15,2011-01-15',
+ 'periods' => array('day'),
+ 'testSuffix' => '_MultipleDatesNotSupported',
+ )),
+
+ //---------------------------------------
+ // THEN some Socials tests. Share these...
+ array('Referers.getSocials', array('idSite' => 'all',
+ 'date' => '2010-12-13,2011-01-18',
+ 'periods' => array('range'))),
+
+ array('Referers.getSocials', array('idSite' => 'all',
+ 'date' => '2010-12-10',
+ 'periods' => array('day'),
+ 'setDateLastN' => true,
+ 'testSuffix' => '_IndexedByDate')),
- // test that multiple periods are not supported
- array('MultiSites.getAll', array( 'date' => '2010-12-15,2011-01-15',
- 'periods' => array('day'),
- 'testSuffix' => '_MultipleDatesNotSupported',
- )),
+ array('Referers.getUrlsForSocial', array('idSite' => 'all', // test w/o idSubtable
+ 'date' => '2010-12-13,2011-01-18',
+ 'periods' => 'range',
+ 'testSuffix' => '_noIdSubtable')),
- //---------------------------------------
- // THEN some Socials tests. Share these...
- array('Referers.getSocials', array('idSite' => 'all',
- 'date' => '2010-12-13,2011-01-18',
- 'periods' => array('range'))),
-
- array('Referers.getSocials', array('idSite' => 'all',
- 'date' => '2010-12-10',
- 'periods' => array('day'),
- 'setDateLastN' => true,
- 'testSuffix' => '_IndexedByDate')),
-
- array('Referers.getUrlsForSocial', array('idSite' => 'all', // test w/o idSubtable
- 'date' => '2010-12-13,2011-01-18',
- 'periods' => 'range',
- 'testSuffix' => '_noIdSubtable')),
-
- array('Referers.getUrlsForSocial', array('idSite' => 1, // test w/ idSubtable
- 'date' => '2010-12-13,2011-01-18',
- 'periods' => 'range',
- 'supertableApi' => 'Referers.getSocials')),
+ array('Referers.getUrlsForSocial', array('idSite' => 1, // test w/ idSubtable
+ 'date' => '2010-12-13,2011-01-18',
+ 'periods' => 'range',
+ 'supertableApi' => 'Referers.getSocials')),
);
}
@@ -92,5 +92,5 @@ class Test_Piwik_Integration_OneVisitorOneWebsite_SeveralDaysDateRange extends I
}
Test_Piwik_Integration_OneVisitorOneWebsite_SeveralDaysDateRange::$fixture
- = new Test_Piwik_Fixture_VisitsOverSeveralDays();
+ = new Test_Piwik_Fixture_VisitsOverSeveralDays();
diff --git a/tests/PHPUnit/Integration/OneVisitorOneWebsite_SeveralDaysDateRange_ArchivingTestsTest.php b/tests/PHPUnit/Integration/OneVisitorOneWebsite_SeveralDaysDateRange_ArchivingTestsTest.php
index 4632eeb60b..cbeaf000b5 100755
--- a/tests/PHPUnit/Integration/OneVisitorOneWebsite_SeveralDaysDateRange_ArchivingTestsTest.php
+++ b/tests/PHPUnit/Integration/OneVisitorOneWebsite_SeveralDaysDateRange_ArchivingTestsTest.php
@@ -12,7 +12,7 @@
*/
class Test_Piwik_Integration_OneVisitorOneWebsite_SeveralDaysDateRange_ArchivingTests extends IntegrationTestCase
{
- public static $fixture = null; // initialized below test definition
+ public static $fixture = null; // initialized below test definition
public function getOutputPrefix()
{
@@ -31,13 +31,13 @@ class Test_Piwik_Integration_OneVisitorOneWebsite_SeveralDaysDateRange_Archiving
public function getApiForTesting()
{
- $idSite = self::$fixture->idSite;
-
+ $idSite = self::$fixture->idSite;
+
$apiToCall = array('Actions.getPageUrls',
- 'VisitsSummary.get',
- 'UserSettings.getResolution',
- 'VisitFrequency.get',
- 'VisitTime.getVisitInformationPerServerTime');
+ 'VisitsSummary.get',
+ 'UserSettings.getResolution',
+ 'VisitFrequency.get',
+ 'VisitTime.getVisitInformationPerServerTime');
// 2 segments: ALL and another way of expressing ALL but triggering the Segment code path
$segments = array(
@@ -83,15 +83,15 @@ class Test_Piwik_Integration_OneVisitorOneWebsite_SeveralDaysDateRange_Archiving
'archive_numeric_2011_01' => 0,
);
foreach ($tests as $table => $expectedRows) {
- $sql = "SELECT count(*) FROM " . Piwik_Common::prefixTable($table) . " WHERE period = " . Piwik::$idPeriods['range'];
+ $sql = "SELECT count(*) FROM " . Piwik_Common::prefixTable($table) . " WHERE period = " . Piwik::$idPeriods['range'];
$countBlobs = Zend_Registry::get('db')->fetchOne($sql);
- $this->assertEquals($expectedRows, $countBlobs, "$table expected $expectedRows, got $countBlobs");
+ $this->assertEquals($expectedRows, $countBlobs, "$table expected $expectedRows, got $countBlobs");
}
}
}
Test_Piwik_Integration_OneVisitorOneWebsite_SeveralDaysDateRange_ArchivingTests::$fixture
- = new Test_Piwik_Fixture_VisitsOverSeveralDays();
+ = new Test_Piwik_Fixture_VisitsOverSeveralDays();
diff --git a/tests/PHPUnit/Integration/OneVisitorTwoVisitsTest.php b/tests/PHPUnit/Integration/OneVisitorTwoVisitsTest.php
index 3035c8a718..5d07e49b24 100755
--- a/tests/PHPUnit/Integration/OneVisitorTwoVisitsTest.php
+++ b/tests/PHPUnit/Integration/OneVisitorTwoVisitsTest.php
@@ -18,18 +18,18 @@
*/
class Test_Piwik_Integration_OneVisitorTwoVisits extends IntegrationTestCase
{
- public static $fixture = null; // initialized below class
-
- public function setUp()
- {
- Piwik_API_Proxy::getInstance()->setHideIgnoredFunctions(false);
- }
-
- public function tearDown()
- {
- Piwik_API_Proxy::getInstance()->setHideIgnoredFunctions(true);
- }
-
+ public static $fixture = null; // initialized below class
+
+ public function setUp()
+ {
+ Piwik_API_Proxy::getInstance()->setHideIgnoredFunctions(false);
+ }
+
+ public function tearDown()
+ {
+ Piwik_API_Proxy::getInstance()->setHideIgnoredFunctions(true);
+ }
+
/**
* @dataProvider getApiForTesting
* @group Integration
@@ -42,19 +42,18 @@ class Test_Piwik_Integration_OneVisitorTwoVisits extends IntegrationTestCase
public function getApiForTesting()
{
- $idSite = self::$fixture->idSite;
- $dateTime = self::$fixture->dateTime;
-
+ $idSite = self::$fixture->idSite;
+ $dateTime = self::$fixture->dateTime;
+
$enExtraParam = array('expanded' => 1, 'flat' => 1, 'include_aggregate_rows' => 0, 'translateColumnNames' => 1);
- $bulkUrls = array(
- "idSite=".$idSite."&date=2010-03-06&format=json&expanded=1&period=day&method=VisitsSummary.get",
- "idSite=".$idSite."&date=2010-03-06&format=xml&expanded=1&period=day&method=VisitsSummary.get",
- "idSite=".$idSite."&date=2010-03-06&format=json&expanded=1&period=day&method="
+ $bulkUrls = array(
+ "idSite=" . $idSite . "&date=2010-03-06&format=json&expanded=1&period=day&method=VisitsSummary.get",
+ "idSite=" . $idSite . "&date=2010-03-06&format=xml&expanded=1&period=day&method=VisitsSummary.get",
+ "idSite=" . $idSite . "&date=2010-03-06&format=json&expanded=1&period=day&method="
. "VisitorInterest.getNumberOfVisitsPerVisitDuration"
);
- foreach ($bulkUrls as &$url)
- {
- $url = urlencode($url);
+ foreach ($bulkUrls as &$url) {
+ $url = urlencode($url);
}
return array(
array('all', array('idSite' => $idSite, 'date' => $dateTime)),
@@ -71,101 +70,99 @@ class Test_Piwik_Integration_OneVisitorTwoVisits extends IntegrationTestCase
'testSuffix' => '_csv')),
array('API.getBulkRequest', array('otherRequestParameters' => array('urls' => $bulkUrls))),
-
+
// test API.getProcessedReport w/ report that is its own 'actionToLoadSubTables'
- array('API.getProcessedReport', array('idSite' => $idSite,
- 'date' => $dateTime,
- 'periods' => array('week'),
- 'apiModule' => 'Actions',
- 'apiAction' => 'getPageUrls',
- 'supertableApi' => 'Actions.getPageUrls',
- 'testSuffix' => '__subtable')),
-
- // test hideColumns && showColumns parameters
- array('VisitsSummary.get', array('idSite' => $idSite, 'date' => $dateTime, 'periods' => 'day',
- 'testSuffix' => '_hideColumns_',
- 'otherRequestParameters' => array(
- 'hideColumns' => 'nb_visits_converted,max_actions,bounce_count,nb_hits,'
- .'nb_visits,nb_actions,sum_visit_length,avg_time_on_site'
- ))),
- array('VisitsSummary.get', array('idSite' => $idSite, 'date' => $dateTime, 'periods' => 'day',
- 'testSuffix' => '_showColumns_',
- 'otherRequestParameters' => array(
- 'showColumns' => 'nb_visits,nb_actions,nb_hits'
- ))),
- array('VisitsSummary.get', array('idSite' => $idSite, 'date' => $dateTime, 'periods' => 'day',
- 'testSuffix' => '_hideAllColumns_',
- 'otherRequestParameters' => array(
- 'hideColumns' => 'nb_visits_converted,max_actions,bounce_count,nb_hits,'
- .'nb_visits,nb_actions,sum_visit_length,avg_time_on_site,'
- .'bounce_rate,nb_uniq_visitors,nb_actions_per_visit,'
- ))),
-
- // test hideColumns w/ API.getProcessedReport
- array('API.getProcessedReport', array('idSite' => $idSite, 'date' => $dateTime,
- 'periods' => 'day', 'apiModule' => 'Actions',
- 'apiAction' => 'getPageTitles', 'testSuffix' => '_hideColumns_',
- 'otherRequestParameters' => array(
- 'hideColumns' => 'nb_visits_converted,xyzaug,entry_nb_visits,'.
- 'bounce_rate,nb_hits,nb_visits,avg_time_on_page,avg_time_generation'
- ))),
-
- array('API.getProcessedReport', array('idSite' => $idSite, 'date' => $dateTime,
- 'periods' => 'day', 'apiModule' => 'Actions',
- 'apiAction' => 'getPageTitles', 'testSuffix' => '_showColumns_',
- 'otherRequestParameters' => array(
- 'showColumns' => 'nb_visits_converted,xuena,entry_nb_visits,'.
- 'bounce_rate,nb_hits'
- ))),
- array('API.getProcessedReport', array('idSite' => $idSite, 'date' => $dateTime,
- 'periods' => 'day', 'apiModule' => 'VisitTime',
- 'apiAction' => 'getVisitInformationPerServerTime',
- 'testSuffix' => '_showColumnsWithProcessedMetrics_',
- 'otherRequestParameters' => array(
- 'showColumns' => 'nb_visits,revenue'
- ))),
-
- // test hideColumns w/ expanded=1
- array('Actions.getPageTitles', array('idSite' => $idSite, 'date' => $dateTime,
- 'periods' => 'day', 'testSuffix' => '_hideColumns_',
- 'otherRequestParameters' => array(
- 'hideColumns' => 'nb_visits_converted,entry_nb_visits,'.
- 'bounce_rate,nb_hits,nb_visits,sum_time_spent,'.
- 'entry_sum_visit_length,entry_bounce_count,exit_nb_visits,'.
- 'entry_nb_uniq_visitors,exit_nb_uniq_visitors,entry_nb_actions,'.
- 'avg_time_generation',
- 'expanded' => '1'
- ))),
+ array('API.getProcessedReport', array('idSite' => $idSite,
+ 'date' => $dateTime,
+ 'periods' => array('week'),
+ 'apiModule' => 'Actions',
+ 'apiAction' => 'getPageUrls',
+ 'supertableApi' => 'Actions.getPageUrls',
+ 'testSuffix' => '__subtable')),
+
+ // test hideColumns && showColumns parameters
+ array('VisitsSummary.get', array('idSite' => $idSite, 'date' => $dateTime, 'periods' => 'day',
+ 'testSuffix' => '_hideColumns_',
+ 'otherRequestParameters' => array(
+ 'hideColumns' => 'nb_visits_converted,max_actions,bounce_count,nb_hits,'
+ . 'nb_visits,nb_actions,sum_visit_length,avg_time_on_site'
+ ))),
+ array('VisitsSummary.get', array('idSite' => $idSite, 'date' => $dateTime, 'periods' => 'day',
+ 'testSuffix' => '_showColumns_',
+ 'otherRequestParameters' => array(
+ 'showColumns' => 'nb_visits,nb_actions,nb_hits'
+ ))),
+ array('VisitsSummary.get', array('idSite' => $idSite, 'date' => $dateTime, 'periods' => 'day',
+ 'testSuffix' => '_hideAllColumns_',
+ 'otherRequestParameters' => array(
+ 'hideColumns' => 'nb_visits_converted,max_actions,bounce_count,nb_hits,'
+ . 'nb_visits,nb_actions,sum_visit_length,avg_time_on_site,'
+ . 'bounce_rate,nb_uniq_visitors,nb_actions_per_visit,'
+ ))),
+
+ // test hideColumns w/ API.getProcessedReport
+ array('API.getProcessedReport', array('idSite' => $idSite, 'date' => $dateTime,
+ 'periods' => 'day', 'apiModule' => 'Actions',
+ 'apiAction' => 'getPageTitles', 'testSuffix' => '_hideColumns_',
+ 'otherRequestParameters' => array(
+ 'hideColumns' => 'nb_visits_converted,xyzaug,entry_nb_visits,' .
+ 'bounce_rate,nb_hits,nb_visits,avg_time_on_page,avg_time_generation'
+ ))),
+
+ array('API.getProcessedReport', array('idSite' => $idSite, 'date' => $dateTime,
+ 'periods' => 'day', 'apiModule' => 'Actions',
+ 'apiAction' => 'getPageTitles', 'testSuffix' => '_showColumns_',
+ 'otherRequestParameters' => array(
+ 'showColumns' => 'nb_visits_converted,xuena,entry_nb_visits,' .
+ 'bounce_rate,nb_hits'
+ ))),
+ array('API.getProcessedReport', array('idSite' => $idSite, 'date' => $dateTime,
+ 'periods' => 'day', 'apiModule' => 'VisitTime',
+ 'apiAction' => 'getVisitInformationPerServerTime',
+ 'testSuffix' => '_showColumnsWithProcessedMetrics_',
+ 'otherRequestParameters' => array(
+ 'showColumns' => 'nb_visits,revenue'
+ ))),
+
+ // test hideColumns w/ expanded=1
+ array('Actions.getPageTitles', array('idSite' => $idSite, 'date' => $dateTime,
+ 'periods' => 'day', 'testSuffix' => '_hideColumns_',
+ 'otherRequestParameters' => array(
+ 'hideColumns' => 'nb_visits_converted,entry_nb_visits,' .
+ 'bounce_rate,nb_hits,nb_visits,sum_time_spent,' .
+ 'entry_sum_visit_length,entry_bounce_count,exit_nb_visits,' .
+ 'entry_nb_uniq_visitors,exit_nb_uniq_visitors,entry_nb_actions,' .
+ 'avg_time_generation',
+ 'expanded' => '1'
+ ))),
);
}
-
- /**
- * Test that Archive_Single::preFetchBlob won't fetch extra unnecessary blobs.
- *
- * @group Integration
- * @group OneVisitorTwoVisits
- */
- public function testArchiveSinglePreFetchBlob()
- {
- $archive = Piwik_Archive::build(self::$fixture->idSite, 'day', self::$fixture->dateTime);
- $archive->preFetchBlob('Actions_actions');
- $cache = $archive->getBlobCache();
-
- $foundSubtable = false;
-
- $this->assertTrue(count($cache) > 0, "empty blob cache");
- foreach ($cache as $name => $value)
- {
- $this->assertTrue(strpos($name, "Actions_actions_url") === false, "found blob w/ name '$name'");
-
- if (strpos($name, "Actions_actions_") !== false)
- {
- $foundSubtable = true;
- }
- }
-
- $this->assertTrue($foundSubtable, "Actions_actions subtable was not loaded");
- }
+
+ /**
+ * Test that Archive_Single::preFetchBlob won't fetch extra unnecessary blobs.
+ *
+ * @group Integration
+ * @group OneVisitorTwoVisits
+ */
+ public function testArchiveSinglePreFetchBlob()
+ {
+ $archive = Piwik_Archive::build(self::$fixture->idSite, 'day', self::$fixture->dateTime);
+ $archive->preFetchBlob('Actions_actions');
+ $cache = $archive->getBlobCache();
+
+ $foundSubtable = false;
+
+ $this->assertTrue(count($cache) > 0, "empty blob cache");
+ foreach ($cache as $name => $value) {
+ $this->assertTrue(strpos($name, "Actions_actions_url") === false, "found blob w/ name '$name'");
+
+ if (strpos($name, "Actions_actions_") !== false) {
+ $foundSubtable = true;
+ }
+ }
+
+ $this->assertTrue($foundSubtable, "Actions_actions subtable was not loaded");
+ }
}
Test_Piwik_Integration_OneVisitorTwoVisits::$fixture = new Test_Piwik_Fixture_OneVisitorTwoVisits();
diff --git a/tests/PHPUnit/Integration/OneVisitorTwoVisits_withCookieSupportTest.php b/tests/PHPUnit/Integration/OneVisitorTwoVisits_withCookieSupportTest.php
index cdc3b669ea..6baa804192 100755
--- a/tests/PHPUnit/Integration/OneVisitorTwoVisits_withCookieSupportTest.php
+++ b/tests/PHPUnit/Integration/OneVisitorTwoVisits_withCookieSupportTest.php
@@ -12,7 +12,7 @@
*/
class Test_Piwik_Integration_OneVisitorTwoVisits_WithCookieSupport extends IntegrationTestCase
{
- public static $fixture = null; // initialized below class
+ public static $fixture = null; // initialized below class
/**
* @dataProvider getApiForTesting
diff --git a/tests/PHPUnit/Integration/OneVisitor_LongUrlsTruncatedTest.php b/tests/PHPUnit/Integration/OneVisitor_LongUrlsTruncatedTest.php
index 8504b51b8d..4d18196094 100644
--- a/tests/PHPUnit/Integration/OneVisitor_LongUrlsTruncatedTest.php
+++ b/tests/PHPUnit/Integration/OneVisitor_LongUrlsTruncatedTest.php
@@ -10,7 +10,7 @@
*/
class Test_Piwik_Integration_OneVisitor_LongUrlsTruncated extends IntegrationTestCase
{
- public static $fixture = null; // initialized below class definition
+ public static $fixture = null; // initialized below class definition
/**
* @dataProvider getApiForTesting
diff --git a/tests/PHPUnit/Integration/OneVisitor_NoKeywordSpecifiedTest.php b/tests/PHPUnit/Integration/OneVisitor_NoKeywordSpecifiedTest.php
index de5fe1ab80..966c85f2ef 100755
--- a/tests/PHPUnit/Integration/OneVisitor_NoKeywordSpecifiedTest.php
+++ b/tests/PHPUnit/Integration/OneVisitor_NoKeywordSpecifiedTest.php
@@ -14,7 +14,7 @@
*/
class Test_Piwik_Integration_OneVisitor_NoKeywordSpecified extends IntegrationTestCase
{
- public static $fixture = null; // initialized below class definition
+ public static $fixture = null; // initialized below class definition
/**
* @dataProvider getApiForTesting
@@ -31,9 +31,9 @@ class Test_Piwik_Integration_OneVisitor_NoKeywordSpecified extends IntegrationTe
$apiToCall = array('Referers.getKeywords', 'Live.getLastVisitsDetails');
return array(
- array($apiToCall, array('idSite' => self::$fixture->idSite,
- 'date' => self::$fixture->dateTime,
- 'language' => 'fr') )
+ array($apiToCall, array('idSite' => self::$fixture->idSite,
+ 'date' => self::$fixture->dateTime,
+ 'language' => 'fr'))
);
}
diff --git a/tests/PHPUnit/Integration/PeriodIsRange_DateIsLastN_MetadataAndNormalAPITest.php b/tests/PHPUnit/Integration/PeriodIsRange_DateIsLastN_MetadataAndNormalAPITest.php
index 28586368cf..e8dd0e63bd 100755
--- a/tests/PHPUnit/Integration/PeriodIsRange_DateIsLastN_MetadataAndNormalAPITest.php
+++ b/tests/PHPUnit/Integration/PeriodIsRange_DateIsLastN_MetadataAndNormalAPITest.php
@@ -11,31 +11,30 @@
*/
class Test_Piwik_Integration_PeriodIsRange_DateIsLastN_MetadataAndNormalAPI extends IntegrationTestCase
{
- public static $fixture = null;
-
- static $shouldSkipTestThisTime = false;
+ public static $fixture = null;
- public static function setUpBeforeClass()
+ static $shouldSkipTestThisTime = false;
+
+ public static function setUpBeforeClass()
{
- self::$shouldSkipTestThisTime = in_array(date('G'), array(22, 23));
+ self::$shouldSkipTestThisTime = in_array(date('G'), array(22, 23));
- if (self::$shouldSkipTestThisTime)
- {
- print("\nSKIPPED test PeriodIsRange_DateIsLastN_MetadataAndNormalAPI since it fails around midnight...\n");
- return;
- }
+ if (self::$shouldSkipTestThisTime) {
+ print("\nSKIPPED test PeriodIsRange_DateIsLastN_MetadataAndNormalAPI since it fails around midnight...\n");
+ return;
+ }
self::$fixture->dateTime = Piwik_Date::factory('now')->getDateTime();
parent::setUpBeforeClass();
}
-
+
public static function tearDownAfterClass()
{
- if (self::$shouldSkipTestThisTime) {
- return;
- }
-
- parent::tearDownAfterClass();
+ if (self::$shouldSkipTestThisTime) {
+ return;
+ }
+
+ parent::tearDownAfterClass();
}
/**
@@ -45,18 +44,17 @@ class Test_Piwik_Integration_PeriodIsRange_DateIsLastN_MetadataAndNormalAPI exte
*/
public function testApi($api, $params)
{
- if (self::$shouldSkipTestThisTime)
- {
- return;
- }
- $this->runApiTests($api, $params);
+ if (self::$shouldSkipTestThisTime) {
+ return;
+ }
+ $this->runApiTests($api, $params);
}
public function getApiForTesting()
{
- $idSite = self::$fixture->idSite;
- $visitorId = self::$fixture->visitorId;
-
+ $idSite = self::$fixture->idSite;
+ $visitorId = self::$fixture->visitorId;
+
$apiToCall = array(
'API.getProcessedReport',
'Actions.getPageUrls',
@@ -75,7 +73,7 @@ class Test_Piwik_Integration_PeriodIsRange_DateIsLastN_MetadataAndNormalAPI exte
'visitorId!=33c31e01394bdc63;daysSinceFirstVisit!=50',
//'pageUrl!=http://unknown/not/viewed',
);
- $dates = array(
+ $dates = array(
'last7',
Piwik_Date::factory('now')->subDay(6)->toString() . ',today',
Piwik_Date::factory('now')->subDay(6)->toString() . ',now',
@@ -86,7 +84,7 @@ class Test_Piwik_Integration_PeriodIsRange_DateIsLastN_MetadataAndNormalAPI exte
foreach ($dates as $date) {
$result[] = array($apiToCall, array('idSite' => $idSite, 'date' => $date,
'periods' => array('range'), 'segment' => $segment,
- // testing getLastVisitsForVisitor requires a visitor ID
+ // testing getLastVisitsForVisitor requires a visitor ID
'visitorId' => $visitorId));
}
}
@@ -101,6 +99,6 @@ class Test_Piwik_Integration_PeriodIsRange_DateIsLastN_MetadataAndNormalAPI exte
}
Test_Piwik_Integration_PeriodIsRange_DateIsLastN_MetadataAndNormalAPI::$fixture =
- new Test_Piwik_Fixture_TwoVisitsWithCustomVariables();
+ new Test_Piwik_Fixture_TwoVisitsWithCustomVariables();
Test_Piwik_Integration_PeriodIsRange_DateIsLastN_MetadataAndNormalAPI::$fixture->doExtraQuoteTests = false;
diff --git a/tests/PHPUnit/Integration/RowEvolutionTest.php b/tests/PHPUnit/Integration/RowEvolutionTest.php
index a0da7c54c1..616822417c 100755
--- a/tests/PHPUnit/Integration/RowEvolutionTest.php
+++ b/tests/PHPUnit/Integration/RowEvolutionTest.php
@@ -11,7 +11,7 @@
*/
class Test_Piwik_Integration_RowEvolution extends IntegrationTestCase
{
- public static $fixture = null; // initialized below class definition
+ public static $fixture = null; // initialized below class definition
/**
* @dataProvider getApiForTesting
@@ -25,11 +25,11 @@ class Test_Piwik_Integration_RowEvolution extends IntegrationTestCase
public function getApiForTesting()
{
- $idSite = self::$fixture->idSite;
- $idSite2 = self::$fixture->idSite2;
- $today = self::$fixture->today;
- $keywords = self::$fixture->keywords;
-
+ $idSite = self::$fixture->idSite;
+ $idSite2 = self::$fixture->idSite2;
+ $today = self::$fixture->today;
+ $keywords = self::$fixture->keywords;
+
$return = array();
$config = array(
@@ -49,110 +49,110 @@ class Test_Piwik_Integration_RowEvolution extends IntegrationTestCase
$return[] = array('API.getRowEvolution', $config);
// Websites, hierarchical
- $config['testSuffix'] = '_referrer2';
- $referrerLabel = urlencode('www.referrer0.com') . '>' . urlencode('theReferrerPage1.html');
+ $config['testSuffix'] = '_referrer2';
+ $referrerLabel = urlencode('www.referrer0.com') . '>' . urlencode('theReferrerPage1.html');
$config['otherRequestParameters']['label'] = urlencode($referrerLabel);
- $return[] = array('API.getRowEvolution', $config);
+ $return[] = array('API.getRowEvolution', $config);
// Websites, multiple labels including one hierarchical
- $config['testSuffix'] = '_referrerMulti1';
- $referrerLabel = $referrerLabel . ',' . urlencode('www.referrer2.com');
+ $config['testSuffix'] = '_referrerMulti1';
+ $referrerLabel = $referrerLabel . ',' . urlencode('www.referrer2.com');
$config['otherRequestParameters']['label'] = urlencode($referrerLabel);
- $return[] = array('API.getRowEvolution', $config);
+ $return[] = array('API.getRowEvolution', $config);
// Keywords, label containing > and ,
$config['otherRequestParameters']['apiAction'] = 'getKeywords';
- $config['testSuffix'] = '_LabelReservedCharacters';
- $keywordsStr = urlencode($keywords[0]) . ',' . urlencode($keywords[1]);
- $config['otherRequestParameters']['label'] = urlencode($keywordsStr);
- $return[] = array('API.getRowEvolution', $config);
+ $config['testSuffix'] = '_LabelReservedCharacters';
+ $keywordsStr = urlencode($keywords[0]) . ',' . urlencode($keywords[1]);
+ $config['otherRequestParameters']['label'] = urlencode($keywordsStr);
+ $return[] = array('API.getRowEvolution', $config);
// Keywords, hierarchical
$config['otherRequestParameters']['apiAction'] = 'getSearchEngines';
- $config['testSuffix'] = '_LabelReservedCharactersHierarchical';
- $keywordsStr = "Google>" . urlencode(strtolower($keywords[0]))
+ $config['testSuffix'] = '_LabelReservedCharactersHierarchical';
+ $keywordsStr = "Google>" . urlencode(strtolower($keywords[0]))
. ',Google>' . urlencode(strtolower($keywords[1]))
. ',Google>' . urlencode(strtolower($keywords[2]));
// Test multiple labels search engines, Google should also have a 'logo' entry
$config['otherRequestParameters']['label'] = urlencode($keywordsStr . ",Google");
- $return[] = array('API.getRowEvolution', $config);
+ $return[] = array('API.getRowEvolution', $config);
// Actions > Pages titles, standard label
- $config['testSuffix'] = '_pageTitles';
- $config['periods'] = array('day', 'week');
+ $config['testSuffix'] = '_pageTitles';
+ $config['periods'] = array('day', 'week');
$config['otherRequestParameters']['apiModule'] = 'Actions';
$config['otherRequestParameters']['apiAction'] = 'getPageTitles';
- $config['otherRequestParameters']['label'] = urlencode('incredible title 0');
- $return[] = array('API.getRowEvolution', $config);
+ $config['otherRequestParameters']['label'] = urlencode('incredible title 0');
+ $return[] = array('API.getRowEvolution', $config);
// Actions > Page titles, multiple labels
- $config['testSuffix'] = '_pageTitlesMulti';
- $label = urlencode('incredible title 0') . ',' . urlencode('incredible title 2');
+ $config['testSuffix'] = '_pageTitlesMulti';
+ $label = urlencode('incredible title 0') . ',' . urlencode('incredible title 2');
$config['otherRequestParameters']['label'] = urlencode($label);
- $return[] = array('API.getRowEvolution', $config);
+ $return[] = array('API.getRowEvolution', $config);
// Actions > Page URLS, hierarchical label
- $config['testSuffix'] = '_pageUrls';
- $config['periods'] = array('range');
- $config['otherRequestParameters']['date'] = '2010-03-01,2010-03-06';
+ $config['testSuffix'] = '_pageUrls';
+ $config['periods'] = array('range');
+ $config['otherRequestParameters']['date'] = '2010-03-01,2010-03-06';
$config['otherRequestParameters']['apiModule'] = 'Actions';
$config['otherRequestParameters']['apiAction'] = 'getPageUrls';
- $config['otherRequestParameters']['label'] = urlencode('my>dir>' . urlencode('/page3?foo=bar&baz=bar'));
- $return[] = array('API.getRowEvolution', $config);
+ $config['otherRequestParameters']['label'] = urlencode('my>dir>' . urlencode('/page3?foo=bar&baz=bar'));
+ $return[] = array('API.getRowEvolution', $config);
// Goals > Visits Until Conversion, idGoal != 0
- $config['testSuffix'] = '_goals_visitsUntilConversion';
- $config['periods'] = array('day');
- $config['otherRequestParameters']['date'] = '2010-02-06,2010-03-06';
- $config['otherRequestParameters']['period'] = 'day';
+ $config['testSuffix'] = '_goals_visitsUntilConversion';
+ $config['periods'] = array('day');
+ $config['otherRequestParameters']['date'] = '2010-02-06,2010-03-06';
+ $config['otherRequestParameters']['period'] = 'day';
$config['otherRequestParameters']['apiModule'] = 'Goals';
$config['otherRequestParameters']['apiAction'] = 'getVisitsUntilConversion';
- $config['otherRequestParameters']['label'] = urlencode('1 visit, 2 visits');
- $config['otherRequestParameters']['idGoal'] = '2';
- $return[] = array('API.getRowEvolution', $config);
+ $config['otherRequestParameters']['label'] = urlencode('1 visit, 2 visits');
+ $config['otherRequestParameters']['idGoal'] = '2';
+ $return[] = array('API.getRowEvolution', $config);
// Goals > Visits Until Conversion, idGoal != 0, without specifying labels
- $config['testSuffix'] = '_goals_visitsUntilConversion_WithoutLabels';
- $config['periods'] = array('day');
- $config['otherRequestParameters']['date'] = '2010-02-06,2010-03-06';
- $config['otherRequestParameters']['period'] = 'day';
- $config['otherRequestParameters']['apiModule'] = 'Goals';
- $config['otherRequestParameters']['apiAction'] = 'getVisitsUntilConversion';
- $config['otherRequestParameters']['label'] = false;
- $config['otherRequestParameters']['filter_limit'] = 2;
+ $config['testSuffix'] = '_goals_visitsUntilConversion_WithoutLabels';
+ $config['periods'] = array('day');
+ $config['otherRequestParameters']['date'] = '2010-02-06,2010-03-06';
+ $config['otherRequestParameters']['period'] = 'day';
+ $config['otherRequestParameters']['apiModule'] = 'Goals';
+ $config['otherRequestParameters']['apiAction'] = 'getVisitsUntilConversion';
+ $config['otherRequestParameters']['label'] = false;
+ $config['otherRequestParameters']['filter_limit'] = 2;
$config['otherRequestParameters']['filter_sort_column'] = 'nb_conversions';
- $config['otherRequestParameters']['idGoal'] = '2';
- $return[] = array('API.getRowEvolution', $config);
-
+ $config['otherRequestParameters']['idGoal'] = '2';
+ $return[] = array('API.getRowEvolution', $config);
+
// test date range where most recent date has no data (for #3465)
$return[] = array('API.getRowEvolution', array(
- 'testSuffix' => '_multipleDates_lastNoData',
- 'periods' => 'month',
- 'idSite' => $idSite,
- 'date' => $today,
- 'otherRequestParameters' => array(
- 'date' => '2010-02-01,2010-04-08',
- 'period' => 'month',
- 'apiModule' => 'Referers',
- 'apiAction' => 'getKeywords',
- // no label
- )
+ 'testSuffix' => '_multipleDates_lastNoData',
+ 'periods' => 'month',
+ 'idSite' => $idSite,
+ 'date' => $today,
+ 'otherRequestParameters' => array(
+ 'date' => '2010-02-01,2010-04-08',
+ 'period' => 'month',
+ 'apiModule' => 'Referers',
+ 'apiAction' => 'getKeywords',
+ // no label
+ )
));
-
+
// test that reports that process row labels are treated correctly
$return[] = array('API.getRowEvolution', array(
- 'testSuffix' => '_processedRowLabel',
- 'periods' => 'day',
- 'idSite' => $idSite2,
- 'date' => $today,
- 'otherRequestParameters' => array(
- 'date' => '2010-03-01,2010-03-06',
- 'period' => 'month',
- 'apiModule' => 'UserSettings',
- 'apiAction' => 'getBrowser',
- 'label' => 'Firefox,Chrome,Opera'
- )
-
+ 'testSuffix' => '_processedRowLabel',
+ 'periods' => 'day',
+ 'idSite' => $idSite2,
+ 'date' => $today,
+ 'otherRequestParameters' => array(
+ 'date' => '2010-03-01,2010-03-06',
+ 'period' => 'month',
+ 'apiModule' => 'UserSettings',
+ 'apiAction' => 'getBrowser',
+ 'label' => 'Firefox,Chrome,Opera'
+ )
+
));
return $return;
@@ -165,5 +165,5 @@ class Test_Piwik_Integration_RowEvolution extends IntegrationTestCase
}
Test_Piwik_Integration_RowEvolution::$fixture
- = new Test_Piwik_Fixture_TwoSitesManyVisitsOverSeveralDaysWithSearchEngineReferrers();
+ = new Test_Piwik_Fixture_TwoSitesManyVisitsOverSeveralDaysWithSearchEngineReferrers();
diff --git a/tests/PHPUnit/Integration/SiteSearchTest.php b/tests/PHPUnit/Integration/SiteSearchTest.php
index 881f17530c..545c794b38 100755
--- a/tests/PHPUnit/Integration/SiteSearchTest.php
+++ b/tests/PHPUnit/Integration/SiteSearchTest.php
@@ -11,7 +11,7 @@
*/
class Test_Piwik_Integration_SiteSearch extends IntegrationTestCase
{
- public static $fixture = null; // initialized below class definition
+ public static $fixture = null; // initialized below class definition
/**
* @dataProvider getApiForTesting
@@ -27,23 +27,23 @@ class Test_Piwik_Integration_SiteSearch extends IntegrationTestCase
{
return array(
'Actions.get',
- 'Actions.getPageUrls',
+ 'Actions.getPageUrls',
'Actions.getPageTitles',
- 'CustomVariables.getCustomVariables',
- 'Actions.getSiteSearchKeywords',
- 'Actions.getSiteSearchCategories',
- 'Actions.getSiteSearchNoResultKeywords',
- 'Actions.getPageTitlesFollowingSiteSearch',
- 'Actions.getPageUrlsFollowingSiteSearch',
+ 'CustomVariables.getCustomVariables',
+ 'Actions.getSiteSearchKeywords',
+ 'Actions.getSiteSearchCategories',
+ 'Actions.getSiteSearchNoResultKeywords',
+ 'Actions.getPageTitlesFollowingSiteSearch',
+ 'Actions.getPageUrlsFollowingSiteSearch',
);
}
public function getApiForTesting()
{
- $dateTime = self::$fixture->dateTime;
- $idSite1 = self::$fixture->idSite1;
-
- $apiToCall = $this->getApiToCall();
+ $dateTime = self::$fixture->dateTime;
+ $idSite1 = self::$fixture->idSite1;
+
+ $apiToCall = $this->getApiToCall();
$periods = array('day', 'month');
@@ -53,15 +53,15 @@ class Test_Piwik_Integration_SiteSearch extends IntegrationTestCase
'date' => $dateTime,
'periods' => $periods,
'setDateLastN' => true,
- 'testSuffix' => '_AllSites')),
+ 'testSuffix' => '_AllSites')),
- // We also test a single period/single site to check that this use case (Reports per idSite in the response) works
- array($apiToCall, array(
- 'idSite' => $idSite1,
- 'date' => $dateTime,
- 'periods' => $periods,
- 'setDateLastN' => false,
- 'testSuffix' => '_NotLastNPeriods')),
+ // We also test a single period/single site to check that this use case (Reports per idSite in the response) works
+ array($apiToCall, array(
+ 'idSite' => $idSite1,
+ 'date' => $dateTime,
+ 'periods' => $periods,
+ 'setDateLastN' => false,
+ 'testSuffix' => '_NotLastNPeriods')),
);
// testing metadata API for multiple periods
diff --git a/tests/PHPUnit/Integration/TrackCustomVariablesAndCampaigns_ForceUsingVisitIdNotHeuristicsTest.php b/tests/PHPUnit/Integration/TrackCustomVariablesAndCampaigns_ForceUsingVisitIdNotHeuristicsTest.php
index 73b6f00efc..3616dfe3a9 100755
--- a/tests/PHPUnit/Integration/TrackCustomVariablesAndCampaigns_ForceUsingVisitIdNotHeuristicsTest.php
+++ b/tests/PHPUnit/Integration/TrackCustomVariablesAndCampaigns_ForceUsingVisitIdNotHeuristicsTest.php
@@ -12,7 +12,7 @@
*/
class Test_Piwik_Integration_TrackCustomVariablesAndCampaigns_ForceUsingVisitIdNotHeuristics extends IntegrationTestCase
{
- public static $fixture = null; // initialized below class definition
+ public static $fixture = null; // initialized below class definition
/**
* @dataProvider getApiForTesting
@@ -41,5 +41,5 @@ class Test_Piwik_Integration_TrackCustomVariablesAndCampaigns_ForceUsingVisitIdN
}
Test_Piwik_Integration_TrackCustomVariablesAndCampaigns_ForceUsingVisitIdNotHeuristics::$fixture =
- new Test_Piwik_Fixture_SomeVisitsCustomVariablesCampaignsNotHeuristics();
+ new Test_Piwik_Fixture_SomeVisitsCustomVariablesCampaignsNotHeuristics();
diff --git a/tests/PHPUnit/Integration/TrackGoals_AllowMultipleConversionsPerVisitTest.php b/tests/PHPUnit/Integration/TrackGoals_AllowMultipleConversionsPerVisitTest.php
index 0127a38161..1c7b05699f 100755
--- a/tests/PHPUnit/Integration/TrackGoals_AllowMultipleConversionsPerVisitTest.php
+++ b/tests/PHPUnit/Integration/TrackGoals_AllowMultipleConversionsPerVisitTest.php
@@ -12,7 +12,7 @@
*/
class Test_Piwik_Integration_TrackGoals_AllowMultipleConversionsPerVisit extends IntegrationTestCase
{
- public static $fixture = null;
+ public static $fixture = null;
/**
* @dataProvider getApiForTesting
@@ -21,7 +21,7 @@ class Test_Piwik_Integration_TrackGoals_AllowMultipleConversionsPerVisit extends
*/
public function testApi($api, $params)
{
- $this->runApiTests($api, $params);
+ $this->runApiTests($api, $params);
}
/**
@@ -58,4 +58,4 @@ class Test_Piwik_Integration_TrackGoals_AllowMultipleConversionsPerVisit extends
}
Test_Piwik_Integration_TrackGoals_AllowMultipleConversionsPerVisit::$fixture
- = new Piwik_Test_Fixture_SomeVisitsAllConversions();
+ = new Piwik_Test_Fixture_SomeVisitsAllConversions();
diff --git a/tests/PHPUnit/Integration/TrackingAPI_SetVisitorIdTest.php b/tests/PHPUnit/Integration/TrackingAPI_SetVisitorIdTest.php
index 0bce1fbad2..5ed1db98f0 100644
--- a/tests/PHPUnit/Integration/TrackingAPI_SetVisitorIdTest.php
+++ b/tests/PHPUnit/Integration/TrackingAPI_SetVisitorIdTest.php
@@ -12,7 +12,7 @@
*/
class Test_Piwik_Integration_TrackingAPI_SetVisitorId extends IntegrationTestCase
{
- public static $fixture = null; // initialized below class definition
+ public static $fixture = null; // initialized below class definition
public function setUp()
{
@@ -38,9 +38,9 @@ class Test_Piwik_Integration_TrackingAPI_SetVisitorId extends IntegrationTestCas
{
return array(
// test hideColumns && showColumns parameters
- array('VisitsSummary.get', array('idSite' => self::$fixture->idSite,
- 'date' => self::$fixture->dateTime,
- 'periods' => 'day',
+ array('VisitsSummary.get', array('idSite' => self::$fixture->idSite,
+ 'date' => self::$fixture->dateTime,
+ 'periods' => 'day',
'testSuffix' => '',
))
);
diff --git a/tests/PHPUnit/Integration/TransitionsTest.php b/tests/PHPUnit/Integration/TransitionsTest.php
index 1d9f8375e2..0523feec4c 100644
--- a/tests/PHPUnit/Integration/TransitionsTest.php
+++ b/tests/PHPUnit/Integration/TransitionsTest.php
@@ -5,36 +5,36 @@
*/
class Test_Piwik_Integration_Transitions extends IntegrationTestCase
{
- public static $fixture = null; // initialized below class definition
-
- /**
- * @dataProvider getApiForTesting
- * @group Integration
- * @group Transitions
- */
- public function testApi($api, $params)
- {
- $this->runApiTests($api, $params);
- }
-
- public function getApiForTesting()
- {
- $return = array();
- $return[] = array('Transitions.getTransitionsForPageUrl', array(
- 'idSite' => self::$fixture->idSite,
- 'date' => self::$fixture->dateTime,
- 'otherRequestParameters' => array(
- 'pageUrl' => 'http://example.org/page/one.html',
- 'limitBeforeGrouping' => 2
- )
+ public static $fixture = null; // initialized below class definition
+
+ /**
+ * @dataProvider getApiForTesting
+ * @group Integration
+ * @group Transitions
+ */
+ public function testApi($api, $params)
+ {
+ $this->runApiTests($api, $params);
+ }
+
+ public function getApiForTesting()
+ {
+ $return = array();
+ $return[] = array('Transitions.getTransitionsForPageUrl', array(
+ 'idSite' => self::$fixture->idSite,
+ 'date' => self::$fixture->dateTime,
+ 'otherRequestParameters' => array(
+ 'pageUrl' => 'http://example.org/page/one.html',
+ 'limitBeforeGrouping' => 2
+ )
));
- return $return;
- }
-
- public function getOutputPrefix()
- {
- return 'Transitions';
- }
+ return $return;
+ }
+
+ public function getOutputPrefix()
+ {
+ return 'Transitions';
+ }
}
Test_Piwik_Integration_Transitions::$fixture = new Test_Piwik_Fixture_SomeVisitsManyPageviewsWithTransitions();
diff --git a/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDaysTest.php b/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDaysTest.php
index a9c89a6a8e..5baf9b0aba 100755
--- a/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDaysTest.php
+++ b/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDaysTest.php
@@ -17,16 +17,16 @@
*/
class Test_Piwik_Integration_TwoVisitors_TwoWebsites_DifferentDays extends IntegrationTestCase
{
- public static $fixture = null; // initialized below class definition
+ public static $fixture = null; // initialized below class definition
- /**
- * @group Integration
- * @group TwoVisitors_TwoWebsites_DifferentDays
- */
- public function testImagesIncludedInTests()
- {
- $this->alertWhenImagesExcludedFromTests();
- }
+ /**
+ * @group Integration
+ * @group TwoVisitors_TwoWebsites_DifferentDays
+ */
+ public function testImagesIncludedInTests()
+ {
+ $this->alertWhenImagesExcludedFromTests();
+ }
/**
* @dataProvider getApiForTesting
@@ -41,22 +41,22 @@ class Test_Piwik_Integration_TwoVisitors_TwoWebsites_DifferentDays extends Integ
protected function getApiToCall()
{
return array('VisitFrequency.get',
- 'VisitsSummary.get',
- 'Referers.getWebsites',
- 'Actions.getPageUrls',
- 'Actions.getPageTitles',
- 'Actions.getOutlinks',
- 'Actions.getPageTitle',
- 'Actions.getPageUrl',
- 'VisitorInterest.getNumberOfVisitsByDaysSinceLast');
+ 'VisitsSummary.get',
+ 'Referers.getWebsites',
+ 'Actions.getPageUrls',
+ 'Actions.getPageTitles',
+ 'Actions.getOutlinks',
+ 'Actions.getPageTitle',
+ 'Actions.getPageUrl',
+ 'VisitorInterest.getNumberOfVisitsByDaysSinceLast');
}
public function getApiForTesting()
{
- $idSite1 = self::$fixture->idSite1;
- $dateTime = self::$fixture->dateTime;
-
- $apiToCall = $this->getApiToCall();
+ $idSite1 = self::$fixture->idSite1;
+ $dateTime = self::$fixture->dateTime;
+
+ $apiToCall = $this->getApiToCall();
$singlePeriodApi = array('VisitsSummary.get', 'Goals.get');
$periods = array('day', 'week', 'month', 'year');
@@ -109,5 +109,5 @@ class Test_Piwik_Integration_TwoVisitors_TwoWebsites_DifferentDays extends Integ
}
Test_Piwik_Integration_TwoVisitors_TwoWebsites_DifferentDays::$fixture =
- new Test_Piwik_Fixture_TwoSitesTwoVisitorsDifferentDays();
+ new Test_Piwik_Fixture_TwoSitesTwoVisitorsDifferentDays();
diff --git a/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDays_ArchivingDisabledTest.php b/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDays_ArchivingDisabledTest.php
index 4ec0475f66..89e28bf0b0 100755
--- a/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDays_ArchivingDisabledTest.php
+++ b/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDays_ArchivingDisabledTest.php
@@ -11,7 +11,7 @@
*/
class Test_Piwik_Integration_TwoVisitors_TwoWebsites_DifferentDays_ArchivingDisabled extends IntegrationTestCase
{
- public static $fixture = null; // initialized below class definition
+ public static $fixture = null; // initialized below class definition
/**
* @dataProvider getApiForTesting
@@ -25,8 +25,8 @@ class Test_Piwik_Integration_TwoVisitors_TwoWebsites_DifferentDays_ArchivingDisa
public function getApiForTesting()
{
- $dateTime = self::$fixture->dateTime;
-
+ $dateTime = self::$fixture->dateTime;
+
$periods = array('day', 'week', 'month', 'year');
return array(
@@ -60,6 +60,6 @@ class Test_Piwik_Integration_TwoVisitors_TwoWebsites_DifferentDays_ArchivingDisa
}
Test_Piwik_Integration_TwoVisitors_TwoWebsites_DifferentDays_ArchivingDisabled::$fixture =
- new Test_Piwik_Fixture_TwoSitesTwoVisitorsDifferentDays();
+ new Test_Piwik_Fixture_TwoSitesTwoVisitorsDifferentDays();
Test_Piwik_Integration_TwoVisitors_TwoWebsites_DifferentDays_ArchivingDisabled::$fixture->allowConversions = true;
diff --git a/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDays_ConversionsTest.php b/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDays_ConversionsTest.php
index f1d13db228..711145107d 100755
--- a/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDays_ConversionsTest.php
+++ b/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDays_ConversionsTest.php
@@ -14,7 +14,7 @@ require_once 'Goals/Goals.php';
*/
class Test_Piwik_Integration_TwoVisitors_TwoWebsites_DifferentDays_Conversions extends IntegrationTestCase
{
- public static $fixture = null; // initialized below class definition
+ public static $fixture = null; // initialized below class definition
/**
* @dataProvider getApiForTesting
@@ -26,20 +26,20 @@ class Test_Piwik_Integration_TwoVisitors_TwoWebsites_DifferentDays_Conversions e
$this->runApiTests($api, $params);
}
- public function getApiToCall()
- {
- return array('Goals.getDaysToConversion', 'MultiSites.getAll');
- }
-
- public function getApiForTesting()
- {
- $dateTime = self::$fixture->dateTime;
- $idSite1 = self::$fixture->idSite1;
-
- // NOTE: copied from TwoVisitors_TwoWebsites_DifferentDays (including the test or inheriting means
- // the test will get run by phpunit, even when we only want to run this one. should be put into
- // non-test class later.)
- $apiToCall = $this->getApiToCall();
+ public function getApiToCall()
+ {
+ return array('Goals.getDaysToConversion', 'MultiSites.getAll');
+ }
+
+ public function getApiForTesting()
+ {
+ $dateTime = self::$fixture->dateTime;
+ $idSite1 = self::$fixture->idSite1;
+
+ // NOTE: copied from TwoVisitors_TwoWebsites_DifferentDays (including the test or inheriting means
+ // the test will get run by phpunit, even when we only want to run this one. should be put into
+ // non-test class later.)
+ $apiToCall = $this->getApiToCall();
$singlePeriodApi = array('VisitsSummary.get', 'Goals.get');
$periods = array('day', 'week', 'month', 'year');
@@ -85,7 +85,7 @@ class Test_Piwik_Integration_TwoVisitors_TwoWebsites_DifferentDays_Conversions e
// Tests that getting a visits summary metric (nb_visits) & a Goal's metric (Goal_revenue)
// at the same time works.
$dateTime = '2010-01-03,2010-01-06';
- $columns = 'nb_visits,' . Piwik_Goals::getRecordName('conversion_rate');
+ $columns = 'nb_visits,' . Piwik_Goals::getRecordName('conversion_rate');
$result[] = array(
'VisitsSummary.get', array('idSite' => 'all', 'date' => $dateTime, 'periods' => 'range',
@@ -103,6 +103,6 @@ class Test_Piwik_Integration_TwoVisitors_TwoWebsites_DifferentDays_Conversions e
}
Test_Piwik_Integration_TwoVisitors_TwoWebsites_DifferentDays_Conversions::$fixture =
- new Test_Piwik_Fixture_TwoSitesTwoVisitorsDifferentDays();
+ new Test_Piwik_Fixture_TwoSitesTwoVisitorsDifferentDays();
Test_Piwik_Integration_TwoVisitors_TwoWebsites_DifferentDays_Conversions::$fixture->allowConversions = true;
diff --git a/tests/PHPUnit/Integration/TwoVisitsWithCustomVariablesTest.php b/tests/PHPUnit/Integration/TwoVisitsWithCustomVariablesTest.php
index 188707de0a..f1be9716b3 100755
--- a/tests/PHPUnit/Integration/TwoVisitsWithCustomVariablesTest.php
+++ b/tests/PHPUnit/Integration/TwoVisitsWithCustomVariablesTest.php
@@ -11,13 +11,13 @@
*/
class Test_Piwik_Integration_TwoVisitsWithCustomVariables extends IntegrationTestCase
{
- public static $fixture = null; // initialized below class definition
+ public static $fixture = null; // initialized below class definition
public function getApiForTesting()
{
- $idSite = self::$fixture->idSite;
- $dateTime = self::$fixture->dateTime;
-
+ $idSite = self::$fixture->idSite;
+ $dateTime = self::$fixture->dateTime;
+
$apiToCall = array('VisitsSummary.get', 'CustomVariables.getCustomVariables');
$return = array(
@@ -25,15 +25,15 @@ class Test_Piwik_Integration_TwoVisitsWithCustomVariables extends IntegrationTes
'date' => $dateTime,
'periods' => array('day', 'week'),
'setDateLastN' => true)),
-
- // test getProcessedReport w/ custom variables subtable
- array('API.getProcessedReport', array('idSite' => $idSite,
- 'date' => $dateTime,
- 'periods' => 'day',
- 'apiModule' => 'CustomVariables',
- 'apiAction' => 'getCustomVariablesValuesFromNameId',
- 'supertableApi' => 'CustomVariables.getCustomVariables',
- 'testSuffix' => '__subtable' )),
+
+ // test getProcessedReport w/ custom variables subtable
+ array('API.getProcessedReport', array('idSite' => $idSite,
+ 'date' => $dateTime,
+ 'periods' => 'day',
+ 'apiModule' => 'CustomVariables',
+ 'apiAction' => 'getCustomVariablesValuesFromNameId',
+ 'supertableApi' => 'CustomVariables.getCustomVariables',
+ 'testSuffix' => '__subtable')),
);
return $return;
diff --git a/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentContainsTest.php b/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentContainsTest.php
index 585c10bbdb..648711e9bb 100755
--- a/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentContainsTest.php
+++ b/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentContainsTest.php
@@ -11,7 +11,7 @@
*/
class Test_Piwik_Integration_TwoVisitsWithCustomVariables_SegmentContains extends IntegrationTestCase
{
- public static $fixture = null; // initialized below class definition
+ public static $fixture = null; // initialized below class definition
public function getOutputPrefix()
{
@@ -30,12 +30,12 @@ class Test_Piwik_Integration_TwoVisitsWithCustomVariables_SegmentContains extend
public function getApiForTesting()
{
- $idSite = self::$fixture->idSite;
- $dateTime = self::$fixture->dateTime;
-
+ $idSite = self::$fixture->idSite;
+ $dateTime = self::$fixture->dateTime;
+
$return = array();
- $api = array('Actions.getPageUrls', 'Actions.getPageTitles', 'VisitsSummary.get');
+ $api = array('Actions.getPageUrls', 'Actions.getPageTitles', 'VisitsSummary.get');
$segmentsToTest = array(
// array( SegmentString , TestSuffix , Array of API to test)
array("pageTitle=@*_)%", '_SegmentPageTitleContainsStrangeCharacters', array('Actions.getPageTitles', 'VisitsSummary.get')),
@@ -48,10 +48,10 @@ class Test_Piwik_Integration_TwoVisitsWithCustomVariables_SegmentContains extend
foreach ($segmentsToTest as $segment) {
// Also test "Page URL / Page title CONTAINS string" feature
$return[] = array($segment[2],
- array('idSite' => $idSite, 'date' => $dateTime, 'periods' => array('day'),
- 'setDateLastN' => false,
- 'segment' => $segment[0],
- 'testSuffix' => $segment[1])
+ array('idSite' => $idSite, 'date' => $dateTime, 'periods' => array('day'),
+ 'setDateLastN' => false,
+ 'segment' => $segment[0],
+ 'testSuffix' => $segment[1])
);
}
return $return;
@@ -59,6 +59,6 @@ class Test_Piwik_Integration_TwoVisitsWithCustomVariables_SegmentContains extend
}
Test_Piwik_Integration_TwoVisitsWithCustomVariables_SegmentContains::$fixture
- = new Test_Piwik_Fixture_TwoVisitsWithCustomVariables();
+ = new Test_Piwik_Fixture_TwoVisitsWithCustomVariables();
Test_Piwik_Integration_TwoVisitsWithCustomVariables_SegmentContains::$fixture->doExtraQuoteTests = false;
diff --git a/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchALL_NoGoalDataTest.php b/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchALL_NoGoalDataTest.php
index 26b136dff7..f217be8d0b 100755
--- a/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchALL_NoGoalDataTest.php
+++ b/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchALL_NoGoalDataTest.php
@@ -8,7 +8,7 @@
class Test_Piwik_Integration_TwoVisitsWithCustomVariables_SegmentMatchALL_NoGoalData extends IntegrationTestCase
{
- public static $fixture = null; // initialized below class definition
+ public static $fixture = null; // initialized below class definition
/**
* @dataProvider getApiForTesting
@@ -27,7 +27,7 @@ class Test_Piwik_Integration_TwoVisitsWithCustomVariables_SegmentMatchALL_NoGoal
// Segment matching ALL
// + adding DOES NOT CONTAIN segment always matched, to test this particular operator
$resolution = self::$fixture->resolutionWidthToUse . 'x' . self::$fixture->resolutionHeightToUse;
- $segment = 'resolution==' . $resolution . ';customVariableName1!@randomvalue does not exist';
+ $segment = 'resolution==' . $resolution . ';customVariableName1!@randomvalue does not exist';
return array(
array($apiToCall, array('idSite' => 'all',
@@ -45,6 +45,6 @@ class Test_Piwik_Integration_TwoVisitsWithCustomVariables_SegmentMatchALL_NoGoal
}
Test_Piwik_Integration_TwoVisitsWithCustomVariables_SegmentMatchALL_NoGoalData::$fixture
- = new Test_Piwik_Fixture_TwoVisitsWithCustomVariables();
+ = new Test_Piwik_Fixture_TwoVisitsWithCustomVariables();
Test_Piwik_Integration_TwoVisitsWithCustomVariables_SegmentMatchALL_NoGoalData::$fixture->doExtraQuoteTests = false;
diff --git a/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchNONETest.php b/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchNONETest.php
index 000ed8bc96..0d721f4c7b 100755
--- a/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchNONETest.php
+++ b/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchNONETest.php
@@ -11,7 +11,7 @@
*/
class Test_Piwik_Integration_TwoVisitsWithCustomVariables_SegmentMatchNONE extends IntegrationTestCase
{
- public static $fixture = null; // initialized below class definition
+ public static $fixture = null; // initialized below class definition
/**
* @dataProvider getApiForTesting
@@ -39,7 +39,7 @@ class Test_Piwik_Integration_TwoVisitsWithCustomVariables_SegmentMatchNONE exten
public function getSegmentToTest()
{
// Segment matching NONE
- $segments = Piwik_API_API::getInstance()->getSegmentsMetadata(self::$fixture->idSite);
+ $segments = Piwik_API_API::getInstance()->getSegmentsMetadata(self::$fixture->idSite);
$segmentExpression = array();
$seenVisitorId = false;
@@ -47,7 +47,7 @@ class Test_Piwik_Integration_TwoVisitsWithCustomVariables_SegmentMatchNONE exten
$value = 'campaign';
if ($segment['segment'] == 'visitorId') {
$seenVisitorId = true;
- $value = '34c31e04394bdc63';
+ $value = '34c31e04394bdc63';
}
if ($segment['segment'] == 'visitEcommerceStatus') {
$value = 'none';
@@ -71,6 +71,6 @@ class Test_Piwik_Integration_TwoVisitsWithCustomVariables_SegmentMatchNONE exten
}
Test_Piwik_Integration_TwoVisitsWithCustomVariables_SegmentMatchNONE::$fixture
- = new Test_Piwik_Fixture_TwoVisitsWithCustomVariables();
+ = new Test_Piwik_Fixture_TwoVisitsWithCustomVariables();
Test_Piwik_Integration_TwoVisitsWithCustomVariables_SegmentMatchNONE::$fixture->doExtraQuoteTests = false;
diff --git a/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchVisitorTypeTest.php b/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchVisitorTypeTest.php
index f9a26a3276..17bc92db2d 100755
--- a/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchVisitorTypeTest.php
+++ b/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchVisitorTypeTest.php
@@ -11,7 +11,7 @@
*/
class Test_Piwik_Integration_TwoVisitsWithCustomVariables_SegmentMatchVisitorType extends IntegrationTestCase
{
- public static $fixture = null; // initialized below class definition
+ public static $fixture = null; // initialized below class definition
/**
* @dataProvider getApiForTesting
@@ -27,7 +27,7 @@ class Test_Piwik_Integration_TwoVisitsWithCustomVariables_SegmentMatchVisitorTyp
{
// Segment matching some
$segments = array('customVariableName1==VisitorType;customVariableValue1==LoggedIn',
- 'customVariableName1==VisitorType;customVariableValue1=@LoggedI');
+ 'customVariableName1==VisitorType;customVariableValue1=@LoggedI');
$apiToCall = array('Referers.getKeywords', 'CustomVariables.getCustomVariables', 'VisitsSummary.get');
@@ -85,7 +85,7 @@ class Test_Piwik_Integration_TwoVisitsWithCustomVariables_SegmentMatchVisitorTyp
'archive_numeric_2009_12' => (6 + 2 + 3) * 2,
);
foreach ($tests as $table => $expectedRows) {
- $sql = "SELECT count(*) FROM " . Piwik_Common::prefixTable($table);
+ $sql = "SELECT count(*) FROM " . Piwik_Common::prefixTable($table);
$countBlobs = Zend_Registry::get('db')->fetchOne($sql);
$this->assertEquals($expectedRows, $countBlobs, "$table: %s");
}
@@ -98,6 +98,6 @@ class Test_Piwik_Integration_TwoVisitsWithCustomVariables_SegmentMatchVisitorTyp
}
Test_Piwik_Integration_TwoVisitsWithCustomVariables_SegmentMatchVisitorType::$fixture
- = new Test_Piwik_Fixture_TwoVisitsWithCustomVariables();
+ = new Test_Piwik_Fixture_TwoVisitsWithCustomVariables();
Test_Piwik_Integration_TwoVisitsWithCustomVariables_SegmentMatchVisitorType::$fixture->doExtraQuoteTests = false;
diff --git a/tests/PHPUnit/Integration/UrlNormalizationTest.php b/tests/PHPUnit/Integration/UrlNormalizationTest.php
index 9a7678446f..690a2a57ba 100644
--- a/tests/PHPUnit/Integration/UrlNormalizationTest.php
+++ b/tests/PHPUnit/Integration/UrlNormalizationTest.php
@@ -4,7 +4,7 @@
*/
class Test_Piwik_Integration_UrlNormalization extends IntegrationTestCase
{
- public static $fixture = null; // initialized below class definition
+ public static $fixture = null; // initialized below class definition
/**
* @dataProvider getApiForTesting
@@ -18,10 +18,10 @@ class Test_Piwik_Integration_UrlNormalization extends IntegrationTestCase
public function getApiForTesting()
{
- $idSite = self::$fixture->idSite;
- $dateTime = self::$fixture->dateTime;
-
- $return = array();
+ $idSite = self::$fixture->idSite;
+ $dateTime = self::$fixture->dateTime;
+
+ $return = array();
$return[] = array('Actions.getPageUrls', array(
'testSuffix' => '_urls',
'idSite' => $idSite,
@@ -32,7 +32,7 @@ class Test_Piwik_Integration_UrlNormalization extends IntegrationTestCase
'idSite' => $idSite,
'date' => $dateTime,
));
-
+
$return[] = array('Actions.getPageUrls', array(
'testSuffix' => '_pagesSegmented',
'idSite' => $idSite,
@@ -83,15 +83,15 @@ class Test_Piwik_Integration_UrlNormalization extends IntegrationTestCase
*/
public function testCheckPostConditions()
{
- $sql = "SELECT count(*) FROM " . Piwik_Common::prefixTable('log_action');
- $count = Zend_Registry::get('db')->fetchOne($sql);
+ $sql = "SELECT count(*) FROM " . Piwik_Common::prefixTable('log_action');
+ $count = Zend_Registry::get('db')->fetchOne($sql);
$expected = 9; // 4 urls + 5 titles
$this->assertEquals($expected, $count, "only $expected actions expected");
- $sql = "SELECT name, url_prefix FROM " . Piwik_Common::prefixTable('log_action')
+ $sql = "SELECT name, url_prefix FROM " . Piwik_Common::prefixTable('log_action')
. " WHERE type = " . Piwik_Tracker_Action::TYPE_ACTION_URL
. " ORDER BY idaction ASC";
- $urls = Zend_Registry::get('db')->fetchAll($sql);
+ $urls = Zend_Registry::get('db')->fetchAll($sql);
$expected = array(
array('name' => 'example.org/foo/bar.html', 'url_prefix' => 0),
array('name' => 'example.org/foo/bar2.html', 'url_prefix' => 3),
diff --git a/tests/PHPUnit/Integration/VisitsInPast_InvalidateOldReportsTest.php b/tests/PHPUnit/Integration/VisitsInPast_InvalidateOldReportsTest.php
index 851137cbb3..d93876413a 100644
--- a/tests/PHPUnit/Integration/VisitsInPast_InvalidateOldReportsTest.php
+++ b/tests/PHPUnit/Integration/VisitsInPast_InvalidateOldReportsTest.php
@@ -11,7 +11,7 @@
*/
class Test_Piwik_Integration_VisitsInPast_InvalidateOldReports extends IntegrationTestCase
{
- public static $fixture = null; // initialized below class definition
+ public static $fixture = null; // initialized below class definition
/**
* @dataProvider getApiForTesting
@@ -28,11 +28,11 @@ class Test_Piwik_Integration_VisitsInPast_InvalidateOldReports extends Integrati
*/
public function getApiForTesting()
{
- $idSite = self::$fixture->idSite;
- $idSite2 = self::$fixture->idSite2;
- $dateTimeDateInPastWebsite1 = self::$fixture->dateTimeDateInPastWebsite1;
- $dateTimeDateInPastWebsite2 = self::$fixture->dateTimeDateInPastWebsite2;
-
+ $idSite = self::$fixture->idSite;
+ $idSite2 = self::$fixture->idSite2;
+ $dateTimeDateInPastWebsite1 = self::$fixture->dateTimeDateInPastWebsite1;
+ $dateTimeDateInPastWebsite2 = self::$fixture->dateTimeDateInPastWebsite2;
+
// We test a typical Numeric and a Recursive blob reports
$apiToCall = array('VisitsSummary.get', 'Actions.getPageUrls');
@@ -42,13 +42,13 @@ class Test_Piwik_Integration_VisitsInPast_InvalidateOldReports extends Integrati
// Build tests for the 2 websites
return array(
array($apiToCall, array('idSite' => $idSite,
- 'testSuffix' => 'Website'.$idSite.'_OldReportsShouldNotAppear',
+ 'testSuffix' => 'Website' . $idSite . '_OldReportsShouldNotAppear',
'date' => $dateTimeDateInPastWebsite1,
'periods' => 'month',
'setDateLastN' => 4, // 4months ahead
'otherRequestParameters' => array('expanded' => 1))),
array($apiToCall, array('idSite' => $idSite2,
- 'testSuffix' => 'Website'.$idSite2.'_OldReportsShouldNotAppear',
+ 'testSuffix' => 'Website' . $idSite2 . '_OldReportsShouldNotAppear',
'date' => $dateTimeDateInPastWebsite2,
'periods' => 'month',
'setDateLastN' => 4, // 4months ahead
@@ -64,9 +64,9 @@ class Test_Piwik_Integration_VisitsInPast_InvalidateOldReports extends Integrati
*/
public function testAnotherApi($api, $params)
{
- $idSite = self::$fixture->idSite;
- $idSite2 = self::$fixture->idSite2;
-
+ $idSite = self::$fixture->idSite;
+ $idSite2 = self::$fixture->idSite2;
+
// 1) Invalidate old reports for the 2 websites
// Test invalidate 1 date only
$r = new Piwik_API_Request("module=API&method=CoreAdminHome.invalidateArchivedReports&idSites=4,5,6,55,-1,s',1&dates=2010-01-03");
@@ -91,11 +91,11 @@ class Test_Piwik_Integration_VisitsInPast_InvalidateOldReports extends Integrati
*/
public function getAnotherApiForTesting()
{
- $idSite = self::$fixture->idSite;
- $idSite2 = self::$fixture->idSite2;
- $dateTimeDateInPastWebsite1 = self::$fixture->dateTimeDateInPastWebsite1;
- $dateTimeDateInPastWebsite2 = self::$fixture->dateTimeDateInPastWebsite2;
-
+ $idSite = self::$fixture->idSite;
+ $idSite2 = self::$fixture->idSite2;
+ $dateTimeDateInPastWebsite1 = self::$fixture->dateTimeDateInPastWebsite1;
+ $dateTimeDateInPastWebsite2 = self::$fixture->dateTimeDateInPastWebsite2;
+
$apiToCall = array('VisitsSummary.get', 'Actions.getPageUrls');
return array(
diff --git a/tests/PHPUnit/Integration/expected/test_TwoVisitors_twoWebsites_differentDays_Actions.getPageTitles_firstSite_lastN__API.getProcessedReport_day.xml b/tests/PHPUnit/Integration/expected/test_TwoVisitors_twoWebsites_differentDays_Actions.getPageTitles_firstSite_lastN__API.getProcessedReport_day.xml
index e495613069..31af17abfe 100644
--- a/tests/PHPUnit/Integration/expected/test_TwoVisitors_twoWebsites_differentDays_Actions.getPageTitles_firstSite_lastN__API.getProcessedReport_day.xml
+++ b/tests/PHPUnit/Integration/expected/test_TwoVisitors_twoWebsites_differentDays_Actions.getPageTitles_firstSite_lastN__API.getProcessedReport_day.xml
@@ -92,10 +92,10 @@
<result prettyDate="Monday 4 January 2010" />
<result prettyDate="Tuesday 5 January 2010">
<row>
- <idsubdatatable>72</idsubdatatable>
+
</row>
<row>
- <idsubdatatable>71</idsubdatatable>
+
</row>
</result>
<result prettyDate="Wednesday 6 January 2010" />
diff --git a/tests/PHPUnit/Integration/expected/test_TwoVisitors_twoWebsites_differentDays_scheduled_report_in_html_tables_only__PDFReports.generateReport_month.original.html b/tests/PHPUnit/Integration/expected/test_TwoVisitors_twoWebsites_differentDays_scheduled_report_in_html_tables_only__PDFReports.generateReport_month.original.html
index 2b5020a907..7ca0bbd340 100644
--- a/tests/PHPUnit/Integration/expected/test_TwoVisitors_twoWebsites_differentDays_scheduled_report_in_html_tables_only__PDFReports.generateReport_month.original.html
+++ b/tests/PHPUnit/Integration/expected/test_TwoVisitors_twoWebsites_differentDays_scheduled_report_in_html_tables_only__PDFReports.generateReport_month.original.html
@@ -1,10 +1,10 @@
<html>
<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body style="color: rgb(68,68,68);">
<a name="reportTop"/>
-<a target="_blank" href=""><img title="Go to Piwik" border="0" alt="Piwik" src='themes/default/images/logo-header.png' /></a>
+<a target="_blank" href=""><img title="Go to Piwik" border="0" alt="Piwik" src='themes/default/images/logo-header.png'/></a>
<h1 style="color: rgb(126,115,99); font-size: 11pt;">
Website Site 1
</h1>
@@ -245,7 +245,7 @@ Mobile vs Desktop
Browser language
</a>
</li>
-</ul><a name ="MultiSites_getAll"/>
+</ul><a name="MultiSites_getAll"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
All Websites dashboard
</h2>
@@ -334,7 +334,7 @@ $ 0
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="VisitsSummary_get"/>
+</a><a name="VisitsSummary_get"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Visits Summary
</h2>
@@ -409,7 +409,7 @@ Avg. Visit Duration (in seconds)
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="VisitTime_getVisitInformationPerServerTime"/>
+</a><a name="VisitTime_getVisitInformationPerServerTime"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Visits by Server Time
</h2>
@@ -995,7 +995,7 @@ $ 0
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="VisitTime_getVisitInformationPerLocalTime"/>
+</a><a name="VisitTime_getVisitInformationPerLocalTime"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Visits by Local Time
</h2>
@@ -1581,7 +1581,7 @@ Visits by Local Time
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="VisitTime_getByDayOfWeek"/>
+</a><a name="VisitTime_getByDayOfWeek"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Visits by Day of Week
</h2>
@@ -1776,7 +1776,7 @@ Sunday
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="Actions_get"/>
+</a><a name="Actions_get"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Actions - Main metrics
</h2>
@@ -1859,7 +1859,7 @@ Unique Keywords
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="Actions_getPageUrls"/>
+</a><a name="Actions_getPageUrls"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Page URLs
</h2>
@@ -1993,7 +1993,7 @@ Page URL not defined
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="Actions_getEntryPageUrls"/>
+</a><a name="Actions_getEntryPageUrls"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Entry pages
</h2>
@@ -2050,7 +2050,7 @@ Entry pages
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="Actions_getExitPageUrls"/>
+</a><a name="Actions_getExitPageUrls"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Exit pages
</h2>
@@ -2107,7 +2107,7 @@ Exit pages
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="Actions_getPageTitles"/>
+</a><a name="Actions_getPageTitles"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Page titles
</h2>
@@ -2233,7 +2233,7 @@ Page Name not defined
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="Actions_getEntryPageTitles"/>
+</a><a name="Actions_getEntryPageTitles"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Entry page titles
</h2>
@@ -2286,7 +2286,7 @@ second visitor
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="Actions_getExitPageTitles"/>
+</a><a name="Actions_getExitPageTitles"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Exit page titles
</h2>
@@ -2339,15 +2339,15 @@ Checkout
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="Actions_getOutlinks"/>
+</a><a name="Actions_getOutlinks"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Outlinks
</h2>
-There is no data for this report.<a name ="Actions_getDownloads"/>
+There is no data for this report.<a name="Actions_getDownloads"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Downloads
</h2>
-There is no data for this report.<a name ="Referers_getRefererType"/>
+There is no data for this report.<a name="Referers_getRefererType"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Referrer Type
</h2>
@@ -2427,7 +2427,7 @@ $ 0
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="Referers_getAll"/>
+</a><a name="Referers_getAll"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
All Referrers
</h2>
@@ -2484,11 +2484,11 @@ referer.com
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="Referers_getKeywords"/>
+</a><a name="Referers_getKeywords"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Keywords
</h2>
-There is no data for this report.<a name ="Referers_getWebsites"/>
+There is no data for this report.<a name="Referers_getWebsites"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Websites
</h2>
@@ -2545,19 +2545,19 @@ $ 0
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="Referers_getSearchEngines"/>
+</a><a name="Referers_getSearchEngines"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Search Engines
</h2>
-There is no data for this report.<a name ="Referers_getCampaigns"/>
+There is no data for this report.<a name="Referers_getCampaigns"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Campaigns
</h2>
-There is no data for this report.<a name ="Referers_getSocials"/>
+There is no data for this report.<a name="Referers_getSocials"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Social Networks
</h2>
-There is no data for this report.<a name ="Goals_get"/>
+There is no data for this report.<a name="Goals_get"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Goals
</h2>
@@ -2608,15 +2608,15 @@ $ 0
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="Goals_getVisitsUntilConversion"/>
+</a><a name="Goals_getVisitsUntilConversion"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Visits to Conversion
</h2>
-There is no data for this report.<a name ="Goals_getDaysToConversion"/>
+There is no data for this report.<a name="Goals_getDaysToConversion"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Days to Conversion
</h2>
-There is no data for this report.<a name ="UserCountry_getCountry"/>
+There is no data for this report.<a name="UserCountry_getCountry"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Country
</h2>
@@ -2647,7 +2647,8 @@ Country
<tbody>
<tr style="">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserCountry/flags/fr.png'>&nbsp;
+<img src='plugins/UserCountry/flags/fr.png'>
+&nbsp;
France
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -2674,7 +2675,7 @@ $ 0
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="UserCountry_getContinent"/>
+</a><a name="UserCountry_getContinent"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Continent
</h2>
@@ -2731,7 +2732,7 @@ $ 0
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="UserCountry_getRegion"/>
+</a><a name="UserCountry_getRegion"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Region
</h2>
@@ -2762,7 +2763,8 @@ Region
<tbody>
<tr style="">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserCountry/flags/xx.png'>&nbsp;
+<img src='plugins/UserCountry/flags/xx.png'>
+&nbsp;
Unknown
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -2789,7 +2791,7 @@ $ 0
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="UserCountry_getCity"/>
+</a><a name="UserCountry_getCity"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
City
</h2>
@@ -2820,7 +2822,8 @@ City
<tbody>
<tr style="">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserCountry/flags/xx.png'>&nbsp;
+<img src='plugins/UserCountry/flags/xx.png'>
+&nbsp;
Unknown
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -2847,11 +2850,11 @@ $ 0
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="CustomVariables_getCustomVariables"/>
+</a><a name="CustomVariables_getCustomVariables"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Custom Variables
</h2>
-There is no data for this report.<a name ="VisitorInterest_getNumberOfVisitsPerVisitDuration"/>
+There is no data for this report.<a name="VisitorInterest_getNumberOfVisitsPerVisitDuration"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Length of Visits
</h2>
@@ -2950,7 +2953,7 @@ Length of Visits
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="VisitorInterest_getNumberOfVisitsPerPage"/>
+</a><a name="VisitorInterest_getNumberOfVisitsPerPage"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Pages per Visit
</h2>
@@ -3049,7 +3052,7 @@ Pages per Visit
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="VisitorInterest_getNumberOfVisitsByVisitCount"/>
+</a><a name="VisitorInterest_getNumberOfVisitsByVisitCount"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Visits by Visit Number
</h2>
@@ -3225,7 +3228,7 @@ Visits by Visit Number
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="VisitorInterest_getNumberOfVisitsByDaysSinceLast"/>
+</a><a name="VisitorInterest_getNumberOfVisitsByDaysSinceLast"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Visits by days since last visit
</h2>
@@ -3364,7 +3367,7 @@ New visits
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="VisitFrequency_get"/>
+</a><a name="VisitFrequency_get"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Returning Visits
</h2>
@@ -3431,7 +3434,7 @@ Unique returning visitors
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="Provider_getProvider"/>
+</a><a name="Provider_getProvider"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Provider
</h2>
@@ -3490,7 +3493,7 @@ Unknown
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="UserSettings_getResolution"/>
+</a><a name="UserSettings_getResolution"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Screen Resolution
</h2>
@@ -3570,7 +3573,7 @@ Screen Resolution
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="UserSettings_getBrowser"/>
+</a><a name="UserSettings_getBrowser"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Visitor Browser
</h2>
@@ -3601,7 +3604,8 @@ Visitor Browser
<tbody>
<tr style="">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserSettings/images/browsers/OP.gif'>&nbsp;
+<img src='plugins/UserSettings/images/browsers/OP.gif'>
+&nbsp;
Opera
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -3625,7 +3629,8 @@ Opera
</tr>
<tr style="background-color: rgb(249,250,250)">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserSettings/images/browsers/FF.gif'>&nbsp;
+<img src='plugins/UserSettings/images/browsers/FF.gif'>
+&nbsp;
Firefox
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -3652,7 +3657,7 @@ Firefox
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="UserSettings_getBrowserVersion"/>
+</a><a name="UserSettings_getBrowserVersion"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Browser Version
</h2>
@@ -3683,7 +3688,8 @@ Browser Version
<tbody>
<tr style="">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserSettings/images/browsers/OP.gif'>&nbsp;
+<img src='plugins/UserSettings/images/browsers/OP.gif'>
+&nbsp;
Opera 9.63
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -3707,7 +3713,8 @@ Opera 9.63
</tr>
<tr style="background-color: rgb(249,250,250)">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserSettings/images/browsers/FF.gif'>&nbsp;
+<img src='plugins/UserSettings/images/browsers/FF.gif'>
+&nbsp;
Firefox 3.6
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -3734,7 +3741,7 @@ Firefox 3.6
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="UserSettings_getBrowserType"/>
+</a><a name="UserSettings_getBrowserType"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Browser Family
</h2>
@@ -3814,7 +3821,7 @@ Gecko (Firefox)
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="UserSettings_getPlugin"/>
+</a><a name="UserSettings_getPlugin"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Browser Plugins
</h2>
@@ -3833,7 +3840,8 @@ Browser Plugins
<tbody>
<tr style="">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserSettings/images/plugins/cookie.gif'>&nbsp;
+<img src='plugins/UserSettings/images/plugins/cookie.gif'>
+&nbsp;
Cookie
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -3845,7 +3853,8 @@ Cookie
</tr>
<tr style="background-color: rgb(249,250,250)">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserSettings/images/plugins/flash.gif'>&nbsp;
+<img src='plugins/UserSettings/images/plugins/flash.gif'>
+&nbsp;
Flash
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -3857,7 +3866,8 @@ Flash
</tr>
<tr style="">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserSettings/images/plugins/java.gif'>&nbsp;
+<img src='plugins/UserSettings/images/plugins/java.gif'>
+&nbsp;
Java
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -3869,7 +3879,8 @@ Java
</tr>
<tr style="background-color: rgb(249,250,250)">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserSettings/images/plugins/director.gif'>&nbsp;
+<img src='plugins/UserSettings/images/plugins/director.gif'>
+&nbsp;
Director
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -3881,7 +3892,8 @@ Director
</tr>
<tr style="">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserSettings/images/plugins/gears.gif'>&nbsp;
+<img src='plugins/UserSettings/images/plugins/gears.gif'>
+&nbsp;
Gears
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -3893,7 +3905,8 @@ Gears
</tr>
<tr style="background-color: rgb(249,250,250)">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserSettings/images/plugins/pdf.gif'>&nbsp;
+<img src='plugins/UserSettings/images/plugins/pdf.gif'>
+&nbsp;
Pdf
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -3905,7 +3918,8 @@ Pdf
</tr>
<tr style="">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserSettings/images/plugins/quicktime.gif'>&nbsp;
+<img src='plugins/UserSettings/images/plugins/quicktime.gif'>
+&nbsp;
Quicktime
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -3917,7 +3931,8 @@ Quicktime
</tr>
<tr style="background-color: rgb(249,250,250)">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserSettings/images/plugins/realplayer.gif'>&nbsp;
+<img src='plugins/UserSettings/images/plugins/realplayer.gif'>
+&nbsp;
Realplayer
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -3929,7 +3944,8 @@ Realplayer
</tr>
<tr style="">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserSettings/images/plugins/silverlight.gif'>&nbsp;
+<img src='plugins/UserSettings/images/plugins/silverlight.gif'>
+&nbsp;
Silverlight
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -3941,7 +3957,8 @@ Silverlight
</tr>
<tr style="background-color: rgb(249,250,250)">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserSettings/images/plugins/windowsmedia.gif'>&nbsp;
+<img src='plugins/UserSettings/images/plugins/windowsmedia.gif'>
+&nbsp;
Windowsmedia
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -3956,7 +3973,7 @@ Windowsmedia
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="UserSettings_getWideScreen"/>
+</a><a name="UserSettings_getWideScreen"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Normal / Widescreen
</h2>
@@ -3987,7 +4004,8 @@ Normal / Widescreen
<tbody>
<tr style="">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserSettings/images/screens/dual.gif'>&nbsp;
+<img src='plugins/UserSettings/images/screens/dual.gif'>
+&nbsp;
Dual
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -4011,7 +4029,8 @@ Dual
</tr>
<tr style="background-color: rgb(249,250,250)">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserSettings/images/screens/normal.gif'>&nbsp;
+<img src='plugins/UserSettings/images/screens/normal.gif'>
+&nbsp;
Normal
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -4038,7 +4057,7 @@ Normal
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="UserSettings_getOS"/>
+</a><a name="UserSettings_getOS"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Operating System
</h2>
@@ -4069,7 +4088,8 @@ Operating System
<tbody>
<tr style="">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserSettings/images/os/WXP.gif'>&nbsp;
+<img src='plugins/UserSettings/images/os/WXP.gif'>
+&nbsp;
Windows XP
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -4096,7 +4116,7 @@ Windows XP
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="UserSettings_getConfiguration"/>
+</a><a name="UserSettings_getConfiguration"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Visitor Configuration
</h2>
@@ -4176,7 +4196,7 @@ Windows XP / Firefox / 1024x768
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="UserSettings_getOSFamily"/>
+</a><a name="UserSettings_getOSFamily"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Operating System Family
</h2>
@@ -4207,7 +4227,8 @@ Operating System Family
<tbody>
<tr style="">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserSettings/images/os/WXP.gif'>&nbsp;
+<img src='plugins/UserSettings/images/os/WXP.gif'>
+&nbsp;
Windows
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -4234,7 +4255,7 @@ Windows
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="UserSettings_getMobileVsDesktop"/>
+</a><a name="UserSettings_getMobileVsDesktop"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Mobile vs Desktop
</h2>
@@ -4265,7 +4286,8 @@ Mobile vs Desktop
<tbody>
<tr style="">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserSettings/images/screens/normal.gif'>&nbsp;
+<img src='plugins/UserSettings/images/screens/normal.gif'>
+&nbsp;
Desktop
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -4289,7 +4311,8 @@ Desktop
</tr>
<tr style="background-color: rgb(249,250,250)">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserSettings/images/screens/mobile.gif'>&nbsp;
+<img src='plugins/UserSettings/images/screens/mobile.gif'>
+&nbsp;
Mobile
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -4316,7 +4339,7 @@ Mobile
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="UserSettings_getLanguage"/>
+</a><a name="UserSettings_getLanguage"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Browser language
</h2>
diff --git a/tests/PHPUnit/Integration/expected/test_ecommerceOrderWithItems_scheduled_report_in_html_tables_only__PDFReports.generateReport_week.original.html b/tests/PHPUnit/Integration/expected/test_ecommerceOrderWithItems_scheduled_report_in_html_tables_only__PDFReports.generateReport_week.original.html
index 8b317600a8..aaa75b3f2a 100644
--- a/tests/PHPUnit/Integration/expected/test_ecommerceOrderWithItems_scheduled_report_in_html_tables_only__PDFReports.generateReport_week.original.html
+++ b/tests/PHPUnit/Integration/expected/test_ecommerceOrderWithItems_scheduled_report_in_html_tables_only__PDFReports.generateReport_week.original.html
@@ -1,10 +1,10 @@
<html>
<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body style="color: rgb(68,68,68);">
<a name="reportTop"/>
-<a target="_blank" href=""><img title="Go to Piwik" border="0" alt="Piwik" src='themes/default/images/logo-header.png' /></a>
+<a target="_blank" href=""><img title="Go to Piwik" border="0" alt="Piwik" src='themes/default/images/logo-header.png'/></a>
<h1 style="color: rgb(126,115,99); font-size: 11pt;">
Website Piwik test
</h1>
@@ -305,7 +305,7 @@ Mobile vs Desktop
Browser language
</a>
</li>
-</ul><a name ="MultiSites_getAll"/>
+</ul><a name="MultiSites_getAll"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
All Websites dashboard
</h2>
@@ -394,7 +394,7 @@ $ 0
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="VisitsSummary_get"/>
+</a><a name="VisitsSummary_get"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Visits Summary
</h2>
@@ -469,7 +469,7 @@ Avg. Visit Duration (in seconds)
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="VisitTime_getVisitInformationPerServerTime"/>
+</a><a name="VisitTime_getVisitInformationPerServerTime"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Visits by Server Time
</h2>
@@ -1055,7 +1055,7 @@ $ 0
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="VisitTime_getVisitInformationPerLocalTime"/>
+</a><a name="VisitTime_getVisitInformationPerLocalTime"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Visits by Local Time
</h2>
@@ -1641,7 +1641,7 @@ Visits by Local Time
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="VisitTime_getByDayOfWeek"/>
+</a><a name="VisitTime_getByDayOfWeek"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Visits by Day of Week
</h2>
@@ -1836,7 +1836,7 @@ Sunday
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="Goals_get_idGoal--ecommerceOrder"/>
+</a><a name="Goals_get_idGoal--ecommerceOrder"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Ecommerce Orders
</h2>
@@ -1935,7 +1935,7 @@ $ 3337.78
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="Goals_getVisitsUntilConversion_idGoal--ecommerceOrder"/>
+</a><a name="Goals_getVisitsUntilConversion_idGoal--ecommerceOrder"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Ecommerce Orders - Visits to Conversion
</h2>
@@ -2058,7 +2058,7 @@ Ecommerce Orders - Visits to Conversion
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="Goals_getDaysToConversion_idGoal--ecommerceOrder"/>
+</a><a name="Goals_getDaysToConversion_idGoal--ecommerceOrder"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Ecommerce Orders - Days to Conversion
</h2>
@@ -2189,7 +2189,7 @@ Ecommerce Orders - Days to Conversion
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="Goals_get_idGoal--ecommerceAbandonedCart"/>
+</a><a name="Goals_get_idGoal--ecommerceAbandonedCart"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Abandoned Carts
</h2>
@@ -2240,7 +2240,7 @@ Products left in cart
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="Goals_getVisitsUntilConversion_idGoal--ecommerceAbandonedCart"/>
+</a><a name="Goals_getVisitsUntilConversion_idGoal--ecommerceAbandonedCart"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Abandoned Carts - Visits to Conversion
</h2>
@@ -2363,7 +2363,7 @@ Abandoned Carts - Visits to Conversion
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="Goals_getDaysToConversion_idGoal--ecommerceAbandonedCart"/>
+</a><a name="Goals_getDaysToConversion_idGoal--ecommerceAbandonedCart"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Abandoned Carts - Days to Conversion
</h2>
@@ -2494,7 +2494,7 @@ Abandoned Carts - Days to Conversion
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="Goals_getItemsSku"/>
+</a><a name="Goals_getItemsSku"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Product SKU
</h2>
@@ -2661,7 +2661,7 @@ $ 0
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="Goals_getItemsName"/>
+</a><a name="Goals_getItemsName"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Product Name
</h2>
@@ -2854,7 +2854,7 @@ $ 0
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="Goals_getItemsCategory"/>
+</a><a name="Goals_getItemsCategory"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Product Category
</h2>
@@ -3099,7 +3099,7 @@ $ 0
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="Actions_get"/>
+</a><a name="Actions_get"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Actions - Main metrics
</h2>
@@ -3182,7 +3182,7 @@ Unique Keywords
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="Actions_getPageUrls"/>
+</a><a name="Actions_getPageUrls"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Page URLs
</h2>
@@ -3235,7 +3235,7 @@ Page URLs
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="Actions_getEntryPageUrls"/>
+</a><a name="Actions_getEntryPageUrls"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Entry pages
</h2>
@@ -3276,7 +3276,7 @@ Entry pages
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="Actions_getExitPageUrls"/>
+</a><a name="Actions_getExitPageUrls"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Exit pages
</h2>
@@ -3317,7 +3317,7 @@ Exit pages
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="Actions_getPageTitles"/>
+</a><a name="Actions_getPageTitles"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Page titles
</h2>
@@ -3508,7 +3508,7 @@ Looking at product page
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="Actions_getEntryPageTitles"/>
+</a><a name="Actions_getEntryPageTitles"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Entry page titles
</h2>
@@ -3575,7 +3575,7 @@ Looking at Electronics &amp; Cameras page with a page level custom variable
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="Actions_getExitPageTitles"/>
+</a><a name="Actions_getExitPageTitles"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Exit page titles
</h2>
@@ -3628,15 +3628,15 @@ Another Product page with multiple categories
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="Actions_getOutlinks"/>
+</a><a name="Actions_getOutlinks"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Outlinks
</h2>
-There is no data for this report.<a name ="Actions_getDownloads"/>
+There is no data for this report.<a name="Actions_getDownloads"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Downloads
</h2>
-There is no data for this report.<a name ="Referers_getRefererType"/>
+There is no data for this report.<a name="Referers_getRefererType"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Referrer Type
</h2>
@@ -3693,31 +3693,31 @@ $ 13361.11
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="Referers_getAll"/>
+</a><a name="Referers_getAll"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
All Referrers
</h2>
-There is no data for this report.<a name ="Referers_getKeywords"/>
+There is no data for this report.<a name="Referers_getKeywords"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Keywords
</h2>
-There is no data for this report.<a name ="Referers_getWebsites"/>
+There is no data for this report.<a name="Referers_getWebsites"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Websites
</h2>
-There is no data for this report.<a name ="Referers_getSearchEngines"/>
+There is no data for this report.<a name="Referers_getSearchEngines"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Search Engines
</h2>
-There is no data for this report.<a name ="Referers_getCampaigns"/>
+There is no data for this report.<a name="Referers_getCampaigns"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Campaigns
</h2>
-There is no data for this report.<a name ="Referers_getSocials"/>
+There is no data for this report.<a name="Referers_getSocials"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Social Networks
</h2>
-There is no data for this report.<a name ="Goals_get"/>
+There is no data for this report.<a name="Goals_get"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Goals
</h2>
@@ -3768,7 +3768,7 @@ $ 13361.11
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="Goals_getVisitsUntilConversion"/>
+</a><a name="Goals_getVisitsUntilConversion"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Visits to Conversion
</h2>
@@ -3933,7 +3933,7 @@ $ 0
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="Goals_getDaysToConversion"/>
+</a><a name="Goals_getDaysToConversion"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Days to Conversion
</h2>
@@ -4109,7 +4109,7 @@ $ 0
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="Goals_get_idGoal--1"/>
+</a><a name="Goals_get_idGoal--1"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Goal title match, triggered ONCE
</h2>
@@ -4160,7 +4160,7 @@ $ 10
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="Goals_getVisitsUntilConversion_idGoal--1"/>
+</a><a name="Goals_getVisitsUntilConversion_idGoal--1"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
title match, triggered ONCE - Visits to Conversion
</h2>
@@ -4283,7 +4283,7 @@ title match, triggered ONCE - Visits to Conversion
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="Goals_getDaysToConversion_idGoal--1"/>
+</a><a name="Goals_getDaysToConversion_idGoal--1"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
title match, triggered ONCE - Days to Conversion
</h2>
@@ -4414,7 +4414,7 @@ title match, triggered ONCE - Days to Conversion
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="UserCountry_getCountry"/>
+</a><a name="UserCountry_getCountry"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Country
</h2>
@@ -4445,7 +4445,8 @@ Country
<tbody>
<tr style="">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserCountry/flags/fr.png'>&nbsp;
+<img src='plugins/UserCountry/flags/fr.png'>
+&nbsp;
France
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -4472,7 +4473,7 @@ $ 13361.11
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="UserCountry_getContinent"/>
+</a><a name="UserCountry_getContinent"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Continent
</h2>
@@ -4529,7 +4530,7 @@ $ 13361.11
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="UserCountry_getRegion"/>
+</a><a name="UserCountry_getRegion"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Region
</h2>
@@ -4560,7 +4561,8 @@ Region
<tbody>
<tr style="">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserCountry/flags/xx.png'>&nbsp;
+<img src='plugins/UserCountry/flags/xx.png'>
+&nbsp;
Unknown
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -4587,7 +4589,7 @@ $ 13361.11
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="UserCountry_getCity"/>
+</a><a name="UserCountry_getCity"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
City
</h2>
@@ -4618,7 +4620,8 @@ City
<tbody>
<tr style="">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserCountry/flags/xx.png'>&nbsp;
+<img src='plugins/UserCountry/flags/xx.png'>
+&nbsp;
Unknown
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -4645,7 +4648,7 @@ $ 13361.11
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="CustomVariables_getCustomVariables"/>
+</a><a name="CustomVariables_getCustomVariables"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Custom Variables
</h2>
@@ -4748,7 +4751,7 @@ $ 13351.11
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="VisitorInterest_getNumberOfVisitsPerVisitDuration"/>
+</a><a name="VisitorInterest_getNumberOfVisitsPerVisitDuration"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Length of Visits
</h2>
@@ -4847,7 +4850,7 @@ Length of Visits
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="VisitorInterest_getNumberOfVisitsPerPage"/>
+</a><a name="VisitorInterest_getNumberOfVisitsPerPage"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Pages per Visit
</h2>
@@ -4946,7 +4949,7 @@ Pages per Visit
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="VisitorInterest_getNumberOfVisitsByVisitCount"/>
+</a><a name="VisitorInterest_getNumberOfVisitsByVisitCount"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Visits by Visit Number
</h2>
@@ -5122,7 +5125,7 @@ Visits by Visit Number
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="VisitorInterest_getNumberOfVisitsByDaysSinceLast"/>
+</a><a name="VisitorInterest_getNumberOfVisitsByDaysSinceLast"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Visits by days since last visit
</h2>
@@ -5261,7 +5264,7 @@ New visits
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="VisitFrequency_get"/>
+</a><a name="VisitFrequency_get"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Returning Visits
</h2>
@@ -5328,7 +5331,7 @@ Unique returning visitors
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="Provider_getProvider"/>
+</a><a name="Provider_getProvider"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Provider
</h2>
@@ -5387,7 +5390,7 @@ Unknown
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="UserSettings_getResolution"/>
+</a><a name="UserSettings_getResolution"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Screen Resolution
</h2>
@@ -5444,7 +5447,7 @@ Screen Resolution
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="UserSettings_getBrowser"/>
+</a><a name="UserSettings_getBrowser"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Visitor Browser
</h2>
@@ -5475,7 +5478,8 @@ Visitor Browser
<tbody>
<tr style="">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserSettings/images/browsers/FF.gif'>&nbsp;
+<img src='plugins/UserSettings/images/browsers/FF.gif'>
+&nbsp;
Firefox
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -5502,7 +5506,7 @@ Firefox
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="UserSettings_getBrowserVersion"/>
+</a><a name="UserSettings_getBrowserVersion"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Browser Version
</h2>
@@ -5533,7 +5537,8 @@ Browser Version
<tbody>
<tr style="">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserSettings/images/browsers/FF.gif'>&nbsp;
+<img src='plugins/UserSettings/images/browsers/FF.gif'>
+&nbsp;
Firefox 3.6
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -5560,7 +5565,7 @@ Firefox 3.6
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="UserSettings_getBrowserType"/>
+</a><a name="UserSettings_getBrowserType"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Browser Family
</h2>
@@ -5617,7 +5622,7 @@ Gecko (Firefox)
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="UserSettings_getPlugin"/>
+</a><a name="UserSettings_getPlugin"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Browser Plugins
</h2>
@@ -5636,7 +5641,8 @@ Browser Plugins
<tbody>
<tr style="">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserSettings/images/plugins/cookie.gif'>&nbsp;
+<img src='plugins/UserSettings/images/plugins/cookie.gif'>
+&nbsp;
Cookie
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -5648,7 +5654,8 @@ Cookie
</tr>
<tr style="background-color: rgb(249,250,250)">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserSettings/images/plugins/flash.gif'>&nbsp;
+<img src='plugins/UserSettings/images/plugins/flash.gif'>
+&nbsp;
Flash
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -5660,7 +5667,8 @@ Flash
</tr>
<tr style="">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserSettings/images/plugins/java.gif'>&nbsp;
+<img src='plugins/UserSettings/images/plugins/java.gif'>
+&nbsp;
Java
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -5672,7 +5680,8 @@ Java
</tr>
<tr style="background-color: rgb(249,250,250)">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserSettings/images/plugins/director.gif'>&nbsp;
+<img src='plugins/UserSettings/images/plugins/director.gif'>
+&nbsp;
Director
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -5684,7 +5693,8 @@ Director
</tr>
<tr style="">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserSettings/images/plugins/gears.gif'>&nbsp;
+<img src='plugins/UserSettings/images/plugins/gears.gif'>
+&nbsp;
Gears
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -5696,7 +5706,8 @@ Gears
</tr>
<tr style="background-color: rgb(249,250,250)">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserSettings/images/plugins/pdf.gif'>&nbsp;
+<img src='plugins/UserSettings/images/plugins/pdf.gif'>
+&nbsp;
Pdf
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -5708,7 +5719,8 @@ Pdf
</tr>
<tr style="">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserSettings/images/plugins/quicktime.gif'>&nbsp;
+<img src='plugins/UserSettings/images/plugins/quicktime.gif'>
+&nbsp;
Quicktime
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -5720,7 +5732,8 @@ Quicktime
</tr>
<tr style="background-color: rgb(249,250,250)">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserSettings/images/plugins/realplayer.gif'>&nbsp;
+<img src='plugins/UserSettings/images/plugins/realplayer.gif'>
+&nbsp;
Realplayer
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -5732,7 +5745,8 @@ Realplayer
</tr>
<tr style="">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserSettings/images/plugins/silverlight.gif'>&nbsp;
+<img src='plugins/UserSettings/images/plugins/silverlight.gif'>
+&nbsp;
Silverlight
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -5744,7 +5758,8 @@ Silverlight
</tr>
<tr style="background-color: rgb(249,250,250)">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserSettings/images/plugins/windowsmedia.gif'>&nbsp;
+<img src='plugins/UserSettings/images/plugins/windowsmedia.gif'>
+&nbsp;
Windowsmedia
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -5759,7 +5774,7 @@ Windowsmedia
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="UserSettings_getWideScreen"/>
+</a><a name="UserSettings_getWideScreen"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Normal / Widescreen
</h2>
@@ -5790,7 +5805,8 @@ Normal / Widescreen
<tbody>
<tr style="">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserSettings/images/screens/normal.gif'>&nbsp;
+<img src='plugins/UserSettings/images/screens/normal.gif'>
+&nbsp;
Normal
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -5817,7 +5833,7 @@ Normal
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="UserSettings_getOS"/>
+</a><a name="UserSettings_getOS"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Operating System
</h2>
@@ -5848,7 +5864,8 @@ Operating System
<tbody>
<tr style="">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserSettings/images/os/WXP.gif'>&nbsp;
+<img src='plugins/UserSettings/images/os/WXP.gif'>
+&nbsp;
Windows XP
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -5875,7 +5892,7 @@ Windows XP
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="UserSettings_getConfiguration"/>
+</a><a name="UserSettings_getConfiguration"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Visitor Configuration
</h2>
@@ -5932,7 +5949,7 @@ Windows XP / Firefox / 1024x768
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="UserSettings_getOSFamily"/>
+</a><a name="UserSettings_getOSFamily"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Operating System Family
</h2>
@@ -5963,7 +5980,8 @@ Operating System Family
<tbody>
<tr style="">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserSettings/images/os/WXP.gif'>&nbsp;
+<img src='plugins/UserSettings/images/os/WXP.gif'>
+&nbsp;
Windows
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -5990,7 +6008,7 @@ Windows
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="UserSettings_getMobileVsDesktop"/>
+</a><a name="UserSettings_getMobileVsDesktop"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Mobile vs Desktop
</h2>
@@ -6021,7 +6039,8 @@ Mobile vs Desktop
<tbody>
<tr style="">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserSettings/images/screens/normal.gif'>&nbsp;
+<img src='plugins/UserSettings/images/screens/normal.gif'>
+&nbsp;
Desktop
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -6045,7 +6064,8 @@ Desktop
</tr>
<tr style="background-color: rgb(249,250,250)">
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
-<img src='plugins/UserSettings/images/screens/mobile.gif'>&nbsp;
+<img src='plugins/UserSettings/images/screens/mobile.gif'>
+&nbsp;
Mobile
</td>
<td style="font-size: 11pt; border-bottom: 1px solid rgb(231,231,231); padding: 5px 0 5px 5px;">
@@ -6072,7 +6092,7 @@ Mobile
<br/>
<a style="text-decoration:none; color: rgb(126,115,99); font-size: 9pt" href="#reportTop">
Back to top
-</a><a name ="UserSettings_getLanguage"/>
+</a><a name="UserSettings_getLanguage"/>
<h2 style="color: rgb(126,115,99); font-size: 11pt;">
Browser language
</h2>
diff --git a/tests/PHPUnit/IntegrationTestCase.php b/tests/PHPUnit/IntegrationTestCase.php
index 3ee7c7f59c..b81027fc31 100755
--- a/tests/PHPUnit/IntegrationTestCase.php
+++ b/tests/PHPUnit/IntegrationTestCase.php
@@ -21,101 +21,94 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
* @var string
*/
protected $lastLanguage;
-
- /**
- * Creates a config object for use w/ tests.
- */
- public static function createTestConfig()
- {
+
+ /**
+ * Creates a config object for use w/ tests.
+ */
+ public static function createTestConfig()
+ {
Piwik::createConfigObject();
Piwik_Config::getInstance()->setTestEnvironment();
- }
-
- /**
- * Connects to MySQL w/o specifying a database.
- */
- public static function connectWithoutDatabase()
- {
+ }
+
+ /**
+ * Connects to MySQL w/o specifying a database.
+ */
+ public static function connectWithoutDatabase()
+ {
$dbConfig = Piwik_Config::getInstance()->database;
$oldDbName = $dbConfig['dbname'];
$dbConfig['dbname'] = null;
-
+
Piwik::createDatabaseObject($dbConfig);
-
+
$dbConfig['dbname'] = $oldDbName;
- }
-
- public static function setUpBeforeClass()
- {
- self::_setUpBeforeClass();
-
- if (isset(static::$fixture))
- {
- self::setupFixture(static::$fixture);
- }
- }
-
- protected static function setupFixture( $fixture )
- {
- try
- {
- $fixture->setUp();
- }
- catch(Exception $e)
- {
- // Skip whole test suite if an error occurs while setup
- throw new PHPUnit_Framework_SkippedTestSuiteError($e->getMessage()."\n".$e->getTraceAsString());
- }
- }
-
- protected static function teardownFixture( $fixture )
- {
- if (isset(static::$fixture))
- {
- self::tearDownFixture(static::$fixture);
- }
-
- $fixture->tearDown();
- }
-
- /**
- * setupBeforeClass' implementation. Can be called by derived classes in case
- * they need to do some custom setup procedure.
- */
- public static function _setUpBeforeClass( $dbName = false, $createEmptyDatabase = true, $createConfig = true )
+ }
+
+ public static function setUpBeforeClass()
+ {
+ self::_setUpBeforeClass();
+
+ if (isset(static::$fixture)) {
+ self::setupFixture(static::$fixture);
+ }
+ }
+
+ protected static function setupFixture($fixture)
{
try {
- Piwik::$piwikUrlCache = '';
-
- if ($createConfig)
- {
- self::createTestConfig();
- }
-
- if ($dbName === false) // must be after test config is created
- {
- $dbName = Piwik_Config::getInstance()->database['dbname'];
- }
-
- self::connectWithoutDatabase();
- if ($createEmptyDatabase)
+ $fixture->setUp();
+ } catch (Exception $e) {
+ // Skip whole test suite if an error occurs while setup
+ throw new PHPUnit_Framework_SkippedTestSuiteError($e->getMessage() . "\n" . $e->getTraceAsString());
+ }
+ }
+
+ protected static function teardownFixture($fixture)
+ {
+ if (isset(static::$fixture)) {
+ self::tearDownFixture(static::$fixture);
+ }
+
+ $fixture->tearDown();
+ }
+
+ /**
+ * setupBeforeClass' implementation. Can be called by derived classes in case
+ * they need to do some custom setup procedure.
+ */
+ public static function _setUpBeforeClass($dbName = false, $createEmptyDatabase = true, $createConfig = true)
+ {
+ try {
+ Piwik::$piwikUrlCache = '';
+
+ if ($createConfig) {
+ self::createTestConfig();
+ }
+
+ if ($dbName === false) // must be after test config is created
{
+ $dbName = Piwik_Config::getInstance()->database['dbname'];
+ }
+
+ self::connectWithoutDatabase();
+ if ($createEmptyDatabase) {
Piwik::dropDatabase();
}
Piwik::createDatabase($dbName);
Piwik::disconnectDatabase();
-
- // reconnect once we're sure the database exists
- Piwik_Config::getInstance()->database['dbname'] = $dbName;
+
+ // reconnect once we're sure the database exists
+ Piwik_Config::getInstance()->database['dbname'] = $dbName;
Piwik::createDatabaseObject();
-
+
Piwik::createTables();
Piwik::createLogObject();
Piwik_PluginsManager::getInstance()->loadPlugins(array());
- } catch(Exception $e) {
- self::fail("TEST INITIALIZATION FAILED: " .$e->getMessage());
+ } catch (Exception $e) {
+ self::fail("TEST INITIALIZATION FAILED: " . $e->getMessage());
}
include "DataFiles/SearchEngines.php";
@@ -129,16 +122,16 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
// We need to be SU to create websites for tests
Piwik::setUserIsSuperUser();
- Piwik_Tracker_Cache::deleteTrackerCache();
+ Piwik_Tracker_Cache::deleteTrackerCache();
// Load and install plugins
$pluginsManager = Piwik_PluginsManager::getInstance();
$plugins = $pluginsManager->readPluginsDirectory();
- $pluginsManager->loadPlugins( $plugins );
+ $pluginsManager->loadPlugins($plugins);
if ($createEmptyDatabase) // only install if database is empty
{
- $pluginsManager->installLoadedPlugins();
+ $pluginsManager->installLoadedPlugins();
}
$_GET = $_REQUEST = array();
@@ -151,30 +144,29 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
// List of Modules, or Module.Method that should not be called as part of the XML output compare
// Usually these modules either return random changing data, or are already tested in specific unit tests.
self::setApiNotToCall(self::$defaultApiNotToCall);
- self::setApiToCall( array());
+ self::setApiToCall(array());
}
- public static function tearDownAfterClass()
- {
- self::_tearDownAfterClass();
- }
+ public static function tearDownAfterClass()
+ {
+ self::_tearDownAfterClass();
+ }
- public static function _tearDownAfterClass( $dropDatabase = true )
+ public static function _tearDownAfterClass($dropDatabase = true)
{
- Piwik::$piwikUrlCache = null;
-
+ Piwik::$piwikUrlCache = null;
+
try {
$plugins = Piwik_PluginsManager::getInstance()->getLoadedPlugins();
- foreach($plugins AS $plugin) {
- if ($dropDatabase)
- {
- $plugin->uninstall();
+ foreach ($plugins AS $plugin) {
+ if ($dropDatabase) {
+ $plugin->uninstall();
}
}
Piwik_PluginsManager::getInstance()->unloadPlugins();
- } catch (Exception $e) {}
- if ($dropDatabase)
- {
+ } catch (Exception $e) {
+ }
+ if ($dropDatabase) {
Piwik::dropDatabase();
}
Piwik_DataTable_Manager::getInstance()->deleteAll();
@@ -195,8 +187,8 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
public function setUp()
{
- // Make sure the browser running the test does not influence the Country detection code
- $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en';
+ // Make sure the browser running the test does not influence the Country detection code
+ $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en';
$this->changeLanguage('en');
}
@@ -210,7 +202,7 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
'UsersManager',
'SitesManager',
'ExampleUI',
- 'Overlay',
+ 'Overlay',
'Live',
'SEO',
'ExampleAPI',
@@ -224,7 +216,7 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
);
const DEFAULT_USER_PASSWORD = 'nopass';
-
+
protected $missingExpectedFiles = array();
protected $comparisonFailures = array();
@@ -238,14 +230,12 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
* @throws Exception
* @return void
*/
- protected static function setApiToCall( $apiToCall )
+ protected static function setApiToCall($apiToCall)
{
- if(func_num_args() != 1)
- {
+ if (func_num_args() != 1) {
throw new Exception('setApiToCall expects an array');
}
- if(!is_array($apiToCall))
- {
+ if (!is_array($apiToCall)) {
$apiToCall = array($apiToCall);
}
self::$apiToCall = $apiToCall;
@@ -258,164 +248,160 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
*
* @return void
*/
- protected static function setApiNotToCall( $apiNotToCall )
+ protected static function setApiNotToCall($apiNotToCall)
{
- if(!is_array($apiNotToCall))
- {
+ if (!is_array($apiNotToCall)) {
$apiNotToCall = array($apiNotToCall);
}
self::$apiNotToCall = $apiNotToCall;
}
- protected function alertWhenImagesExcludedFromTests()
- {
- if(!Test_Piwik_BaseFixture::canImagesBeIncludedInScheduledReports())
- {
- $this->markTestSkipped(
- 'Do take note that scheduled reports are not being tested with images. ' .
- 'If images contained in scheduled reports have been altered, tests will fail on the Piwik QA Server. ' .
- 'To include images in the test suite, please use a machine with the following specifications : ' .
- 'OS = Linux precise32, PHP Version = 5.3.10 and GD Version = 2.0' .
- "\n Ignore this message if you're running on your dev machine, but pay attention when it comes from Jenkins."
-
- );
- }
- }
-
- /**
- * Return 4 Api Urls for testing scheduled reports :
- * - one in HTML format with all available reports
- * - one in PDF format with all available reports
- * - two in SMS (one for each available report: MultiSites.getOne & MultiSites.getAll)
- *
- * @param string $dateTime eg '2010-01-01 12:34:56'
- * @param string $period eg 'day', 'week', 'month', 'year'
- */
- protected static function getApiForTestingScheduledReports($dateTime, $period)
- {
- $apiCalls = array();
-
- // HTML Scheduled Report
- array_push(
- $apiCalls,
- array(
- 'PDFReports.generateReport',
- array(
- 'testSuffix' => '_scheduled_report_in_html_tables_only',
- 'date' => $dateTime,
- 'periods' => array($period),
- 'format' => 'original',
- 'fileExtension' => 'html',
- 'otherRequestParameters' => array(
- 'idReport' => 1,
- 'reportFormat' => Piwik_ReportRenderer::HTML_FORMAT,
- 'outputType' => Piwik_PDFReports_API::OUTPUT_RETURN
- )
- )
- )
- );
-
- // This particular PDF file looks different on recent PHP
- // Differences with expected in: tests/PHPUnit/Integration/processed/test_ecommerceOrderWithItems_scheduled_report_in_pdf_tables_only__PDFReports.generateReport_week.original.pdf
- // Failed asserting that 486675 matches expected 486668.
- // So we disable this test for 5.4 and 5.5
- if(stristr(phpversion(), '5.4') === false && stristr(phpversion(), '5.5') === false)
- {
- // PDF Scheduled Report
- array_push(
- $apiCalls,
- array(
- 'PDFReports.generateReport',
- array(
- 'testSuffix' => '_scheduled_report_in_pdf_tables_only',
- 'date' => $dateTime,
- 'periods' => array($period),
- 'format' => 'original',
- 'fileExtension' => 'pdf',
- 'otherRequestParameters' => array(
- 'idReport' => 1,
- 'reportFormat' => Piwik_ReportRenderer::PDF_FORMAT,
- 'outputType' => Piwik_PDFReports_API::OUTPUT_RETURN
- )
- )
- )
- );
- }
-
- // SMS Scheduled Report, one site
- array_push(
- $apiCalls,
- array(
- 'PDFReports.generateReport',
- array(
- 'testSuffix' => '_scheduled_report_via_sms_one_site',
- 'date' => $dateTime,
- 'periods' => array($period),
- 'format' => 'original',
- 'fileExtension' => 'sms.txt',
- 'otherRequestParameters' => array(
- 'idReport' => 2,
- 'outputType' => Piwik_PDFReports_API::OUTPUT_RETURN
- )
- )
- )
- );
-
- // SMS Scheduled Report, all sites
- array_push(
- $apiCalls,
- array(
- 'PDFReports.generateReport',
- array(
- 'testSuffix' => '_scheduled_report_via_sms_all_sites',
- 'date' => $dateTime,
- 'periods' => array($period),
- 'format' => 'original',
- 'fileExtension' => 'sms.txt',
- 'otherRequestParameters' => array(
- 'idReport' => 3,
- 'outputType' => Piwik_PDFReports_API::OUTPUT_RETURN
- )
- )
- )
- );
-
- if(Test_Piwik_BaseFixture::canImagesBeIncludedInScheduledReports())
- {
- // HTML Scheduled Report with images
- array_push(
- $apiCalls,
- array(
- 'PDFReports.generateReport',
- array(
- 'testSuffix' => '_scheduled_report_in_html_tables_and_graph',
- 'date' => $dateTime,
- 'periods' => array($period),
- 'format' => 'original',
- 'fileExtension' => 'html',
- 'otherRequestParameters' => array(
- 'idReport' => 4,
- 'reportFormat' => Piwik_ReportRenderer::HTML_FORMAT,
- 'outputType' => Piwik_PDFReports_API::OUTPUT_RETURN
- )
- )
- )
- );
- }
-
- return $apiCalls;
- }
+ protected function alertWhenImagesExcludedFromTests()
+ {
+ if (!Test_Piwik_BaseFixture::canImagesBeIncludedInScheduledReports()) {
+ $this->markTestSkipped(
+ 'Do take note that scheduled reports are not being tested with images. ' .
+ 'If images contained in scheduled reports have been altered, tests will fail on the Piwik QA Server. ' .
+ 'To include images in the test suite, please use a machine with the following specifications : ' .
+ 'OS = Linux precise32, PHP Version = 5.3.10 and GD Version = 2.0' .
+ "\n Ignore this message if you're running on your dev machine, but pay attention when it comes from Jenkins."
+
+ );
+ }
+ }
+
+ /**
+ * Return 4 Api Urls for testing scheduled reports :
+ * - one in HTML format with all available reports
+ * - one in PDF format with all available reports
+ * - two in SMS (one for each available report: MultiSites.getOne & MultiSites.getAll)
+ *
+ * @param string $dateTime eg '2010-01-01 12:34:56'
+ * @param string $period eg 'day', 'week', 'month', 'year'
+ */
+ protected static function getApiForTestingScheduledReports($dateTime, $period)
+ {
+ $apiCalls = array();
+
+ // HTML Scheduled Report
+ array_push(
+ $apiCalls,
+ array(
+ 'PDFReports.generateReport',
+ array(
+ 'testSuffix' => '_scheduled_report_in_html_tables_only',
+ 'date' => $dateTime,
+ 'periods' => array($period),
+ 'format' => 'original',
+ 'fileExtension' => 'html',
+ 'otherRequestParameters' => array(
+ 'idReport' => 1,
+ 'reportFormat' => Piwik_ReportRenderer::HTML_FORMAT,
+ 'outputType' => Piwik_PDFReports_API::OUTPUT_RETURN
+ )
+ )
+ )
+ );
+
+ // This particular PDF file looks different on recent PHP
+ // Differences with expected in: tests/PHPUnit/Integration/processed/test_ecommerceOrderWithItems_scheduled_report_in_pdf_tables_only__PDFReports.generateReport_week.original.pdf
+ // Failed asserting that 486675 matches expected 486668.
+ // So we disable this test for 5.4 and 5.5
+ if (stristr(phpversion(), '5.4') === false && stristr(phpversion(), '5.5') === false) {
+ // PDF Scheduled Report
+ array_push(
+ $apiCalls,
+ array(
+ 'PDFReports.generateReport',
+ array(
+ 'testSuffix' => '_scheduled_report_in_pdf_tables_only',
+ 'date' => $dateTime,
+ 'periods' => array($period),
+ 'format' => 'original',
+ 'fileExtension' => 'pdf',
+ 'otherRequestParameters' => array(
+ 'idReport' => 1,
+ 'reportFormat' => Piwik_ReportRenderer::PDF_FORMAT,
+ 'outputType' => Piwik_PDFReports_API::OUTPUT_RETURN
+ )
+ )
+ )
+ );
+ }
+
+ // SMS Scheduled Report, one site
+ array_push(
+ $apiCalls,
+ array(
+ 'PDFReports.generateReport',
+ array(
+ 'testSuffix' => '_scheduled_report_via_sms_one_site',
+ 'date' => $dateTime,
+ 'periods' => array($period),
+ 'format' => 'original',
+ 'fileExtension' => 'sms.txt',
+ 'otherRequestParameters' => array(
+ 'idReport' => 2,
+ 'outputType' => Piwik_PDFReports_API::OUTPUT_RETURN
+ )
+ )
+ )
+ );
+
+ // SMS Scheduled Report, all sites
+ array_push(
+ $apiCalls,
+ array(
+ 'PDFReports.generateReport',
+ array(
+ 'testSuffix' => '_scheduled_report_via_sms_all_sites',
+ 'date' => $dateTime,
+ 'periods' => array($period),
+ 'format' => 'original',
+ 'fileExtension' => 'sms.txt',
+ 'otherRequestParameters' => array(
+ 'idReport' => 3,
+ 'outputType' => Piwik_PDFReports_API::OUTPUT_RETURN
+ )
+ )
+ )
+ );
+
+ if (Test_Piwik_BaseFixture::canImagesBeIncludedInScheduledReports()) {
+ // HTML Scheduled Report with images
+ array_push(
+ $apiCalls,
+ array(
+ 'PDFReports.generateReport',
+ array(
+ 'testSuffix' => '_scheduled_report_in_html_tables_and_graph',
+ 'date' => $dateTime,
+ 'periods' => array($period),
+ 'format' => 'original',
+ 'fileExtension' => 'html',
+ 'otherRequestParameters' => array(
+ 'idReport' => 4,
+ 'reportFormat' => Piwik_ReportRenderer::HTML_FORMAT,
+ 'outputType' => Piwik_PDFReports_API::OUTPUT_RETURN
+ )
+ )
+ )
+ );
+ }
+
+ return $apiCalls;
+ }
/**
* Given a list of default parameters to set, returns the URLs of APIs to call
* If any API was specified in setApiToCall() we ensure only these are tested.
* If any API is set as excluded (see list below) then it will be ignored.
*
- * @param array $parametersToSet Parameters to set in api call
- * @param array $formats Array of 'format' to fetch from API
- * @param array $periods Array of 'period' to query API
- * @param bool $supertableApi
- * @param bool $setDateLastN If set to true, the 'date' parameter will be rewritten to query instead a range of dates, rather than one period only.
+ * @param array $parametersToSet Parameters to set in api call
+ * @param array $formats Array of 'format' to fetch from API
+ * @param array $periods Array of 'period' to query API
+ * @param bool $supertableApi
+ * @param bool $setDateLastN If set to true, the 'date' parameter will be rewritten to query instead a range of dates, rather than one period only.
* @param bool|string $language 2 letter language code, defaults to default piwik language
* @param bool|string $segment
* @param bool|string $fileExtension
@@ -423,29 +409,26 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
* @throws Exception
* @return array of API URLs query strings
*/
- protected function generateUrlsApi( $parametersToSet, $formats, $periods, $supertableApi = false, $setDateLastN = false, $language = false, $segment = false, $fileExtension = false )
+ protected function generateUrlsApi($parametersToSet, $formats, $periods, $supertableApi = false, $setDateLastN = false, $language = false, $segment = false, $fileExtension = false)
{
// Get the URLs to query against the API for all functions starting with get*
$skipped = $requestUrls = array();
$apiMetadata = new Piwik_API_DocumentationGenerator;
- foreach(Piwik_API_Proxy::getInstance()->getMetadata() as $class => $info)
- {
+ foreach (Piwik_API_Proxy::getInstance()->getMetadata() as $class => $info) {
$moduleName = Piwik_API_Proxy::getInstance()->getModuleNameFromClassName($class);
- foreach($info as $methodName => $infoMethod)
- {
- $apiId = $moduleName.'.'.$methodName;
+ foreach ($info as $methodName => $infoMethod) {
+ $apiId = $moduleName . '.' . $methodName;
// If Api to test were set, we only test these
- if(!empty(self::$apiToCall)
+ if (!empty(self::$apiToCall)
&& in_array($moduleName, self::$apiToCall) === false
- && in_array($apiId, self::$apiToCall) === false)
- {
+ && in_array($apiId, self::$apiToCall) === false
+ ) {
// echo "Skipped $apiId... \n";
$skipped[] = $apiId;
- continue;
- }
- // Excluded modules from test
- elseif(
+ continue;
+ } // Excluded modules from test
+ elseif (
((strpos($methodName, 'get') !== 0 && $methodName != 'generateReport')
|| in_array($moduleName, self::$apiNotToCall) === true
|| in_array($apiId, self::$apiNotToCall) === true
@@ -454,28 +437,23 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
|| $methodName == 'hasSVGLogo'
|| $methodName == 'getHeaderLogoUrl'
)
- )
- {
+ ) {
// echo "Skipped $apiId... \n";
$skipped[] = $apiId;
continue;
}
- foreach($periods as $period)
- {
+ foreach ($periods as $period) {
$parametersToSet['period'] = $period;
// If date must be a date range, we process this date range by adding 6 periods to it
- if($setDateLastN)
- {
- if(!isset($parametersToSet['dateRewriteBackup']))
- {
+ if ($setDateLastN) {
+ if (!isset($parametersToSet['dateRewriteBackup'])) {
$parametersToSet['dateRewriteBackup'] = $parametersToSet['date'];
}
$lastCount = (int)$setDateLastN;
- if($setDateLastN === true)
- {
+ if ($setDateLastN === true) {
$lastCount = 6;
}
$firstDate = $parametersToSet['dateRewriteBackup'];
@@ -484,52 +462,45 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
}
// Set response language
- if($language !== false)
- {
+ if ($language !== false) {
$parametersToSet['language'] = $language;
}
// set idSubtable if subtable API is set
- if ($supertableApi !== false)
- {
- $request = new Piwik_API_Request(array(
- 'module' => 'API',
- 'method' => $supertableApi,
- 'idSite' => $parametersToSet['idSite'],
- 'period' => $parametersToSet['period'],
- 'date' => $parametersToSet['date'],
- 'format' => 'php',
- 'serialize' => 0,
- ));
-
- // find first row w/ subtable
- foreach ($request->process() as $row)
- {
- if (isset($row['idsubdatatable']))
- {
- $parametersToSet['idSubtable'] = $row['idsubdatatable'];
- break;
- }
- }
-
- // if no subtable found, throw
- if (!isset($parametersToSet['idSubtable']))
- {
- throw new Exception(
- "Cannot find subtable to load for $apiId in $supertableApi.");
- }
+ if ($supertableApi !== false) {
+ $request = new Piwik_API_Request(array(
+ 'module' => 'API',
+ 'method' => $supertableApi,
+ 'idSite' => $parametersToSet['idSite'],
+ 'period' => $parametersToSet['period'],
+ 'date' => $parametersToSet['date'],
+ 'format' => 'php',
+ 'serialize' => 0,
+ ));
+
+ // find first row w/ subtable
+ foreach ($request->process() as $row) {
+ if (isset($row['idsubdatatable'])) {
+ $parametersToSet['idSubtable'] = $row['idsubdatatable'];
+ break;
+ }
+ }
+
+ // if no subtable found, throw
+ if (!isset($parametersToSet['idSubtable'])) {
+ throw new Exception(
+ "Cannot find subtable to load for $apiId in $supertableApi.");
+ }
}
// Generate for each specified format
- foreach($formats as $format)
- {
+ foreach ($formats as $format) {
$parametersToSet['format'] = $format;
$parametersToSet['hideIdSubDatable'] = 1;
$parametersToSet['serialize'] = 1;
$exampleUrl = $apiMetadata->getExampleUrl($class, $methodName, $parametersToSet);
- if($exampleUrl === false)
- {
+ if ($exampleUrl === false) {
$skipped[] = $apiId;
continue;
}
@@ -537,17 +508,15 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
// Remove the first ? in the query string
$exampleUrl = substr($exampleUrl, 1);
$apiRequestId = $apiId;
- if(strpos($exampleUrl, 'period=') !== false)
- {
+ if (strpos($exampleUrl, 'period=') !== false) {
$apiRequestId .= '_' . $period;
}
$apiRequestId .= '.' . $format;
- if($fileExtension)
- {
- $apiRequestId .= '.' . $fileExtension;
- }
+ if ($fileExtension) {
+ $apiRequestId .= '.' . $fileExtension;
+ }
$requestUrls[$apiRequestId] = $exampleUrl;
}
@@ -560,118 +529,109 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
/**
* Will return all api urls for the given data
*
- * @param string|array $formats String or array of formats to fetch from API
- * @param int|bool $idSite Id site
- * @param string|bool $dateTime Date time string of reports to request
+ * @param string|array $formats String or array of formats to fetch from API
+ * @param int|bool $idSite Id site
+ * @param string|bool $dateTime Date time string of reports to request
* @param array|bool|string $periods String or array of strings of periods (day, week, month, year)
- * @param bool $setDateLastN When set to true, 'date' parameter passed to API request will be rewritten to query a range of dates rather than 1 date only
- * @param string|bool $language 2 letter language code to request data in
- * @param string|bool $segment Custom Segment to query the data for
- * @param string|bool $visitorId Only used for Live! API testing
- * @param bool $abandonedCarts Only used in Goals API testing
- * @param bool $idGoal
- * @param bool $apiModule
- * @param bool $apiAction
- * @param array $otherRequestParameters
- * @param array|bool $supertableApi
- * @param array|bool $fileExtension
+ * @param bool $setDateLastN When set to true, 'date' parameter passed to API request will be rewritten to query a range of dates rather than 1 date only
+ * @param string|bool $language 2 letter language code to request data in
+ * @param string|bool $segment Custom Segment to query the data for
+ * @param string|bool $visitorId Only used for Live! API testing
+ * @param bool $abandonedCarts Only used in Goals API testing
+ * @param bool $idGoal
+ * @param bool $apiModule
+ * @param bool $apiAction
+ * @param array $otherRequestParameters
+ * @param array|bool $supertableApi
+ * @param array|bool $fileExtension
*
* @return array
*/
protected function _generateApiUrls($formats = 'xml', $idSite = false, $dateTime = false, $periods = false,
- $setDateLastN = false, $language = false, $segment = false, $visitorId = false,
- $abandonedCarts = false, $idGoal = false, $apiModule = false, $apiAction = false,
- $otherRequestParameters = array(), $supertableApi = false, $fileExtension = false)
+ $setDateLastN = false, $language = false, $segment = false, $visitorId = false,
+ $abandonedCarts = false, $idGoal = false, $apiModule = false, $apiAction = false,
+ $otherRequestParameters = array(), $supertableApi = false, $fileExtension = false)
{
list($pathProcessed, $pathExpected) = $this->getProcessedAndExpectedDirs();
- if($periods === false)
- {
+ if ($periods === false) {
$periods = 'day';
}
- if(!is_array($periods))
- {
+ if (!is_array($periods)) {
$periods = array($periods);
}
- if(!is_array($formats))
- {
+ if (!is_array($formats)) {
$formats = array($formats);
}
- if(!is_writable($pathProcessed))
- {
- $this->fail('To run the tests, you need to give write permissions to the following directory (create it if it doesn\'t exist).<code><br/>mkdir '. $pathProcessed.'<br/>chmod 777 '.$pathProcessed.'</code><br/>');
+ if (!is_writable($pathProcessed)) {
+ $this->fail('To run the tests, you need to give write permissions to the following directory (create it if it doesn\'t exist).<code><br/>mkdir ' . $pathProcessed . '<br/>chmod 777 ' . $pathProcessed . '</code><br/>');
}
$parametersToSet = array(
- 'idSite' => $idSite,
- 'date' => $periods == array('range') ? $dateTime : date('Y-m-d', strtotime($dateTime)),
- 'expanded' => '1',
- 'piwikUrl' => 'http://example.org/piwik/',
+ 'idSite' => $idSite,
+ 'date' => $periods == array('range') ? $dateTime : date('Y-m-d', strtotime($dateTime)),
+ 'expanded' => '1',
+ 'piwikUrl' => 'http://example.org/piwik/',
// Used in getKeywordsForPageUrl
- 'url' => 'http://example.org/store/purchase.htm',
+ 'url' => 'http://example.org/store/purchase.htm',
// Used in Actions.getPageUrl, .getDownload, etc.
// tied to Main.test.php doTest_oneVisitorTwoVisits
// will need refactoring when these same API functions are tested in a new function
- 'downloadUrl' => 'http://piwik.org/path/again/latest.zip?phpsessid=this is ignored when searching',
- 'outlinkUrl' => 'http://dev.piwik.org/svn',
- 'pageUrl' => 'http://example.org/index.htm?sessionid=this is also ignored by default',
- 'pageName' => ' Checkout / Purchasing... ',
+ 'downloadUrl' => 'http://piwik.org/path/again/latest.zip?phpsessid=this is ignored when searching',
+ 'outlinkUrl' => 'http://dev.piwik.org/svn',
+ 'pageUrl' => 'http://example.org/index.htm?sessionid=this is also ignored by default',
+ 'pageName' => ' Checkout / Purchasing... ',
// do not show the millisec timer in response or tests would always fail as value is changing
- 'showTimer' => 0,
+ 'showTimer' => 0,
- 'language' => $language ? $language : 'en',
- 'abandonedCarts' => $abandonedCarts ? 1 : 0,
- 'idSites' => $idSite,
+ 'language' => $language ? $language : 'en',
+ 'abandonedCarts' => $abandonedCarts ? 1 : 0,
+ 'idSites' => $idSite,
);
$parametersToSet = array_merge($parametersToSet, $otherRequestParameters);
- if(!empty($visitorId ))
- {
+ if (!empty($visitorId)) {
$parametersToSet['visitorId'] = $visitorId;
}
- if(!empty($apiModule ))
- {
+ if (!empty($apiModule)) {
$parametersToSet['apiModule'] = $apiModule;
}
- if(!empty($apiAction))
- {
+ if (!empty($apiAction)) {
$parametersToSet['apiAction'] = $apiAction;
}
- if(!empty($segment))
- {
+ if (!empty($segment)) {
$parametersToSet['segment'] = $segment;
}
- if($idGoal !== false)
- {
+ if ($idGoal !== false) {
$parametersToSet['idGoal'] = $idGoal;
}
$requestUrls = $this->generateUrlsApi($parametersToSet, $formats, $periods, $supertableApi, $setDateLastN, $language, $segment, $fileExtension);
- $this->checkEnoughUrlsAreTested($requestUrls);
+ $this->checkEnoughUrlsAreTested($requestUrls);
- return $requestUrls;
+ return $requestUrls;
+ }
+
+ protected function checkEnoughUrlsAreTested($requestUrls)
+ {
+ $countUrls = count($requestUrls);
+ $approximateCountApiToCall = count(self::$apiToCall);
+ if (empty($requestUrls)
+ || $approximateCountApiToCall > $countUrls
+ ) {
+ throw new Exception("Only generated $countUrls API calls to test but was expecting more for this test.\n" .
+ "Want to test APIs: " . implode(", ", self::$apiToCall) . ")\n" .
+ "But only generated these URLs: \n" . implode("\n", $requestUrls) . ")\n"
+ );
+ }
}
- protected function checkEnoughUrlsAreTested($requestUrls)
- {
- $countUrls = count($requestUrls);
- $approximateCountApiToCall = count(self::$apiToCall);
- if (empty($requestUrls)
- || $approximateCountApiToCall > $countUrls
- ) {
- throw new Exception("Only generated $countUrls API calls to test but was expecting more for this test.\n".
- "Want to test APIs: " . implode(", ", self::$apiToCall) . ")\n".
- "But only generated these URLs: \n" . implode("\n", $requestUrls) . ")\n"
- );
- }
- }
-
- protected function _testApiUrl($testName, $apiId, $requestUrl)
+ protected function _testApiUrl($testName, $apiId, $requestUrl)
{
$isLiveMustDeleteDates = strpos($requestUrl, 'Live.getLastVisits') !== false;
- $request = new Piwik_API_Request($requestUrl);
- $dateTime = Piwik_Common::getRequestVar('date', '', 'string', Piwik_Common::getArrayFromQueryString($requestUrl));
+ $request = new Piwik_API_Request($requestUrl);
+ $dateTime = Piwik_Common::getRequestVar('date', '', 'string', Piwik_Common::getArrayFromQueryString($requestUrl));
list($processedFilePath, $expectedFilePath) = $this->getProcessedAndExpectedPaths($testName, $apiId);
@@ -684,24 +644,24 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
$response = $this->removeAllLiveDatesFromXml($response);
}
- // normalize date markups and document ID in pdf files :
- // - /LastModified (D:20120820204023+00'00')
- // - /CreationDate (D:20120820202226+00'00')
- // - /ModDate (D:20120820202226+00'00')
- // - /M (D:20120820202226+00'00')
- // - /ID [ <0f5cc387dc28c0e13e682197f485fe65> <0f5cc387dc28c0e13e682197f485fe65> ]
- $response = preg_replace('/\(D:[0-9]{14}/', '(D:19700101000000', $response);
- $response = preg_replace('/\/ID \[ <.*> ]/', '', $response);
+ // normalize date markups and document ID in pdf files :
+ // - /LastModified (D:20120820204023+00'00')
+ // - /CreationDate (D:20120820202226+00'00')
+ // - /ModDate (D:20120820202226+00'00')
+ // - /M (D:20120820202226+00'00')
+ // - /ID [ <0f5cc387dc28c0e13e682197f485fe65> <0f5cc387dc28c0e13e682197f485fe65> ]
+ $response = preg_replace('/\(D:[0-9]{14}/', '(D:19700101000000', $response);
+ $response = preg_replace('/\/ID \[ <.*> ]/', '', $response);
file_put_contents($processedFilePath, $response);
$expected = $this->loadExpectedFile($expectedFilePath);
if (empty($expected)) {
- print("The expected file is not found at '$expectedFilePath'. The Processed response was:");
- print("\n----------------------------\n\n");
- var_dump($response);
- print("\n----------------------------\n");
- return;
+ print("The expected file is not found at '$expectedFilePath'. The Processed response was:");
+ print("\n----------------------------\n\n");
+ var_dump($response);
+ print("\n----------------------------\n");
+ return;
}
// @todo This should not vary between systems AFAIK... "idsubdatatable can differ"
@@ -724,22 +684,20 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
$response = $this->removeXmlElement($response, 'sum_daily_nb_uniq_visitors');
$expected = $this->removeXmlElement($expected, 'nb_visits_converted');
$response = $this->removeXmlElement($response, 'nb_visits_converted');
-
-
- if (strpos($requestUrl, 'date=') !== false)
- {
- $regex = "/date=[-0-9,%Ca-z]+/"; // need to remove %2C which is encoded ,
- $expected = preg_replace($regex, 'date=', $expected);
- $response = preg_replace($regex, 'date=', $response);
- }
+
+
+ if (strpos($requestUrl, 'date=') !== false) {
+ $regex = "/date=[-0-9,%Ca-z]+/"; // need to remove %2C which is encoded ,
+ $expected = preg_replace($regex, 'date=', $expected);
+ $response = preg_replace($regex, 'date=', $response);
+ }
}
// if idSubtable is in request URL, make sure idSubtable values are not in any urls
- if (strpos($requestUrl, 'idSubtable=') !== false)
- {
- $regex = "/idSubtable=[0-9]+/";
- $expected = preg_replace($regex, 'idSubtable=', $expected);
- $response = preg_replace($regex, 'idSubtable=', $response);
+ if (strpos($requestUrl, 'idSubtable=') !== false) {
+ $regex = "/idSubtable=[0-9]+/";
+ $expected = preg_replace($regex, 'idSubtable=', $expected);
+ $response = preg_replace($regex, 'idSubtable=', $response);
}
// is there a better way to test for the current DB type in use?
@@ -747,32 +705,29 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
// Do not test for TRUNCATE(SUM()) returning .00 on mysqli since this is not working
// http://bugs.php.net/bug.php?id=54508
$expected = str_replace('.000000</l', '</l', $expected); //lat/long
- $response = str_replace('.000000</l', '</l', $response); //lat/long
- $expected = str_replace('.00</revenue>', '</revenue>', $expected);
+ $response = str_replace('.000000</l', '</l', $response); //lat/long
+ $expected = str_replace('.00</revenue>', '</revenue>', $expected);
$response = str_replace('.00</revenue>', '</revenue>', $response);
- $response = str_replace('.1</revenue>', '</revenue>', $response);
- $expected = str_replace('.1</revenue>', '</revenue>', $expected);
- $expected = str_replace('.11</revenue>', '</revenue>', $expected);
- $response = str_replace('.11</revenue>', '</revenue>', $response);
+ $response = str_replace('.1</revenue>', '</revenue>', $response);
+ $expected = str_replace('.1</revenue>', '</revenue>', $expected);
+ $expected = str_replace('.11</revenue>', '</revenue>', $expected);
+ $response = str_replace('.11</revenue>', '</revenue>', $response);
}
- try
- {
- if (strpos($requestUrl, 'format=xml') !== false) {
- $this->assertXmlStringEqualsXmlString($expected, $response, "Differences with expected in: $processedFilePath");
- } else {
- $this->assertEquals(strlen($expected), strlen($response), "Differences with expected in: $processedFilePath");
- $this->assertEquals($expected, $response, "Differences with expected in: $processedFilePath");
- }
-
- if (trim($response) == trim($expected)) {
- file_put_contents($processedFilePath, $response);
- }
- }
- catch (Exception $ex)
- {
- $this->comparisonFailures[] = $ex;
- }
+ try {
+ if (strpos($requestUrl, 'format=xml') !== false) {
+ $this->assertXmlStringEqualsXmlString($expected, $response, "Differences with expected in: $processedFilePath");
+ } else {
+ $this->assertEquals(strlen($expected), strlen($response), "Differences with expected in: $processedFilePath");
+ $this->assertEquals($expected, $response, "Differences with expected in: $processedFilePath");
+ }
+
+ if (trim($response) == trim($expected)) {
+ file_put_contents($processedFilePath, $response);
+ }
+ } catch (Exception $ex) {
+ $this->comparisonFailures[] = $ex;
+ }
}
protected function removeAllLiveDatesFromXml($input)
@@ -791,7 +746,7 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
'serverTimePretty',
'visitorId'
);
- foreach($toRemove as $xml) {
+ foreach ($toRemove as $xml) {
$input = $this->removeXmlElement($input, $xml);
}
return $input;
@@ -804,13 +759,12 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
protected function removeXmlElement($input, $xmlElement, $testNotSmallAfter = true)
{
- // Only raise error if there was some data before
- $testNotSmallAfter = strlen($input > 100 ) && $testNotSmallAfter;
-
- $input = preg_replace('/(<'.$xmlElement.'>.+?<\/'.$xmlElement.'>)/', '', $input);
+ // Only raise error if there was some data before
+ $testNotSmallAfter = strlen($input > 100) && $testNotSmallAfter;
+
+ $input = preg_replace('/(<' . $xmlElement . '>.+?<\/' . $xmlElement . '>)/', '', $input);
//check we didn't delete the whole string
- if($testNotSmallAfter)
- {
+ if ($testNotSmallAfter) {
$this->assertTrue(strlen($input) > 100);
}
return $input;
@@ -825,8 +779,7 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
private function getProcessedAndExpectedPaths($testName, $testId, $format = null)
{
$filename = $testName . '__' . $testId;
- if ($format)
- {
+ if ($format) {
$filename .= ".$format";
}
@@ -838,8 +791,7 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
private function loadExpectedFile($filePath)
{
$result = @file_get_contents($filePath);
- if(empty($result))
- {
+ if (empty($result)) {
$expectedDir = dirname($filePath);
$this->missingExpectedFiles[] = $filePath;
return null;
@@ -885,7 +837,8 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
*
* All test options are optional, except 'idSite' & 'date'.
*/
- public function getApiForTesting() {
+ public function getApiForTesting()
+ {
return array();
}
@@ -899,28 +852,24 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
protected function _setCallableApi($api)
{
- if ($api == 'all')
- {
+ if ($api == 'all') {
self::setApiToCall(array());
self::setApiNotToCall(self::$defaultApiNotToCall);
- }
- else
- {
- if (!is_array($api))
- {
+ } else {
+ if (!is_array($api)) {
$api = array($api);
}
self::setApiToCall($api);
- if(!in_array('UserCountry.getLocationFromIP', $api)) {
- self::setApiNotToCall( array(
- 'API.getPiwikVersion',
- 'UserCountry.getLocationFromIP'
- ));
- } else {
- self::setApiNotToCall( array());
- }
+ if (!in_array('UserCountry.getLocationFromIP', $api)) {
+ self::setApiNotToCall(array(
+ 'API.getPiwikVersion',
+ 'UserCountry.getLocationFromIP'
+ ));
+ } else {
+ self::setApiNotToCall(array());
+ }
}
}
@@ -935,73 +884,65 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
$this->_setCallableApi($api);
- if (isset($params['disableArchiving']) && $params['disableArchiving'] === true)
- {
+ if (isset($params['disableArchiving']) && $params['disableArchiving'] === true) {
Piwik_ArchiveProcessing::$forceDisableArchiving = true;
- }
- else
- {
+ } else {
Piwik_ArchiveProcessing::$forceDisableArchiving = false;
}
- if (isset($params['language']))
- {
+ if (isset($params['language'])) {
$this->changeLanguage($params['language']);
}
$testSuffix = isset($params['testSuffix']) ? $params['testSuffix'] : '';
$requestUrls = $this->_generateApiUrls(
- isset($params['format']) ? $params['format'] : 'xml',
- isset($params['idSite']) ? $params['idSite'] : false,
- isset($params['date']) ? $params['date'] : false,
- isset($params['periods']) ? $params['periods'] : false,
- isset($params['setDateLastN']) ? $params['setDateLastN'] : false,
- isset($params['language']) ? $params['language'] : false,
- isset($params['segment']) ? $params['segment'] : false,
- isset($params['visitorId']) ? $params['visitorId'] : false,
- isset($params['abandonedCarts']) ? $params['abandonedCarts'] : false,
- isset($params['idGoal']) ? $params['idGoal'] : false,
- isset($params['apiModule']) ? $params['apiModule'] : false,
- isset($params['apiAction']) ? $params['apiAction'] : false,
- isset($params['otherRequestParameters']) ? $params['otherRequestParameters'] : array(),
- isset($params['supertableApi']) ? $params['supertableApi'] : false,
- isset($params['fileExtension']) ? $params['fileExtension'] : false);
-
- foreach($requestUrls as $apiId => $requestUrl)
- {
- $this->_testApiUrl( $testName . $testSuffix, $apiId, $requestUrl);
+ isset($params['format']) ? $params['format'] : 'xml',
+ isset($params['idSite']) ? $params['idSite'] : false,
+ isset($params['date']) ? $params['date'] : false,
+ isset($params['periods']) ? $params['periods'] : false,
+ isset($params['setDateLastN']) ? $params['setDateLastN'] : false,
+ isset($params['language']) ? $params['language'] : false,
+ isset($params['segment']) ? $params['segment'] : false,
+ isset($params['visitorId']) ? $params['visitorId'] : false,
+ isset($params['abandonedCarts']) ? $params['abandonedCarts'] : false,
+ isset($params['idGoal']) ? $params['idGoal'] : false,
+ isset($params['apiModule']) ? $params['apiModule'] : false,
+ isset($params['apiAction']) ? $params['apiAction'] : false,
+ isset($params['otherRequestParameters']) ? $params['otherRequestParameters'] : array(),
+ isset($params['supertableApi']) ? $params['supertableApi'] : false,
+ isset($params['fileExtension']) ? $params['fileExtension'] : false);
+
+ foreach ($requestUrls as $apiId => $requestUrl) {
+ $this->_testApiUrl($testName . $testSuffix, $apiId, $requestUrl);
}
// change the language back to en
- if ($this->lastLanguage != 'en')
- {
+ if ($this->lastLanguage != 'en') {
$this->changeLanguage('en');
}
-
- if (!empty($this->missingExpectedFiles))
- {
+
+ if (!empty($this->missingExpectedFiles)) {
$expectedDir = dirname(reset($this->missingExpectedFiles));
$this->markTestIncomplete(" ERROR: Could not find expected API output '"
- . implode("', '", $this->missingExpectedFiles)
- . "'. For new tests, to pass the test, you can copy files from the processed/ directory into"
- . " $expectedDir after checking that the output is valid. %s ");
+ . implode("', '", $this->missingExpectedFiles)
+ . "'. For new tests, to pass the test, you can copy files from the processed/ directory into"
+ . " $expectedDir after checking that the output is valid. %s ");
}
- // Display as one error all sub-failures
- if (!empty($this->comparisonFailures))
- {
- $messages = '';
- $i = 1;
- foreach($this->comparisonFailures as $failure) {
- $msg = $failure->getMessage();
- $msg = strtok($msg, "\n");
- $messages .= "\n#" . $i++ . ": " . $msg;
- }
- $messages .= " \n ";
- print($messages);
- $first = reset($this->comparisonFailures);
- throw $first;
+ // Display as one error all sub-failures
+ if (!empty($this->comparisonFailures)) {
+ $messages = '';
+ $i = 1;
+ foreach ($this->comparisonFailures as $failure) {
+ $msg = $failure->getMessage();
+ $msg = strtok($msg, "\n");
+ $messages .= "\n#" . $i++ . ": " . $msg;
+ }
+ $messages .= " \n ";
+ print($messages);
+ $first = reset($this->comparisonFailures);
+ throw $first;
}
}
@@ -1011,10 +952,9 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
*
* @param string $langId
*/
- protected function changeLanguage( $langId )
+ protected function changeLanguage($langId)
{
- if ($this->lastLanguage != $langId)
- {
+ if ($this->lastLanguage != $langId) {
$_GET['language'] = $langId;
Piwik_Translate::reset();
Piwik_Translate::getInstance()->reloadLanguage($langId);
@@ -1028,96 +968,82 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
*/
public function getPathToTestDirectory()
{
- return dirname(__FILE__).DIRECTORY_SEPARATOR.'Integration';
+ return dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Integration';
}
-
+
/**
* Returns an array associating table names w/ lists of row data.
- *
+ *
* @return array
*/
protected static function getDbTablesWithData()
{
- $result = array();
- foreach (Piwik::getTablesInstalled() as $tableName)
- {
- $result[$tableName] = Piwik_FetchAll("SELECT * FROM $tableName");
- }
- return $result;
+ $result = array();
+ foreach (Piwik::getTablesInstalled() as $tableName) {
+ $result[$tableName] = Piwik_FetchAll("SELECT * FROM $tableName");
+ }
+ return $result;
}
-
+
/**
* Truncates all tables then inserts the data in $tables into each
* mapped table.
- *
+ *
* @param array $tables Array mapping table names with arrays of row data.
*/
- protected static function restoreDbTables( $tables )
+ protected static function restoreDbTables($tables)
+ {
+ // truncate existing tables
+ Piwik::truncateAllTables();
+
+ // insert data
+ $existingTables = Piwik::getTablesInstalled();
+ foreach ($tables as $table => $rows) {
+ // create table if it's an archive table
+ if (strpos($table, 'archive_') !== false && !in_array($table, $existingTables)) {
+ $tableType = strpos($table, 'archive_numeric') !== false ? 'archive_numeric' : 'archive_blob';
+
+ $createSql = Piwik::getTableCreateSql($tableType);
+ $createSql = str_replace(Piwik_Common::prefixTable($tableType), $table, $createSql);
+ Piwik_Query($createSql);
+ }
+
+ if (empty($rows)) {
+ continue;
+ }
+
+ $rowsSql = array();
+ foreach ($rows as $row) {
+ $values = array();
+ foreach ($row as $name => $value) {
+ if (is_null($value)) {
+ $values[] = 'NULL';
+ } else if (is_numeric($value)) {
+ $values[] = $value;
+ } else if (!ctype_print($value)) {
+ $values[] = "x'" . bin2hex(substr($value, 1)) . "'";
+ } else {
+ $values[] = "'$value'";
+ }
+ }
+
+ $rowsSql[] = "(" . implode(',', $values) . ")";
+ }
+
+ $sql = "INSERT INTO $table VALUES " . implode(',', $rowsSql);
+ Piwik_Query($sql);
+ }
+ }
+
+ /**
+ * Drops all archive tables.
+ */
+ public static function deleteArchiveTables()
{
- // truncate existing tables
- Piwik::truncateAllTables();
-
- // insert data
- $existingTables = Piwik::getTablesInstalled();
- foreach ($tables as $table => $rows)
- {
- // create table if it's an archive table
- if (strpos($table, 'archive_') !== false && !in_array($table, $existingTables))
- {
- $tableType = strpos($table, 'archive_numeric') !== false ? 'archive_numeric' : 'archive_blob';
-
- $createSql = Piwik::getTableCreateSql($tableType);
- $createSql = str_replace(Piwik_Common::prefixTable($tableType), $table, $createSql);
- Piwik_Query($createSql);
- }
-
- if (empty($rows))
- {
- continue;
- }
-
- $rowsSql = array();
- foreach ($rows as $row)
- {
- $values = array();
- foreach ($row as $name => $value)
- {
- if (is_null($value))
- {
- $values[] = 'NULL';
- }
- else if (is_numeric($value))
- {
- $values[] = $value;
- }
- else if (!ctype_print($value))
- {
- $values[] = "x'".bin2hex(substr($value, 1))."'";
- }
- else
- {
- $values[] = "'$value'";
- }
- }
-
- $rowsSql[] = "(".implode(',', $values).")";
- }
-
- $sql = "INSERT INTO $table VALUES ".implode(',', $rowsSql);
- Piwik_Query($sql);
- }
+ foreach (Piwik::getTablesArchivesInstalled() as $table) {
+ Piwik_Query("DROP TABLE IF EXISTS $table");
+ }
+
+ Piwik_TablePartitioning::$tablesAlreadyInstalled = Piwik::getTablesInstalled($forceReload = true);
}
-
- /**
- * Drops all archive tables.
- */
- public static function deleteArchiveTables()
- {
- foreach (Piwik::getTablesArchivesInstalled() as $table)
- {
- Piwik_Query("DROP TABLE IF EXISTS $table");
- }
-
- Piwik_TablePartitioning::$tablesAlreadyInstalled = Piwik::getTablesInstalled($forceReload = true);
- }
}
diff --git a/tests/PHPUnit/MockEventDispatcher.php b/tests/PHPUnit/MockEventDispatcher.php
index a7026df572..a5528e61e0 100644
--- a/tests/PHPUnit/MockEventDispatcher.php
+++ b/tests/PHPUnit/MockEventDispatcher.php
@@ -7,16 +7,17 @@
*/
class MockEventDispatcher extends Event_Dispatcher
{
- private $forcedNotificationObject = false;
+ private $forcedNotificationObject = false;
- function __construct($forcedNotificationObject) {
- $this->forcedNotificationObject = $forcedNotificationObject;
- }
+ function __construct($forcedNotificationObject)
+ {
+ $this->forcedNotificationObject = $forcedNotificationObject;
+ }
- function &postNotification(&$notification, $pending = true, $bubble = true)
- {
- $notification->_notificationObject = $this->forcedNotificationObject;
+ function &postNotification(&$notification, $pending = true, $bubble = true)
+ {
+ $notification->_notificationObject = $this->forcedNotificationObject;
- return $notification;
- }
+ return $notification;
+ }
}
diff --git a/tests/PHPUnit/MockLocationProvider.php b/tests/PHPUnit/MockLocationProvider.php
index c8cbf12363..68c1c43502 100755
--- a/tests/PHPUnit/MockLocationProvider.php
+++ b/tests/PHPUnit/MockLocationProvider.php
@@ -8,46 +8,43 @@
class MockLocationProvider extends Piwik_UserCountry_LocationProvider
{
- public static $locations = array();
- private $currentLocation = 0;
- private $ipToLocations = array();
-
- public function getLocation( $info )
- {
- $ip = $info['ip'];
-
- if (isset($this->ipToLocations[$ip]))
- {
- $result = $this->ipToLocations[$ip];
- }
- else
- {
- $result = self::$locations[$this->currentLocation];
- $this->currentLocation = ($this->currentLocation + 1) % count(self::$locations);
-
- $this->ipToLocations[$ip] = $result;
- }
- $this->completeLocationResult($result);
- return $result;
- }
-
- public function getInfo()
- {
- return array('id' => 'mock_provider', 'title' => 'mock provider', 'description' => 'mock provider');
- }
-
- public function isAvailable()
- {
- return true;
- }
-
- public function isWorking()
- {
- return true;
- }
-
- public function getSupportedLocationInfo()
- {
- return array(); // unimplemented
- }
+ public static $locations = array();
+ private $currentLocation = 0;
+ private $ipToLocations = array();
+
+ public function getLocation($info)
+ {
+ $ip = $info['ip'];
+
+ if (isset($this->ipToLocations[$ip])) {
+ $result = $this->ipToLocations[$ip];
+ } else {
+ $result = self::$locations[$this->currentLocation];
+ $this->currentLocation = ($this->currentLocation + 1) % count(self::$locations);
+
+ $this->ipToLocations[$ip] = $result;
+ }
+ $this->completeLocationResult($result);
+ return $result;
+ }
+
+ public function getInfo()
+ {
+ return array('id' => 'mock_provider', 'title' => 'mock provider', 'description' => 'mock provider');
+ }
+
+ public function isAvailable()
+ {
+ return true;
+ }
+
+ public function isWorking()
+ {
+ return true;
+ }
+
+ public function getSupportedLocationInfo()
+ {
+ return array(); // unimplemented
+ }
}
diff --git a/tests/PHPUnit/MockPiwikOption.php b/tests/PHPUnit/MockPiwikOption.php
index 5ead64c3ae..455638032c 100644
--- a/tests/PHPUnit/MockPiwikOption.php
+++ b/tests/PHPUnit/MockPiwikOption.php
@@ -7,19 +7,20 @@
*/
class MockPiwikOption extends Piwik_Option
{
- private $forcedOptionValue = false;
+ private $forcedOptionValue = false;
- function __construct($forcedOptionValue) {
- $this->forcedOptionValue = $forcedOptionValue;
- }
+ function __construct($forcedOptionValue)
+ {
+ $this->forcedOptionValue = $forcedOptionValue;
+ }
- public function get($name)
- {
- return $this->forcedOptionValue;
- }
+ public function get($name)
+ {
+ return $this->forcedOptionValue;
+ }
- public function set($name, $value, $autoload = 0)
- {
- $this->forcedOptionValue = $value;
- }
+ public function set($name, $value, $autoload = 0)
+ {
+ $this->forcedOptionValue = $value;
+ }
}
diff --git a/tests/PHPUnit/Plugins/ActionsTest.php b/tests/PHPUnit/Plugins/ActionsTest.php
index 71b2036a11..ce3acfcf6e 100644
--- a/tests/PHPUnit/Plugins/ActionsTest.php
+++ b/tests/PHPUnit/Plugins/ActionsTest.php
@@ -23,84 +23,84 @@ class ActionsTests extends PHPUnit_Framework_TestCase
{
return array(
array(
- 'params' => array('name' => 'http://example.org/', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL, 'urlPrefix' => null),
- 'expected' => array('/index'),
+ 'params' => array('name' => 'http://example.org/', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL, 'urlPrefix' => null),
+ 'expected' => array('/index'),
),
array(
- 'params' => array('name' => 'example.org/', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL, 'urlPrefix' => 1),
- 'expected' => array('/index'),
+ 'params' => array('name' => 'example.org/', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL, 'urlPrefix' => 1),
+ 'expected' => array('/index'),
),
array(
- 'params' => array('name' => 'example.org/', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL, 'urlPrefix' => 2),
- 'expected' => array('/index'),
+ 'params' => array('name' => 'example.org/', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL, 'urlPrefix' => 2),
+ 'expected' => array('/index'),
),
array(
- 'params' => array('name' => 'example.org/', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL, 'urlPrefix' => 3),
- 'expected' => array('/index'),
+ 'params' => array('name' => 'example.org/', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL, 'urlPrefix' => 3),
+ 'expected' => array('/index'),
),
array(
- 'params' => array('name' => 'example.org/', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL, 'urlPrefix' => 4),
- 'expected' => array('/index'),
+ 'params' => array('name' => 'example.org/', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL, 'urlPrefix' => 4),
+ 'expected' => array('/index'),
),
array(
- 'params' => array('name' => 'example.org/path/', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL, 'urlPrefix' => 4),
- 'expected' => array('path', '/index'),
+ 'params' => array('name' => 'example.org/path/', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL, 'urlPrefix' => 4),
+ 'expected' => array('path', '/index'),
),
array(
- 'params' => array('name' => 'example.org/test/path', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL, 'urlPrefix' => 1),
- 'expected' => array('test', '/path'),
+ 'params' => array('name' => 'example.org/test/path', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL, 'urlPrefix' => 1),
+ 'expected' => array('test', '/path'),
),
array(
- 'params' => array('name' => 'http://example.org/path/', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
- 'expected' => array('path', '/index'),
+ 'params' => array('name' => 'http://example.org/path/', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
+ 'expected' => array('path', '/index'),
),
array(
- 'params' => array('name' => 'example.org/test/path', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL, 'urlPrefix' => 1),
- 'expected' => array('test', '/path'),
+ 'params' => array('name' => 'example.org/test/path', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL, 'urlPrefix' => 1),
+ 'expected' => array('test', '/path'),
),
array(
- 'params' => array('name' => 'Test / Path', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
- 'expected' => array('Test', '/Path'),
+ 'params' => array('name' => 'Test / Path', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
+ 'expected' => array('Test', '/Path'),
),
array(
- 'params' => array('name' => ' Test trim ', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
- 'expected' => array('/Test trim'),
+ 'params' => array('name' => ' Test trim ', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
+ 'expected' => array('/Test trim'),
),
array(
- 'params' => array('name' => 'Category / Subcategory', 'type' => Piwik_Tracker_Action::TYPE_ACTION_NAME),
- 'expected' => array('Category', ' Subcategory'),
+ 'params' => array('name' => 'Category / Subcategory', 'type' => Piwik_Tracker_Action::TYPE_ACTION_NAME),
+ 'expected' => array('Category', ' Subcategory'),
),
array(
- 'params' => array('name' => '/path/index.php?var=test', 'type' => Piwik_Tracker_Action::TYPE_ACTION_NAME),
- 'expected' => array('path', ' index.php?var=test'),
+ 'params' => array('name' => '/path/index.php?var=test', 'type' => Piwik_Tracker_Action::TYPE_ACTION_NAME),
+ 'expected' => array('path', ' index.php?var=test'),
),
array(
- 'params' => array('name' => 'http://example.org/path/Default.aspx#anchor', 'type' => Piwik_Tracker_Action::TYPE_ACTION_NAME),
- 'expected' => array('path', ' Default.aspx#anchor'),
+ 'params' => array('name' => 'http://example.org/path/Default.aspx#anchor', 'type' => Piwik_Tracker_Action::TYPE_ACTION_NAME),
+ 'expected' => array('path', ' Default.aspx#anchor'),
),
array(
- 'params' => array('name' => '', 'type' => Piwik_Tracker_Action::TYPE_ACTION_NAME),
- 'expected' => array('Page Name not defined'),
+ 'params' => array('name' => '', 'type' => Piwik_Tracker_Action::TYPE_ACTION_NAME),
+ 'expected' => array('Page Name not defined'),
),
array(
- 'params' => array('name' => '', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
- 'expected' => array('Page URL not defined'),
+ 'params' => array('name' => '', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
+ 'expected' => array('Page URL not defined'),
),
array(
- 'params' => array('name' => 'http://example.org/download.zip', 'type' => Piwik_Tracker_Action::TYPE_DOWNLOAD),
- 'expected' => array('example.org', '/download.zip'),
+ 'params' => array('name' => 'http://example.org/download.zip', 'type' => Piwik_Tracker_Action::TYPE_DOWNLOAD),
+ 'expected' => array('example.org', '/download.zip'),
),
array(
- 'params' => array('name' => 'http://example.org/download/1/', 'type' => Piwik_Tracker_Action::TYPE_DOWNLOAD),
- 'expected' => array('example.org', '/download/1/'),
+ 'params' => array('name' => 'http://example.org/download/1/', 'type' => Piwik_Tracker_Action::TYPE_DOWNLOAD),
+ 'expected' => array('example.org', '/download/1/'),
),
array(
- 'params' => array('name' => 'http://example.org/link', 'type' => Piwik_Tracker_Action::TYPE_OUTLINK),
- 'expected' => array('example.org', '/link'),
+ 'params' => array('name' => 'http://example.org/link', 'type' => Piwik_Tracker_Action::TYPE_OUTLINK),
+ 'expected' => array('example.org', '/link'),
),
array(
- 'params' => array('name' => 'http://example.org/some/path/', 'type' => Piwik_Tracker_Action::TYPE_OUTLINK),
- 'expected' => array('example.org', '/some/path/'),
+ 'params' => array('name' => 'http://example.org/some/path/', 'type' => Piwik_Tracker_Action::TYPE_OUTLINK),
+ 'expected' => array('example.org', '/some/path/'),
),
);
}
@@ -112,8 +112,8 @@ class ActionsTests extends PHPUnit_Framework_TestCase
*/
public function testGetActionExplodedNames($params, $expected)
{
- Piwik_Actions_ArchivingHelper::reloadConfig();
- $processed = Piwik_Actions_ArchivingHelper::getActionExplodedNames($params['name'], $params['type'], (isset($params['urlPrefix'])?$params['urlPrefix']:null));
+ Piwik_Actions_ArchivingHelper::reloadConfig();
+ $processed = Piwik_Actions_ArchivingHelper::getActionExplodedNames($params['name'], $params['type'], (isset($params['urlPrefix']) ? $params['urlPrefix'] : null));
$this->assertEquals($expected, $processed);
}
}
diff --git a/tests/PHPUnit/Plugins/AnonymizeIPTest.php b/tests/PHPUnit/Plugins/AnonymizeIPTest.php
index b319b0351d..a164403130 100644
--- a/tests/PHPUnit/Plugins/AnonymizeIPTest.php
+++ b/tests/PHPUnit/Plugins/AnonymizeIPTest.php
@@ -10,22 +10,23 @@ require_once 'AnonymizeIP/AnonymizeIP.php';
class AnonymizeIPTest extends PHPUnit_Framework_TestCase
{
// IPv4 addresses and expected results
- public function getipv4Addresses() {
+ public function getipv4Addresses()
+ {
return array(
// ip, array( expected0, expected1, expected2, expected3, expected4 ),
- array('0.0.0.0' , array( "\x00\x00\x00\x00", "\x00\x00\x00\x00", "\x00\x00\x00\x00", "\x00\x00\x00\x00", "\x00\x00\x00\x00" )),
- array('0.0.0.1' , array( "\x00\x00\x00\x01", "\x00\x00\x00\x00", "\x00\x00\x00\x00", "\x00\x00\x00\x00", "\x00\x00\x00\x00" )),
- array('0.0.0.255' , array( "\x00\x00\x00\xff", "\x00\x00\x00\x00", "\x00\x00\x00\x00", "\x00\x00\x00\x00", "\x00\x00\x00\x00" )),
- array('0.0.1.0' , array( "\x00\x00\x01\x00", "\x00\x00\x01\x00", "\x00\x00\x00\x00", "\x00\x00\x00\x00", "\x00\x00\x00\x00" )),
- array('0.0.1.1' , array( "\x00\x00\x01\x01", "\x00\x00\x01\x00", "\x00\x00\x00\x00", "\x00\x00\x00\x00", "\x00\x00\x00\x00" )),
- array('0.0.255.255' , array( "\x00\x00\xff\xff", "\x00\x00\xff\x00", "\x00\x00\x00\x00", "\x00\x00\x00\x00", "\x00\x00\x00\x00" )),
- array('0.1.0.0' , array( "\x00\x01\x00\x00", "\x00\x01\x00\x00", "\x00\x01\x00\x00", "\x00\x00\x00\x00", "\x00\x00\x00\x00" )),
- array('0.1.1.1' , array( "\x00\x01\x01\x01", "\x00\x01\x01\x00", "\x00\x01\x00\x00", "\x00\x00\x00\x00", "\x00\x00\x00\x00" )),
- array('0.255.255.255' , array( "\x00\xff\xff\xff", "\x00\xff\xff\x00", "\x00\xff\x00\x00", "\x00\x00\x00\x00", "\x00\x00\x00\x00" )),
- array('1.0.0.0' , array( "\x01\x00\x00\x00", "\x01\x00\x00\x00", "\x01\x00\x00\x00", "\x01\x00\x00\x00", "\x00\x00\x00\x00" )),
- array('127.255.255.255' , array( "\x7f\xff\xff\xff", "\x7f\xff\xff\x00", "\x7f\xff\x00\x00", "\x7f\x00\x00\x00", "\x00\x00\x00\x00" )),
- array('128.0.0.0' , array( "\x80\x00\x00\x00", "\x80\x00\x00\x00", "\x80\x00\x00\x00", "\x80\x00\x00\x00", "\x00\x00\x00\x00" )),
- array('255.255.255.255' , array( "\xff\xff\xff\xff", "\xff\xff\xff\x00", "\xff\xff\x00\x00", "\xff\x00\x00\x00", "\x00\x00\x00\x00" )),
+ array('0.0.0.0', array("\x00\x00\x00\x00", "\x00\x00\x00\x00", "\x00\x00\x00\x00", "\x00\x00\x00\x00", "\x00\x00\x00\x00")),
+ array('0.0.0.1', array("\x00\x00\x00\x01", "\x00\x00\x00\x00", "\x00\x00\x00\x00", "\x00\x00\x00\x00", "\x00\x00\x00\x00")),
+ array('0.0.0.255', array("\x00\x00\x00\xff", "\x00\x00\x00\x00", "\x00\x00\x00\x00", "\x00\x00\x00\x00", "\x00\x00\x00\x00")),
+ array('0.0.1.0', array("\x00\x00\x01\x00", "\x00\x00\x01\x00", "\x00\x00\x00\x00", "\x00\x00\x00\x00", "\x00\x00\x00\x00")),
+ array('0.0.1.1', array("\x00\x00\x01\x01", "\x00\x00\x01\x00", "\x00\x00\x00\x00", "\x00\x00\x00\x00", "\x00\x00\x00\x00")),
+ array('0.0.255.255', array("\x00\x00\xff\xff", "\x00\x00\xff\x00", "\x00\x00\x00\x00", "\x00\x00\x00\x00", "\x00\x00\x00\x00")),
+ array('0.1.0.0', array("\x00\x01\x00\x00", "\x00\x01\x00\x00", "\x00\x01\x00\x00", "\x00\x00\x00\x00", "\x00\x00\x00\x00")),
+ array('0.1.1.1', array("\x00\x01\x01\x01", "\x00\x01\x01\x00", "\x00\x01\x00\x00", "\x00\x00\x00\x00", "\x00\x00\x00\x00")),
+ array('0.255.255.255', array("\x00\xff\xff\xff", "\x00\xff\xff\x00", "\x00\xff\x00\x00", "\x00\x00\x00\x00", "\x00\x00\x00\x00")),
+ array('1.0.0.0', array("\x01\x00\x00\x00", "\x01\x00\x00\x00", "\x01\x00\x00\x00", "\x01\x00\x00\x00", "\x00\x00\x00\x00")),
+ array('127.255.255.255', array("\x7f\xff\xff\xff", "\x7f\xff\xff\x00", "\x7f\xff\x00\x00", "\x7f\x00\x00\x00", "\x00\x00\x00\x00")),
+ array('128.0.0.0', array("\x80\x00\x00\x00", "\x80\x00\x00\x00", "\x80\x00\x00\x00", "\x80\x00\x00\x00", "\x00\x00\x00\x00")),
+ array('255.255.255.255', array("\xff\xff\xff\xff", "\xff\xff\xff\x00", "\xff\xff\x00\x00", "\xff\x00\x00\x00", "\x00\x00\x00\x00")),
);
}
@@ -37,24 +38,22 @@ class AnonymizeIPTest extends PHPUnit_Framework_TestCase
public function testApplyIPMask($ip, $expected)
{
// each IP is tested with 0 to 4 octets masked
- for($maskLength = 0; $maskLength <= 4; $maskLength++)
- {
+ for ($maskLength = 0; $maskLength <= 4; $maskLength++) {
$res = Piwik_AnonymizeIP::applyIPMask(Piwik_IP::P2N($ip), $maskLength);
- $this->assertEquals($expected[$maskLength], $res, "Got ".bin2hex($res).", Expected " . bin2hex($expected[$maskLength]));
+ $this->assertEquals($expected[$maskLength], $res, "Got " . bin2hex($res) . ", Expected " . bin2hex($expected[$maskLength]));
}
// edge case (bounds check)
$this->assertEquals("\x00\x00\x00\x00", Piwik_AnonymizeIP::applyIPMask(Piwik_IP::P2N($ip), 5));
// mask IPv4 mapped addresses
- for($maskLength = 0; $maskLength <= 4; $maskLength++)
- {
- $res = Piwik_AnonymizeIP::applyIPMask(Piwik_IP::P2N('::ffff:'.$ip), $maskLength);
- $this->assertEquals( $res, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff".$expected[$maskLength], "Got ".bin2hex($res).", Expected " . bin2hex($expected[$maskLength]) );
+ for ($maskLength = 0; $maskLength <= 4; $maskLength++) {
+ $res = Piwik_AnonymizeIP::applyIPMask(Piwik_IP::P2N('::ffff:' . $ip), $maskLength);
+ $this->assertEquals($res, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff" . $expected[$maskLength], "Got " . bin2hex($res) . ", Expected " . bin2hex($expected[$maskLength]));
}
- $this->assertEquals("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00\x00\x00\x00\x00", Piwik_AnonymizeIP::applyIPMask(Piwik_IP::P2N('::ffff:'.$ip), 5));
+ $this->assertEquals("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00\x00\x00\x00\x00", Piwik_AnonymizeIP::applyIPMask(Piwik_IP::P2N('::ffff:' . $ip), 5));
// edge case (bounds check)
- $this->assertEquals("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", Piwik_AnonymizeIP::applyIPMask(Piwik_IP::P2N('2001::ffff:'.$ip), 17));
+ $this->assertEquals("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", Piwik_AnonymizeIP::applyIPMask(Piwik_IP::P2N('2001::ffff:' . $ip), 17));
}
}
diff --git a/tests/PHPUnit/Plugins/LanguagesManagerTest.php b/tests/PHPUnit/Plugins/LanguagesManagerTest.php
index b58bf7312b..9acc5f3a9e 100755
--- a/tests/PHPUnit/Plugins/LanguagesManagerTest.php
+++ b/tests/PHPUnit/Plugins/LanguagesManagerTest.php
@@ -24,21 +24,21 @@ class Test_LanguagesManager extends PHPUnit_Framework_TestCase
function getTestDataForLanguageFiles()
{
- self::$allLanguages = Piwik_Common::getLanguagesList();
- self::$allCountries = Piwik_Common::getCountriesList();
+ self::$allLanguages = Piwik_Common::getLanguagesList();
+ self::$allCountries = Piwik_Common::getCountriesList();
self::$englishStringsWithParameters = array();
- self::$englishStringsIndexed = array();
- self::$expectedLanguageKeys = array();
- $englishStrings = Piwik_LanguagesManager_API::getInstance()->getTranslationsForLanguage('en');
+ self::$englishStringsIndexed = array();
+ self::$expectedLanguageKeys = array();
+ $englishStrings = Piwik_LanguagesManager_API::getInstance()->getTranslationsForLanguage('en');
foreach ($englishStrings as $englishString) {
$stringLabel = $englishString['label'];
$stringValue = $englishString['value'];
- $count = $this->getCountParametersToReplace($stringValue);
+ $count = $this->getCountParametersToReplace($stringValue);
if ($count > 0) {
self::$englishStringsWithParameters[$stringLabel] = $count;
}
self::$englishStringsIndexed[$stringLabel] = $stringValue;
- self::$expectedLanguageKeys[] = $stringLabel;
+ self::$expectedLanguageKeys[] = $stringLabel;
}
// we also test that none of the language php files outputs any character on the screen (eg. space before the <?php)
@@ -64,11 +64,11 @@ class Test_LanguagesManager extends PHPUnit_Framework_TestCase
{
self::$errors = array();
ob_start();
- $writeCleanedFile = false;
- $strings = Piwik_LanguagesManager_API::getInstance()->getTranslationsForLanguage($language);
- $content = ob_get_flush();
+ $writeCleanedFile = false;
+ $strings = Piwik_LanguagesManager_API::getInstance()->getTranslationsForLanguage($language);
+ $content = ob_get_flush();
$serializedStrings = serialize($strings);
- $invalids = array("<script", 'document.', 'javascript:', 'src=', 'BACKGROUND=', 'onload=');
+ $invalids = array("<script", 'document.', 'javascript:', 'src=', 'BACKGROUND=', 'onload=');
foreach ($invalids as $invalid) {
$this->assertTrue(stripos($serializedStrings, $invalid) === false, "$language: language file containing javascript");
}
@@ -80,31 +80,31 @@ class Test_LanguagesManager extends PHPUnit_Framework_TestCase
$stringLabel = $string['label'];
$stringValue = $string['value'];
- $plugin = substr($stringLabel, 0, strpos($stringLabel, '_'));
+ $plugin = substr($stringLabel, 0, strpos($stringLabel, '_'));
$plugins[$plugin] = true;
// Testing that the translated string is not empty => '',
if (empty($stringValue) || trim($stringValue) === '') {
- $writeCleanedFile = true;
- self::$errors[] = "$language: The string $stringLabel is empty in the translation file, removing the line.";
+ $writeCleanedFile = true;
+ self::$errors[] = "$language: The string $stringLabel is empty in the translation file, removing the line.";
$cleanedStrings[$stringLabel] = false;
} elseif (!in_array($stringLabel, self::$expectedLanguageKeys)
// translation files should not contain 3rd plugin translations, but if they are there, we shall not delete them
// since translators have spent time working on it... at least for now we shall leave them in (until V2 and plugin repository is done)
&& !in_array($plugin, array('GeoIP', 'Forecast', 'EntryPage', 'UserLanguage'))
) {
- $writeCleanedFile = true;
- self::$errors[] = "$language: The string $stringLabel was not found in the English language file, removing the line.";
+ $writeCleanedFile = true;
+ self::$errors[] = "$language: The string $stringLabel was not found in the English language file, removing the line.";
$cleanedStrings[$stringLabel] = false;
} else {
// checking that translated strings have the same number of %s as the english source strings
if (isset(self::$englishStringsWithParameters[$stringLabel])) {
$englishParametersCount = self::$englishStringsWithParameters[$stringLabel];
- $countTranslation = $this->getCountParametersToReplace($stringValue);
+ $countTranslation = $this->getCountParametersToReplace($stringValue);
if ($englishParametersCount != $countTranslation) {
// Write fixed file in given location
// Will trigger a ->fail()
$writeCleanedFile = true;
- self::$errors[] = "$language: The string $stringLabel has $englishParametersCount parameters in English, but $countTranslation in this translation.";
+ self::$errors[] = "$language: The string $stringLabel has $englishParametersCount parameters in English, but $countTranslation in this translation.";
} else {
$cleanedStrings[$stringLabel] = $stringValue;
}
@@ -124,8 +124,8 @@ class Test_LanguagesManager extends PHPUnit_Framework_TestCase
&& strpos($stringLabel, 'UserCountry_') === false
&& $language != 'de'
) {
- $writeCleanedFile = true;
- self::$errors[] = "$language: The string $stringLabel is the same as in English, removing...";
+ $writeCleanedFile = true;
+ self::$errors[] = "$language: The string $stringLabel is the same as in English, removing...";
$cleanedStrings[$stringLabel] = false;
}
// remove excessive line breaks (and leading/trailing whitespace) from translations
@@ -135,8 +135,8 @@ class Test_LanguagesManager extends PHPUnit_Framework_TestCase
$stringNoLineBreak = str_replace(array("\n", "\r"), " ", $stringNoLineBreak);
}
if ($cleanedStrings[$stringLabel] !== $stringNoLineBreak) {
- self::$errors[] = "$language: found unnecessary whitespace in some strings in $stringLabel";
- $writeCleanedFile = true;
+ self::$errors[] = "$language: found unnecessary whitespace in some strings in $stringLabel";
+ $writeCleanedFile = true;
$cleanedStrings[$stringLabel] = $stringNoLineBreak;
}
}
@@ -154,10 +154,10 @@ class Test_LanguagesManager extends PHPUnit_Framework_TestCase
}
if (isset($cleanedStrings[$stringLabel])) {
$currentString = $cleanedStrings[$stringLabel];
- $decoded = Piwik_TranslationWriter::clean($currentString);
+ $decoded = Piwik_TranslationWriter::clean($currentString);
if ($currentString != $decoded) {
- self::$errors[] = "$language: found encoded entities in $stringLabel, converting entities to characters";
- $writeCleanedFile = true;
+ self::$errors[] = "$language: found encoded entities in $stringLabel, converting entities to characters";
+ $writeCleanedFile = true;
$cleanedStrings[$stringLabel] = $decoded;
}
}
@@ -167,9 +167,9 @@ class Test_LanguagesManager extends PHPUnit_Framework_TestCase
if (!empty($cleanedStrings['General_LayoutDirection'])
&& !in_array($cleanedStrings['General_LayoutDirection'], array('rtl', 'ltr'))
) {
- $writeCleanedFile = true;
+ $writeCleanedFile = true;
$cleanedStrings['General_LayoutDirection'] = false;
- self::$errors[] = "$language: General_LayoutDirection must be rtl or ltr";
+ self::$errors[] = "$language: General_LayoutDirection must be rtl or ltr";
}
if ($writeCleanedFile) {
$path = Piwik_TranslationWriter::getTranslationPath($language, 'tmp');
@@ -218,7 +218,7 @@ class Test_LanguagesManager extends PHPUnit_Framework_TestCase
private function getCountParametersToReplace($string)
{
$sprintfParameters = array('%s', '%1$s', '%2$s', '%3$s', '%4$s', '%5$s', '%6$s');
- $count = 0;
+ $count = 0;
foreach ($sprintfParameters as $parameter) {
$count += substr_count($string, $parameter);
}
diff --git a/tests/PHPUnit/Plugins/LoginTest.php b/tests/PHPUnit/Plugins/LoginTest.php
index 5edbf1326b..783d137167 100644
--- a/tests/PHPUnit/Plugins/LoginTest.php
+++ b/tests/PHPUnit/Plugins/LoginTest.php
@@ -12,21 +12,21 @@ class LoginTest extends DatabaseTestCase
public function setUp()
{
parent::setUp();
-
+
// setup the access layer
$pseudoMockAccess = new FakeAccess;
- FakeAccess::setIdSitesView( array(1,2));
- FakeAccess::setIdSitesAdmin( array(3,4));
-
+ FakeAccess::setIdSitesView(array(1, 2));
+ FakeAccess::setIdSitesAdmin(array(3, 4));
+
//finally we set the user as a super user by default
FakeAccess::$superUser = true;
Zend_Registry::set('access', $pseudoMockAccess);
-
+
// we make sure the tests don't depend on the config file content
Piwik_Config::getInstance()->superuser = array(
- 'login'=>'superusertest',
- 'password'=>md5('passwordsuperusertest'),
- 'email'=>'superuser@example.com'
+ 'login' => 'superusertest',
+ 'password' => md5('passwordsuperusertest'),
+ 'email' => 'superuser@example.com'
);
}
@@ -204,12 +204,13 @@ class LoginTest extends DatabaseTestCase
$this->assertEquals(Piwik_Auth_Result::SUCCESS, $rc->getCode());
}
- protected function _setUpUser() {
- $user = array( 'login'=>'user',
- 'password'=>"geqgeagae",
- 'email'=>"test@test.com",
- 'alias'=>"alias");
- Piwik_UsersManager_API::getInstance()->addUser($user['login'],$user['password'] ,$user['email'] ,$user['alias'] );
+ protected function _setUpUser()
+ {
+ $user = array('login' => 'user',
+ 'password' => "geqgeagae",
+ 'email' => "test@test.com",
+ 'alias' => "alias");
+ Piwik_UsersManager_API::getInstance()->addUser($user['login'], $user['password'], $user['email'], $user['alias']);
$password = md5($user['password']);
$user['tokenAuth'] = Piwik_UsersManager_API::getInstance()->getTokenAuth($user['login'], $password);
return $user;
diff --git a/tests/PHPUnit/Plugins/MobileMessagingTest.php b/tests/PHPUnit/Plugins/MobileMessagingTest.php
index ac0b67fa07..94796c5da3 100644
--- a/tests/PHPUnit/Plugins/MobileMessagingTest.php
+++ b/tests/PHPUnit/Plugins/MobileMessagingTest.php
@@ -8,207 +8,207 @@
class MobileMessagingTest extends DatabaseTestCase
{
- protected $idSiteAccess;
+ protected $idSiteAccess;
- public function setUp()
- {
- parent::setUp();
+ public function setUp()
+ {
+ parent::setUp();
- // setup the access layer
- $pseudoMockAccess = new FakeAccess;
- FakeAccess::$superUser = true;
- //finally we set the user as a super user by default
- Zend_Registry::set('access', $pseudoMockAccess);
+ // setup the access layer
+ $pseudoMockAccess = new FakeAccess;
+ FakeAccess::$superUser = true;
+ //finally we set the user as a super user by default
+ Zend_Registry::set('access', $pseudoMockAccess);
- $this->idSiteAccess = Piwik_SitesManager_API::getInstance()->addSite("test","http://test");
+ $this->idSiteAccess = Piwik_SitesManager_API::getInstance()->addSite("test", "http://test");
- Piwik_PluginsManager::getInstance()->loadPlugins( array('PDFReports', 'MobileMessaging', 'MultiSites') );
- Piwik_PluginsManager::getInstance()->installLoadedPlugins();
- }
+ Piwik_PluginsManager::getInstance()->loadPlugins(array('PDFReports', 'MobileMessaging', 'MultiSites'));
+ Piwik_PluginsManager::getInstance()->installLoadedPlugins();
+ }
- /**
- * When the MultiSites plugin is not activated, the SMS content should invite the user to activate it back
- *
- * @group Plugins
- * @group MobileMessaging
- */
- public function testWarnUserViaSMSMultiSitesDeactivated()
- {
- // safety net
- Piwik_PluginsManager::getInstance()->loadPlugins(array('PDFReports', 'MobileMessaging'));
- $this->assertFalse(Piwik_PluginsManager::getInstance()->isPluginActivated('MultiSites'));
+ /**
+ * When the MultiSites plugin is not activated, the SMS content should invite the user to activate it back
+ *
+ * @group Plugins
+ * @group MobileMessaging
+ */
+ public function testWarnUserViaSMSMultiSitesDeactivated()
+ {
+ // safety net
+ Piwik_PluginsManager::getInstance()->loadPlugins(array('PDFReports', 'MobileMessaging'));
+ $this->assertFalse(Piwik_PluginsManager::getInstance()->isPluginActivated('MultiSites'));
- $PdfReportsAPIInstance = Piwik_PDFReports_API::getInstance();
- $reportId = $PdfReportsAPIInstance->addReport(
- $this->idSiteAccess,
- 'description',
- 'month',
- 0,
- 'mobile',
- 'sms',
- array(),
- array("phoneNumbers" => array('33698896656'))
- );
+ $PdfReportsAPIInstance = Piwik_PDFReports_API::getInstance();
+ $reportId = $PdfReportsAPIInstance->addReport(
+ $this->idSiteAccess,
+ 'description',
+ 'month',
+ 0,
+ 'mobile',
+ 'sms',
+ array(),
+ array("phoneNumbers" => array('33698896656'))
+ );
- list($outputFilename, $prettyDate, $websiteName, $additionalFiles) =
- $PdfReportsAPIInstance->generateReport(
- $reportId,
- '01-01-2010',
- 'en',
- 2
- );
+ list($outputFilename, $prettyDate, $websiteName, $additionalFiles) =
+ $PdfReportsAPIInstance->generateReport(
+ $reportId,
+ '01-01-2010',
+ 'en',
+ 2
+ );
- $handle = fopen($outputFilename, "r");
- $contents = fread($handle, filesize($outputFilename));
- fclose($handle);
+ $handle = fopen($outputFilename, "r");
+ $contents = fread($handle, filesize($outputFilename));
+ fclose($handle);
- $this->assertEquals(
- Piwik_Translate('MobileMessaging_MultiSites_Must_Be_Activated'),
- $contents
- );
- }
+ $this->assertEquals(
+ Piwik_Translate('MobileMessaging_MultiSites_Must_Be_Activated'),
+ $contents
+ );
+ }
- /**
- * Dataprovider for testTruncate
- */
- public function getTruncateTestCases()
- {
-
- $stdGSMx459 = str_repeat('a', 459);
-
- $extGSMx229 = str_repeat('€', 229);
-
- $alternatedGSMx153 = str_repeat('a€', 153);
-
- $GSMWithRegExpSpecialChars = $stdGSMx459 . '[\^$.|?*+()';
-
- $UCS2x201 = str_repeat('控', 201);
-
- // appended strings
- $stdGSMAppendedString = 'too long';
- $extGSMAppendedString = '[too long]';
- $UCS2AppendedString = '[控控]';
-
- return array(
-
- // maximum number of standard GSM characters
- array($stdGSMx459, $stdGSMx459, 3, 'N/A'),
-
- // maximum number of extended GSM characters
- array($extGSMx229, $extGSMx229, 3, 'N/A'),
-
- // maximum number of alternated GSM characters
- array($alternatedGSMx153, $alternatedGSMx153, 3, 'N/A'),
-
- // standard GSM, one 'a' too many, appended with standard GSM characters
- array(str_repeat('a', 451) . $stdGSMAppendedString, $stdGSMx459 . 'a', 3, $stdGSMAppendedString),
-
- // standard GSM, one 'a' too many, appended with extended GSM characters
- array(str_repeat('a', 447) . $extGSMAppendedString, $stdGSMx459 . 'a', 3, $extGSMAppendedString),
-
- // standard GSM, one 'a' too many, appended with UCS2 characters
- array(str_repeat('a', 197) . $UCS2AppendedString, $stdGSMx459 . 'a', 3, $UCS2AppendedString),
-
- // extended GSM, one '€' too many, appended with standard GSM characters
- array(str_repeat('€', 225) . $stdGSMAppendedString, $extGSMx229 . '€', 3, $stdGSMAppendedString),
-
- // extended GSM, one '€' too many, appended with extended GSM characters
- array(str_repeat('€', 223) . $extGSMAppendedString, $extGSMx229 . '€', 3, $extGSMAppendedString),
-
- // extended GSM, one '€' too many, appended with UCS2 characters
- array(str_repeat('€', 197) . $UCS2AppendedString, $extGSMx229 . '€', 3, $UCS2AppendedString),
-
- // alternated GSM, one 'a' too many, appended with standard GSM characters
- array(str_repeat('a€', 150) . 'a' . $stdGSMAppendedString, $alternatedGSMx153 . 'a', 3, $stdGSMAppendedString),
-
- // alternated GSM, one 'a' too many, appended with extended GSM characters
- array(str_repeat('a€', 149) . $extGSMAppendedString, $alternatedGSMx153 . 'a', 3, $extGSMAppendedString),
-
- // alternated GSM, one 'a' too many, appended with UCS2 characters
- array(str_repeat('a€', 98) . 'a' . $UCS2AppendedString, $alternatedGSMx153 . 'a', 3, $UCS2AppendedString),
-
- // alternated GSM, one '€' too many, appended with standard GSM characters
- array(str_repeat('a€', 150) . 'a' . $stdGSMAppendedString, $alternatedGSMx153 . '€', 3, $stdGSMAppendedString),
-
- // alternated GSM, one '€' too many, appended with extended GSM characters
- array(str_repeat('a€', 149) . $extGSMAppendedString, $alternatedGSMx153 . '€', 3, $extGSMAppendedString),
-
- // alternated GSM, one '€' too many, appended with UCS2 characters
- array(str_repeat('a€', 98) . 'a' . $UCS2AppendedString, $alternatedGSMx153 . '€', 3, $UCS2AppendedString),
-
- // GSM with RegExp reserved special chars
- array(str_repeat('a', 451) . $stdGSMAppendedString, $GSMWithRegExpSpecialChars, 3, $stdGSMAppendedString),
-
- // maximum number of UCS-2 characters
- array($UCS2x201, $UCS2x201, 3, 'N/A'),
-
- // UCS-2, one '控' too many, appended with UCS2 characters
- array(str_repeat('控', 197) . $UCS2AppendedString, $UCS2x201 . '控', 3, $UCS2AppendedString),
-
- // UCS-2, one '控' too many, appended with standard GSM characters
- array(str_repeat('控', 193) . $stdGSMAppendedString, $UCS2x201 . '控', 3, $stdGSMAppendedString),
- );
- }
-
- /**
- * @group Plugins
- * @group MobileMessaging
- * @dataProvider getTruncateTestCases
- */
- public function testTruncate($expected, $stringToTruncate, $maximumNumberOfConcatenatedSMS, $appendedString)
- {
- $this->assertEquals(
- $expected,
- Piwik_MobileMessaging_SMSProvider::truncate($stringToTruncate, $maximumNumberOfConcatenatedSMS, $appendedString)
- );
- }
-
-
- /**
- * Dataprovider for testContainsUCS2Characters
- */
- public function getContainsUCS2CharactersTestCases()
- {
- return array(
- array(false, 'too long'),
- array(false, '[too long]'),
- array(false, '€'),
- array(true, '[控控]'),
- );
- }
-
- /**
- * @group Plugins
- * @group MobileMessaging
- * @dataProvider getContainsUCS2CharactersTestCases
- */
- public function testContainsUCS2Characters($expected, $stringToTest)
- {
- $this->assertEquals(
- $expected,
- Piwik_MobileMessaging_SMSProvider::containsUCS2Characters($stringToTest)
- );
- }
-
- /**
- * @group Plugins
- * @group MobileMessaging
- */
- public function testSanitizePhoneNumber()
- {
- $this->assertEquals('676932647', Piwik_MobileMessaging_API::sanitizePhoneNumber(' 6 76 93 26 47'));
- }
-
- /**
- * @group Plugins
- * @group MobileMessaging
- */
- public function testPhoneNumberIsSanitized()
- {
- $mobileMessagingAPI = new Piwik_MobileMessaging_API();
- $mobileMessagingAPI->setSMSAPICredential('StubbedProvider', '');
- $mobileMessagingAPI->addPhoneNumber(' 6 76 93 26 47');
- $this->assertEquals('676932647', key($mobileMessagingAPI->getPhoneNumbers()));
- }
+ /**
+ * Dataprovider for testTruncate
+ */
+ public function getTruncateTestCases()
+ {
+
+ $stdGSMx459 = str_repeat('a', 459);
+
+ $extGSMx229 = str_repeat('€', 229);
+
+ $alternatedGSMx153 = str_repeat('a€', 153);
+
+ $GSMWithRegExpSpecialChars = $stdGSMx459 . '[\^$.|?*+()';
+
+ $UCS2x201 = str_repeat('控', 201);
+
+ // appended strings
+ $stdGSMAppendedString = 'too long';
+ $extGSMAppendedString = '[too long]';
+ $UCS2AppendedString = '[控控]';
+
+ return array(
+
+ // maximum number of standard GSM characters
+ array($stdGSMx459, $stdGSMx459, 3, 'N/A'),
+
+ // maximum number of extended GSM characters
+ array($extGSMx229, $extGSMx229, 3, 'N/A'),
+
+ // maximum number of alternated GSM characters
+ array($alternatedGSMx153, $alternatedGSMx153, 3, 'N/A'),
+
+ // standard GSM, one 'a' too many, appended with standard GSM characters
+ array(str_repeat('a', 451) . $stdGSMAppendedString, $stdGSMx459 . 'a', 3, $stdGSMAppendedString),
+
+ // standard GSM, one 'a' too many, appended with extended GSM characters
+ array(str_repeat('a', 447) . $extGSMAppendedString, $stdGSMx459 . 'a', 3, $extGSMAppendedString),
+
+ // standard GSM, one 'a' too many, appended with UCS2 characters
+ array(str_repeat('a', 197) . $UCS2AppendedString, $stdGSMx459 . 'a', 3, $UCS2AppendedString),
+
+ // extended GSM, one '€' too many, appended with standard GSM characters
+ array(str_repeat('€', 225) . $stdGSMAppendedString, $extGSMx229 . '€', 3, $stdGSMAppendedString),
+
+ // extended GSM, one '€' too many, appended with extended GSM characters
+ array(str_repeat('€', 223) . $extGSMAppendedString, $extGSMx229 . '€', 3, $extGSMAppendedString),
+
+ // extended GSM, one '€' too many, appended with UCS2 characters
+ array(str_repeat('€', 197) . $UCS2AppendedString, $extGSMx229 . '€', 3, $UCS2AppendedString),
+
+ // alternated GSM, one 'a' too many, appended with standard GSM characters
+ array(str_repeat('a€', 150) . 'a' . $stdGSMAppendedString, $alternatedGSMx153 . 'a', 3, $stdGSMAppendedString),
+
+ // alternated GSM, one 'a' too many, appended with extended GSM characters
+ array(str_repeat('a€', 149) . $extGSMAppendedString, $alternatedGSMx153 . 'a', 3, $extGSMAppendedString),
+
+ // alternated GSM, one 'a' too many, appended with UCS2 characters
+ array(str_repeat('a€', 98) . 'a' . $UCS2AppendedString, $alternatedGSMx153 . 'a', 3, $UCS2AppendedString),
+
+ // alternated GSM, one '€' too many, appended with standard GSM characters
+ array(str_repeat('a€', 150) . 'a' . $stdGSMAppendedString, $alternatedGSMx153 . '€', 3, $stdGSMAppendedString),
+
+ // alternated GSM, one '€' too many, appended with extended GSM characters
+ array(str_repeat('a€', 149) . $extGSMAppendedString, $alternatedGSMx153 . '€', 3, $extGSMAppendedString),
+
+ // alternated GSM, one '€' too many, appended with UCS2 characters
+ array(str_repeat('a€', 98) . 'a' . $UCS2AppendedString, $alternatedGSMx153 . '€', 3, $UCS2AppendedString),
+
+ // GSM with RegExp reserved special chars
+ array(str_repeat('a', 451) . $stdGSMAppendedString, $GSMWithRegExpSpecialChars, 3, $stdGSMAppendedString),
+
+ // maximum number of UCS-2 characters
+ array($UCS2x201, $UCS2x201, 3, 'N/A'),
+
+ // UCS-2, one '控' too many, appended with UCS2 characters
+ array(str_repeat('控', 197) . $UCS2AppendedString, $UCS2x201 . '控', 3, $UCS2AppendedString),
+
+ // UCS-2, one '控' too many, appended with standard GSM characters
+ array(str_repeat('控', 193) . $stdGSMAppendedString, $UCS2x201 . '控', 3, $stdGSMAppendedString),
+ );
+ }
+
+ /**
+ * @group Plugins
+ * @group MobileMessaging
+ * @dataProvider getTruncateTestCases
+ */
+ public function testTruncate($expected, $stringToTruncate, $maximumNumberOfConcatenatedSMS, $appendedString)
+ {
+ $this->assertEquals(
+ $expected,
+ Piwik_MobileMessaging_SMSProvider::truncate($stringToTruncate, $maximumNumberOfConcatenatedSMS, $appendedString)
+ );
+ }
+
+
+ /**
+ * Dataprovider for testContainsUCS2Characters
+ */
+ public function getContainsUCS2CharactersTestCases()
+ {
+ return array(
+ array(false, 'too long'),
+ array(false, '[too long]'),
+ array(false, '€'),
+ array(true, '[控控]'),
+ );
+ }
+
+ /**
+ * @group Plugins
+ * @group MobileMessaging
+ * @dataProvider getContainsUCS2CharactersTestCases
+ */
+ public function testContainsUCS2Characters($expected, $stringToTest)
+ {
+ $this->assertEquals(
+ $expected,
+ Piwik_MobileMessaging_SMSProvider::containsUCS2Characters($stringToTest)
+ );
+ }
+
+ /**
+ * @group Plugins
+ * @group MobileMessaging
+ */
+ public function testSanitizePhoneNumber()
+ {
+ $this->assertEquals('676932647', Piwik_MobileMessaging_API::sanitizePhoneNumber(' 6 76 93 26 47'));
+ }
+
+ /**
+ * @group Plugins
+ * @group MobileMessaging
+ */
+ public function testPhoneNumberIsSanitized()
+ {
+ $mobileMessagingAPI = new Piwik_MobileMessaging_API();
+ $mobileMessagingAPI->setSMSAPICredential('StubbedProvider', '');
+ $mobileMessagingAPI->addPhoneNumber(' 6 76 93 26 47');
+ $this->assertEquals('676932647', key($mobileMessagingAPI->getPhoneNumbers()));
+ }
}
diff --git a/tests/PHPUnit/Plugins/MultiSitesTest.php b/tests/PHPUnit/Plugins/MultiSitesTest.php
index 9052c4c4dc..8305809dc5 100644
--- a/tests/PHPUnit/Plugins/MultiSitesTest.php
+++ b/tests/PHPUnit/Plugins/MultiSitesTest.php
@@ -8,36 +8,36 @@
class MultiSitesTest extends DatabaseTestCase
{
- protected $idSiteAccess;
-
- public function setUp()
- {
- parent::setUp();
-
- $access = new Piwik_Access();
- Zend_Registry::set('access', $access);
- $access->setSuperUser(true);
-
- $this->idSiteAccess = Piwik_SitesManager_API::getInstance()->addSite("test","http://test");
-
- Piwik_PluginsManager::getInstance()->loadPlugins( array('MultiSites','VisitsSummary','Actions') );
- Piwik_PluginsManager::getInstance()->installLoadedPlugins();
- }
-
-
- /**
- * Testing that getOne returns a row even when there are no data
- * This is necessary otherwise Piwik_API_ResponseBuilder throws 'Call to a member function getColumns() on a non-object'
- *
- * @group Plugins
- * @group MultiSites
- */
- public function testWhenNoDataGetOneReturnsRow()
- {
- $dataTable = Piwik_MultiSites_API::getInstance()->getOne($this->idSiteAccess, 'month', '01-01-2010');
- $this->assertEquals(1, $dataTable->getRowsCount());
-
- // safety net
- $this->assertEquals(0, $dataTable->getFirstRow()->getColumn('nb_visits'));
- }
+ protected $idSiteAccess;
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $access = new Piwik_Access();
+ Zend_Registry::set('access', $access);
+ $access->setSuperUser(true);
+
+ $this->idSiteAccess = Piwik_SitesManager_API::getInstance()->addSite("test", "http://test");
+
+ Piwik_PluginsManager::getInstance()->loadPlugins(array('MultiSites', 'VisitsSummary', 'Actions'));
+ Piwik_PluginsManager::getInstance()->installLoadedPlugins();
+ }
+
+
+ /**
+ * Testing that getOne returns a row even when there are no data
+ * This is necessary otherwise Piwik_API_ResponseBuilder throws 'Call to a member function getColumns() on a non-object'
+ *
+ * @group Plugins
+ * @group MultiSites
+ */
+ public function testWhenNoDataGetOneReturnsRow()
+ {
+ $dataTable = Piwik_MultiSites_API::getInstance()->getOne($this->idSiteAccess, 'month', '01-01-2010');
+ $this->assertEquals(1, $dataTable->getRowsCount());
+
+ // safety net
+ $this->assertEquals(0, $dataTable->getFirstRow()->getColumn('nb_visits'));
+ }
}
diff --git a/tests/PHPUnit/Plugins/PDFReportsTest.php b/tests/PHPUnit/Plugins/PDFReportsTest.php
index e619fc7913..31320e36e2 100644
--- a/tests/PHPUnit/Plugins/PDFReportsTest.php
+++ b/tests/PHPUnit/Plugins/PDFReportsTest.php
@@ -9,470 +9,465 @@ require_once 'PDFReports/PDFReports.php';
class PDFReportsTest extends DatabaseTestCase
{
- private $idSite = 1;
-
- public function setUp()
- {
- parent::setUp();
-
- // setup the access layer
- self::setSuperUser();
- Piwik_PluginsManager::getInstance()->loadPlugins(array('API', 'UserCountry', 'PDFReports', 'MobileMessaging'));
- Piwik_PluginsManager::getInstance()->installLoadedPlugins();
-
- Piwik_SitesManager_API::getInstance()->addSite("Test", array("http://piwik.net"));
-
- Piwik_SitesManager_API::getInstance()->addSite("Test", array("http://piwik.net"));
- FakeAccess::setIdSitesView(array($this->idSite, 2));
- Piwik_PDFReports_API::$cache = array();
- }
-
- /**
- * @group Plugins
- * @group PDFReports
- */
- public function testAddReportGetReports()
- {
- $data = array(
- 'idsite' => $this->idSite,
- 'description' => 'test description"',
- 'type' => 'email',
- 'period' => Piwik_ScheduledTime::PERIOD_DAY,
- 'hour' => '4',
- 'format' => 'pdf',
- 'reports' => array('UserCountry_getCountry'),
- 'parameters' => array(
- 'displayFormat' => '1',
- 'emailMe' => true,
- 'additionalEmails' => array('test@test.com', 't2@test.com'),
- 'evolutionGraph' => true
- )
- );
-
- $dataWebsiteTwo = $data;
- $dataWebsiteTwo['idsite'] = 2;
- $dataWebsiteTwo['period'] = Piwik_ScheduledTime::PERIOD_MONTH;
-
- self::addReport($dataWebsiteTwo);
-
- // Testing getReports without parameters
- $tmp = Piwik_PDFReports_API::getInstance()->getReports();
- $report = reset($tmp);
- $this->assertReportsEqual($report, $dataWebsiteTwo);
-
- $idReport = self::addReport($data);
-
- // Passing 3 parameters
- $tmp = Piwik_PDFReports_API::getInstance()->getReports($this->idSite, $data['period'], $idReport);
- $report = reset($tmp);
- $this->assertReportsEqual($report, $data);
-
- // Passing only idsite
- $tmp = Piwik_PDFReports_API::getInstance()->getReports($this->idSite);
- $report = reset($tmp);
- $this->assertReportsEqual($report, $data);
-
- // Passing only period
- $tmp = Piwik_PDFReports_API::getInstance()->getReports($idSite = false, $data['period']);
- $report = reset($tmp);
- $this->assertReportsEqual($report, $data);
-
- // Passing only idreport
- $tmp = Piwik_PDFReports_API::getInstance()->getReports($idSite = false, $period = false, $idReport);
- $report = reset($tmp);
- $this->assertReportsEqual($report, $data);
- }
-
- /**
- * @group Plugins
- * @group PDFReports
- */
- public function testGetReportsIdReportNotFound()
- {
- try
- {
- Piwik_PDFReports_API::getInstance()->getReports($idSite = false, $period = false, $idReport = 1);
- } catch (Exception $e) {
- return;
- }
- $this->fail('Expected exception not raised');
- }
-
- /**
- * @group Plugins
- * @group PDFReports
- */
- public function testGetReportsInvalidPermission()
- {
- try
- {
- Piwik_PDFReports_API::getInstance()->getReports(
- $idSite = 44,
- $period = false,
- self::addReport(self::getDailyPDFReportData($this->idSite))
- );
-
- } catch (Exception $e) {
- return;
- }
- $this->fail('Expected exception not raised');
- }
-
- /**
- * @group Plugins
- * @group PDFReports
- */
- public function testAddReportInvalidWebsite()
- {
- try
- {
- self::addReport(self::getDailyPDFReportData(33));
- } catch (Exception $e) {
- return;
- }
- $this->fail('Expected exception not raised');
- }
-
- /**
- * @group Plugins
- * @group PDFReports
- */
- public function testAddReportInvalidPeriod()
- {
- try
- {
- $data = self::getDailyPDFReportData($this->idSite);
- $data['period'] = 'dx';
- self::addReport($data);
- } catch (Exception $e) {
- return;
- }
- $this->fail('Expected exception not raised');
- }
-
- /**
- * @group Plugins
- * @group PDFReports
- */
- public function testUpdateReport()
- {
- $idReport = self::addReport(self::getDailyPDFReportData($this->idSite));
- $dataAfter = self::getMonthlyEmailReportData($this->idSite);
-
- self::updateReport($idReport, $dataAfter);
-
- $reports = Piwik_PDFReports_API::getInstance()->getReports($idSite = false, $period = false, $idReport);
-
- $this->assertReportsEqual(
- reset($reports),
- $dataAfter
- );
- }
-
- /**
- * @group Plugins
- * @group PDFReports
- */
- public function testDeleteReport()
- {
- // Deletes non existing report throws exception
- try {
- Piwik_PDFReports_API::getInstance()->deleteReport($idReport = 1);
- $this->fail('Exception not raised');
- } catch (Exception $e) {
- }
-
- $idReport = self::addReport(self::getMonthlyEmailReportData($this->idSite));
- $this->assertEquals(1, count(Piwik_PDFReports_API::getInstance()->getReports()));
- Piwik_PDFReports_API::getInstance()->deleteReport($idReport);
- $this->assertEquals(0, count(Piwik_PDFReports_API::getInstance()->getReports()));
- }
-
- /**
- * @group Plugins
- * @group PDFReports
- */
- public function testGetTopMenuTranslationKeyMobileMessagingInactive()
- {
- // unload MobileMessaging plugin
- Piwik_PluginsManager::getInstance()->loadPlugins(array('PDFReports'));
-
- $pdfReportPlugin = new Piwik_PDFReports();
- $this->assertEquals(
- Piwik_PDFReports::PDF_REPORTS_TOP_MENU_TRANSLATION_KEY,
- $pdfReportPlugin->getTopMenuTranslationKey()
- );
- }
-
- /**
- * @group Plugins
- * @group PDFReports
- */
- public function testGetTopMenuTranslationKeyUserIsAnonymous()
- {
- $anonymousAccess = new FakeAccess;
- FakeAccess::$identity = 'anonymous';
- Zend_Registry::set('access', $anonymousAccess);
-
- $pdfReportPlugin = new Piwik_PDFReports();
- $this->assertEquals(
- Piwik_PDFReports::MOBILE_MESSAGING_TOP_MENU_TRANSLATION_KEY,
- $pdfReportPlugin->getTopMenuTranslationKey()
- );
- }
-
- /**
- * top menu should display 'Email & SMS reports' when the user has set-up a valid mobile provider account
- * even though there is no sms reports configured
- *
- * @group Plugins
- * @group PDFReports
- */
- public function testGetTopMenuTranslationKeyNoReportMobileAccountOK()
- {
- // set mobile provider account
- self::setSuperUser();
- Piwik_MobileMessaging_API::getInstance()->setSMSAPICredential('StubbedProvider', '');
-
- $pdfReportPlugin = new Piwik_PDFReports();
- $this->assertEquals(
- Piwik_PDFReports::MOBILE_MESSAGING_TOP_MENU_TRANSLATION_KEY,
- $pdfReportPlugin->getTopMenuTranslationKey()
- );
- }
-
- /**
- * top menu should display 'Email reports' when the user has not set-up a valid mobile provider account
- * and no reports at all have been configured
- *
- * @group Plugins
- * @group PDFReports
- */
- public function testGetTopMenuTranslationKeyNoReportMobileAccountKO()
- {
- $pdfReportPlugin = new Piwik_PDFReports();
- $this->assertEquals(
- Piwik_PDFReports::PDF_REPORTS_TOP_MENU_TRANSLATION_KEY,
- $pdfReportPlugin->getTopMenuTranslationKey()
- );
- }
-
- /**
- * top menu should display 'Email & SMS reports' if there is at least one sms report
- * whatever the status of the mobile provider account
- *
- * @group Plugins
- * @group PDFReports
- */
- public function testGetTopMenuTranslationKeyOneSMSReportMobileAccountKO()
- {
- Piwik_PDFReports_API::getInstance()->addReport(
- 1,
- '',
- Piwik_ScheduledTime::PERIOD_DAY,
- 0,
- Piwik_MobileMessaging::MOBILE_TYPE,
- Piwik_MobileMessaging::SMS_FORMAT,
- array(),
- array(
- Piwik_MobileMessaging::PHONE_NUMBERS_PARAMETER => array()
- )
- );
-
- $pdfReportPlugin = new Piwik_PDFReports();
- $this->assertEquals(
- Piwik_PDFReports::MOBILE_MESSAGING_TOP_MENU_TRANSLATION_KEY,
- $pdfReportPlugin->getTopMenuTranslationKey()
- );
- }
-
- /**
- * top menu should display 'Email reports' if there are no SMS reports and at least one email report
- * whatever the status of the mobile provider account
- *
- * @group Plugins
- * @group PDFReports
- */
- public function testGetTopMenuTranslationKeyNoSMSReportAccountOK()
- {
- // set mobile provider account
- self::setSuperUser();
- Piwik_MobileMessaging_API::getInstance()->setSMSAPICredential('StubbedProvider', '');
-
- self::addReport(self::getMonthlyEmailReportData($this->idSite));
-
- $pdfReportPlugin = new Piwik_PDFReports();
- $this->assertEquals(
- Piwik_PDFReports::PDF_REPORTS_TOP_MENU_TRANSLATION_KEY,
- $pdfReportPlugin->getTopMenuTranslationKey()
- );
- }
-
- /**
- * @group Plugins
- * @group PDFReports
- */
- public function testGetScheduledTasks()
- {
- // stub Piwik_PDFReports_API to control getReports() return values
- $report1 = self::getDailyPDFReportData($this->idSite);
- $report1['idreport'] = 1;
- $report1['hour'] = 0;
- $report1['deleted'] = 0;
-
- $report2 = self::getMonthlyEmailReportData($this->idSite);
- $report2['idreport'] = 2;
- $report2['idsite'] = 2;
- $report2['hour'] = 0;
- $report2['deleted'] = 0;
-
- $report3 = self::getMonthlyEmailReportData($this->idSite);
- $report3['idreport'] = 3;
- $report3['deleted'] = 1; // should not be scheduled
-
- $report4 = self::getMonthlyEmailReportData($this->idSite);
- $report4['idreport'] = 4;
- $report4['idsite'] = 1;
- $report4['hour'] = 8;
- $report4['deleted'] = 0;
-
- $report5 = self::getMonthlyEmailReportData($this->idSite);
- $report5['idreport'] = 5;
- $report5['idsite'] = 2;
- $report5['hour'] = 8;
- $report5['deleted'] = 0;
-
- // test no exception is raised when a scheduled report is set to never send
- $report6 = self::getMonthlyEmailReportData($this->idSite);
- $report6['idreport'] = 6;
- $report6['period'] = Piwik_ScheduledTime::PERIOD_NEVER;
- $report6['deleted'] = 0;
-
- $stubbedPDFReportsAPI = $this->getMock('Piwik_PDFReports_API');
- $stubbedPDFReportsAPI->expects($this->any())->method('getReports')->will($this->returnValue(
- array($report1, $report2, $report3, $report4, $report5, $report6))
- );
-
- $stubbedPDFReportsAPIClass = new ReflectionProperty('Piwik_PDFReports_API', 'instance');
- $stubbedPDFReportsAPIClass->setAccessible(true);
- $stubbedPDFReportsAPIClass->setValue($stubbedPDFReportsAPI);
-
- // initialize sites 1 and 2
- Piwik_Site::$infoSites = array(
- 1 => array('timezone' => 'Europe/Paris'),
- 2 => array('timezone' => 'UTC-6.5'),
- );
-
- // expected tasks
- $scheduleTask1 = new Piwik_ScheduledTime_Daily();
- $scheduleTask1->setHour(23); // paris is UTC-1, period ends at 23h UTC
-
- $scheduleTask2 = new Piwik_ScheduledTime_Monthly();
- $scheduleTask2->setHour(7); // site is UTC-6.5, period ends at 6h30 UTC, smallest resolution is hour
-
- $scheduleTask3 = new Piwik_ScheduledTime_Monthly();
- $scheduleTask3->setHour(7); // paris is UTC-1, configured to be sent at 8h
-
- $scheduleTask4 = new Piwik_ScheduledTime_Monthly();
- $scheduleTask4->setHour(15); // site is UTC-6.5, configured to be sent at 8h
-
- $expectedTasks = array(
- new Piwik_ScheduledTask (Piwik_PDFReports_API::getInstance(), 'sendReport', 1, $scheduleTask1),
- new Piwik_ScheduledTask (Piwik_PDFReports_API::getInstance(), 'sendReport', 2, $scheduleTask2),
- new Piwik_ScheduledTask (Piwik_PDFReports_API::getInstance(), 'sendReport', 4, $scheduleTask3),
- new Piwik_ScheduledTask (Piwik_PDFReports_API::getInstance(), 'sendReport', 5, $scheduleTask4),
- );
-
- $pdfReportPlugin = new Piwik_PDFReports();
- $tasks = array();
- $pdfReportPlugin->getScheduledTasks(new Piwik_Event_Notification($tasks, 'fakeEvent'));
- $this->assertEquals($expectedTasks, $tasks);
-
- // restore Piwik_PDFReports_API
- $stubbedPDFReportsAPIClass->setValue(null);
- }
-
- private function assertReportsEqual($report, $data)
- {
- foreach ($data as $key => $value)
- {
- if ($key == 'description') $value = substr($value, 0, 250);
- $this->assertEquals($value, $report[$key], "Error for $key for report " . var_export($report, true) . " and data " . var_export($data, true));
- }
- }
-
- private static function addReport($data)
- {
- $idReport = Piwik_PDFReports_API::getInstance()->addReport(
- $data['idsite'],
- $data['description'],
- $data['period'],
- $data['hour'],
- $data['type'],
- $data['format'],
- $data['reports'],
- $data['parameters']
- );
- return $idReport;
- }
-
- private static function getDailyPDFReportData($idSite)
- {
- return array(
- 'idsite' => $idSite,
- 'description' => 'test description"',
- 'period' => Piwik_ScheduledTime::PERIOD_DAY,
- 'hour' => '7',
- 'type' => 'email',
- 'format' => 'pdf',
- 'reports' => array('UserCountry_getCountry'),
- 'parameters' => array(
- 'displayFormat' => '1',
- 'emailMe' => true,
- 'additionalEmails' => array('test@test.com', 't2@test.com'),
- 'evolutionGraph' => false
- )
- );
- }
-
- private static function getMonthlyEmailReportData($idSite)
- {
- return array(
- 'idsite' => $idSite,
- 'description' => 'very very long and possibly truncated description. very very long and possibly truncated description. very very long and possibly truncated description. very very long and possibly truncated description. very very long and possibly truncated description. ',
- 'period' => Piwik_ScheduledTime::PERIOD_MONTH,
- 'hour' => '0',
- 'type' => 'email',
- 'format' => 'pdf',
- 'reports' => array('UserCountry_getContinent'),
- 'parameters' => array(
- 'displayFormat' => '1',
- 'emailMe' => false,
- 'additionalEmails' => array('blabla@ec.fr'),
- 'evolutionGraph' => false
- )
- );
- }
-
- private static function updateReport($idReport, $data)
- {
- $idReport = Piwik_PDFReports_API::getInstance()->updateReport(
- $idReport,
- $data['idsite'],
- $data['description'],
- $data['period'],
- $data['hour'],
- $data['type'],
- $data['format'],
- $data['reports'],
- $data['parameters']);
- return $idReport;
- }
-
- private static function setSuperUser()
- {
- $pseudoMockAccess = new FakeAccess;
- FakeAccess::$superUser = true;
- Zend_Registry::set('access', $pseudoMockAccess);
- }
+ private $idSite = 1;
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ // setup the access layer
+ self::setSuperUser();
+ Piwik_PluginsManager::getInstance()->loadPlugins(array('API', 'UserCountry', 'PDFReports', 'MobileMessaging'));
+ Piwik_PluginsManager::getInstance()->installLoadedPlugins();
+
+ Piwik_SitesManager_API::getInstance()->addSite("Test", array("http://piwik.net"));
+
+ Piwik_SitesManager_API::getInstance()->addSite("Test", array("http://piwik.net"));
+ FakeAccess::setIdSitesView(array($this->idSite, 2));
+ Piwik_PDFReports_API::$cache = array();
+ }
+
+ /**
+ * @group Plugins
+ * @group PDFReports
+ */
+ public function testAddReportGetReports()
+ {
+ $data = array(
+ 'idsite' => $this->idSite,
+ 'description' => 'test description"',
+ 'type' => 'email',
+ 'period' => Piwik_ScheduledTime::PERIOD_DAY,
+ 'hour' => '4',
+ 'format' => 'pdf',
+ 'reports' => array('UserCountry_getCountry'),
+ 'parameters' => array(
+ 'displayFormat' => '1',
+ 'emailMe' => true,
+ 'additionalEmails' => array('test@test.com', 't2@test.com'),
+ 'evolutionGraph' => true
+ )
+ );
+
+ $dataWebsiteTwo = $data;
+ $dataWebsiteTwo['idsite'] = 2;
+ $dataWebsiteTwo['period'] = Piwik_ScheduledTime::PERIOD_MONTH;
+
+ self::addReport($dataWebsiteTwo);
+
+ // Testing getReports without parameters
+ $tmp = Piwik_PDFReports_API::getInstance()->getReports();
+ $report = reset($tmp);
+ $this->assertReportsEqual($report, $dataWebsiteTwo);
+
+ $idReport = self::addReport($data);
+
+ // Passing 3 parameters
+ $tmp = Piwik_PDFReports_API::getInstance()->getReports($this->idSite, $data['period'], $idReport);
+ $report = reset($tmp);
+ $this->assertReportsEqual($report, $data);
+
+ // Passing only idsite
+ $tmp = Piwik_PDFReports_API::getInstance()->getReports($this->idSite);
+ $report = reset($tmp);
+ $this->assertReportsEqual($report, $data);
+
+ // Passing only period
+ $tmp = Piwik_PDFReports_API::getInstance()->getReports($idSite = false, $data['period']);
+ $report = reset($tmp);
+ $this->assertReportsEqual($report, $data);
+
+ // Passing only idreport
+ $tmp = Piwik_PDFReports_API::getInstance()->getReports($idSite = false, $period = false, $idReport);
+ $report = reset($tmp);
+ $this->assertReportsEqual($report, $data);
+ }
+
+ /**
+ * @group Plugins
+ * @group PDFReports
+ */
+ public function testGetReportsIdReportNotFound()
+ {
+ try {
+ Piwik_PDFReports_API::getInstance()->getReports($idSite = false, $period = false, $idReport = 1);
+ } catch (Exception $e) {
+ return;
+ }
+ $this->fail('Expected exception not raised');
+ }
+
+ /**
+ * @group Plugins
+ * @group PDFReports
+ */
+ public function testGetReportsInvalidPermission()
+ {
+ try {
+ Piwik_PDFReports_API::getInstance()->getReports(
+ $idSite = 44,
+ $period = false,
+ self::addReport(self::getDailyPDFReportData($this->idSite))
+ );
+
+ } catch (Exception $e) {
+ return;
+ }
+ $this->fail('Expected exception not raised');
+ }
+
+ /**
+ * @group Plugins
+ * @group PDFReports
+ */
+ public function testAddReportInvalidWebsite()
+ {
+ try {
+ self::addReport(self::getDailyPDFReportData(33));
+ } catch (Exception $e) {
+ return;
+ }
+ $this->fail('Expected exception not raised');
+ }
+
+ /**
+ * @group Plugins
+ * @group PDFReports
+ */
+ public function testAddReportInvalidPeriod()
+ {
+ try {
+ $data = self::getDailyPDFReportData($this->idSite);
+ $data['period'] = 'dx';
+ self::addReport($data);
+ } catch (Exception $e) {
+ return;
+ }
+ $this->fail('Expected exception not raised');
+ }
+
+ /**
+ * @group Plugins
+ * @group PDFReports
+ */
+ public function testUpdateReport()
+ {
+ $idReport = self::addReport(self::getDailyPDFReportData($this->idSite));
+ $dataAfter = self::getMonthlyEmailReportData($this->idSite);
+
+ self::updateReport($idReport, $dataAfter);
+
+ $reports = Piwik_PDFReports_API::getInstance()->getReports($idSite = false, $period = false, $idReport);
+
+ $this->assertReportsEqual(
+ reset($reports),
+ $dataAfter
+ );
+ }
+
+ /**
+ * @group Plugins
+ * @group PDFReports
+ */
+ public function testDeleteReport()
+ {
+ // Deletes non existing report throws exception
+ try {
+ Piwik_PDFReports_API::getInstance()->deleteReport($idReport = 1);
+ $this->fail('Exception not raised');
+ } catch (Exception $e) {
+ }
+
+ $idReport = self::addReport(self::getMonthlyEmailReportData($this->idSite));
+ $this->assertEquals(1, count(Piwik_PDFReports_API::getInstance()->getReports()));
+ Piwik_PDFReports_API::getInstance()->deleteReport($idReport);
+ $this->assertEquals(0, count(Piwik_PDFReports_API::getInstance()->getReports()));
+ }
+
+ /**
+ * @group Plugins
+ * @group PDFReports
+ */
+ public function testGetTopMenuTranslationKeyMobileMessagingInactive()
+ {
+ // unload MobileMessaging plugin
+ Piwik_PluginsManager::getInstance()->loadPlugins(array('PDFReports'));
+
+ $pdfReportPlugin = new Piwik_PDFReports();
+ $this->assertEquals(
+ Piwik_PDFReports::PDF_REPORTS_TOP_MENU_TRANSLATION_KEY,
+ $pdfReportPlugin->getTopMenuTranslationKey()
+ );
+ }
+
+ /**
+ * @group Plugins
+ * @group PDFReports
+ */
+ public function testGetTopMenuTranslationKeyUserIsAnonymous()
+ {
+ $anonymousAccess = new FakeAccess;
+ FakeAccess::$identity = 'anonymous';
+ Zend_Registry::set('access', $anonymousAccess);
+
+ $pdfReportPlugin = new Piwik_PDFReports();
+ $this->assertEquals(
+ Piwik_PDFReports::MOBILE_MESSAGING_TOP_MENU_TRANSLATION_KEY,
+ $pdfReportPlugin->getTopMenuTranslationKey()
+ );
+ }
+
+ /**
+ * top menu should display 'Email & SMS reports' when the user has set-up a valid mobile provider account
+ * even though there is no sms reports configured
+ *
+ * @group Plugins
+ * @group PDFReports
+ */
+ public function testGetTopMenuTranslationKeyNoReportMobileAccountOK()
+ {
+ // set mobile provider account
+ self::setSuperUser();
+ Piwik_MobileMessaging_API::getInstance()->setSMSAPICredential('StubbedProvider', '');
+
+ $pdfReportPlugin = new Piwik_PDFReports();
+ $this->assertEquals(
+ Piwik_PDFReports::MOBILE_MESSAGING_TOP_MENU_TRANSLATION_KEY,
+ $pdfReportPlugin->getTopMenuTranslationKey()
+ );
+ }
+
+ /**
+ * top menu should display 'Email reports' when the user has not set-up a valid mobile provider account
+ * and no reports at all have been configured
+ *
+ * @group Plugins
+ * @group PDFReports
+ */
+ public function testGetTopMenuTranslationKeyNoReportMobileAccountKO()
+ {
+ $pdfReportPlugin = new Piwik_PDFReports();
+ $this->assertEquals(
+ Piwik_PDFReports::PDF_REPORTS_TOP_MENU_TRANSLATION_KEY,
+ $pdfReportPlugin->getTopMenuTranslationKey()
+ );
+ }
+
+ /**
+ * top menu should display 'Email & SMS reports' if there is at least one sms report
+ * whatever the status of the mobile provider account
+ *
+ * @group Plugins
+ * @group PDFReports
+ */
+ public function testGetTopMenuTranslationKeyOneSMSReportMobileAccountKO()
+ {
+ Piwik_PDFReports_API::getInstance()->addReport(
+ 1,
+ '',
+ Piwik_ScheduledTime::PERIOD_DAY,
+ 0,
+ Piwik_MobileMessaging::MOBILE_TYPE,
+ Piwik_MobileMessaging::SMS_FORMAT,
+ array(),
+ array(
+ Piwik_MobileMessaging::PHONE_NUMBERS_PARAMETER => array()
+ )
+ );
+
+ $pdfReportPlugin = new Piwik_PDFReports();
+ $this->assertEquals(
+ Piwik_PDFReports::MOBILE_MESSAGING_TOP_MENU_TRANSLATION_KEY,
+ $pdfReportPlugin->getTopMenuTranslationKey()
+ );
+ }
+
+ /**
+ * top menu should display 'Email reports' if there are no SMS reports and at least one email report
+ * whatever the status of the mobile provider account
+ *
+ * @group Plugins
+ * @group PDFReports
+ */
+ public function testGetTopMenuTranslationKeyNoSMSReportAccountOK()
+ {
+ // set mobile provider account
+ self::setSuperUser();
+ Piwik_MobileMessaging_API::getInstance()->setSMSAPICredential('StubbedProvider', '');
+
+ self::addReport(self::getMonthlyEmailReportData($this->idSite));
+
+ $pdfReportPlugin = new Piwik_PDFReports();
+ $this->assertEquals(
+ Piwik_PDFReports::PDF_REPORTS_TOP_MENU_TRANSLATION_KEY,
+ $pdfReportPlugin->getTopMenuTranslationKey()
+ );
+ }
+
+ /**
+ * @group Plugins
+ * @group PDFReports
+ */
+ public function testGetScheduledTasks()
+ {
+ // stub Piwik_PDFReports_API to control getReports() return values
+ $report1 = self::getDailyPDFReportData($this->idSite);
+ $report1['idreport'] = 1;
+ $report1['hour'] = 0;
+ $report1['deleted'] = 0;
+
+ $report2 = self::getMonthlyEmailReportData($this->idSite);
+ $report2['idreport'] = 2;
+ $report2['idsite'] = 2;
+ $report2['hour'] = 0;
+ $report2['deleted'] = 0;
+
+ $report3 = self::getMonthlyEmailReportData($this->idSite);
+ $report3['idreport'] = 3;
+ $report3['deleted'] = 1; // should not be scheduled
+
+ $report4 = self::getMonthlyEmailReportData($this->idSite);
+ $report4['idreport'] = 4;
+ $report4['idsite'] = 1;
+ $report4['hour'] = 8;
+ $report4['deleted'] = 0;
+
+ $report5 = self::getMonthlyEmailReportData($this->idSite);
+ $report5['idreport'] = 5;
+ $report5['idsite'] = 2;
+ $report5['hour'] = 8;
+ $report5['deleted'] = 0;
+
+ // test no exception is raised when a scheduled report is set to never send
+ $report6 = self::getMonthlyEmailReportData($this->idSite);
+ $report6['idreport'] = 6;
+ $report6['period'] = Piwik_ScheduledTime::PERIOD_NEVER;
+ $report6['deleted'] = 0;
+
+ $stubbedPDFReportsAPI = $this->getMock('Piwik_PDFReports_API');
+ $stubbedPDFReportsAPI->expects($this->any())->method('getReports')->will($this->returnValue(
+ array($report1, $report2, $report3, $report4, $report5, $report6))
+ );
+
+ $stubbedPDFReportsAPIClass = new ReflectionProperty('Piwik_PDFReports_API', 'instance');
+ $stubbedPDFReportsAPIClass->setAccessible(true);
+ $stubbedPDFReportsAPIClass->setValue($stubbedPDFReportsAPI);
+
+ // initialize sites 1 and 2
+ Piwik_Site::$infoSites = array(
+ 1 => array('timezone' => 'Europe/Paris'),
+ 2 => array('timezone' => 'UTC-6.5'),
+ );
+
+ // expected tasks
+ $scheduleTask1 = new Piwik_ScheduledTime_Daily();
+ $scheduleTask1->setHour(23); // paris is UTC-1, period ends at 23h UTC
+
+ $scheduleTask2 = new Piwik_ScheduledTime_Monthly();
+ $scheduleTask2->setHour(7); // site is UTC-6.5, period ends at 6h30 UTC, smallest resolution is hour
+
+ $scheduleTask3 = new Piwik_ScheduledTime_Monthly();
+ $scheduleTask3->setHour(7); // paris is UTC-1, configured to be sent at 8h
+
+ $scheduleTask4 = new Piwik_ScheduledTime_Monthly();
+ $scheduleTask4->setHour(15); // site is UTC-6.5, configured to be sent at 8h
+
+ $expectedTasks = array(
+ new Piwik_ScheduledTask (Piwik_PDFReports_API::getInstance(), 'sendReport', 1, $scheduleTask1),
+ new Piwik_ScheduledTask (Piwik_PDFReports_API::getInstance(), 'sendReport', 2, $scheduleTask2),
+ new Piwik_ScheduledTask (Piwik_PDFReports_API::getInstance(), 'sendReport', 4, $scheduleTask3),
+ new Piwik_ScheduledTask (Piwik_PDFReports_API::getInstance(), 'sendReport', 5, $scheduleTask4),
+ );
+
+ $pdfReportPlugin = new Piwik_PDFReports();
+ $tasks = array();
+ $pdfReportPlugin->getScheduledTasks(new Piwik_Event_Notification($tasks, 'fakeEvent'));
+ $this->assertEquals($expectedTasks, $tasks);
+
+ // restore Piwik_PDFReports_API
+ $stubbedPDFReportsAPIClass->setValue(null);
+ }
+
+ private function assertReportsEqual($report, $data)
+ {
+ foreach ($data as $key => $value) {
+ if ($key == 'description') $value = substr($value, 0, 250);
+ $this->assertEquals($value, $report[$key], "Error for $key for report " . var_export($report, true) . " and data " . var_export($data, true));
+ }
+ }
+
+ private static function addReport($data)
+ {
+ $idReport = Piwik_PDFReports_API::getInstance()->addReport(
+ $data['idsite'],
+ $data['description'],
+ $data['period'],
+ $data['hour'],
+ $data['type'],
+ $data['format'],
+ $data['reports'],
+ $data['parameters']
+ );
+ return $idReport;
+ }
+
+ private static function getDailyPDFReportData($idSite)
+ {
+ return array(
+ 'idsite' => $idSite,
+ 'description' => 'test description"',
+ 'period' => Piwik_ScheduledTime::PERIOD_DAY,
+ 'hour' => '7',
+ 'type' => 'email',
+ 'format' => 'pdf',
+ 'reports' => array('UserCountry_getCountry'),
+ 'parameters' => array(
+ 'displayFormat' => '1',
+ 'emailMe' => true,
+ 'additionalEmails' => array('test@test.com', 't2@test.com'),
+ 'evolutionGraph' => false
+ )
+ );
+ }
+
+ private static function getMonthlyEmailReportData($idSite)
+ {
+ return array(
+ 'idsite' => $idSite,
+ 'description' => 'very very long and possibly truncated description. very very long and possibly truncated description. very very long and possibly truncated description. very very long and possibly truncated description. very very long and possibly truncated description. ',
+ 'period' => Piwik_ScheduledTime::PERIOD_MONTH,
+ 'hour' => '0',
+ 'type' => 'email',
+ 'format' => 'pdf',
+ 'reports' => array('UserCountry_getContinent'),
+ 'parameters' => array(
+ 'displayFormat' => '1',
+ 'emailMe' => false,
+ 'additionalEmails' => array('blabla@ec.fr'),
+ 'evolutionGraph' => false
+ )
+ );
+ }
+
+ private static function updateReport($idReport, $data)
+ {
+ $idReport = Piwik_PDFReports_API::getInstance()->updateReport(
+ $idReport,
+ $data['idsite'],
+ $data['description'],
+ $data['period'],
+ $data['hour'],
+ $data['type'],
+ $data['format'],
+ $data['reports'],
+ $data['parameters']);
+ return $idReport;
+ }
+
+ private static function setSuperUser()
+ {
+ $pseudoMockAccess = new FakeAccess;
+ FakeAccess::$superUser = true;
+ Zend_Registry::set('access', $pseudoMockAccess);
+ }
}
diff --git a/tests/PHPUnit/Plugins/PrivacyManagerTest.php b/tests/PHPUnit/Plugins/PrivacyManagerTest.php
index 50aadf3f19..bee4871960 100755
--- a/tests/PHPUnit/Plugins/PrivacyManagerTest.php
+++ b/tests/PHPUnit/Plugins/PrivacyManagerTest.php
@@ -26,10 +26,10 @@ class PrivacyManagerTest extends IntegrationTestCase
private static $idSite = 1;
private static $dateTime = '2012-02-28';
private static $daysAgoStart = 50;
-
+
// maps table names w/ array rows
private static $dbData = null;
-
+
/**
* @var Piwik_PrivacyManager
*/
@@ -42,44 +42,43 @@ class PrivacyManagerTest extends IntegrationTestCase
{
parent::setUpBeforeClass();
- // Temporarily disable the purge of old archives so that getNumeric('nb_visits')
- // in _addReportData does not trigger the data purge of data we've just imported
- Piwik_ArchiveProcessing_Period::$enablePurgeOutdated = false;
+ // Temporarily disable the purge of old archives so that getNumeric('nb_visits')
+ // in _addReportData does not trigger the data purge of data we've just imported
+ Piwik_ArchiveProcessing_Period::$enablePurgeOutdated = false;
- self::_addLogData();
- self::_addReportData();
+ self::_addLogData();
+ self::_addReportData();
- Piwik_ArchiveProcessing_Period::$enablePurgeOutdated = true;
+ Piwik_ArchiveProcessing_Period::$enablePurgeOutdated = true;
self::$dbData = self::getDbTablesWithData();
}
-
+
public function setUp()
{
- parent::setUp();
-
+ parent::setUp();
+
Piwik_PrivacyManager_LogDataPurger::$selectSegmentSize = 2;
Piwik_PrivacyManager_ReportsPurger::$selectSegmentSize = 2;
Piwik::$lockPrivilegeGranted = null;
-
+
self::restoreDbTables(self::$dbData);
-
+
$dateTime = Piwik_Date::factory(self::$dateTime);
-
+
// purging depends upon today's date, so 'older_than' parts must be dependent upon today
$today = Piwik_Date::factory('today');
$daysSinceToday = ($today->getTimestamp() - $dateTime->getTimestamp()) / (24 * 60 * 60);
-
+
$monthsSinceToday = 0;
- for ($date = $today; $date->toString('Y-m') != $dateTime->toString('Y-m'); $date = $date->subMonth(1))
- {
+ for ($date = $today; $date->toString('Y-m') != $dateTime->toString('Y-m'); $date = $date->subMonth(1)) {
++$monthsSinceToday;
}
-
+
// set default config
$settings = array();
$settings['delete_logs_enable'] = 1;
-
+
// purging log data from before 2012-01-24
$settings['delete_logs_older_than'] = 35 + $daysSinceToday;
$settings['delete_logs_schedule_lowest_interval'] = 7;
@@ -94,11 +93,11 @@ class PrivacyManagerTest extends IntegrationTestCase
$settings['delete_reports_keep_range_reports'] = 0;
$settings['delete_reports_keep_segment_reports'] = 0;
Piwik_PrivacyManager::savePurgeDataSettings($settings);
-
+
$this->settings = $settings;
$this->instance = new Piwik_PrivacyManager();
}
-
+
public function tearDown()
{
parent::tearDown();
@@ -107,11 +106,11 @@ class PrivacyManagerTest extends IntegrationTestCase
Piwik_Site::clearCache();
Piwik_Tracker_Cache::deleteTrackerCache();
Piwik_TablePartitioning::$tablesAlreadyInstalled = null;
-
+
$tempTableName = Piwik_Common::prefixTable(Piwik_PrivacyManager_LogDataPurger::TEMP_TABLE_NAME);
- Piwik_Query("DROP TABLE IF EXISTS ".$tempTableName);
+ Piwik_Query("DROP TABLE IF EXISTS " . $tempTableName);
}
-
+
/**
* Make sure the first time deleteLogData is run, nothing happens.
*
@@ -120,16 +119,16 @@ class PrivacyManagerTest extends IntegrationTestCase
*/
public function testDeleteLogDataInitialRun()
{
- $this->instance->deleteLogData();
+ $this->instance->deleteLogData();
// check that initial option is set
$this->assertEquals(
1, Piwik_GetOption(Piwik_PrivacyManager::OPTION_LAST_DELETE_PIWIK_LOGS_INITIAL));
-
+
// perform other checks
$this->_checkNoDataChanges();
}
-
+
/**
* Make sure the first time deleteReportData is run, nothing happens.
*
@@ -139,14 +138,14 @@ class PrivacyManagerTest extends IntegrationTestCase
public function testDeleteReportDataInitialRun()
{
$this->instance->deleteReportData();
-
+
// check that initial option is set
$this->assertEquals(1, Piwik_GetOption(Piwik_PrivacyManager::OPTION_LAST_DELETE_PIWIK_LOGS_INITIAL));
-
+
// perform other checks
$this->_checkNoDataChanges();
}
-
+
/**
* Make sure the task is not run when its scheduled for later.
*
@@ -156,17 +155,17 @@ class PrivacyManagerTest extends IntegrationTestCase
public function testPurgeDataNotTimeToRun()
{
$yesterdaySecs = Piwik_Date::factory('yesterday')->getTimestamp();
-
+
Piwik_SetOption(Piwik_PrivacyManager::OPTION_LAST_DELETE_PIWIK_LOGS_INITIAL, 1);
Piwik_SetOption(Piwik_PrivacyManager::OPTION_LAST_DELETE_PIWIK_LOGS, $yesterdaySecs);
Piwik_SetOption(Piwik_PrivacyManager::OPTION_LAST_DELETE_PIWIK_REPORTS, $yesterdaySecs);
$this->instance->deleteLogData();
$this->instance->deleteReportData();
-
+
// perform checks
$this->_checkNoDataChanges();
}
-
+
/**
* Make sure purging data runs when scheduled.
*
@@ -177,43 +176,43 @@ class PrivacyManagerTest extends IntegrationTestCase
{
// get purge data prediction
$prediction = Piwik_PrivacyManager::getPurgeEstimate();
-
+
// perform checks on prediction
$expectedPrediction = array(
- Piwik_Common::prefixTable('log_conversion') => 6,
- Piwik_Common::prefixTable('log_link_visit_action') => 6,
- Piwik_Common::prefixTable('log_visit') => 3,
- Piwik_Common::prefixTable('log_conversion_item') => 3,
+ Piwik_Common::prefixTable('log_conversion') => 6,
+ Piwik_Common::prefixTable('log_link_visit_action') => 6,
+ Piwik_Common::prefixTable('log_visit') => 3,
+ Piwik_Common::prefixTable('log_conversion_item') => 3,
Piwik_Common::prefixTable('archive_numeric_2012_01') => -1,
- Piwik_Common::prefixTable('archive_blob_2012_01') => -1
+ Piwik_Common::prefixTable('archive_blob_2012_01') => -1
);
$this->assertEquals($expectedPrediction, $prediction);
-
+
// purge data
$this->_setTimeToRun();
$this->instance->deleteLogData();
$this->instance->deleteReportData();
-
+
// perform checks
$this->checkLogDataPurged();
-
+
$archiveTables = self::_getArchiveTableNames();
-
+
// January numeric table should be dropped
$this->assertFalse($this->_tableExists($archiveTables['numeric'][0])); // January
-
+
// Check february metric count (5 metrics per period w/ visits + 1 'done' archive for every period)
// + 1 garbage metric
$febRowCount = self::FEB_METRIC_ARCHIVE_COUNT * 5 + self::TOTAL_FEB_ARCHIVE_COUNT + 1;
$this->assertEquals($febRowCount, $this->_getTableCount($archiveTables['numeric'][1])); // February
-
+
// January blob table should be dropped
$this->assertFalse($this->_tableExists($archiveTables['blob'][0])); // January
-
+
// Check february blob count (1 blob per period w/ visits + 1 garbage report)
$this->assertEquals(self::FEB_METRIC_ARCHIVE_COUNT + 1, $this->_getTableCount($archiveTables['blob'][1])); // February
}
-
+
/**
* Make sure nothing happens when deleting logs & reports are both disabled.
*
@@ -223,26 +222,26 @@ class PrivacyManagerTest extends IntegrationTestCase
public function testPurgeDataBothDisabled()
{
Piwik_PrivacyManager::savePurgeDataSettings(array(
- 'delete_logs_enable' => 0,
- 'delete_reports_enable' => 0
- ));
+ 'delete_logs_enable' => 0,
+ 'delete_reports_enable' => 0
+ ));
// get purge data prediction
$prediction = Piwik_PrivacyManager::getPurgeEstimate();
-
+
// perform checks on prediction
$expectedPrediction = array();
$this->assertEquals($expectedPrediction, $prediction);
-
+
// purge data
$this->_setTimeToRun();
$this->instance->deleteLogData();
$this->instance->deleteReportData();
-
+
// perform checks
$this->_checkNoDataChanges();
}
-
+
/**
* Test that purgeData works when there's no data.
*
@@ -251,37 +250,36 @@ class PrivacyManagerTest extends IntegrationTestCase
*/
public function testPurgeDataDeleteLogsNoData()
{
- Piwik::truncateAllTables();
- foreach (Piwik::getTablesArchivesInstalled() as $table)
- {
- Piwik_Exec("DROP TABLE $table");
- }
-
+ Piwik::truncateAllTables();
+ foreach (Piwik::getTablesArchivesInstalled() as $table) {
+ Piwik_Exec("DROP TABLE $table");
+ }
+
// get purge data prediction
$prediction = Piwik_PrivacyManager::getPurgeEstimate();
-
+
// perform checks on prediction
$expectedPrediction = array();
$this->assertEquals($expectedPrediction, $prediction);
-
+
// purge data
$this->_setTimeToRun();
$this->instance->deleteLogData();
$this->instance->deleteReportData();
-
+
// perform checks
$this->assertEquals(0, $this->_getTableCount('log_visit'));
$this->assertEquals(0, $this->_getTableCount('log_conversion'));
$this->assertEquals(0, $this->_getTableCount('log_link_visit_action'));
$this->assertEquals(0, $this->_getTableCount('log_conversion_item'));
-
+
$archiveTables = self::_getArchiveTableNames();
$this->assertFalse($this->_tableExists($archiveTables['numeric'][0])); // January
$this->assertFalse($this->_tableExists($archiveTables['numeric'][1])); // February
$this->assertFalse($this->_tableExists($archiveTables['blob'][0])); // January
$this->assertFalse($this->_tableExists($archiveTables['blob'][1])); // February
}
-
+
/**
* Test that purgeData works correctly when the 'keep basic metrics' setting is set to true.
*
@@ -291,48 +289,48 @@ class PrivacyManagerTest extends IntegrationTestCase
public function testPurgeDataDeleteReportsKeepBasicMetrics()
{
Piwik_PrivacyManager::savePurgeDataSettings(array(
- 'delete_reports_keep_basic_metrics' => 1
- ));
-
+ 'delete_reports_keep_basic_metrics' => 1
+ ));
+
// get purge data prediction
$prediction = Piwik_PrivacyManager::getPurgeEstimate();
-
+
// perform checks on prediction
$expectedPrediction = array(
- Piwik_Common::prefixTable('log_conversion') => 6,
- Piwik_Common::prefixTable('log_link_visit_action') => 6,
- Piwik_Common::prefixTable('log_visit') => 3,
- Piwik_Common::prefixTable('log_conversion_item') => 3,
+ Piwik_Common::prefixTable('log_conversion') => 6,
+ Piwik_Common::prefixTable('log_link_visit_action') => 6,
+ Piwik_Common::prefixTable('log_visit') => 3,
+ Piwik_Common::prefixTable('log_conversion_item') => 3,
Piwik_Common::prefixTable('archive_numeric_2012_01') => 1, // remove the garbage metric
- Piwik_Common::prefixTable('archive_blob_2012_01') => -1
+ Piwik_Common::prefixTable('archive_blob_2012_01') => -1
);
$this->assertEquals($expectedPrediction, $prediction);
-
+
// purge data
$this->_setTimeToRun();
$this->instance->deleteLogData();
$this->instance->deleteReportData();
-
+
// perform checks
$this->checkLogDataPurged();
-
+
$archiveTables = self::_getArchiveTableNames();
-
+
// all numeric metrics should be saved except the garbage metric
$janRowCount = $this->_getExpectedNumericArchiveCountJan() - 1;
$this->assertEquals($janRowCount, $this->_getTableCount($archiveTables['numeric'][0])); // January
-
+
// check february numerics not deleted
$febRowCount = $this->_getExpectedNumericArchiveCountFeb();
$this->assertEquals($febRowCount, $this->_getTableCount($archiveTables['numeric'][1])); // February
-
+
// check that the january blob table was dropped
$this->assertFalse($this->_tableExists($archiveTables['blob'][0])); // January
-
+
// check for no changes in the february blob table
$this->assertEquals(self::FEB_METRIC_ARCHIVE_COUNT + 1, $this->_getTableCount($archiveTables['blob'][1])); // February
}
-
+
/**
* Test that purgeData works correctly when the 'keep daily reports' setting is set to true.
*
@@ -342,33 +340,33 @@ class PrivacyManagerTest extends IntegrationTestCase
public function testPurgeDataDeleteReportsKeepDailyReports()
{
Piwik_PrivacyManager::savePurgeDataSettings(array(
- 'delete_reports_keep_day_reports' => 1
- ));
+ 'delete_reports_keep_day_reports' => 1
+ ));
// get purge data prediction
$prediction = Piwik_PrivacyManager::getPurgeEstimate();
-
+
// perform checks on prediction
$expectedPrediction = array(
- Piwik_Common::prefixTable('log_conversion') => 6,
- Piwik_Common::prefixTable('log_link_visit_action') => 6,
- Piwik_Common::prefixTable('log_visit') => 3,
- Piwik_Common::prefixTable('log_conversion_item') => 3,
+ Piwik_Common::prefixTable('log_conversion') => 6,
+ Piwik_Common::prefixTable('log_link_visit_action') => 6,
+ Piwik_Common::prefixTable('log_visit') => 3,
+ Piwik_Common::prefixTable('log_conversion_item') => 3,
Piwik_Common::prefixTable('archive_numeric_2012_01') => -1,
- Piwik_Common::prefixTable('archive_blob_2012_01') => 10 // removing 4 weeks, 1 month & 1 year + 1 garbage report + 2 range reports + 1 segmented report
+ Piwik_Common::prefixTable('archive_blob_2012_01') => 10 // removing 4 weeks, 1 month & 1 year + 1 garbage report + 2 range reports + 1 segmented report
);
$this->assertEquals($expectedPrediction, $prediction);
-
+
// purge data
$this->_setTimeToRun();
$this->instance->deleteLogData();
$this->instance->deleteReportData();
-
+
// perform checks
$this->checkLogDataPurged();
$this->_checkReportsAndMetricsPurged($janBlobsRemaining = 5); // 5 blobs for 5 days
}
-
+
/**
* Test that purgeData works correctly when the 'keep weekly reports' setting is set to true.
*
@@ -378,33 +376,33 @@ class PrivacyManagerTest extends IntegrationTestCase
public function testPurgeDataDeleteReportsKeepWeeklyReports()
{
Piwik_PrivacyManager::savePurgeDataSettings(array(
- 'delete_reports_keep_week_reports' => 1
- ));
+ 'delete_reports_keep_week_reports' => 1
+ ));
// get purge data prediction
$prediction = Piwik_PrivacyManager::getPurgeEstimate();
-
+
// perform checks on prediction
$expectedPrediction = array(
- Piwik_Common::prefixTable('log_conversion') => 6,
- Piwik_Common::prefixTable('log_link_visit_action') => 6,
- Piwik_Common::prefixTable('log_visit') => 3,
- Piwik_Common::prefixTable('log_conversion_item') => 3,
+ Piwik_Common::prefixTable('log_conversion') => 6,
+ Piwik_Common::prefixTable('log_link_visit_action') => 6,
+ Piwik_Common::prefixTable('log_visit') => 3,
+ Piwik_Common::prefixTable('log_conversion_item') => 3,
Piwik_Common::prefixTable('archive_numeric_2012_01') => -1,
- Piwik_Common::prefixTable('archive_blob_2012_01') => 11 // 5 days, 1 month & 1 year to remove + 1 garbage report + 2 range reports + 1 segmented report
+ Piwik_Common::prefixTable('archive_blob_2012_01') => 11 // 5 days, 1 month & 1 year to remove + 1 garbage report + 2 range reports + 1 segmented report
);
$this->assertEquals($expectedPrediction, $prediction);
-
+
// purge data
$this->_setTimeToRun();
$this->instance->deleteLogData();
$this->instance->deleteReportData();
-
+
// perform checks
$this->checkLogDataPurged();
$this->_checkReportsAndMetricsPurged($janBlobsRemaining = 4); // 4 blobs for 4 weeks
}
-
+
/**
* Test that purgeData works correctly when the 'keep monthly reports' setting is set to true.
*
@@ -414,33 +412,33 @@ class PrivacyManagerTest extends IntegrationTestCase
public function testPurgeDataDeleteReportsKeepMonthlyReports()
{
Piwik_PrivacyManager::savePurgeDataSettings(array(
- 'delete_reports_keep_month_reports' => 1
- ));
+ 'delete_reports_keep_month_reports' => 1
+ ));
// get purge data prediction
$prediction = Piwik_PrivacyManager::getPurgeEstimate();
-
+
// perform checks on prediction
$expectedPrediction = array(
- Piwik_Common::prefixTable('log_conversion') => 6,
- Piwik_Common::prefixTable('log_link_visit_action') => 6,
- Piwik_Common::prefixTable('log_visit') => 3,
- Piwik_Common::prefixTable('log_conversion_item') => 3,
+ Piwik_Common::prefixTable('log_conversion') => 6,
+ Piwik_Common::prefixTable('log_link_visit_action') => 6,
+ Piwik_Common::prefixTable('log_visit') => 3,
+ Piwik_Common::prefixTable('log_conversion_item') => 3,
Piwik_Common::prefixTable('archive_numeric_2012_01') => -1,
- Piwik_Common::prefixTable('archive_blob_2012_01') => 14 // 5 days, 4 weeks, 1 year to remove + 1 garbage report + 2 range reports + 1 segmented report
+ Piwik_Common::prefixTable('archive_blob_2012_01') => 14 // 5 days, 4 weeks, 1 year to remove + 1 garbage report + 2 range reports + 1 segmented report
);
$this->assertEquals($expectedPrediction, $prediction);
-
+
// purge data
$this->_setTimeToRun();
$this->instance->deleteLogData();
$this->instance->deleteReportData();
-
+
// perform checks
$this->checkLogDataPurged();
$this->_checkReportsAndMetricsPurged($janBlobsRemaining = 1); // 1 blob for 1 month
}
-
+
/**
* Test that purgeData works correctly when the 'keep yearly reports' setting is set to true.
*
@@ -450,33 +448,33 @@ class PrivacyManagerTest extends IntegrationTestCase
public function testPurgeDataDeleteReportsKeepYearlyReports()
{
Piwik_PrivacyManager::savePurgeDataSettings(array(
- 'delete_reports_keep_year_reports' => 1
- ));
+ 'delete_reports_keep_year_reports' => 1
+ ));
// get purge data prediction
$prediction = Piwik_PrivacyManager::getPurgeEstimate();
-
+
// perform checks on prediction
$expectedPrediction = array(
- Piwik_Common::prefixTable('log_conversion') => 6,
- Piwik_Common::prefixTable('log_link_visit_action') => 6,
- Piwik_Common::prefixTable('log_visit') => 3,
- Piwik_Common::prefixTable('log_conversion_item') => 3,
+ Piwik_Common::prefixTable('log_conversion') => 6,
+ Piwik_Common::prefixTable('log_link_visit_action') => 6,
+ Piwik_Common::prefixTable('log_visit') => 3,
+ Piwik_Common::prefixTable('log_conversion_item') => 3,
Piwik_Common::prefixTable('archive_numeric_2012_01') => -1,
- Piwik_Common::prefixTable('archive_blob_2012_01') => 14 // 5 days, 4 weeks & 1 year to remove + 1 garbage report + 2 range reports + 1 segmented report
+ Piwik_Common::prefixTable('archive_blob_2012_01') => 14 // 5 days, 4 weeks & 1 year to remove + 1 garbage report + 2 range reports + 1 segmented report
);
$this->assertEquals($expectedPrediction, $prediction);
-
+
// purge data
$this->_setTimeToRun();
$this->instance->deleteLogData();
$this->instance->deleteReportData();
-
+
// perform checks
$this->checkLogDataPurged();
$this->_checkReportsAndMetricsPurged($janBlobsRemaining = 1); // 1 blob for 1 year
}
-
+
/**
* Test no concurrency issues when deleting log data from log_action table.
*
@@ -486,26 +484,26 @@ class PrivacyManagerTest extends IntegrationTestCase
public function testPurgeLogDataConcurrency()
{
Piwik_AddAction("LogDataPurger.actionsToKeepInserted.olderThan", array($this, 'addReferenceToUnusedAction'));
-
+
$purger = Piwik_PrivacyManager_LogDataPurger::make($this->settings, true);
-
+
$this->unusedIdAction = Piwik_FetchOne(
- "SELECT idaction FROM ".Piwik_Common::prefixTable('log_action')." WHERE name = ?",
+ "SELECT idaction FROM " . Piwik_Common::prefixTable('log_action') . " WHERE name = ?",
array('whatever.com/_40'));
$this->assertTrue($this->unusedIdAction > 0);
-
+
// purge data
$purger->purgeData();
-
+
// check that actions were purged
$this->assertEquals(22, $this->_getTableCount('log_action')); // January
-
+
// check that the unused action still exists
$count = Piwik_FetchOne(
- "SELECT COUNT(*) FROM ".Piwik_Common::prefixTable('log_action')." WHERE idaction = ?",
+ "SELECT COUNT(*) FROM " . Piwik_Common::prefixTable('log_action') . " WHERE idaction = ?",
array($this->unusedIdAction));
$this->assertEquals(1, $count);
-
+
$this->unusedIdAction = null; // so the hook won't get executed twice
}
@@ -518,33 +516,33 @@ class PrivacyManagerTest extends IntegrationTestCase
public function testPurgeDataDeleteReportsKeepRangeReports()
{
Piwik_PrivacyManager::savePurgeDataSettings(array(
- 'delete_reports_keep_range_reports' => 1
- ));
-
+ 'delete_reports_keep_range_reports' => 1
+ ));
+
// get purge data prediction
$prediction = Piwik_PrivacyManager::getPurgeEstimate();
-
+
// perform checks on prediction
$expectedPrediction = array(
- Piwik_Common::prefixTable('log_conversion') => 6,
- Piwik_Common::prefixTable('log_link_visit_action') => 6,
- Piwik_Common::prefixTable('log_visit') => 3,
- Piwik_Common::prefixTable('log_conversion_item') => 3,
+ Piwik_Common::prefixTable('log_conversion') => 6,
+ Piwik_Common::prefixTable('log_link_visit_action') => 6,
+ Piwik_Common::prefixTable('log_visit') => 3,
+ Piwik_Common::prefixTable('log_conversion_item') => 3,
Piwik_Common::prefixTable('archive_numeric_2012_01') => -1,
- Piwik_Common::prefixTable('archive_blob_2012_01') => 13 // 5 days, 4 weeks, 1 month & 1 year + 1 garbage report + 1 segmented report
+ Piwik_Common::prefixTable('archive_blob_2012_01') => 13 // 5 days, 4 weeks, 1 month & 1 year + 1 garbage report + 1 segmented report
);
$this->assertEquals($expectedPrediction, $prediction);
-
+
// purge data
$this->_setTimeToRun();
$this->instance->deleteLogData();
$this->instance->deleteReportData();
-
+
// perform checks
$this->checkLogDataPurged();
$this->_checkReportsAndMetricsPurged($janBlobsRemaining = 2); // 2 range blobs
}
-
+
/**
* Tests that purgeData works correctly when the 'keep segment reports' setting is set to true.
*
@@ -554,36 +552,36 @@ class PrivacyManagerTest extends IntegrationTestCase
public function testPurgeDataDeleteReportsKeepSegmentsReports()
{
Piwik_PrivacyManager::savePurgeDataSettings(array(
- 'delete_reports_keep_day_reports' => 1,
- 'delete_reports_keep_segment_reports' => 1
- ));
-
+ 'delete_reports_keep_day_reports' => 1,
+ 'delete_reports_keep_segment_reports' => 1
+ ));
+
// get purge data prediction
$prediction = Piwik_PrivacyManager::getPurgeEstimate();
-
+
// perform checks on prediction
$expectedPrediction = array(
- Piwik_Common::prefixTable('log_conversion') => 6,
- Piwik_Common::prefixTable('log_link_visit_action') => 6,
- Piwik_Common::prefixTable('log_visit') => 3,
- Piwik_Common::prefixTable('log_conversion_item') => 3,
+ Piwik_Common::prefixTable('log_conversion') => 6,
+ Piwik_Common::prefixTable('log_link_visit_action') => 6,
+ Piwik_Common::prefixTable('log_visit') => 3,
+ Piwik_Common::prefixTable('log_conversion_item') => 3,
Piwik_Common::prefixTable('archive_numeric_2012_01') => -1,
- Piwik_Common::prefixTable('archive_blob_2012_01') => 9 // 4 weeks, 1 month & 1 year + 1 garbage report + 2 range reports
+ Piwik_Common::prefixTable('archive_blob_2012_01') => 9 // 4 weeks, 1 month & 1 year + 1 garbage report + 2 range reports
);
$this->assertEquals($expectedPrediction, $prediction);
-
+
// purge data
$this->_setTimeToRun();
$this->instance->deleteLogData();
$this->instance->deleteReportData();
-
+
// perform checks
$this->checkLogDataPurged();
$this->_checkReportsAndMetricsPurged($janBlobsRemaining = 6); // 1 segmented blob + 5 day blobs
}
-
+
// --- utility functions follow ---
-
+
protected static function _addLogData()
{
// tracks visits on the following days:
@@ -599,7 +597,7 @@ class PrivacyManagerTest extends IntegrationTestCase
// - 2012-02-23
// - 2012-02-28
// 6 visits in feb, 5 in jan
-
+
// following actions are created:
// - 'First page view'
// - 'Second page view'
@@ -609,86 +607,86 @@ class PrivacyManagerTest extends IntegrationTestCase
// - for every visit (11 visits total):
// - http://whatever.com/_{$daysSinceLastVisit}
// - http://whatever.com/42/{$daysSinceLastVisit}
-
+
$start = Piwik_Date::factory(self::$dateTime);
- self::$idSite = Test_Piwik_BaseFixture::createWebsite('2012-01-01', $ecommerce=1);
+ self::$idSite = Test_Piwik_BaseFixture::createWebsite('2012-01-01', $ecommerce = 1);
$idGoal = Piwik_Goals_API::getInstance()->addGoal(self::$idSite, 'match all', 'url', 'http', 'contains');
-
+
$t = Test_Piwik_BaseFixture::getTracker(self::$idSite, $start, $defaultInit = true);
$t->enableBulkTracking();
- $t->setTokenAuth(Test_Piwik_BaseFixture::getTokenAuth());
+ $t->setTokenAuth(Test_Piwik_BaseFixture::getTokenAuth());
for ($daysAgo = self::$daysAgoStart; $daysAgo >= 0; $daysAgo -= 5) // one visit every 5 days
{
$dateTime = $start->subDay($daysAgo)->toString();
-
+
$t->setForceVisitDateTime($dateTime);
$t->setUserAgent('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 (.NET CLR 3.5.30729)');
-
+
// use $daysAgo to make sure new actions are created for every day and aren't used again.
// when deleting visits, some of these actions will no longer be referenced in the DB.
$t->setUrl("http://whatever.com/_$daysAgo");
$t->doTrackPageView('First page view');
-
+
$t->setUrl("http://whatever.com/42/$daysAgo");
$t->doTrackPageView('Second page view');
-
- $t->addEcommerceItem($sku = 'SKU2', $name = 'Canon SLR' , $category = 'Electronics & Cameras',
- $price = 1500, $quantity = 1);
- $t->doTrackEcommerceOrder($orderId = '937nsjusu '.$dateTime, $grandTotal = 1111.11, $subTotal = 1000,
- $tax = 111, $shipping = 0.11, $discount = 666);
+
+ $t->addEcommerceItem($sku = 'SKU2', $name = 'Canon SLR', $category = 'Electronics & Cameras',
+ $price = 1500, $quantity = 1);
+ $t->doTrackEcommerceOrder($orderId = '937nsjusu ' . $dateTime, $grandTotal = 1111.11, $subTotal = 1000,
+ $tax = 111, $shipping = 0.11, $discount = 666);
}
- Test_Piwik_BaseFixture::checkResponse($t->doBulkTrack());
+ Test_Piwik_BaseFixture::checkResponse($t->doBulkTrack());
}
-
+
protected static function _addReportData()
{
- $date = Piwik_Date::factory(self::$dateTime);
-
+ $date = Piwik_Date::factory(self::$dateTime);
+
$archive = Piwik_Archive::build(self::$idSite, 'year', $date);
$archive->getNumeric('nb_visits', 'nb_hits');
-
+
Piwik_VisitorInterest_API::getInstance()->getNumberOfVisitsPerVisitDuration(self::$idSite, 'year', $date);
-
+
// months are added via the 'year' period, but weeks must be done manually
for ($daysAgo = self::$daysAgoStart; $daysAgo > 0; $daysAgo -= 7) // every week
{
$dateTime = $date->subDay($daysAgo);
-
+
$archive = Piwik_Archive::build(self::$idSite, 'week', $dateTime);
$archive->getNumeric('nb_visits');
-
+
Piwik_VisitorInterest_API::getInstance()->getNumberOfVisitsPerVisitDuration(
self::$idSite, 'week', $dateTime);
}
-
+
// add segment for one day
$archive = Piwik_Archive::build(self::$idSite, 'day', '2012-01-14', 'browserName==FF');
$archive->getNumeric('nb_visits', 'nb_hits');
-
+
Piwik_VisitorInterest_API::getInstance()->getNumberOfVisitsPerVisitDuration(
self::$idSite, 'day', '2012-01-14', 'browserName==FF');
-
+
// add range within January
$rangeEnd = Piwik_Date::factory('2012-01-29');
$rangeStart = $rangeEnd->subDay(1);
- $range = $rangeStart->toString('Y-m-d').",".$rangeEnd->toString('Y-m-d');
-
+ $range = $rangeStart->toString('Y-m-d') . "," . $rangeEnd->toString('Y-m-d');
+
$rangeArchive = Piwik_Archive::build(self::$idSite, 'range', $range);
$rangeArchive->getNumeric('nb_visits', 'nb_hits');
-
+
Piwik_VisitorInterest_API::getInstance()->getNumberOfVisitsPerVisitDuration(self::$idSite, 'range', $range);
-
+
// add range between January & February
$rangeStart = $rangeEnd;
$rangeEnd = $rangeStart->addDay(3);
- $range = $rangeStart->toString('Y-m-d').",".$rangeEnd->toString('Y-m-d');
-
+ $range = $rangeStart->toString('Y-m-d') . "," . $rangeEnd->toString('Y-m-d');
+
$rangeArchive = Piwik_Archive::build(self::$idSite, 'range', $range);
$rangeArchive->getNumeric('nb_visits', 'nb_hits');
-
+
Piwik_VisitorInterest_API::getInstance()->getNumberOfVisitsPerVisitDuration(self::$idSite, 'range', $range);
-
+
// when archiving is initiated, the archive metrics & reports for EVERY loaded plugin
// are archived. don't want this test to depend on every possible metric, so get rid of
// the unwanted archive data now.
@@ -699,39 +697,37 @@ class PrivacyManagerTest extends IntegrationTestCase
Piwik_Goals::getRecordName('nb_conversions', 1),
Piwik_Goals::getRecordName('revenue', Piwik_Tracker_GoalManager::IDGOAL_ORDER)
);
-
+
$archiveTables = self::_getArchiveTableNames();
- foreach ($archiveTables['numeric'] as $table)
- {
+ foreach ($archiveTables['numeric'] as $table) {
$realTable = Piwik_Common::prefixTable($table);
- Piwik_Query("DELETE FROM $realTable WHERE name NOT IN ('".implode("','", $metricsToSave)."') AND name NOT LIKE 'done%'");
+ Piwik_Query("DELETE FROM $realTable WHERE name NOT IN ('" . implode("','", $metricsToSave) . "') AND name NOT LIKE 'done%'");
}
- foreach ($archiveTables['blob'] as $table)
- {
+ foreach ($archiveTables['blob'] as $table) {
$realTable = Piwik_Common::prefixTable($table);
Piwik_Query("DELETE FROM $realTable WHERE name NOT IN ('VisitorInterest_timeGap')");
}
-
+
// add garbage metrics
$janDate1 = '2012-01-05';
$febDate1 = '2012-02-04';
-
+
$sql = "INSERT INTO %s (idarchive,name,idsite,date1,date2,period,ts_archived,value)
VALUES (10000,?,1,?,?,?,?,?)";
-
+
// one metric for jan & one for feb
Piwik_Query(sprintf($sql, Piwik_Common::prefixTable($archiveTables['numeric'][0])),
- array(self::GARBAGE_FIELD, $janDate1, $janDate1, $janDate1, 1, 100));
+ array(self::GARBAGE_FIELD, $janDate1, $janDate1, $janDate1, 1, 100));
Piwik_Query(sprintf($sql, Piwik_Common::prefixTable($archiveTables['numeric'][1])),
- array(self::GARBAGE_FIELD, $febDate1, $febDate1, $febDate1, 1, 200));
-
+ array(self::GARBAGE_FIELD, $febDate1, $febDate1, $febDate1, 1, 200));
+
// add garbage reports
Piwik_Query(sprintf($sql, Piwik_Common::prefixTable($archiveTables['blob'][0])),
- array(self::GARBAGE_FIELD, $janDate1, $janDate1, $janDate1, 10, 'blobval'));
+ array(self::GARBAGE_FIELD, $janDate1, $janDate1, $janDate1, 10, 'blobval'));
Piwik_Query(sprintf($sql, Piwik_Common::prefixTable($archiveTables['blob'][1])),
- array(self::GARBAGE_FIELD, $febDate1, $febDate1, $febDate1, 20, 'blobval'));
+ array(self::GARBAGE_FIELD, $febDate1, $febDate1, $febDate1, 20, 'blobval'));
}
-
+
protected function _checkNoDataChanges()
{
// 11 visits total w/ 2 actions per visit & 2 conversions per visit. 1 e-commerce order per visit.
@@ -740,44 +736,44 @@ class PrivacyManagerTest extends IntegrationTestCase
$this->assertEquals(22, $this->_getTableCount('log_link_visit_action'));
$this->assertEquals(11, $this->_getTableCount('log_conversion_item'));
$this->assertEquals(27, $this->_getTableCount('log_action'));
-
+
$archiveTables = self::_getArchiveTableNames();
-
+
$janMetricCount = $this->_getExpectedNumericArchiveCountJan();
$this->assertEquals($janMetricCount, $this->_getTableCount($archiveTables['numeric'][0])); // January
-
+
// no range metric for february
$febMetricCount = $this->_getExpectedNumericArchiveCountFeb();
$this->assertEquals($febMetricCount, $this->_getTableCount($archiveTables['numeric'][1])); // February
-
+
// 1 entry per period w/ visits + 1 garbage report + 2 range reports + 1 segment report
$this->assertEquals(self::JAN_METRIC_ARCHIVE_COUNT + 1 + 2 + 1, $this->_getTableCount($archiveTables['blob'][0])); // January
$this->assertEquals(self::FEB_METRIC_ARCHIVE_COUNT + 1, $this->_getTableCount($archiveTables['blob'][1])); // February
}
-
+
/**
* Helper method. Performs checks after reports are purged. Checks that the january numeric table
* was dropped, that the february metric & blob tables are unaffected, and that the january blob
* table has a certain number of blobs.
*/
- protected function _checkReportsAndMetricsPurged( $janBlobsRemaining )
+ protected function _checkReportsAndMetricsPurged($janBlobsRemaining)
{
$archiveTables = self::_getArchiveTableNames();
-
+
// check that the january numeric table was dropped
$this->assertFalse($this->_tableExists($archiveTables['numeric'][0])); // January
-
+
// check february numerics not deleted
$febRowCount = $this->_getExpectedNumericArchiveCountFeb();
$this->assertEquals($febRowCount, $this->_getTableCount($archiveTables['numeric'][1])); // February
-
+
// check the january blob count
$this->assertEquals($janBlobsRemaining, $this->_getTableCount($archiveTables['blob'][0])); // January
-
+
// check for no changes in the february blob table (1 blob for every period w/ visits in feb + 1 garbage report)
$this->assertEquals(self::FEB_METRIC_ARCHIVE_COUNT + 1, $this->_getTableCount($archiveTables['blob'][1])); // February
}
-
+
private function checkLogDataPurged()
{
// 3 days removed by purge, so 3 visits, 6 conversions, 6 visit actions, 3 e-commerce orders
@@ -788,7 +784,7 @@ class PrivacyManagerTest extends IntegrationTestCase
$this->assertEquals(8, $this->_getTableCount('log_conversion_item'));
$this->assertEquals(21, $this->_getTableCount('log_action'));
}
-
+
/**
* Event hook that adds a row into the DB that references unused idaction AFTER LogDataPurger
* does the insert into the temporary table. When log_actions are deleted, this idaction should still
@@ -797,49 +793,49 @@ class PrivacyManagerTest extends IntegrationTestCase
*
* @param Piwik_Event_Notification $notification notification object
*/
- public function addReferenceToUnusedAction( $notification )
+ public function addReferenceToUnusedAction($notification)
{
$unusedIdAction = $this->unusedIdAction;
if (empty($unusedIdAction)) // make sure we only do this for one test case
{
return;
}
-
+
$tempTableName = Piwik_Common::prefixTable(Piwik_PrivacyManager_LogDataPurger::TEMP_TABLE_NAME);
$logLinkVisitActionTable = Piwik_Common::prefixTable("log_link_visit_action");
-
+
$sql = "INSERT INTO $logLinkVisitActionTable
(idsite, idvisitor, server_time, idvisit, idaction_url, idaction_url_ref,
idaction_name, idaction_name_ref, time_spent_ref_action)
VALUES (1, 'abc', NOW(), 15, $unusedIdAction, $unusedIdAction,
$unusedIdAction, $unusedIdAction, 1000)";
-
+
Piwik_Query($sql);
}
-
+
protected function _setTimeToRun()
{
$lastDateSecs = Piwik_Date::factory('today')->subDay(8)->getTimestamp();
-
+
Piwik_SetOption(Piwik_PrivacyManager::OPTION_LAST_DELETE_PIWIK_LOGS_INITIAL, 1);
Piwik_SetOption(Piwik_PrivacyManager::OPTION_LAST_DELETE_PIWIK_LOGS, $lastDateSecs);
Piwik_SetOption(Piwik_PrivacyManager::OPTION_LAST_DELETE_PIWIK_REPORTS, $lastDateSecs);
}
-
- protected function _getTableCount( $tableName, $where = '' )
+
+ protected function _getTableCount($tableName, $where = '')
{
- $sql = "SELECT COUNT(*) FROM ".Piwik_Common::prefixTable($tableName)." $where";
+ $sql = "SELECT COUNT(*) FROM " . Piwik_Common::prefixTable($tableName) . " $where";
return Piwik_FetchOne($sql);
}
-
- protected function _tableExists( $tableName )
+
+ protected function _tableExists($tableName)
{
$dbName = Piwik_Config::getInstance()->database['dbname'];
-
+
$sql = "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = ? AND table_name = ?";
return Piwik_FetchOne($sql, array($dbName, Piwik_Common::prefixTable($tableName))) == 1;
}
-
+
protected static function _getArchiveTableNames()
{
return array(
@@ -847,13 +843,13 @@ class PrivacyManagerTest extends IntegrationTestCase
'archive_numeric_2012_01',
'archive_numeric_2012_02'
),
- 'blob' => array(
+ 'blob' => array(
'archive_blob_2012_01',
'archive_blob_2012_02'
)
);
}
-
+
protected function _getExpectedNumericArchiveCountJan()
{
// 5 entries per period w/ visits
@@ -863,7 +859,7 @@ class PrivacyManagerTest extends IntegrationTestCase
// + 2 entries per segment (2 total) + 2 'done...' entries per segment (2 total)
return self::JAN_METRIC_ARCHIVE_COUNT * 5 + self::TOTAL_JAN_ARCHIVE_COUNT + 1 + 8 + 4;
}
-
+
protected function _getExpectedNumericArchiveCountFeb()
{
// (5 metrics per period w/ visits
diff --git a/tests/PHPUnit/Plugins/ReferersTest.php b/tests/PHPUnit/Plugins/ReferersTest.php
index 8757ebde67..547ec37576 100644
--- a/tests/PHPUnit/Plugins/ReferersTest.php
+++ b/tests/PHPUnit/Plugins/ReferersTest.php
@@ -17,8 +17,7 @@ class ReferersTest extends PHPUnit_Framework_TestCase
include PIWIK_PATH_TEST_TO_ROOT . '/core/DataFiles/SearchEngines.php';
$searchEngines = array();
- foreach($GLOBALS['Piwik_SearchEngines'] AS $url => $searchEngine)
- {
+ foreach ($GLOBALS['Piwik_SearchEngines'] AS $url => $searchEngine) {
$searchEngines[] = array($url, $searchEngine);
}
return $searchEngines;
@@ -26,7 +25,7 @@ class ReferersTest extends PHPUnit_Framework_TestCase
/**
* search engine has at least one keyword
- *
+ *
* @group Plugins
* @group Referers
* @dataProvider getSearchEngines
@@ -36,9 +35,8 @@ class ReferersTest extends PHPUnit_Framework_TestCase
// Get list of search engines and first appearing URL
static $searchEngines = array();
- $name = parse_url('http://'.$url);
- if(!array_key_exists($searchEngine[0], $searchEngines))
- {
+ $name = parse_url('http://' . $url);
+ if (!array_key_exists($searchEngine[0], $searchEngines)) {
$searchEngines[$searchEngine[0]] = $url;
$this->assertTrue(!empty($searchEngine[1]), $name['host']);
@@ -47,7 +45,7 @@ class ReferersTest extends PHPUnit_Framework_TestCase
/**
* search engine is defined in DataFiles/SearchEngines.php but there's no favicon
- *
+ *
* @group Plugins
* @group Referers
* @dataProvider getSearchEngines
@@ -60,9 +58,8 @@ class ReferersTest extends PHPUnit_Framework_TestCase
// Get list of search engines and first appearing URL
static $searchEngines = array();
- $name = parse_url('http://'.$url);
- if(!array_key_exists($searchEngine[0], $searchEngines))
- {
+ $name = parse_url('http://' . $url);
+ if (!array_key_exists($searchEngine[0], $searchEngines)) {
$searchEngines[$searchEngine[0]] = $url;
$this->assertTrue(in_array($name['host'] . '.png', $favicons), $name['host']);
@@ -71,7 +68,7 @@ class ReferersTest extends PHPUnit_Framework_TestCase
/**
* favicon exists but there's no corresponding search engine defined in DataFiles/SearchEngines.php
- *
+ *
* @group Plugins
* @group Referers
*/
@@ -81,21 +78,17 @@ class ReferersTest extends PHPUnit_Framework_TestCase
// Get list of search engines and first appearing URL
$searchEngines = array();
- foreach($GLOBALS['Piwik_SearchEngines'] as $url => $searchEngine)
- {
- $name = parse_url('http://'.$url);
- if(!array_key_exists($name['host'], $searchEngines))
- {
+ foreach ($GLOBALS['Piwik_SearchEngines'] as $url => $searchEngine) {
+ $name = parse_url('http://' . $url);
+ if (!array_key_exists($name['host'], $searchEngines)) {
$searchEngines[$name['host']] = true;
}
}
// Get list of existing favicons
$favicons = scandir(PIWIK_PATH_TEST_TO_ROOT . '/plugins/Referers/images/searchEngines/');
- foreach($favicons as $name)
- {
- if($name[0] == '.' || strpos($name, 'xx.') === 0)
- {
+ foreach ($favicons as $name) {
+ if ($name[0] == '.' || strpos($name, 'xx.') === 0) {
continue;
}
@@ -106,7 +99,7 @@ class ReferersTest extends PHPUnit_Framework_TestCase
/**
* get search engine host from url
- *
+ *
* @group Plugins
* @group Referers
*/
@@ -114,11 +107,10 @@ class ReferersTest extends PHPUnit_Framework_TestCase
{
$data = array(
'http://www.google.com/cse' => array('www.google.com', 'www.google.com/cse'),
- 'http://www.google.com' => array('www.google.com', 'www.google.com'),
+ 'http://www.google.com' => array('www.google.com', 'www.google.com'),
);
- foreach($data as $url => $expected)
- {
+ foreach ($data as $url => $expected) {
$this->assertEquals($expected[0], Piwik_getSearchEngineHostFromUrl($url));
$this->assertEquals($expected[1], Piwik_getSearchEngineHostPathFromUrl($url));
}
diff --git a/tests/PHPUnit/Plugins/SEOTest.php b/tests/PHPUnit/Plugins/SEOTest.php
index 2d3483cc9a..31272c919d 100644
--- a/tests/PHPUnit/Plugins/SEOTest.php
+++ b/tests/PHPUnit/Plugins/SEOTest.php
@@ -13,8 +13,8 @@ class SEOTest extends PHPUnit_Framework_TestCase
// setup the access layer
$pseudoMockAccess = new FakeAccess;
- FakeAccess::setIdSitesView( array(1,2));
- FakeAccess::setIdSitesAdmin( array(3,4));
+ FakeAccess::setIdSitesView(array(1, 2));
+ FakeAccess::setIdSitesAdmin(array(3, 4));
//finally we set the user as a super user by default
FakeAccess::$superUser = true;
@@ -42,8 +42,7 @@ class SEOTest extends PHPUnit_Framework_TestCase
$renderer = Piwik_DataTable_Renderer::factory('php');
$renderer->setSerialize(false);
$ranks = $renderer->render($dataTable);
- foreach ($ranks as $rank)
- {
+ foreach ($ranks as $rank) {
$this->assertNotEmpty($rank['rank'], $rank['id'] . ' expected non-zero rank, got [' . $rank['rank'] . ']');
}
}
diff --git a/tests/PHPUnit/Plugins/SitesManagerTest.php b/tests/PHPUnit/Plugins/SitesManagerTest.php
index 59d7670221..50aa07cd58 100644
--- a/tests/PHPUnit/Plugins/SitesManagerTest.php
+++ b/tests/PHPUnit/Plugins/SitesManagerTest.php
@@ -16,40 +16,40 @@ class SitesManagerTest extends DatabaseTestCase
FakeAccess::$superUser = true;
Zend_Registry::set('access', $pseudoMockAccess);
}
-
+
/**
* empty name -> exception
- *
+ *
* @group Plugins
* @group SitesManager
*/
public function testAddSiteEmptyName()
{
try {
- Piwik_SitesManager_API::getInstance()->addSite("",array("http://piwik.net"));
+ Piwik_SitesManager_API::getInstance()->addSite("", array("http://piwik.net"));
} catch (Exception $e) {
return;
}
$this->fail('Expected exception not raised');
}
-
+
/**
* DataProvider for testAddSiteWrongUrls
*/
public function getInvalidUrlData()
{
return array(
- array(array()), // no urls
+ array(array()), // no urls
array(array("")),
array(""),
array("httpww://piwik.net"),
array("httpww://piwik.net/gqg~#"),
);
}
-
+
/**
* wrong urls -> exception
- *
+ *
* @dataProvider getInvalidUrlData
* @group Plugins
* @group SitesManager
@@ -63,39 +63,39 @@ class SitesManagerTest extends DatabaseTestCase
}
$this->fail('Expected exception not raised');
}
-
+
/**
* Test with valid IPs
- *
+ *
* @group Plugins
* @group SitesManager
*/
public function testAddSiteExcludedIpsAndtimezoneAndCurrencyAndExcludedQueryParametersValid()
{
$ips = '1.2.3.4,1.1.1.*,1.2.*.*,1.*.*.*';
- $timezone = 'Europe/Paris';
+ $timezone = 'Europe/Paris';
$currency = 'EUR';
$excludedQueryParameters = 'p1,P2, P33333';
$expectedExcludedQueryParameters = 'p1,P2,P33333';
$excludedUserAgents = " p1,P2, \nP3333 ";
$expectedExcludedUserAgents = "p1,P2,P3333";
- $idsite = Piwik_SitesManager_API::getInstance()->addSite("name","http://piwik.net/", $ecommerce = 1,
- $siteSearch = 1, $searchKeywordParameters = 'search,param', $searchCategoryParameters = 'cat,category',
- $ips, $excludedQueryParameters,$timezone, $currency, $group = null, $startDate = null, $excludedUserAgents);
+ $idsite = Piwik_SitesManager_API::getInstance()->addSite("name", "http://piwik.net/", $ecommerce = 1,
+ $siteSearch = 1, $searchKeywordParameters = 'search,param', $searchCategoryParameters = 'cat,category',
+ $ips, $excludedQueryParameters, $timezone, $currency, $group = null, $startDate = null, $excludedUserAgents);
$siteInfo = Piwik_SitesManager_API::getInstance()->getSiteFromId($idsite);
$this->assertEquals($ips, $siteInfo['excluded_ips']);
$this->assertEquals($timezone, $siteInfo['timezone']);
$this->assertEquals($currency, $siteInfo['currency']);
- $this->assertEquals($ecommerce, $siteInfo['ecommerce']);
- $this->assertTrue(Piwik_Site::isEcommerceEnabledFor($idsite));
- $this->assertEquals($siteSearch, $siteInfo['sitesearch']);
- $this->assertTrue(Piwik_Site::isSiteSearchEnabledFor($idsite));
- $this->assertEquals($searchKeywordParameters, $siteInfo['sitesearch_keyword_parameters']);
- $this->assertEquals($searchCategoryParameters, $siteInfo['sitesearch_category_parameters']);
+ $this->assertEquals($ecommerce, $siteInfo['ecommerce']);
+ $this->assertTrue(Piwik_Site::isEcommerceEnabledFor($idsite));
+ $this->assertEquals($siteSearch, $siteInfo['sitesearch']);
+ $this->assertTrue(Piwik_Site::isSiteSearchEnabledFor($idsite));
+ $this->assertEquals($searchKeywordParameters, $siteInfo['sitesearch_keyword_parameters']);
+ $this->assertEquals($searchCategoryParameters, $siteInfo['sitesearch_category_parameters']);
$this->assertEquals($expectedExcludedQueryParameters, $siteInfo['excluded_parameters']);
$this->assertEquals($expectedExcludedUserAgents, $siteInfo['excluded_user_agents']);
}
-
+
/**
* dataProvider for testAddSiteExcludedIpsNotValid
*/
@@ -109,12 +109,12 @@ class SitesManagerTest extends DatabaseTestCase
array('*.*.1.1'),
array('*.*.*.1'),
array('1.1.1.1.1'),
- );
+ );
}
-
+
/**
* Test with invalid IPs
- *
+ *
* @dataProvider getInvalidIPsData
* @group Plugins
* @group SitesManager
@@ -122,17 +122,17 @@ class SitesManagerTest extends DatabaseTestCase
public function testAddSiteExcludedIpsNotValid($ip)
{
try {
- Piwik_SitesManager_API::getInstance()->addSite("name","http://piwik.net/", $ecommerce = 0,
- $siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null, $ip);
+ Piwik_SitesManager_API::getInstance()->addSite("name", "http://piwik.net/", $ecommerce = 0,
+ $siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null, $ip);
} catch (Exception $e) {
return;
}
$this->fail('Expected exception not raised');
}
-
+
/**
* one url -> one main_url and nothing inserted as alias urls
- *
+ *
* @group Plugins
* @group SitesManager
*/
@@ -140,53 +140,54 @@ class SitesManagerTest extends DatabaseTestCase
{
$url = "http://piwik.net/";
$urlOK = "http://piwik.net";
- $idsite = Piwik_SitesManager_API::getInstance()->addSite("name",$url);
+ $idsite = Piwik_SitesManager_API::getInstance()->addSite("name", $url);
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_INT, $idsite);
-
+
$siteInfo = Piwik_SitesManager_API::getInstance()->getSiteFromId($idsite);
$this->assertEquals($urlOK, $siteInfo['main_url']);
$this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($siteInfo['ts_created'])));
-
+
$siteUrls = Piwik_SitesManager_API::getInstance()->getSiteUrlsFromId($idsite);
$this->assertEquals(1, count($siteUrls));
}
-
+
/**
* several urls -> one main_url and others as alias urls
- *
+ *
* @group Plugins
* @group SitesManager
*/
public function testAddSiteSeveralUrls()
{
- $urls = array("http://piwik.net/","http://piwik.com","https://piwik.net/test/");
- $urlsOK = array("http://piwik.net","http://piwik.com","https://piwik.net/test");
- $idsite = Piwik_SitesManager_API::getInstance()->addSite("super website",$urls);
+ $urls = array("http://piwik.net/", "http://piwik.com", "https://piwik.net/test/");
+ $urlsOK = array("http://piwik.net", "http://piwik.com", "https://piwik.net/test");
+ $idsite = Piwik_SitesManager_API::getInstance()->addSite("super website", $urls);
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_INT, $idsite);
-
+
$siteInfo = Piwik_SitesManager_API::getInstance()->getSiteFromId($idsite);
$this->assertEquals($urlsOK[0], $siteInfo['main_url']);
-
+
$siteUrls = Piwik_SitesManager_API::getInstance()->getSiteUrlsFromId($idsite);
$this->assertEquals($urlsOK, $siteUrls);
}
-
+
/**
* strange name
- *
+ *
* @group Plugins
* @group SitesManager
*/
public function testAddSiteStrangeName()
{
$name = "supertest(); ~@@()''!£\$'%%^'!£ போ";
- $idsite = Piwik_SitesManager_API::getInstance()->addSite($name,"http://piwik.net");
+ $idsite = Piwik_SitesManager_API::getInstance()->addSite($name, "http://piwik.net");
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_INT, $idsite);
-
+
$siteInfo = Piwik_SitesManager_API::getInstance()->getSiteFromId($idsite);
$this->assertEquals($name, $siteInfo['name']);
-
+
}
+
/**
* adds a site
* use by several other unit tests
@@ -194,144 +195,144 @@ class SitesManagerTest extends DatabaseTestCase
protected function _addSite()
{
$name = "website ";
- $idsite = Piwik_SitesManager_API::getInstance()->addSite($name,array("http://piwik.net","http://piwik.com/test/"));
+ $idsite = Piwik_SitesManager_API::getInstance()->addSite($name, array("http://piwik.net", "http://piwik.com/test/"));
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_INT, $idsite);
-
+
$siteInfo = Piwik_SitesManager_API::getInstance()->getSiteFromId($idsite);
$this->assertEquals($name, $siteInfo['name']);
$this->assertEquals("http://piwik.net", $siteInfo['main_url']);
-
+
$siteUrls = Piwik_SitesManager_API::getInstance()->getSiteUrlsFromId($idsite);
- $this->assertEquals(array("http://piwik.net","http://piwik.com/test"), $siteUrls);
-
+ $this->assertEquals(array("http://piwik.net", "http://piwik.com/test"), $siteUrls);
+
return $idsite;
}
-
+
/**
* no duplicate -> all the urls are saved
- *
+ *
* @group Plugins
* @group SitesManager
*/
public function testAddSiteUrlsnoDuplicate()
{
$idsite = $this->_addSite();
-
+
$siteUrlsBefore = Piwik_SitesManager_API::getInstance()->getSiteUrlsFromId($idsite);
-
- $toAdd = array( "http://piwik1.net",
- "http://piwik2.net",
- "http://piwik3.net/test/",
- "http://localhost/test",
- "http://localho5.st/test",
- "http://l42578gqege.f4",
- "http://super.com/test/test/atqata675675/te"
- );
+
+ $toAdd = array("http://piwik1.net",
+ "http://piwik2.net",
+ "http://piwik3.net/test/",
+ "http://localhost/test",
+ "http://localho5.st/test",
+ "http://l42578gqege.f4",
+ "http://super.com/test/test/atqata675675/te"
+ );
$toAddValid = array("http://piwik1.net",
- "http://piwik2.net",
+ "http://piwik2.net",
"http://piwik3.net/test",
- "http://localhost/test",
- "http://localho5.st/test",
- "http://l42578gqege.f4",
+ "http://localhost/test",
+ "http://localho5.st/test",
+ "http://l42578gqege.f4",
"http://super.com/test/test/atqata675675/te");
-
+
$insertedUrls = Piwik_SitesManager_API::getInstance()->addSiteAliasUrls($idsite, $toAdd);
$this->assertEquals(count($toAdd), $insertedUrls);
-
+
$siteUrlsAfter = Piwik_SitesManager_API::getInstance()->getSiteUrlsFromId($idsite);
-
+
$shouldHave = array_merge($siteUrlsBefore, $toAddValid);
sort($shouldHave);
-
+
sort($siteUrlsAfter);
-
+
$this->assertEquals($shouldHave, $siteUrlsAfter);
}
-
+
/**
* duplicate -> don't save the already existing URLs
- *
+ *
* @group Plugins
* @group SitesManager
*/
public function testAddSiteUrlsDuplicate()
- {
+ {
$idsite = $this->_addSite();
-
+
$siteUrlsBefore = Piwik_SitesManager_API::getInstance()->getSiteUrlsFromId($idsite);
-
- $toAdd = array_merge($siteUrlsBefore, array("http://piwik1.net","http://piwik2.net"));
-
+
+ $toAdd = array_merge($siteUrlsBefore, array("http://piwik1.net", "http://piwik2.net"));
+
$insertedUrls = Piwik_SitesManager_API::getInstance()->addSiteAliasUrls($idsite, $toAdd);
$this->assertEquals(count($toAdd) - count($siteUrlsBefore), $insertedUrls);
-
+
$siteUrlsAfter = Piwik_SitesManager_API::getInstance()->getSiteUrlsFromId($idsite);
-
+
$shouldHave = $toAdd;
sort($shouldHave);
-
+
sort($siteUrlsAfter);
-
+
$this->assertEquals($shouldHave, $siteUrlsAfter);
}
-
+
/**
* case empty array => nothing happens
- *
+ *
* @group Plugins
* @group SitesManager
*/
public function testAddSiteUrlsNoUrlsToAdd1()
{
$idsite = $this->_addSite();
-
+
$siteUrlsBefore = Piwik_SitesManager_API::getInstance()->getSiteUrlsFromId($idsite);
-
+
$toAdd = array();
-
+
$insertedUrls = Piwik_SitesManager_API::getInstance()->addSiteAliasUrls($idsite, $toAdd);
$this->assertEquals(count($toAdd), $insertedUrls);
-
+
$siteUrlsAfter = Piwik_SitesManager_API::getInstance()->getSiteUrlsFromId($idsite);
-
+
$shouldHave = $siteUrlsBefore;
sort($shouldHave);
-
+
sort($siteUrlsAfter);
-
+
$this->assertEquals($shouldHave, $siteUrlsAfter);
}
-
+
/**
* case array only duplicate => nothing happens
- *
+ *
* @group Plugins
* @group SitesManager
*/
public function testAddSiteUrlsNoUrlsToAdd2()
{
$idsite = $this->_addSite();
-
+
$siteUrlsBefore = Piwik_SitesManager_API::getInstance()->getSiteUrlsFromId($idsite);
-
+
$toAdd = $siteUrlsBefore;
-
+
$insertedUrls = Piwik_SitesManager_API::getInstance()->addSiteAliasUrls($idsite, $toAdd);
$this->assertEquals(0, $insertedUrls);
-
+
$siteUrlsAfter = Piwik_SitesManager_API::getInstance()->getSiteUrlsFromId($idsite);
-
+
$shouldHave = $siteUrlsBefore;
sort($shouldHave);
-
+
sort($siteUrlsAfter);
-
+
$this->assertEquals($shouldHave, $siteUrlsAfter);
}
-
+
/**
* wrong format urls => exception
- *
+ *
* @group Plugins
* @group SitesManager
*/
@@ -346,10 +347,10 @@ class SitesManagerTest extends DatabaseTestCase
}
$this->fail('Expected exception not raised');
}
-
+
/**
* wrong idsite => no exception because simply no access to this resource
- *
+ *
* @group Plugins
* @group SitesManager
*/
@@ -363,10 +364,10 @@ class SitesManagerTest extends DatabaseTestCase
}
$this->fail('Expected exception not raised');
}
-
+
/**
* wrong idsite => exception
- *
+ *
* @group Plugins
* @group SitesManager
*/
@@ -380,10 +381,10 @@ class SitesManagerTest extends DatabaseTestCase
}
$this->fail('Expected exception not raised');
}
-
+
/**
* no Id -> empty array
- *
+ *
* @group Plugins
* @group SitesManager
*/
@@ -392,31 +393,31 @@ class SitesManagerTest extends DatabaseTestCase
$ids = Piwik_SitesManager_API::getInstance()->getAllSitesId();
$this->assertEquals(array(), $ids);
}
-
+
/**
* several Id -> normal array
- *
+ *
* @group Plugins
* @group SitesManager
*/
public function testGetAllSitesIdSeveralId()
{
- $name="tetq";
+ $name = "tetq";
$idsites = array(
- Piwik_SitesManager_API::getInstance()->addSite($name,array("http://piwik.net","http://piwik.com/test/")),
- Piwik_SitesManager_API::getInstance()->addSite($name,array("http://piwik.net","http://piwik.com/test/")),
- Piwik_SitesManager_API::getInstance()->addSite($name,array("http://piwik.net","http://piwik.com/test/")),
- Piwik_SitesManager_API::getInstance()->addSite($name,array("http://piwik.net","http://piwik.com/test/")),
- Piwik_SitesManager_API::getInstance()->addSite($name,array("http://piwik.net","http://piwik.com/test/")),
- );
-
+ Piwik_SitesManager_API::getInstance()->addSite($name, array("http://piwik.net", "http://piwik.com/test/")),
+ Piwik_SitesManager_API::getInstance()->addSite($name, array("http://piwik.net", "http://piwik.com/test/")),
+ Piwik_SitesManager_API::getInstance()->addSite($name, array("http://piwik.net", "http://piwik.com/test/")),
+ Piwik_SitesManager_API::getInstance()->addSite($name, array("http://piwik.net", "http://piwik.com/test/")),
+ Piwik_SitesManager_API::getInstance()->addSite($name, array("http://piwik.net", "http://piwik.com/test/")),
+ );
+
$ids = Piwik_SitesManager_API::getInstance()->getAllSitesId();
$this->assertEquals($idsites, $ids);
}
-
+
/**
* wrong id => exception
- *
+ *
* @group Plugins
* @group SitesManager
*/
@@ -432,7 +433,7 @@ class SitesManagerTest extends DatabaseTestCase
/**
* wrong id => exception
- *
+ *
* @group Plugins
* @group SitesManager
*/
@@ -448,18 +449,18 @@ class SitesManagerTest extends DatabaseTestCase
/**
* wrong id : no access => exception
- *
+ *
* @group Plugins
* @group SitesManager
*/
public function testGetSiteFromIdWrongId3()
{
- $idsite = Piwik_SitesManager_API::getInstance()->addSite("site",array("http://piwik.net","http://piwik.com/test/"));
+ $idsite = Piwik_SitesManager_API::getInstance()->addSite("site", array("http://piwik.net", "http://piwik.com/test/"));
$this->assertEquals(1, $idsite);
-
+
// set noaccess to site 1
- FakeAccess::setIdSitesView (array(2));
- FakeAccess::setIdSitesAdmin (array());
+ FakeAccess::setIdSitesView(array(2));
+ FakeAccess::setIdSitesAdmin(array());
try {
$siteInfo = Piwik_SitesManager_API::getInstance()->getSiteFromId(1);
@@ -468,192 +469,193 @@ class SitesManagerTest extends DatabaseTestCase
}
$this->fail('Expected exception not raised');
}
+
/**
* normal case
- *
+ *
* @group Plugins
* @group SitesManager
*/
public function testGetSiteFromIdNormalId()
{
$name = "website ''";
- $idsite = Piwik_SitesManager_API::getInstance()->addSite($name,array("http://piwik.net","http://piwik.com/test/"));
+ $idsite = Piwik_SitesManager_API::getInstance()->addSite($name, array("http://piwik.net", "http://piwik.com/test/"));
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_INT, $idsite);
-
+
$siteInfo = Piwik_SitesManager_API::getInstance()->getSiteFromId($idsite);
$this->assertEquals($name, $siteInfo['name']);
$this->assertEquals("http://piwik.net", $siteInfo['main_url']);
}
-
-
+
+
/**
* there is no admin site available -> array()
- *
+ *
* @group Plugins
* @group SitesManager
*/
public function testGetSitesWithAdminAccessNoResult()
{
- FakeAccess::setIdSitesAdmin (array());
-
+ FakeAccess::setIdSitesAdmin(array());
+
$sites = Piwik_SitesManager_API::getInstance()->getSitesWithAdminAccess();
$this->assertEquals(array(), $sites);
}
-
+
/**
* normal case, admin and view and noaccess website => return only admin
- *
+ *
* @group Plugins
* @group SitesManager
*/
public function testGetSitesWithAdminAccess()
{
- $idsite = Piwik_SitesManager_API::getInstance()->addSite("site1",array("http://piwik.net","http://piwik.com/test/"));
- $idsite = Piwik_SitesManager_API::getInstance()->addSite("site2",array("http://piwik.com/test/"));
- $idsite = Piwik_SitesManager_API::getInstance()->addSite("site3",array("http://piwik.org"));
-
+ $idsite = Piwik_SitesManager_API::getInstance()->addSite("site1", array("http://piwik.net", "http://piwik.com/test/"));
+ $idsite = Piwik_SitesManager_API::getInstance()->addSite("site2", array("http://piwik.com/test/"));
+ $idsite = Piwik_SitesManager_API::getInstance()->addSite("site3", array("http://piwik.org"));
+
$resultWanted = array(
- 0 => array("idsite" => 1, "name" => "site1", "main_url" =>"http://piwik.net", "ecommerce" => 0, "excluded_ips" => "", 'sitesearch' => 1, 'sitesearch_keyword_parameters' => '', 'sitesearch_category_parameters' => '', 'excluded_parameters' => '', 'excluded_user_agents' => '', 'timezone' => 'UTC', 'currency' => 'USD', 'group' => '', 'keep_url_fragment' => 0),
- 1 => array("idsite" => 3, "name" => "site3", "main_url" =>"http://piwik.org", "ecommerce" => 0,"excluded_ips" => "", 'sitesearch' => 1, 'sitesearch_keyword_parameters' => '', 'sitesearch_category_parameters' => '', 'excluded_parameters' => '', 'excluded_user_agents' => '', 'timezone' => 'UTC', 'currency' => 'USD', 'group' => '', 'keep_url_fragment' => 0),
+ 0 => array("idsite" => 1, "name" => "site1", "main_url" => "http://piwik.net", "ecommerce" => 0, "excluded_ips" => "", 'sitesearch' => 1, 'sitesearch_keyword_parameters' => '', 'sitesearch_category_parameters' => '', 'excluded_parameters' => '', 'excluded_user_agents' => '', 'timezone' => 'UTC', 'currency' => 'USD', 'group' => '', 'keep_url_fragment' => 0),
+ 1 => array("idsite" => 3, "name" => "site3", "main_url" => "http://piwik.org", "ecommerce" => 0, "excluded_ips" => "", 'sitesearch' => 1, 'sitesearch_keyword_parameters' => '', 'sitesearch_category_parameters' => '', 'excluded_parameters' => '', 'excluded_user_agents' => '', 'timezone' => 'UTC', 'currency' => 'USD', 'group' => '', 'keep_url_fragment' => 0),
);
-
- FakeAccess::setIdSitesAdmin (array(1,3));
-
+
+ FakeAccess::setIdSitesAdmin(array(1, 3));
+
$sites = Piwik_SitesManager_API::getInstance()->getSitesWithAdminAccess();
-
+
// we dont test the ts_created
unset($sites[0]['ts_created']);
unset($sites[1]['ts_created']);
$this->assertEquals($resultWanted, $sites);
}
-
+
/**
* there is no admin site available -> array()
- *
+ *
* @group Plugins
* @group SitesManager
*/
public function testGetSitesWithViewAccessNoResult()
{
- FakeAccess::setIdSitesView (array());
- FakeAccess::setIdSitesAdmin (array());
-
+ FakeAccess::setIdSitesView(array());
+ FakeAccess::setIdSitesAdmin(array());
+
$sites = Piwik_SitesManager_API::getInstance()->getSitesWithViewAccess();
$this->assertEquals(array(), $sites);
}
-
+
/**
* normal case, admin and view and noaccess website => return only admin
- *
+ *
* @group Plugins
* @group SitesManager
*/
public function testGetSitesWithViewAccess()
{
- $idsite = Piwik_SitesManager_API::getInstance()->addSite("site1",array("http://piwik.net","http://piwik.com/test/"));
- $idsite = Piwik_SitesManager_API::getInstance()->addSite("site2",array("http://piwik.com/test/"));
- $idsite = Piwik_SitesManager_API::getInstance()->addSite("site3",array("http://piwik.org"));
-
+ $idsite = Piwik_SitesManager_API::getInstance()->addSite("site1", array("http://piwik.net", "http://piwik.com/test/"));
+ $idsite = Piwik_SitesManager_API::getInstance()->addSite("site2", array("http://piwik.com/test/"));
+ $idsite = Piwik_SitesManager_API::getInstance()->addSite("site3", array("http://piwik.org"));
+
$resultWanted = array(
- 0 => array("idsite" => 1, "name" => "site1", "main_url" =>"http://piwik.net", "ecommerce" => 0, 'sitesearch' => 1, 'sitesearch_keyword_parameters' => '', 'sitesearch_category_parameters' => '',"excluded_ips" => "", 'excluded_parameters' => '', 'excluded_user_agents' => '', 'timezone' => 'UTC', 'currency' => 'USD', 'group' => '', 'keep_url_fragment' => 0),
- 1 => array("idsite" => 3, "name" => "site3", "main_url" =>"http://piwik.org", "ecommerce" => 0, 'sitesearch' => 1, 'sitesearch_keyword_parameters' => '', 'sitesearch_category_parameters' => '',"excluded_ips" => "", 'excluded_parameters' => '', 'excluded_user_agents' => '', 'timezone' => 'UTC', 'currency' => 'USD', 'group' => '', 'keep_url_fragment' => 0),
+ 0 => array("idsite" => 1, "name" => "site1", "main_url" => "http://piwik.net", "ecommerce" => 0, 'sitesearch' => 1, 'sitesearch_keyword_parameters' => '', 'sitesearch_category_parameters' => '', "excluded_ips" => "", 'excluded_parameters' => '', 'excluded_user_agents' => '', 'timezone' => 'UTC', 'currency' => 'USD', 'group' => '', 'keep_url_fragment' => 0),
+ 1 => array("idsite" => 3, "name" => "site3", "main_url" => "http://piwik.org", "ecommerce" => 0, 'sitesearch' => 1, 'sitesearch_keyword_parameters' => '', 'sitesearch_category_parameters' => '', "excluded_ips" => "", 'excluded_parameters' => '', 'excluded_user_agents' => '', 'timezone' => 'UTC', 'currency' => 'USD', 'group' => '', 'keep_url_fragment' => 0),
);
-
- FakeAccess::setIdSitesView (array(1,3));
- FakeAccess::setIdSitesAdmin (array());
-
+
+ FakeAccess::setIdSitesView(array(1, 3));
+ FakeAccess::setIdSitesAdmin(array());
+
$sites = Piwik_SitesManager_API::getInstance()->getSitesWithViewAccess();
// we dont test the ts_created
unset($sites[0]['ts_created']);
unset($sites[1]['ts_created']);
$this->assertEquals($resultWanted, $sites);
}
-
+
/**
* there is no admin site available -> array()
- *
+ *
* @group Plugins
* @group SitesManager
*/
public function testGetSitesWithAtLeastViewAccessNoResult()
{
- FakeAccess::setIdSitesView (array());
- FakeAccess::setIdSitesAdmin (array());
-
+ FakeAccess::setIdSitesView(array());
+ FakeAccess::setIdSitesAdmin(array());
+
$sites = Piwik_SitesManager_API::getInstance()->getSitesWithAtLeastViewAccess();
$this->assertEquals(array(), $sites);
}
-
+
/**
* normal case, admin and view and noaccess website => return only admin
- *
+ *
* @group Plugins
* @group SitesManager
*/
public function testGetSitesWithAtLeastViewAccess()
{
- $idsite = Piwik_SitesManager_API::getInstance()->addSite("site1",array("http://piwik.net","http://piwik.com/test/"), $ecommerce=1);
- $idsite = Piwik_SitesManager_API::getInstance()->addSite("site2",array("http://piwik.com/test/"));
- $idsite = Piwik_SitesManager_API::getInstance()->addSite("site3",array("http://piwik.org"));
-
+ $idsite = Piwik_SitesManager_API::getInstance()->addSite("site1", array("http://piwik.net", "http://piwik.com/test/"), $ecommerce = 1);
+ $idsite = Piwik_SitesManager_API::getInstance()->addSite("site2", array("http://piwik.com/test/"));
+ $idsite = Piwik_SitesManager_API::getInstance()->addSite("site3", array("http://piwik.org"));
+
$resultWanted = array(
- 0 => array("idsite" => 1, "name" => "site1", "main_url" =>"http://piwik.net", "ecommerce" => 1,"excluded_ips" => "", 'sitesearch' => 1, 'sitesearch_keyword_parameters' => '', 'sitesearch_category_parameters' => '', 'excluded_parameters' => '', 'excluded_user_agents' => '', 'timezone' => 'UTC', 'currency' => 'USD', 'group' => '', 'keep_url_fragment' => 0),
- 1 => array("idsite" => 3, "name" => "site3", "main_url" =>"http://piwik.org", "ecommerce" => 0,"excluded_ips" => "", 'sitesearch' => 1, 'sitesearch_keyword_parameters' => '', 'sitesearch_category_parameters' => '', 'excluded_parameters' => '', 'excluded_user_agents' => '', 'timezone' => 'UTC', 'currency' => 'USD', 'group' => '', 'keep_url_fragment' => 0),
+ 0 => array("idsite" => 1, "name" => "site1", "main_url" => "http://piwik.net", "ecommerce" => 1, "excluded_ips" => "", 'sitesearch' => 1, 'sitesearch_keyword_parameters' => '', 'sitesearch_category_parameters' => '', 'excluded_parameters' => '', 'excluded_user_agents' => '', 'timezone' => 'UTC', 'currency' => 'USD', 'group' => '', 'keep_url_fragment' => 0),
+ 1 => array("idsite" => 3, "name" => "site3", "main_url" => "http://piwik.org", "ecommerce" => 0, "excluded_ips" => "", 'sitesearch' => 1, 'sitesearch_keyword_parameters' => '', 'sitesearch_category_parameters' => '', 'excluded_parameters' => '', 'excluded_user_agents' => '', 'timezone' => 'UTC', 'currency' => 'USD', 'group' => '', 'keep_url_fragment' => 0),
);
-
- FakeAccess::setIdSitesView (array(1,3));
- FakeAccess::setIdSitesAdmin (array());
-
+
+ FakeAccess::setIdSitesView(array(1, 3));
+ FakeAccess::setIdSitesAdmin(array());
+
$sites = Piwik_SitesManager_API::getInstance()->getSitesWithAtLeastViewAccess();
// we dont test the ts_created
unset($sites[0]['ts_created']);
unset($sites[1]['ts_created']);
$this->assertEquals($resultWanted, $sites);
}
-
+
/**
* no urls for this site => array()
- *
+ *
* @group Plugins
* @group SitesManager
*/
public function testGetSiteUrlsFromIdNoUrls()
{
- $idsite = Piwik_SitesManager_API::getInstance()->addSite("site1",array("http://piwik.net"));
-
+ $idsite = Piwik_SitesManager_API::getInstance()->addSite("site1", array("http://piwik.net"));
+
$urls = Piwik_SitesManager_API::getInstance()->getSiteUrlsFromId($idsite);
$this->assertEquals(array("http://piwik.net"), $urls);
}
-
+
/**
* normal case
- *
+ *
* @group Plugins
* @group SitesManager
*/
public function testGetSiteUrlsFromIdManyUrls()
{
$site = array("http://piwik.net",
- "http://piwik.org",
- "http://piwik.org",
- "http://piwik.com");
+ "http://piwik.org",
+ "http://piwik.org",
+ "http://piwik.com");
sort($site);
-
- $idsite = Piwik_SitesManager_API::getInstance()->addSite("site1",$site);
-
+
+ $idsite = Piwik_SitesManager_API::getInstance()->addSite("site1", $site);
+
$siteWanted = array("http://piwik.net",
- "http://piwik.org",
- "http://piwik.com");
+ "http://piwik.org",
+ "http://piwik.com");
sort($siteWanted);
$urls = Piwik_SitesManager_API::getInstance()->getSiteUrlsFromId($idsite);
-
-
+
+
$this->assertEquals($siteWanted, $urls);
}
-
+
/**
* wrongId => exception
- *
+ *
* @group Plugins
* @group SitesManager
*/
@@ -668,42 +670,42 @@ class SitesManagerTest extends DatabaseTestCase
}
$this->fail('Expected exception not raised');
}
-
+
/**
* one url => no change to alias urls
- *
+ *
* @group Plugins
* @group SitesManager
*/
public function testUpdateSiteOneUrl()
{
$urls = array("http://piwiknew.com",
- "http://piwiknew.net",
- "http://piwiknew.org",
- "http://piwiknew.fr");
+ "http://piwiknew.net",
+ "http://piwiknew.org",
+ "http://piwiknew.fr");
$idsite = Piwik_SitesManager_API::getInstance()->addSite("site1", $urls);
$newMainUrl = "http://main.url";
-
+
// Also test that the group was set to empty, and is searchable
$websites = Piwik_SitesManager_API::getInstance()->getSitesFromGroup('');
$this->assertEquals(1, count($websites));
-
+
// the Update doesn't change the group field
- Piwik_SitesManager_API::getInstance()->updateSite($idsite, "test toto@{}", $newMainUrl );
+ Piwik_SitesManager_API::getInstance()->updateSite($idsite, "test toto@{}", $newMainUrl);
$websites = Piwik_SitesManager_API::getInstance()->getSitesFromGroup('');
$this->assertEquals(1, count($websites));
// Updating the group to something
$group = 'something';
- Piwik_SitesManager_API::getInstance()->updateSite($idsite, "test toto@{}", $newMainUrl, $ecommerce = 0, $ss = true, $ss_kwd = null, $ss_cat = '', $ips=null, $parametersExclude=null, $timezone=null, $currency=null, $group );
+ Piwik_SitesManager_API::getInstance()->updateSite($idsite, "test toto@{}", $newMainUrl, $ecommerce = 0, $ss = true, $ss_kwd = null, $ss_cat = '', $ips = null, $parametersExclude = null, $timezone = null, $currency = null, $group);
$websites = Piwik_SitesManager_API::getInstance()->getSitesFromGroup($group);
$this->assertEquals(1, count($websites));
$this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($websites[0]['ts_created'])));
// Updating the group to nothing
$group = '';
- Piwik_SitesManager_API::getInstance()->updateSite($idsite, "test toto@{}", $newMainUrl, $ecommerce = 0, $ss = false, $ss_kwd = '', $ss_cat = null, $ips=null, $parametersExclude=null, $timezone=null, $currency=null, $group, $startDate = '2010-01-01' );
+ Piwik_SitesManager_API::getInstance()->updateSite($idsite, "test toto@{}", $newMainUrl, $ecommerce = 0, $ss = false, $ss_kwd = '', $ss_cat = null, $ips = null, $parametersExclude = null, $timezone = null, $currency = null, $group, $startDate = '2010-01-01');
$websites = Piwik_SitesManager_API::getInstance()->getSitesFromGroup($group);
$this->assertEquals(1, count($websites));
$this->assertEquals('2010-01-01', date('Y-m-d', strtotime($websites[0]['ts_created'])));
@@ -713,73 +715,73 @@ class SitesManagerTest extends DatabaseTestCase
$aliasUrls = array_slice($allUrls, 1);
$this->assertEquals(array(), $aliasUrls);
}
-
+
/**
* strange name and NO URL => name ok, main_url not updated
- *
+ *
* @group Plugins
* @group SitesManager
*/
public function testUpdateSiteStrangeNameNoUrl()
{
- $idsite = Piwik_SitesManager_API::getInstance()->addSite("site1","http://main.url");
- $newName ="test toto@{'786'}";
-
- Piwik_SitesManager_API::getInstance()->updateSite($idsite, $newName );
-
+ $idsite = Piwik_SitesManager_API::getInstance()->addSite("site1", "http://main.url");
+ $newName = "test toto@{'786'}";
+
+ Piwik_SitesManager_API::getInstance()->updateSite($idsite, $newName);
+
$site = Piwik_SitesManager_API::getInstance()->getSiteFromId($idsite);
-
+
$this->assertEquals($newName, $site['name']);
// url didn't change because parameter url NULL in updateSite
$this->assertEquals("http://main.url", $site['main_url']);
}
-
+
/**
* several urls => both main and alias are updated
* also test the update of group field
- *
+ *
* @group Plugins
* @group SitesManager
*/
public function testUpdateSiteSeveralUrlsAndGroup()
{
$urls = array("http://piwiknew.com",
- "http://piwiknew.net",
- "http://piwiknew.org",
- "http://piwiknew.fr");
-
+ "http://piwiknew.net",
+ "http://piwiknew.org",
+ "http://piwiknew.fr");
+
$group = 'GROUP Before';
- $idsite = Piwik_SitesManager_API::getInstance()->addSite("site1",$urls, $ecommerce =1,
- $siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null,
- $excludedIps = null, $excludedQueryParameters = null, $timezone = null, $currency = null, $group, $startDate = '2011-01-01');
-
+ $idsite = Piwik_SitesManager_API::getInstance()->addSite("site1", $urls, $ecommerce = 1,
+ $siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null,
+ $excludedIps = null, $excludedQueryParameters = null, $timezone = null, $currency = null, $group, $startDate = '2011-01-01');
+
$websites = Piwik_SitesManager_API::getInstance()->getSitesFromGroup($group);
$this->assertEquals(1, count($websites));
-
+
$newurls = array("http://piwiknew2.com",
- "http://piwiknew2.net",
- "http://piwiknew2.org",
- "http://piwiknew2.fr");
+ "http://piwiknew2.net",
+ "http://piwiknew2.org",
+ "http://piwiknew2.fr");
$groupAfter = ' GROUP After';
- Piwik_SitesManager_API::getInstance()->updateSite($idsite, "test toto@{}",$newurls, $ecommerce = 0,
- $siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null,
- $excludedIps = null, $excludedQueryParameters = null, $timezone = null, $currency = null, $groupAfter);
+ Piwik_SitesManager_API::getInstance()->updateSite($idsite, "test toto@{}", $newurls, $ecommerce = 0,
+ $siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null,
+ $excludedIps = null, $excludedQueryParameters = null, $timezone = null, $currency = null, $groupAfter);
// no result for the group before update
$websites = Piwik_SitesManager_API::getInstance()->getSitesFromGroup($group);
$this->assertEquals(0, count($websites));
-
+
// Testing that the group was updated properly (and testing that the group value is trimmed before inserted/searched)
$websites = Piwik_SitesManager_API::getInstance()->getSitesFromGroup($groupAfter . ' ');
$this->assertEquals(1, count($websites));
$this->assertEquals('2011-01-01', date('Y-m-d', strtotime($websites[0]['ts_created'])));
-
+
// Test fetch website groups
$expectedGroups = array(trim($groupAfter));
$fetched = Piwik_SitesManager_API::getInstance()->getSitesGroups();
$this->assertEquals($expectedGroups, $fetched);
-
+
$allUrls = Piwik_SitesManager_API::getInstance()->getSiteUrlsFromId($idsite);
sort($allUrls);
sort($newurls);
@@ -787,23 +789,22 @@ class SitesManagerTest extends DatabaseTestCase
}
/**
- *
+ *
* @group Plugins
* @group SitesManager
*/
public function testGetSitesGroups()
{
- $groups = array( 'group1', ' group1 ', '', 'group2');
- $expectedGroups = array('group1','','group2');
- foreach($groups as $group)
- {
- Piwik_SitesManager_API::getInstance()->addSite("test toto@{}", 'http://example.org',$ecommerce=1,$siteSearch = null, $searchKeywordParameters = null, $searchCategoryParameters = null, $excludedIps = null, $excludedQueryParameters = null, $timezone = null, $currency = null, $group);
+ $groups = array('group1', ' group1 ', '', 'group2');
+ $expectedGroups = array('group1', '', 'group2');
+ foreach ($groups as $group) {
+ Piwik_SitesManager_API::getInstance()->addSite("test toto@{}", 'http://example.org', $ecommerce = 1, $siteSearch = null, $searchKeywordParameters = null, $searchCategoryParameters = null, $excludedIps = null, $excludedQueryParameters = null, $timezone = null, $currency = null, $group);
}
-
+
$this->assertEquals($expectedGroups, Piwik_SitesManager_API::getInstance()->getSitesGroups());
}
-
+
public function getInvalidTimezoneData()
{
return array(
@@ -811,9 +812,9 @@ class SitesManagerTest extends DatabaseTestCase
array('Paris'),
);
}
-
+
/**
- *
+ *
* @dataProvider getInvalidTimezoneData
* @group Plugins
* @group SitesManager
@@ -821,16 +822,16 @@ class SitesManagerTest extends DatabaseTestCase
public function testAddSitesInvalidTimezone($timezone)
{
try {
- $idsite = Piwik_SitesManager_API::getInstance()->addSite("site1",array('http://example.org'),$ecommerce=0,
- $siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null,$ip= '', $params='', $timezone);
+ $idsite = Piwik_SitesManager_API::getInstance()->addSite("site1", array('http://example.org'), $ecommerce = 0,
+ $siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null, $ip = '', $params = '', $timezone);
} catch (Exception $e) {
return;
}
$this->fail('Expected exception not raised');
}
-
+
/**
- *
+ *
* @group Plugins
* @group SitesManager
*/
@@ -838,16 +839,16 @@ class SitesManagerTest extends DatabaseTestCase
{
try {
$invalidCurrency = '€';
- $idsite = Piwik_SitesManager_API::getInstance()->addSite("site1",array('http://example.org'),$ecommerce=0,
- $siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null,'', 'UTC', $invalidCurrency);
+ $idsite = Piwik_SitesManager_API::getInstance()->addSite("site1", array('http://example.org'), $ecommerce = 0,
+ $siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null, '', 'UTC', $invalidCurrency);
} catch (Exception $e) {
return;
}
$this->fail('Expected exception not raised');
}
-
+
/**
- *
+ *
* @group Plugins
* @group SitesManager
*/
@@ -862,9 +863,9 @@ class SitesManagerTest extends DatabaseTestCase
$this->assertEquals('', $excludedIps);
$excludedQueryParameters = Piwik_SitesManager_API::getInstance()->getExcludedQueryParametersGlobal();
$this->assertEquals('', $excludedQueryParameters);
-
+
// test that when not specified, defaults are set as expected
- $idsite = Piwik_SitesManager_API::getInstance()->addSite("site1",array('http://example.org'));
+ $idsite = Piwik_SitesManager_API::getInstance()->addSite("site1", array('http://example.org'));
$site = new Piwik_Site($idsite);
$this->assertEquals('UTC', $site->getTimezone());
$this->assertEquals('USD', $site->getCurrency());
@@ -883,13 +884,13 @@ class SitesManagerTest extends DatabaseTestCase
Piwik_SitesManager_API::getInstance()->setDefaultCurrency($newDefaultCurrency);
$defaultCurrency = Piwik_SitesManager_API::getInstance()->getDefaultCurrency();
$this->assertEquals($newDefaultCurrency, $defaultCurrency);
-
+
// set the global IPs to exclude and get it
$newGlobalExcludedIps = '1.1.1.*,1.1.*.*,150.1.1.1';
Piwik_SitesManager_API::getInstance()->setGlobalExcludedIps($newGlobalExcludedIps);
$globalExcludedIps = Piwik_SitesManager_API::getInstance()->getExcludedIpsGlobal();
$this->assertEquals($newGlobalExcludedIps, $globalExcludedIps);
-
+
// set the global URL query params to exclude and get it
$newGlobalExcludedQueryParameters = 'PHPSESSID,blabla, TesT';
// removed the space
@@ -900,37 +901,37 @@ class SitesManagerTest extends DatabaseTestCase
// create a website and check that default currency and default timezone are set
// however, excluded IPs and excluded query Params are not returned
- $idsite = Piwik_SitesManager_API::getInstance()->addSite("site1",array('http://example.org'),$ecommerce=0,
- $siteSearch = 0, $searchKeywordParameters = 'test1,test2', $searchCategoryParameters = 'test2,test1',
- '', '', $newDefaultTimezone);
+ $idsite = Piwik_SitesManager_API::getInstance()->addSite("site1", array('http://example.org'), $ecommerce = 0,
+ $siteSearch = 0, $searchKeywordParameters = 'test1,test2', $searchCategoryParameters = 'test2,test1',
+ '', '', $newDefaultTimezone);
$site = new Piwik_Site($idsite);
$this->assertEquals($newDefaultTimezone, $site->getTimezone());
$this->assertEquals(date('Y-m-d'), $site->getCreationDate()->toString());
$this->assertEquals($newDefaultCurrency, $site->getCurrency());
- $this->assertEquals('', $site->getExcludedIps());
- $this->assertEquals('', $site->getExcludedQueryParameters());
- $this->assertEquals('test1,test2', $site->getSearchKeywordParameters());
- $this->assertEquals('test2,test1', $site->getSearchCategoryParameters());
- $this->assertFalse($site->isSiteSearchEnabled());
- $this->assertFalse(Piwik_Site::isSiteSearchEnabledFor($idsite));
- $this->assertFalse($site->isEcommerceEnabled());
- $this->assertFalse(Piwik_Site::isEcommerceEnabledFor($idsite));
+ $this->assertEquals('', $site->getExcludedIps());
+ $this->assertEquals('', $site->getExcludedQueryParameters());
+ $this->assertEquals('test1,test2', $site->getSearchKeywordParameters());
+ $this->assertEquals('test2,test1', $site->getSearchCategoryParameters());
+ $this->assertFalse($site->isSiteSearchEnabled());
+ $this->assertFalse(Piwik_Site::isSiteSearchEnabledFor($idsite));
+ $this->assertFalse($site->isEcommerceEnabled());
+ $this->assertFalse(Piwik_Site::isEcommerceEnabledFor($idsite));
}
-
+
/**
- *
+ *
* @group Plugins
* @group SitesManager
*/
public function testGetSitesIdFromSiteUrlSuperUser()
{
- $idsite = Piwik_SitesManager_API::getInstance()->addSite("site1",array("http://piwik.net","http://piwik.com"));
- $idsite = Piwik_SitesManager_API::getInstance()->addSite("site2",array("http://piwik.com","http://piwik.net"));
- $idsite = Piwik_SitesManager_API::getInstance()->addSite("site3",array("http://piwik.com","http://piwik.org"));
+ $idsite = Piwik_SitesManager_API::getInstance()->addSite("site1", array("http://piwik.net", "http://piwik.com"));
+ $idsite = Piwik_SitesManager_API::getInstance()->addSite("site2", array("http://piwik.com", "http://piwik.net"));
+ $idsite = Piwik_SitesManager_API::getInstance()->addSite("site3", array("http://piwik.com", "http://piwik.org"));
$idsites = Piwik_SitesManager_API::getInstance()->getSitesIdFromSiteUrl('http://piwik.org');
$this->assertTrue(count($idsites) == 1);
-
+
$idsites = Piwik_SitesManager_API::getInstance()->getSitesIdFromSiteUrl('http://www.piwik.org');
$this->assertTrue(count($idsites) == 1);
@@ -942,15 +943,15 @@ class SitesManagerTest extends DatabaseTestCase
}
/**
- *
+ *
* @group Plugins
* @group SitesManager
*/
public function testGetSitesIdFromSiteUrlUser()
{
- $idsite = Piwik_SitesManager_API::getInstance()->addSite("site1",array("http://www.piwik.net","http://piwik.com"));
- $idsite = Piwik_SitesManager_API::getInstance()->addSite("site2",array("http://piwik.com","http://piwik.net"));
- $idsite = Piwik_SitesManager_API::getInstance()->addSite("site3",array("http://piwik.com","http://piwik.org"));
+ $idsite = Piwik_SitesManager_API::getInstance()->addSite("site1", array("http://www.piwik.net", "http://piwik.com"));
+ $idsite = Piwik_SitesManager_API::getInstance()->addSite("site2", array("http://piwik.com", "http://piwik.net"));
+ $idsite = Piwik_SitesManager_API::getInstance()->addSite("site3", array("http://piwik.com", "http://piwik.org"));
$saveAccess = Zend_Registry::get('access');
@@ -962,18 +963,18 @@ class SitesManagerTest extends DatabaseTestCase
Piwik_UsersManager_API::getInstance()->setUserAccess("user2", "admin", array(3));
Piwik_UsersManager_API::getInstance()->addUser("user3", "geqgegagae", "tegst3@tesgt.com", "alias");
- Piwik_UsersManager_API::getInstance()->setUserAccess("user3", "view", array(1,2));
+ Piwik_UsersManager_API::getInstance()->setUserAccess("user3", "view", array(1, 2));
Piwik_UsersManager_API::getInstance()->setUserAccess("user3", "admin", array(3));
$pseudoMockAccess = new FakeAccess;
FakeAccess::$superUser = false;
FakeAccess::$identity = 'user1';
- FakeAccess::setIdSitesView (array(1));
- FakeAccess::setIdSitesAdmin (array());
+ FakeAccess::setIdSitesView(array(1));
+ FakeAccess::setIdSitesAdmin(array());
Zend_Registry::set('access', $pseudoMockAccess);
$idsites = Piwik_SitesManager_API::getInstance()->getSitesIdFromSiteUrl('http://piwik.com');
$this->assertEquals(1, count($idsites));
-
+
// testing URL normalization
$idsites = Piwik_SitesManager_API::getInstance()->getSitesIdFromSiteUrl('http://www.piwik.com');
$this->assertEquals(1, count($idsites));
@@ -983,8 +984,8 @@ class SitesManagerTest extends DatabaseTestCase
$pseudoMockAccess = new FakeAccess;
FakeAccess::$superUser = false;
FakeAccess::$identity = 'user2';
- FakeAccess::setIdSitesView (array(1));
- FakeAccess::setIdSitesAdmin (array(3));
+ FakeAccess::setIdSitesView(array(1));
+ FakeAccess::setIdSitesAdmin(array(3));
Zend_Registry::set('access', $pseudoMockAccess);
$idsites = Piwik_SitesManager_API::getInstance()->getSitesIdFromSiteUrl('http://piwik.com');
$this->assertEquals(2, count($idsites));
@@ -992,8 +993,8 @@ class SitesManagerTest extends DatabaseTestCase
$pseudoMockAccess = new FakeAccess;
FakeAccess::$superUser = false;
FakeAccess::$identity = 'user3';
- FakeAccess::setIdSitesView (array(1,2));
- FakeAccess::setIdSitesAdmin (array(3));
+ FakeAccess::setIdSitesView(array(1, 2));
+ FakeAccess::setIdSitesAdmin(array(3));
Zend_Registry::set('access', $pseudoMockAccess);
$idsites = Piwik_SitesManager_API::getInstance()->getSitesIdFromSiteUrl('http://piwik.com');
$this->assertEquals(3, count($idsites));
@@ -1008,11 +1009,11 @@ class SitesManagerTest extends DatabaseTestCase
*/
public function testGetSitesFromTimezones()
{
- $idsite1 = Piwik_SitesManager_API::getInstance()->addSite("site3",array("http://piwik.org"),null,$siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null,null,null,'UTC');
- $idsite2 = Piwik_SitesManager_API::getInstance()->addSite("site3",array("http://piwik.org"),null,$siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null,null,null,'Pacific/Auckland');
- $idsite3 = Piwik_SitesManager_API::getInstance()->addSite("site3",array("http://piwik.org"),null,$siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null,null,null,'Pacific/Auckland');
- $idsite4 = Piwik_SitesManager_API::getInstance()->addSite("site3",array("http://piwik.org"),null,$siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null,null,null,'UTC+10');
+ $idsite1 = Piwik_SitesManager_API::getInstance()->addSite("site3", array("http://piwik.org"), null, $siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null, null, null, 'UTC');
+ $idsite2 = Piwik_SitesManager_API::getInstance()->addSite("site3", array("http://piwik.org"), null, $siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null, null, null, 'Pacific/Auckland');
+ $idsite3 = Piwik_SitesManager_API::getInstance()->addSite("site3", array("http://piwik.org"), null, $siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null, null, null, 'Pacific/Auckland');
+ $idsite4 = Piwik_SitesManager_API::getInstance()->addSite("site3", array("http://piwik.org"), null, $siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null, null, null, 'UTC+10');
$result = Piwik_SitesManager_API::getInstance()->getSitesIdFromTimezones(array('UTC+10', 'Pacific/Auckland'));
- $this->assertEquals(array($idsite2,$idsite3,$idsite4), $result);
+ $this->assertEquals(array($idsite2, $idsite3, $idsite4), $result);
}
}
diff --git a/tests/PHPUnit/Plugins/UserCountryTest.php b/tests/PHPUnit/Plugins/UserCountryTest.php
index 4a41cd054e..dbf4168eaa 100644
--- a/tests/PHPUnit/Plugins/UserCountryTest.php
+++ b/tests/PHPUnit/Plugins/UserCountryTest.php
@@ -5,36 +5,36 @@
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
-require_once PIWIK_INCLUDE_PATH.'/plugins/UserCountry/UserCountry.php';
+require_once PIWIK_INCLUDE_PATH . '/plugins/UserCountry/UserCountry.php';
require_once 'UserCountry/functions.php';
-require_once PIWIK_INCLUDE_PATH.'/core/DataFiles/Countries.php';
+require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/Countries.php';
class Test_Piwik_UserCountry extends PHPUnit_Framework_Testcase
{
/**
- *
+ *
* @group Plugins
* @group UserCountry
*/
public function testGetFlagFromCode()
{
$flag = Piwik_getFlagFromCode("us");
- $this->assertEquals( basename($flag), "us.png" );
+ $this->assertEquals(basename($flag), "us.png");
}
/**
- *
+ *
* @group Plugins
* @group UserCountry
*/
public function testGetFlagFromInvalidCode()
{
$flag = Piwik_getFlagFromCode("foo");
- $this->assertEquals( basename($flag), "xx.png" );
+ $this->assertEquals(basename($flag), "xx.png");
}
/**
- *
+ *
* @group Plugins
* @group UserCountry
*/
@@ -49,8 +49,7 @@ class Test_Piwik_UserCountry extends PHPUnit_Framework_Testcase
$flags = scandir(PIWIK_PATH_TEST_TO_ROOT . '/plugins/UserCountry/flags/');
// Get list of countries
- foreach($countries as $country => $continent)
- {
+ foreach ($countries as $country => $continent) {
// test continent
$this->assertContains($continent, $continents);
@@ -58,10 +57,8 @@ class Test_Piwik_UserCountry extends PHPUnit_Framework_Testcase
$this->assertContains($country . '.png', $flags);
}
- foreach($flags as $filename)
- {
- if($filename == '.' || $filename == '..')
- {
+ foreach ($flags as $filename) {
+ if ($filename == '.' || $filename == '..') {
continue;
}
@@ -71,80 +68,78 @@ class Test_Piwik_UserCountry extends PHPUnit_Framework_Testcase
$this->assertArrayHasKey($country, $countries, $filename);
}
}
-
+
// test that redundant checks work
public function testGeoIpUpdaterRedundantChecks()
{
- Piwik_UserCountry_LocationProvider_GeoIp::$geoIPDatabaseDir = 'tests/lib/geoip-files';
- Piwik_UserCountry_LocationProvider::$providers = null;
-
- // create empty ISP & Org files
- $this->createEmptyISPOrgFiles();
-
- // run redundant checks
- $updater = new Piwik_UserCountry_GeoIPAutoUpdater_publictestRedundantChecks();
- $updater->performRedundantDbChecks();
-
- // check that files are renamed correctly
- $this->checkBrokenGeoIPState();
-
- // create empty files again & run checks again
- $this->createEmptyISPOrgFiles();
- $updater->performRedundantDbChecks();
-
- // check that w/ broken files already there, redundant checks still work correctly
- $this->checkBrokenGeoIPState();
+ Piwik_UserCountry_LocationProvider_GeoIp::$geoIPDatabaseDir = 'tests/lib/geoip-files';
+ Piwik_UserCountry_LocationProvider::$providers = null;
+
+ // create empty ISP & Org files
+ $this->createEmptyISPOrgFiles();
+
+ // run redundant checks
+ $updater = new Piwik_UserCountry_GeoIPAutoUpdater_publictestRedundantChecks();
+ $updater->performRedundantDbChecks();
+
+ // check that files are renamed correctly
+ $this->checkBrokenGeoIPState();
+
+ // create empty files again & run checks again
+ $this->createEmptyISPOrgFiles();
+ $updater->performRedundantDbChecks();
+
+ // check that w/ broken files already there, redundant checks still work correctly
+ $this->checkBrokenGeoIPState();
}
-
+
public function setUp()
{
- Piwik::$shouldLog = null;
+ Piwik::$shouldLog = null;
}
-
+
public function tearDown()
{
- $geoIpDirPath = PIWIK_INCLUDE_PATH.'/tests/lib/geoip-files';
- $filesToRemove = array('GeoIPISP.dat.broken', 'GeoIPOrg.dat.broken', 'GeoIPISP.dat', 'GeoIPOrg.dat');
-
- foreach ($filesToRemove as $name)
- {
- $path = $geoIpDirPath.'/'.$name;
- if (file_exists($path))
- {
- unlink($path);
- }
- }
+ $geoIpDirPath = PIWIK_INCLUDE_PATH . '/tests/lib/geoip-files';
+ $filesToRemove = array('GeoIPISP.dat.broken', 'GeoIPOrg.dat.broken', 'GeoIPISP.dat', 'GeoIPOrg.dat');
+
+ foreach ($filesToRemove as $name) {
+ $path = $geoIpDirPath . '/' . $name;
+ if (file_exists($path)) {
+ unlink($path);
+ }
+ }
}
-
+
private function createEmptyISPOrgFiles()
{
- $geoIpDir = PIWIK_INCLUDE_PATH.'/tests/lib/geoip-files';
-
- $fd = fopen($geoIpDir.'/GeoIPISP.dat', 'w');
- fclose($fd);
-
- $fd = fopen($geoIpDir.'/GeoIPOrg.dat', 'w');
- fclose($fd);
+ $geoIpDir = PIWIK_INCLUDE_PATH . '/tests/lib/geoip-files';
+
+ $fd = fopen($geoIpDir . '/GeoIPISP.dat', 'w');
+ fclose($fd);
+
+ $fd = fopen($geoIpDir . '/GeoIPOrg.dat', 'w');
+ fclose($fd);
}
-
+
private function checkBrokenGeoIPState()
{
- $geoIpDir = PIWIK_INCLUDE_PATH.'/tests/lib/geoip-files';
-
- $this->assertFalse(file_exists($geoIpDir.'/GeoIPCity.dat.broken'));
-
- $this->assertFalse(file_exists($geoIpDir.'/GeoIPISP.dat'));
- $this->assertTrue(file_exists($geoIpDir.'/GeoIPISP.dat.broken'));
-
- $this->assertFalse(file_exists($geoIpDir.'/GeoIPOrg.dat'));
- $this->assertTrue(file_exists($geoIpDir.'/GeoIPOrg.dat.broken'));
+ $geoIpDir = PIWIK_INCLUDE_PATH . '/tests/lib/geoip-files';
+
+ $this->assertFalse(file_exists($geoIpDir . '/GeoIPCity.dat.broken'));
+
+ $this->assertFalse(file_exists($geoIpDir . '/GeoIPISP.dat'));
+ $this->assertTrue(file_exists($geoIpDir . '/GeoIPISP.dat.broken'));
+
+ $this->assertFalse(file_exists($geoIpDir . '/GeoIPOrg.dat'));
+ $this->assertTrue(file_exists($geoIpDir . '/GeoIPOrg.dat.broken'));
}
}
class Piwik_UserCountry_GeoIPAutoUpdater_publictestRedundantChecks extends Piwik_UserCountry_GeoIPAutoUpdater
{
- public function performRedundantDbChecks()
- {
- parent::performRedundantDbChecks();
- }
+ public function performRedundantDbChecks()
+ {
+ parent::performRedundantDbChecks();
+ }
}
diff --git a/tests/PHPUnit/Plugins/UserSettingsTest.php b/tests/PHPUnit/Plugins/UserSettingsTest.php
index a6dfc860f9..fb99c787a6 100644
--- a/tests/PHPUnit/Plugins/UserSettingsTest.php
+++ b/tests/PHPUnit/Plugins/UserSettingsTest.php
@@ -168,7 +168,7 @@ class UserSettingsTest extends PHPUnit_Framework_TestCase
array('BLB', 'BlackBerry', 'BlackBerry'))),
array('Mozilla/5.0 (PlayBook; U; RIM Tablet OS 1.0.0; en-US) AppleWebKit/534.11+ (KHTML, like Gecko) Version/0.0.1 Safari/534.11+', array(
- array('BP', 'PlayBook', 'PlayBook', '0.0', '0', '0', 'webkit' ),
+ array('BP', 'PlayBook', 'PlayBook', '0.0', '0', '0', 'webkit'),
array('QNX', 'QNX', 'QNX'))),
// BrowseX
@@ -1002,10 +1002,9 @@ class UserSettingsTest extends PHPUnit_Framework_TestCase
$res = UserAgentParser::getBrowser($userAgent);
$family = false;
- if($res === false)
+ if ($res === false)
$this->assertFalse($expected[0]);
- else
- {
+ else {
$family = Piwik_getBrowserFamily($res['id']);
$this->assertEquals($expected[0][0], $res['id']);
$this->assertEquals($expected[0][1], $res['name']);
diff --git a/tests/PHPUnit/Plugins/UsersManagerTest.php b/tests/PHPUnit/Plugins/UsersManagerTest.php
index 33a1faf95c..4b8bc9b0e8 100644
--- a/tests/PHPUnit/Plugins/UsersManagerTest.php
+++ b/tests/PHPUnit/Plugins/UsersManagerTest.php
@@ -10,140 +10,137 @@ class UsersManagerTest extends DatabaseTestCase
public function setUp()
{
parent::setUp();
-
+
Piwik_PluginsManager::getInstance()->loadPlugin('UsersManager');
Piwik_PluginsManager::getInstance()->installLoadedPlugins();
-
+
// setup the access layer
$pseudoMockAccess = new FakeAccess;
- FakeAccess::setIdSitesView( array(1,2));
- FakeAccess::setIdSitesAdmin( array(3,4));
-
+ FakeAccess::setIdSitesView(array(1, 2));
+ FakeAccess::setIdSitesAdmin(array(3, 4));
+
//finally we set the user as a super user by default
FakeAccess::$superUser = true;
Zend_Registry::set('access', $pseudoMockAccess);
-
+
// we make sure the tests don't depend on the config file content
Piwik_Config::getInstance()->superuser = array(
- 'login'=>'superusertest',
- 'password'=>'passwordsuperusertest',
- 'email'=>'superuser@example.com'
+ 'login' => 'superusertest',
+ 'password' => 'passwordsuperusertest',
+ 'email' => 'superuser@example.com'
);
}
private function _flatten($sitesAccess)
{
- $result = array();;
+ $result = array();
+ ;
- foreach($sitesAccess as $siteAccess)
- {
- $result[ $siteAccess['site'] ] = $siteAccess['access'];
+ foreach ($sitesAccess as $siteAccess) {
+ $result[$siteAccess['site']] = $siteAccess['access'];
}
return $result;
}
- private function _checkUserHasNotChanged($user, $newPassword, $newEmail = null, $newAlias= null)
+ private function _checkUserHasNotChanged($user, $newPassword, $newEmail = null, $newAlias = null)
{
- if(is_null($newEmail))
- {
+ if (is_null($newEmail)) {
$newEmail = $user['email'];
}
- if(is_null($newAlias))
- {
+ if (is_null($newAlias)) {
$newAlias = $user['alias'];
}
$userAfter = Piwik_UsersManager_API::getInstance()->getUser($user["login"]);
unset($userAfter['date_registered']);
-
+
// we now compute what the token auth should be, it should always be a hash of the login and the current password
// if the password has changed then the token_auth has changed!
- $user['token_auth']= Piwik_UsersManager_API::getInstance()->getTokenAuth($user["login"], md5($newPassword) );
-
- $user['password']=md5($newPassword);
- $user['email']=$newEmail;
- $user['alias']=$newAlias;
- $this->assertEquals($user,$userAfter);
+ $user['token_auth'] = Piwik_UsersManager_API::getInstance()->getTokenAuth($user["login"], md5($newPassword));
+
+ $user['password'] = md5($newPassword);
+ $user['email'] = $newEmail;
+ $user['alias'] = $newAlias;
+ $this->assertEquals($user, $userAfter);
}
-
+
/**
- *
+ *
* @group Plugins
* @group UsersManager
*/
public function testAllSuperUserIncluded()
{
Piwik_Config::getInstance()->superuser = array(
- 'login'=>'superusertest',
- 'password'=>'passwordsuperusertest',
- 'email'=>'superuser@example.com'
+ 'login' => 'superusertest',
+ 'password' => 'passwordsuperusertest',
+ 'email' => 'superuser@example.com'
);
-
- $user = array( 'login'=>'user',
- 'password'=>"geqgeagae",
- 'email'=>"test@test.com",
- 'alias'=>"alias");
- Piwik_UsersManager_API::getInstance()->addUser($user['login'],$user['password'] ,$user['email'] ,$user['alias'] );
-
+
+ $user = array('login' => 'user',
+ 'password' => "geqgeagae",
+ 'email' => "test@test.com",
+ 'alias' => "alias");
+ Piwik_UsersManager_API::getInstance()->addUser($user['login'], $user['password'], $user['email'], $user['alias']);
+
$exceptionNotRaised = false;
try {
- Piwik_UsersManager_API::getInstance()->addUser('superusertest','te','fake@fale.co','ega');
+ Piwik_UsersManager_API::getInstance()->addUser('superusertest', 'te', 'fake@fale.co', 'ega');
$exceptionNotRaised = true;
} catch (Exception $expected) {
$this->assertRegExp("(UsersManager_ExceptionSuperUser)", $expected->getMessage());
}
try {
- Piwik_UsersManager_API::getInstance()->updateUser('superusertest','te','fake@fale.co','ega');
+ Piwik_UsersManager_API::getInstance()->updateUser('superusertest', 'te', 'fake@fale.co', 'ega');
$exceptionNotRaised = true;
} catch (Exception $expected) {
$this->assertRegExp("(UsersManager_ExceptionSuperUser)", $expected->getMessage());
}
try {
- Piwik_UsersManager_API::getInstance()->deleteUser('superusertest','te','fake@fale.co','ega');
+ Piwik_UsersManager_API::getInstance()->deleteUser('superusertest', 'te', 'fake@fale.co', 'ega');
$exceptionNotRaised = true;
} catch (Exception $expected) {
$this->assertRegExp("(UsersManager_ExceptionSuperUser)", $expected->getMessage());
}
try {
- Piwik_UsersManager_API::getInstance()->deleteUser('superusertest','te','fake@fale.co','ega');
+ Piwik_UsersManager_API::getInstance()->deleteUser('superusertest', 'te', 'fake@fale.co', 'ega');
$exceptionNotRaised = true;
} catch (Exception $expected) {
$this->assertRegExp("(UsersManager_ExceptionSuperUser)", $expected->getMessage());
}
- if($exceptionNotRaised) {
+ if ($exceptionNotRaised) {
$this->fail();
}
}
-
+
/**
* bad password => exception
- *
+ *
* @group Plugins
* @group UsersManager
*/
public function testUpdateUserBadpasswd()
{
- $login="login";
- $user = array('login'=>$login,
- 'password'=>"geqgeagae",
- 'email'=>"test@test.com",
- 'alias'=>"alias");
-
- Piwik_UsersManager_API::getInstance()->addUser($user['login'],$user['password'] ,$user['email'] ,$user['alias'] );
-
-
+ $login = "login";
+ $user = array('login' => $login,
+ 'password' => "geqgeagae",
+ 'email' => "test@test.com",
+ 'alias' => "alias");
+
+ Piwik_UsersManager_API::getInstance()->addUser($user['login'], $user['password'], $user['email'], $user['alias']);
+
+
try {
- Piwik_UsersManager_API::getInstance()->updateUser( $login, "pas");
- }
- catch (Exception $expected) {
+ Piwik_UsersManager_API::getInstance()->updateUser($login, "pas");
+ } catch (Exception $expected) {
$this->assertRegExp("(UsersManager_ExceptionInvalidPassword)", $expected->getMessage());
-
- $this->_checkUserHasNotChanged($user,$user['password']);
+
+ $this->_checkUserHasNotChanged($user, $user['password']);
return;
}
$this->fail("Exception not raised.");
-
+
}
-
+
/**
* Dataprovider
*/
@@ -156,9 +153,9 @@ class UsersManagerTest extends DatabaseTestCase
array("geg'ag11gge@", "password", "email@email.com", "alias"), // wrong login / bad characters => exception
);
}
-
+
/**
- *
+ *
* @dataProvider getAddUserInvalidLoginData
* @group Plugins
* @group UsersManager
@@ -167,17 +164,16 @@ class UsersManagerTest extends DatabaseTestCase
{
try {
Piwik_UsersManager_API::getInstance()->addUser($userLogin, $password, $email, $alias);
- }
- catch (Exception $expected) {
+ } catch (Exception $expected) {
$this->assertRegExp("(UsersManager_ExceptionInvalidLogin)", $expected->getMessage());
return;
}
$this->fail("Exception not raised.");
}
-
+
/**
* existing login => exception
- *
+ *
* @group Plugins
* @group UsersManager
*/
@@ -186,13 +182,12 @@ class UsersManagerTest extends DatabaseTestCase
try {
Piwik_UsersManager_API::getInstance()->addUser("test", "password", "email@email.com", "alias");
Piwik_UsersManager_API::getInstance()->addUser("test", "password2", "em2ail@email.com", "al2ias");
- }
- catch (Exception $expected) {
+ } catch (Exception $expected) {
$this->assertRegExp("(UsersManager_ExceptionLoginExists)", $expected->getMessage());
return;
}
$this->fail("Exception not raised.");
-
+
}
/**
@@ -201,9 +196,9 @@ class UsersManagerTest extends DatabaseTestCase
public function getWrongPasswordTestData()
{
return array(
- array("geggeqgeqag", "pas", "email@email.com", "alias"), // too short -> exception
+ array("geggeqgeqag", "pas", "email@email.com", "alias"), // too short -> exception
array("ghqgeggg", "gegageqqqqqqqgeqgqeg84897897897897g122", "email@email.com", "alias"), // too long -> exception
- array("geggeqgeqag", "", "email@email.com", "alias"), // empty -> exception
+ array("geggeqgeqag", "", "email@email.com", "alias"), // empty -> exception
);
}
@@ -217,8 +212,7 @@ class UsersManagerTest extends DatabaseTestCase
{
try {
Piwik_UsersManager_API::getInstance()->addUser($userLogin, $password, $email, $alias);
- }
- catch (Exception $expected) {
+ } catch (Exception $expected) {
$this->assertRegExp("(UsersManager_ExceptionInvalidPassword)", $expected->getMessage());
return;
}
@@ -248,121 +242,118 @@ class UsersManagerTest extends DatabaseTestCase
{
try {
Piwik_UsersManager_API::getInstance()->addUser($userLogin, $password, $email, $alias);
- }
- catch (Exception $expected) {
+ } catch (Exception $expected) {
$this->assertRegExp("(mail)", $expected->getMessage());
return;
}
$this->fail("Exception not raised.");
}
-
+
/**
* empty email => exception
- *
+ *
* @group Plugins
* @group UsersManager
*/
public function testAddUserEmptyEmail()
{
-
+
try {
Piwik_UsersManager_API::getInstance()->addUser("geggeqgeqag", "geqgeagae", "", "alias");
- }
- catch (Exception $expected) {
+ } catch (Exception $expected) {
$this->assertRegExp("(mail)", $expected->getMessage());
return;
}
$this->fail("Exception not raised.");
}
-
+
/**
* empty alias => use login
- *
+ *
* @group Plugins
* @group UsersManager
*/
public function testAddUserEmptyAlias()
{
- $login ="geggeqgeqag";
+ $login = "geggeqgeqag";
Piwik_UsersManager_API::getInstance()->addUser($login, "geqgeagae", "mgeagi@geq.com", "");
$user = Piwik_UsersManager_API::getInstance()->getUser($login);
$this->assertEquals($login, $user['alias']);
$this->assertEquals($login, $user['login']);
}
-
+
/**
* no alias => use login
- *
+ *
* @group Plugins
* @group UsersManager
*/
public function testAddUserNoAliasSpecified()
{
- $login ="geggeqg455eqag";
+ $login = "geggeqg455eqag";
Piwik_UsersManager_API::getInstance()->addUser($login, "geqgeagae", "mgeagi@geq.com");
$user = Piwik_UsersManager_API::getInstance()->getUser($login);
$this->assertEquals($login, $user['alias']);
$this->assertEquals($login, $user['login']);
}
-
+
/**
* normal test case
- *
+ *
* @group Plugins
* @group UsersManager
*/
public function testAddUser()
{
- $login ="geggeq55eqag";
+ $login = "geggeq55eqag";
$password = "mypassword";
$email = "mgeag4544i@geq.com";
$alias = "her is my alias )(&|\" '£%*(&%+))";
-
+
$time = time();
Piwik_UsersManager_API::getInstance()->addUser($login, $password, $email, $alias);
$user = Piwik_UsersManager_API::getInstance()->getUser($login);
-
+
// check that the date registered is correct
- $this->assertTrue( $time <= strtotime($user['date_registered']) && strtotime($user['date_registered']) <= time(),
- "the date_registered ".strtotime($user['date_registered'])." is different from the time() ". time());
- $this->assertTrue($user['date_registered'] <= time() );
-
+ $this->assertTrue($time <= strtotime($user['date_registered']) && strtotime($user['date_registered']) <= time(),
+ "the date_registered " . strtotime($user['date_registered']) . " is different from the time() " . time());
+ $this->assertTrue($user['date_registered'] <= time());
+
// check that token is 32 chars
$this->assertEquals(32, strlen($user['password']));
-
+
// that the password has been md5
- $this->assertEquals(md5($login.md5($password)), $user['token_auth']);
-
+ $this->assertEquals(md5($login . md5($password)), $user['token_auth']);
+
// check that all fields are the same
$this->assertEquals($login, $user['login']);
$this->assertEquals(md5($password), $user['password']);
$this->assertEquals($email, $user['email']);
$this->assertEquals($alias, $user['alias']);
}
-
+
/**
* user doesnt exist => exception
- *
+ *
* @group Plugins
* @group UsersManager
*/
public function testSeleteUserDoesntExist()
- {
+ {
Piwik_UsersManager_API::getInstance()->addUser("geggeqgeqag", "geqgeagae", "test@test.com", "alias");
-
+
try {
Piwik_UsersManager_API::getInstance()->deleteUser("geggeqggnew");
- }
- catch (Exception $expected) {
+ } catch (Exception $expected) {
$this->assertRegExp("(UsersManager_ExceptionDeleteDoesNotExist)", $expected->getMessage());
return;
}
$this->fail("Exception not raised.");
}
-
+
/**
* empty name, doesnt exists =>exception
- *
+ *
* @group Plugins
* @group UsersManager
*/
@@ -370,17 +361,16 @@ class UsersManagerTest extends DatabaseTestCase
{
try {
Piwik_UsersManager_API::getInstance()->deleteUser("");
- }
- catch (Exception $expected) {
+ } catch (Exception $expected) {
$this->assertRegExp("(UsersManager_ExceptionDeleteDoesNotExist)", $expected->getMessage());
return;
}
$this->fail("Exception not raised.");
}
-
+
/**
* null user,, doesnt exists => exception
- *
+ *
* @group Plugins
* @group UsersManager
*/
@@ -388,59 +378,57 @@ class UsersManagerTest extends DatabaseTestCase
{
try {
Piwik_UsersManager_API::getInstance()->deleteUser(null);
- }
- catch (Exception $expected) {
+ } catch (Exception $expected) {
$this->assertRegExp("(UsersManager_ExceptionDeleteDoesNotExist)", $expected->getMessage());
return;
}
$this->fail("Exception not raised.");
}
-
+
/**
* normal case, user deleted
- *
+ *
* @group Plugins
* @group UsersManager
*/
public function testDeleteUser()
{
//create the 3 websites
- $idsite = Piwik_SitesManager_API::getInstance()->addSite("site1",array("http://piwik.net","http://piwik.com/test/"));
- $idsite = Piwik_SitesManager_API::getInstance()->addSite("site2",array("http://piwik.com/test/"));
- $idsite = Piwik_SitesManager_API::getInstance()->addSite("site3",array("http://piwik.org"));
-
+ $idsite = Piwik_SitesManager_API::getInstance()->addSite("site1", array("http://piwik.net", "http://piwik.com/test/"));
+ $idsite = Piwik_SitesManager_API::getInstance()->addSite("site2", array("http://piwik.com/test/"));
+ $idsite = Piwik_SitesManager_API::getInstance()->addSite("site3", array("http://piwik.org"));
+
//add user and set some rights
Piwik_UsersManager_API::getInstance()->addUser("geggeqgeqag", "geqgeagae", "test@test.com", "alias");
- Piwik_UsersManager_API::getInstance()->setUserAccess("geggeqgeqag", "view", array(1,2));
- Piwik_UsersManager_API::getInstance()->setUserAccess("geggeqgeqag", "admin", array(1,3));
-
+ Piwik_UsersManager_API::getInstance()->setUserAccess("geggeqgeqag", "view", array(1, 2));
+ Piwik_UsersManager_API::getInstance()->setUserAccess("geggeqgeqag", "admin", array(1, 3));
+
// check rights are set
$this->assertNotEquals(array(), Piwik_UsersManager_API::getInstance()->getSitesAccessFromUser("geggeqgeqag"));
-
+
// delete the user
Piwik_UsersManager_API::getInstance()->deleteUser("geggeqgeqag");
-
+
// try to get it, it should raise an exception
try {
$user = Piwik_UsersManager_API::getInstance()->getUser("geggeqgeqag");
$this->fail("Exception not raised.");
- }
- catch (Exception $expected) {
+ } catch (Exception $expected) {
$this->assertRegExp("(UsersManager_ExceptionUserDoesNotExist)", $expected->getMessage());
}
// add the same user
Piwik_UsersManager_API::getInstance()->addUser("geggeqgeqag", "geqgeagae", "test@test.com", "alias");
-
+
//checks access have been deleted
//to do so we recreate the same user login and check if the rights are still there
$this->assertEquals(array(), Piwik_UsersManager_API::getInstance()->getSitesAccessFromUser("geggeqgeqag"));
}
-
-
+
+
/**
* no user => exception
- *
+ *
* @group Plugins
* @group UsersManager
*/
@@ -449,44 +437,43 @@ class UsersManagerTest extends DatabaseTestCase
// try to get it, it should raise an exception
try {
$user = Piwik_UsersManager_API::getInstance()->getUser("geggeqgeqag");
- }
- catch (Exception $expected) {
+ } catch (Exception $expected) {
$this->assertRegExp("(UsersManager_ExceptionUserDoesNotExist)", $expected->getMessage());
return;
}
-
+
$this->fail("Exception not raised.");
}
-
+
/**
* normal case
- *
+ *
* @group Plugins
* @group UsersManager
*/
public function test_GetUser()
{
- $login ="geggeq55eqag";
+ $login = "geggeq55eqag";
$password = "mypassword";
$email = "mgeag4544i@geq.com";
$alias = "";
-
+
Piwik_UsersManager_API::getInstance()->addUser($login, $password, $email, $alias);
$user = Piwik_UsersManager_API::getInstance()->getUser($login);
-
+
// check that all fields are the same
$this->assertEquals($login, $user['login']);
$this->assertInternalType('string', $user['password']);
$this->assertInternalType('string', $user['date_registered']);
$this->assertEquals($email, $user['email']);
-
+
//alias shouldnt be empty even if no alias specified
$this->assertGreaterThan(0, strlen($user['alias']));
}
-
+
/**
* no user => empty array
- *
+ *
* @group Plugins
* @group UsersManager
*/
@@ -494,11 +481,11 @@ class UsersManagerTest extends DatabaseTestCase
{
$this->assertEquals(Piwik_UsersManager_API::getInstance()->getUsers(), array());
}
-
+
/**
* normal case
* as well as selecting specific user names, comma separated
- *
+ *
* @group Plugins
* @group UsersManager
*/
@@ -507,51 +494,50 @@ class UsersManagerTest extends DatabaseTestCase
Piwik_UsersManager_API::getInstance()->addUser("gegg4564eqgeqag", "geqgegagae", "tegst@tesgt.com", "alias");
Piwik_UsersManager_API::getInstance()->addUser("geggeqge632ge56a4qag", "geqgegeagae", "tesggt@tesgt.com", "alias");
Piwik_UsersManager_API::getInstance()->addUser("geggeqgeqagqegg", "geqgeaggggae", "tesgggt@tesgt.com");
-
+
$users = Piwik_UsersManager_API::getInstance()->getUsers();
$users = $this->_removeNonTestableFieldsFromUsers($users);
- $user1 = array('login' => "gegg4564eqgeqag", 'password' => md5("geqgegagae"), 'alias' => "alias", 'email' => "tegst@tesgt.com");
- $user2 = array('login' => "geggeqge632ge56a4qag", 'password' => md5("geqgegeagae"),'alias' => "alias", 'email' => "tesggt@tesgt.com");
- $user3 = array('login' => "geggeqgeqagqegg", 'password' => md5("geqgeaggggae"), 'alias' => 'geggeqgeqagqegg','email' => "tesgggt@tesgt.com");
+ $user1 = array('login' => "gegg4564eqgeqag", 'password' => md5("geqgegagae"), 'alias' => "alias", 'email' => "tegst@tesgt.com");
+ $user2 = array('login' => "geggeqge632ge56a4qag", 'password' => md5("geqgegeagae"), 'alias' => "alias", 'email' => "tesggt@tesgt.com");
+ $user3 = array('login' => "geggeqgeqagqegg", 'password' => md5("geqgeaggggae"), 'alias' => 'geggeqgeqagqegg', 'email' => "tesgggt@tesgt.com");
$expectedUsers = array($user1, $user2, $user3);
$this->assertEquals($expectedUsers, $users);
$this->assertEquals(array($user1), $this->_removeNonTestableFieldsFromUsers(Piwik_UsersManager_API::getInstance()->getUsers('gegg4564eqgeqag')));
$this->assertEquals(array($user1, $user2), $this->_removeNonTestableFieldsFromUsers(Piwik_UsersManager_API::getInstance()->getUsers('gegg4564eqgeqag,geggeqge632ge56a4qag')));
-
+
}
-
+
protected function _removeNonTestableFieldsFromUsers($users)
{
- foreach($users as &$user)
- {
+ foreach ($users as &$user) {
unset($user['token_auth']);
unset($user['date_registered']);
}
return $users;
}
-
+
/**
* normal case
- *
+ *
* @group Plugins
* @group UsersManager
*/
public function testGetUsersLogin()
{
-
+
Piwik_UsersManager_API::getInstance()->addUser("gegg4564eqgeqag", "geqgegagae", "tegst@tesgt.com", "alias");
Piwik_UsersManager_API::getInstance()->addUser("geggeqge632ge56a4qag", "geqgegeagae", "tesggt@tesgt.com", "alias");
Piwik_UsersManager_API::getInstance()->addUser("geggeqgeqagqegg", "geqgeaggggae", "tesgggt@tesgt.com");
-
+
$logins = Piwik_UsersManager_API::getInstance()->getUsersLogin();
-
+
$this->assertEquals(array("gegg4564eqgeqag", "geggeqge632ge56a4qag", "geggeqgeqagqegg"), $logins);
}
-
-
+
+
/**
* no login => exception
- *
+ *
* @group Plugins
* @group UsersManager
*/
@@ -560,89 +546,87 @@ class UsersManagerTest extends DatabaseTestCase
// try to get it, it should raise an exception
try {
Piwik_UsersManager_API::getInstance()->setUserAccess("nologin", "view", 1);
- }
- catch (Exception $expected) {
+ } catch (Exception $expected) {
$this->assertRegExp("(UsersManager_ExceptionUserDoesNotExist)", $expected->getMessage());
return;
}
$this->fail("Exception not raised.");
}
-
+
/**
* wrong access specified => exception
- *
+ *
* @group Plugins
* @group UsersManager
*/
public function testSetUserAccessWrongAccess()
{
Piwik_UsersManager_API::getInstance()->addUser("gegg4564eqgeqag", "geqgegagae", "tegst@tesgt.com", "alias");
-
+
// try to get it, it should raise an exception
try {
Piwik_UsersManager_API::getInstance()->setUserAccess("gegg4564eqgeqag", "viewnotknown", 1);
- }
- catch (Exception $expected) {
+ } catch (Exception $expected) {
$this->assertRegExp("(UsersManager_ExceptionAccessValues)", $expected->getMessage());
return;
}
$this->fail("Exception not raised.");
}
-
+
/**
* idsites = all => apply access to all websites with admin access
- *
+ *
* @group Plugins
* @group UsersManager
*/
public function testSetUserAccessIdsitesIsAll()
{
Piwik_UsersManager_API::getInstance()->addUser("gegg4564eqgeqag", "geqgegagae", "tegst@tesgt.com", "alias");
-
+
FakeAccess::$superUser = false;
-
+
Piwik_UsersManager_API::getInstance()->setUserAccess("gegg4564eqgeqag", "view", "all");
-
+
FakeAccess::$superUser = true;
$access = Piwik_UsersManager_API::getInstance()->getSitesAccessFromUser("gegg4564eqgeqag");
$access = $this->_flatten($access);
-
+
FakeAccess::$superUser = false;
- $this->assertEquals( array_keys($access), FakeAccess::getSitesIdWithAdminAccess());
-
+ $this->assertEquals(array_keys($access), FakeAccess::getSitesIdWithAdminAccess());
+
// we want to test the case for which we have actually set some rights
// if this is not OK then change the setUp method and add some admin rights for some websites
$this->assertGreaterThan(0, count(array_keys($access)));
}
-
+
/**
* idsites = all AND user is superuser=> apply access to all websites
- *
+ *
* @group Plugins
* @group UsersManager
*/
public function testSetUserAccessIdsitesIsAllSuperuser()
{
FakeAccess::$superUser = true;
-
- $id1=Piwik_SitesManager_API::getInstance()->addSite("test",array("http://piwik.net","http://piwik.com/test/"));
- $id2=Piwik_SitesManager_API::getInstance()->addSite("test2",array("http://piwik.net","http://piwik.com/test/"));
- $id3=Piwik_SitesManager_API::getInstance()->addSite("test3",array("http://piwik.net","http://piwik.com/test/"));
- $id4=Piwik_SitesManager_API::getInstance()->addSite("test4",array("http://piwik.net","http://piwik.com/test/"));
- $id5=Piwik_SitesManager_API::getInstance()->addSite("test5",array("http://piwik.net","http://piwik.com/test/"));
-
+
+ $id1 = Piwik_SitesManager_API::getInstance()->addSite("test", array("http://piwik.net", "http://piwik.com/test/"));
+ $id2 = Piwik_SitesManager_API::getInstance()->addSite("test2", array("http://piwik.net", "http://piwik.com/test/"));
+ $id3 = Piwik_SitesManager_API::getInstance()->addSite("test3", array("http://piwik.net", "http://piwik.com/test/"));
+ $id4 = Piwik_SitesManager_API::getInstance()->addSite("test4", array("http://piwik.net", "http://piwik.com/test/"));
+ $id5 = Piwik_SitesManager_API::getInstance()->addSite("test5", array("http://piwik.net", "http://piwik.com/test/"));
+
Piwik_UsersManager_API::getInstance()->addUser("gegg4564eqgeqag", "geqgegagae", "tegst@tesgt.com", "alias");
Piwik_UsersManager_API::getInstance()->setUserAccess("gegg4564eqgeqag", "view", "all");
-
+
$access = Piwik_UsersManager_API::getInstance()->getSitesAccessFromUser("gegg4564eqgeqag");
$access = $this->_flatten($access);
- $this->assertEquals( array($id1,$id2,$id3,$id4,$id5), array_keys($access));
-
+ $this->assertEquals(array($id1, $id2, $id3, $id4, $id5), array_keys($access));
+
}
-
+
/**
* idsites is empty => no acccess set
- *
+ *
* @group Plugins
* @group UsersManager
*/
@@ -650,98 +634,98 @@ class UsersManagerTest extends DatabaseTestCase
{
Piwik_UsersManager_API::getInstance()->addUser("gegg4564eqgeqag", "geqgegagae", "tegst@tesgt.com", "alias");
- try {
- Piwik_UsersManager_API::getInstance()->setUserAccess("gegg4564eqgeqag", "view", array());
- $access = Piwik_UsersManager_API::getInstance()->getSitesAccessFromUser("gegg4564eqgeqag");
- } catch(Exception $e) {
- return;
- }
- $this->fail('Expected exception not raised');
+ try {
+ Piwik_UsersManager_API::getInstance()->setUserAccess("gegg4564eqgeqag", "view", array());
+ $access = Piwik_UsersManager_API::getInstance()->getSitesAccessFromUser("gegg4564eqgeqag");
+ } catch (Exception $e) {
+ return;
+ }
+ $this->fail('Expected exception not raised');
}
-
+
/**
* normal case, access set for only one site
- *
+ *
* @group Plugins
* @group UsersManager
*/
public function testSetUserAccessIdsitesOneSite()
{
Piwik_UsersManager_API::getInstance()->addUser("gegg4564eqgeqag", "geqgegagae", "tegst@tesgt.com", "alias");
- $id1=Piwik_SitesManager_API::getInstance()->addSite("test",array("http://piwik.net","http://piwik.com/test/"));
-
+ $id1 = Piwik_SitesManager_API::getInstance()->addSite("test", array("http://piwik.net", "http://piwik.com/test/"));
+
Piwik_UsersManager_API::getInstance()->setUserAccess("gegg4564eqgeqag", "view", array(1));
-
+
$access = Piwik_UsersManager_API::getInstance()->getSitesAccessFromUser("gegg4564eqgeqag");
$access = $this->_flatten($access);
- $this->assertEquals( array(1), array_keys($access));
+ $this->assertEquals(array(1), array_keys($access));
}
-
+
/**
* normal case, access set for multiple sites
- *
+ *
* @group Plugins
* @group UsersManager
*/
public function testSetUserAccessIdsitesMultipleSites()
{
-
+
Piwik_UsersManager_API::getInstance()->addUser("gegg4564eqgeqag", "geqgegagae", "tegst@tesgt.com", "alias");
- $id1=Piwik_SitesManager_API::getInstance()->addSite("test",array("http://piwik.net","http://piwik.com/test/"));
- $id2=Piwik_SitesManager_API::getInstance()->addSite("test",array("http://piwik.net","http://piwik.com/test/"));
- $id3=Piwik_SitesManager_API::getInstance()->addSite("test",array("http://piwik.net","http://piwik.com/test/"));
-
- Piwik_UsersManager_API::getInstance()->setUserAccess("gegg4564eqgeqag", "view", array($id1,$id3));
-
+ $id1 = Piwik_SitesManager_API::getInstance()->addSite("test", array("http://piwik.net", "http://piwik.com/test/"));
+ $id2 = Piwik_SitesManager_API::getInstance()->addSite("test", array("http://piwik.net", "http://piwik.com/test/"));
+ $id3 = Piwik_SitesManager_API::getInstance()->addSite("test", array("http://piwik.net", "http://piwik.com/test/"));
+
+ Piwik_UsersManager_API::getInstance()->setUserAccess("gegg4564eqgeqag", "view", array($id1, $id3));
+
$access = Piwik_UsersManager_API::getInstance()->getSitesAccessFromUser("gegg4564eqgeqag");
$access = $this->_flatten($access);
- $this->assertEquals( array($id1,$id3), array_keys($access));
-
+ $this->assertEquals(array($id1, $id3), array_keys($access));
+
}
-
+
/**
* normal case, string idSites comma separated access set for multiple sites
- *
+ *
* @group Plugins
* @group UsersManager
*/
public function testSetUserAccessWithIdSitesIsStringCommaSeparated()
{
Piwik_UsersManager_API::getInstance()->addUser("gegg4564eqgeqag", "geqgegagae", "tegst@tesgt.com", "alias");
- $id1=Piwik_SitesManager_API::getInstance()->addSite("test",array("http://piwik.net","http://piwik.com/test/"));
- $id2=Piwik_SitesManager_API::getInstance()->addSite("test",array("http://piwik.net","http://piwik.com/test/"));
- $id3=Piwik_SitesManager_API::getInstance()->addSite("test",array("http://piwik.net","http://piwik.com/test/"));
-
+ $id1 = Piwik_SitesManager_API::getInstance()->addSite("test", array("http://piwik.net", "http://piwik.com/test/"));
+ $id2 = Piwik_SitesManager_API::getInstance()->addSite("test", array("http://piwik.net", "http://piwik.com/test/"));
+ $id3 = Piwik_SitesManager_API::getInstance()->addSite("test", array("http://piwik.net", "http://piwik.com/test/"));
+
Piwik_UsersManager_API::getInstance()->setUserAccess("gegg4564eqgeqag", "view", "1,3");
-
+
$access = Piwik_UsersManager_API::getInstance()->getSitesAccessFromUser("gegg4564eqgeqag");
$access = $this->_flatten($access);
- $this->assertEquals( array($id1,$id3), array_keys($access));
+ $this->assertEquals(array($id1, $id3), array_keys($access));
}
-
+
/**
* normal case, set different acccess to different websites for one user
- *
+ *
* @group Plugins
* @group UsersManager
*/
public function testSetUserAccessMultipleCallDistinctAccessSameUser()
{
Piwik_UsersManager_API::getInstance()->addUser("gegg4564eqgeqag", "geqgegagae", "tegst@tesgt.com", "alias");
- $id1=Piwik_SitesManager_API::getInstance()->addSite("test",array("http://piwik.net","http://piwik.com/test/"));
- $id2=Piwik_SitesManager_API::getInstance()->addSite("test",array("http://piwik.net","http://piwik.com/test/"));
-
+ $id1 = Piwik_SitesManager_API::getInstance()->addSite("test", array("http://piwik.net", "http://piwik.com/test/"));
+ $id2 = Piwik_SitesManager_API::getInstance()->addSite("test", array("http://piwik.net", "http://piwik.com/test/"));
+
Piwik_UsersManager_API::getInstance()->setUserAccess("gegg4564eqgeqag", "view", array($id1));
Piwik_UsersManager_API::getInstance()->setUserAccess("gegg4564eqgeqag", "admin", array($id2));
-
+
$access = Piwik_UsersManager_API::getInstance()->getSitesAccessFromUser("gegg4564eqgeqag");
$access = $this->_flatten($access);
- $this->assertEquals( array($id1=>'view',$id2=>'admin'), $access);
+ $this->assertEquals(array($id1 => 'view', $id2 => 'admin'), $access);
}
-
+
/**
* normal case, set different access to different websites for multiple users
- *
+ *
* @group Plugins
* @group UsersManager
*/
@@ -749,44 +733,44 @@ class UsersManagerTest extends DatabaseTestCase
{
Piwik_UsersManager_API::getInstance()->addUser("user1", "geqgegagae", "tegst@tesgt.com", "alias");
Piwik_UsersManager_API::getInstance()->addUser("user2", "geqgegagae", "tegst2@tesgt.com", "alias");
- $id1=Piwik_SitesManager_API::getInstance()->addSite("test1",array("http://piwik.net","http://piwik.com/test/"));
- $id2=Piwik_SitesManager_API::getInstance()->addSite("test2",array("http://piwik.net","http://piwik.com/test/"));
- $id3=Piwik_SitesManager_API::getInstance()->addSite("test2",array("http://piwik.net","http://piwik.com/test/"));
-
- Piwik_UsersManager_API::getInstance()->setUserAccess("user1", "view", array($id1,$id2));
+ $id1 = Piwik_SitesManager_API::getInstance()->addSite("test1", array("http://piwik.net", "http://piwik.com/test/"));
+ $id2 = Piwik_SitesManager_API::getInstance()->addSite("test2", array("http://piwik.net", "http://piwik.com/test/"));
+ $id3 = Piwik_SitesManager_API::getInstance()->addSite("test2", array("http://piwik.net", "http://piwik.com/test/"));
+
+ Piwik_UsersManager_API::getInstance()->setUserAccess("user1", "view", array($id1, $id2));
Piwik_UsersManager_API::getInstance()->setUserAccess("user2", "admin", array($id1));
Piwik_UsersManager_API::getInstance()->setUserAccess("user2", "view", array($id3, $id2));
-
+
$access1 = Piwik_UsersManager_API::getInstance()->getSitesAccessFromUser("user1");
$access1 = $this->_flatten($access1);
$access2 = Piwik_UsersManager_API::getInstance()->getSitesAccessFromUser("user2");
$access2 = $this->_flatten($access2);
- $wanted1 = array( $id1 => 'view', $id2 => 'view', );
- $wanted2 = array( $id1 => 'admin', $id2 => 'view', $id3 => 'view' );
-
+ $wanted1 = array($id1 => 'view', $id2 => 'view',);
+ $wanted2 = array($id1 => 'admin', $id2 => 'view', $id3 => 'view');
+
$this->assertEquals($wanted1, $access1);
$this->assertEquals($wanted2, $access2);
-
-
+
+
$access1 = Piwik_UsersManager_API::getInstance()->getUsersAccessFromSite($id1);
$access2 = Piwik_UsersManager_API::getInstance()->getUsersAccessFromSite($id2);
$access3 = Piwik_UsersManager_API::getInstance()->getUsersAccessFromSite($id3);
- $wanted1 = array( 'user1' => 'view', 'user2' => 'admin', );
- $wanted2 = array( 'user1' => 'view', 'user2' => 'view' );
- $wanted3 = array( 'user2' => 'view' );
-
+ $wanted1 = array('user1' => 'view', 'user2' => 'admin',);
+ $wanted2 = array('user1' => 'view', 'user2' => 'view');
+ $wanted3 = array('user2' => 'view');
+
$this->assertEquals($wanted1, $access1);
$this->assertEquals($wanted2, $access2);
$this->assertEquals($wanted3, $access3);
-
+
$access1 = Piwik_UsersManager_API::getInstance()->getUsersSitesFromAccess('view');
$access2 = Piwik_UsersManager_API::getInstance()->getUsersSitesFromAccess('admin');
- $wanted1 = array( 'user1' => array($id1,$id2), 'user2' => array($id2, $id3) );
- $wanted2 = array( 'user2' => array($id1) );
-
+ $wanted1 = array('user1' => array($id1, $id2), 'user2' => array($id2, $id3));
+ $wanted2 = array('user2' => array($id1));
+
$this->assertEquals($wanted1, $access1);
$this->assertEquals($wanted2, $access2);
-
+
// Test getUsersWithSiteAccess
$users = Piwik_UsersManager_API::getInstance()->getUsersWithSiteAccess($id1, $access = 'view');
$this->assertEquals(1, count($users));
@@ -799,33 +783,33 @@ class UsersManagerTest extends DatabaseTestCase
$users = Piwik_UsersManager_API::getInstance()->getUsersWithSiteAccess($id3, $access = 'admin');
$this->assertEquals(0, count($users));
}
-
+
/**
* we set access for one user for one site several times and check that it is updated
- *
+ *
* @group Plugins
* @group UsersManager
*/
public function testSetUserAccessMultipleCallOverwriteSingleUserOneSite()
{
Piwik_UsersManager_API::getInstance()->addUser("user1", "geqgegagae", "tegst@tesgt.com", "alias");
-
- $id1=Piwik_SitesManager_API::getInstance()->addSite("test1",array("http://piwik.net","http://piwik.com/test/"));
- $id2=Piwik_SitesManager_API::getInstance()->addSite("test2",array("http://piwik.net","http://piwik.com/test/"));
-
- Piwik_UsersManager_API::getInstance()->setUserAccess("user1", "view", array($id1,$id2));
+
+ $id1 = Piwik_SitesManager_API::getInstance()->addSite("test1", array("http://piwik.net", "http://piwik.com/test/"));
+ $id2 = Piwik_SitesManager_API::getInstance()->addSite("test2", array("http://piwik.net", "http://piwik.com/test/"));
+
+ Piwik_UsersManager_API::getInstance()->setUserAccess("user1", "view", array($id1, $id2));
Piwik_UsersManager_API::getInstance()->setUserAccess("user1", "admin", array($id1));
-
+
$access1 = Piwik_UsersManager_API::getInstance()->getSitesAccessFromUser("user1");
$access1 = $this->_flatten($access1);
- $wanted1 = array( $id1 => 'admin', $id2 => 'view', );
-
+ $wanted1 = array($id1 => 'admin', $id2 => 'view',);
+
$this->assertEquals($wanted1, $access1);
}
-
+
/**
* wrong user => exception
- *
+ *
* @group Plugins
* @group UsersManager
*/
@@ -833,17 +817,16 @@ class UsersManagerTest extends DatabaseTestCase
{
try {
$access1 = Piwik_UsersManager_API::getInstance()->getSitesAccessFromUser("user1");
- }
- catch (Exception $expected) {
+ } catch (Exception $expected) {
$this->assertRegExp("(UsersManager_ExceptionUserDoesNotExist)", $expected->getMessage());
return;
}
$this->fail("Exception not raised.");
}
-
+
/**
*wrong idsite => exception
- *
+ *
* @group Plugins
* @group UsersManager
*/
@@ -856,10 +839,10 @@ class UsersManagerTest extends DatabaseTestCase
}
$this->fail('Expected exception not raised');
}
-
+
/**
* wrong access =>exception
- *
+ *
* @group Plugins
* @group UsersManager
*/
@@ -867,99 +850,97 @@ class UsersManagerTest extends DatabaseTestCase
{
try {
$access1 = Piwik_UsersManager_API::getInstance()->getUsersSitesFromAccess('unknown');
- }
- catch (Exception $expected) {
+ } catch (Exception $expected) {
$this->assertRegExp("(UsersManager_ExceptionAccessValues)", $expected->getMessage());
return;
}
$this->fail("Exception not raised.");
}
-
+
/**
* non existing login => exception
- *
+ *
* @group Plugins
* @group UsersManager
*/
public function testUpdateUserWrongLogin()
{
try {
- Piwik_UsersManager_API::getInstance()->updateUser( "lolgin", "password");
- }
- catch (Exception $expected) {
+ Piwik_UsersManager_API::getInstance()->updateUser("lolgin", "password");
+ } catch (Exception $expected) {
$this->assertRegExp("(UsersManager_ExceptionUserDoesNotExist)", $expected->getMessage());
return;
}
$this->fail("Exception not raised.");
}
-
-
+
+
/**
* no email no alias => keep old ones
- *
+ *
* @group Plugins
* @group UsersManager
*/
public function testUpdateUserNoEmailNoAlias()
{
- $login="login";
- $user = array('login'=>$login,
- 'password'=>"geqgeagae",
- 'email'=>"test@test.com",
- 'alias'=>"alias");
-
- Piwik_UsersManager_API::getInstance()->addUser($user['login'],$user['password'] ,$user['email'] ,$user['alias'] );
-
- Piwik_UsersManager_API::getInstance()->updateUser( $login, "passowordOK");
-
+ $login = "login";
+ $user = array('login' => $login,
+ 'password' => "geqgeagae",
+ 'email' => "test@test.com",
+ 'alias' => "alias");
+
+ Piwik_UsersManager_API::getInstance()->addUser($user['login'], $user['password'], $user['email'], $user['alias']);
+
+ Piwik_UsersManager_API::getInstance()->updateUser($login, "passowordOK");
+
$this->_checkUserHasNotChanged($user, "passowordOK");
}
-
+
/**
*no email => keep old ones
- *
+ *
* @group Plugins
* @group UsersManager
*/
public function testUpdateUserNoEmail()
{
- $login="login";
- $user = array('login'=>$login,
- 'password'=>"geqgeagae",
- 'email'=>"test@test.com",
- 'alias'=>"alias");
-
- Piwik_UsersManager_API::getInstance()->addUser($user['login'],$user['password'] ,$user['email'] ,$user['alias'] );
-
- Piwik_UsersManager_API::getInstance()->updateUser( $login, "passowordOK", null, "newalias");
-
+ $login = "login";
+ $user = array('login' => $login,
+ 'password' => "geqgeagae",
+ 'email' => "test@test.com",
+ 'alias' => "alias");
+
+ Piwik_UsersManager_API::getInstance()->addUser($user['login'], $user['password'], $user['email'], $user['alias']);
+
+ Piwik_UsersManager_API::getInstance()->updateUser($login, "passowordOK", null, "newalias");
+
$this->_checkUserHasNotChanged($user, "passowordOK", null, "newalias");
}
-
+
/**
* no alias => keep old ones
- *
+ *
* @group Plugins
* @group UsersManager
*/
public function testUpdateUserNoAlias()
{
- $login="login";
- $user = array('login'=>$login,
- 'password'=>"geqgeagae",
- 'email'=>"test@test.com",
- 'alias'=>"alias");
-
- Piwik_UsersManager_API::getInstance()->addUser($user['login'],$user['password'] ,$user['email'] ,$user['alias'] );
-
- Piwik_UsersManager_API::getInstance()->updateUser( $login, "passowordOK", "email@geaga.com");
-
+ $login = "login";
+ $user = array('login' => $login,
+ 'password' => "geqgeagae",
+ 'email' => "test@test.com",
+ 'alias' => "alias");
+
+ Piwik_UsersManager_API::getInstance()->addUser($user['login'], $user['password'], $user['email'], $user['alias']);
+
+ Piwik_UsersManager_API::getInstance()->updateUser($login, "passowordOK", "email@geaga.com");
+
$this->_checkUserHasNotChanged($user, "passowordOK", "email@geaga.com");
}
-
+
/**
* check to modify as the user
- *
+ *
* @group Plugins
* @group UsersManager
*/
@@ -968,10 +949,10 @@ class UsersManagerTest extends DatabaseTestCase
FakeAccess::$identity = 'login';
$this->testUpdateUserNoEmailNoAlias();
}
-
+
/**
* check to modify as being another user => exception
- *
+ *
* @group Plugins
* @group UsersManager
*/
@@ -986,31 +967,31 @@ class UsersManagerTest extends DatabaseTestCase
}
$this->fail('Expected exception not raised');
}
-
+
/**
* normal case, reused in other tests
- *
+ *
* @group Plugins
* @group UsersManager
*/
public function testUpdateUser()
{
- $login="login";
- $user = array('login'=>$login,
- 'password'=>"geqgeagae",
- 'email'=>"test@test.com",
- 'alias'=>"alias");
-
- Piwik_UsersManager_API::getInstance()->addUser($user['login'],$user['password'] ,$user['email'] ,$user['alias'] );
-
- Piwik_UsersManager_API::getInstance()->updateUser( $login, "passowordOK", "email@geaga.com", "NEW ALIAS");
-
+ $login = "login";
+ $user = array('login' => $login,
+ 'password' => "geqgeagae",
+ 'email' => "test@test.com",
+ 'alias' => "alias");
+
+ Piwik_UsersManager_API::getInstance()->addUser($user['login'], $user['password'], $user['email'], $user['alias']);
+
+ Piwik_UsersManager_API::getInstance()->updateUser($login, "passowordOK", "email@geaga.com", "NEW ALIAS");
+
$this->_checkUserHasNotChanged($user, "passowordOK", "email@geaga.com", "NEW ALIAS");
}
-
+
/**
* test getUserByEmail invalid mail
- *
+ *
* @group Plugins
* @group UsersManager
*/
@@ -1023,10 +1004,10 @@ class UsersManagerTest extends DatabaseTestCase
}
$this->fail('Expected exception not raised');
}
-
+
/**
* test getUserByEmail
- *
+ *
* @group Plugins
* @group UsersManager
*/
@@ -1036,14 +1017,14 @@ class UsersManagerTest extends DatabaseTestCase
'password' => "geqgeagae",
'email' => "test@test.com",
'alias' => "alias");
-
- Piwik_UsersManager_API::getInstance()->addUser($user['login'],$user['password'] ,$user['email'] ,$user['alias'] );
-
+
+ Piwik_UsersManager_API::getInstance()->addUser($user['login'], $user['password'], $user['email'], $user['alias']);
+
$userByMail = Piwik_UsersManager_API::getInstance()->getUserByEmail($user['email']);
-
+
$this->assertEquals($user['login'], $userByMail['login']);
$this->assertEquals($user['email'], $userByMail['email']);
$this->assertEquals($user['alias'], $userByMail['alias']);
}
-
+
}
diff --git a/tests/PHPUnit/bootstrap.php b/tests/PHPUnit/bootstrap.php
index d7fce36cc5..882f3ae579 100644
--- a/tests/PHPUnit/bootstrap.php
+++ b/tests/PHPUnit/bootstrap.php
@@ -1,18 +1,14 @@
<?php
-if(!defined("PIWIK_PATH_TEST_TO_ROOT"))
-{
+if (!defined("PIWIK_PATH_TEST_TO_ROOT")) {
define('PIWIK_PATH_TEST_TO_ROOT', realpath(dirname(__FILE__) . '/../..'));
}
-if(!defined('PIWIK_USER_PATH'))
-{
+if (!defined('PIWIK_USER_PATH')) {
define('PIWIK_USER_PATH', PIWIK_PATH_TEST_TO_ROOT);
}
-if(!defined('PIWIK_INCLUDE_PATH'))
-{
+if (!defined('PIWIK_INCLUDE_PATH')) {
define('PIWIK_INCLUDE_PATH', PIWIK_PATH_TEST_TO_ROOT);
}
-if(!defined('PIWIK_INCLUDE_SEARCH_PATH'))
-{
+if (!defined('PIWIK_INCLUDE_SEARCH_PATH')) {
define('PIWIK_INCLUDE_SEARCH_PATH', get_include_path()
. PATH_SEPARATOR . PIWIK_INCLUDE_PATH . '/core'
. PATH_SEPARATOR . PIWIK_INCLUDE_PATH . '/libs'
@@ -21,27 +17,26 @@ if(!defined('PIWIK_INCLUDE_SEARCH_PATH'))
@ini_set('include_path', PIWIK_INCLUDE_SEARCH_PATH);
@set_include_path(PIWIK_INCLUDE_SEARCH_PATH);
@ini_set('memory_limit', -1);
-error_reporting(E_ALL|E_NOTICE);
+error_reporting(E_ALL | E_NOTICE);
@date_default_timezone_set('UTC');
-require_once PIWIK_INCLUDE_PATH .'/libs/upgradephp/upgrade.php';
-require_once PIWIK_INCLUDE_PATH .'/core/testMinimumPhpVersion.php';
-require_once PIWIK_INCLUDE_PATH .'/core/Loader.php';
-require_once PIWIK_INCLUDE_PATH .'/core/FrontController.php';
-require_once PIWIK_INCLUDE_PATH .'/tests/PHPUnit/DatabaseTestCase.php';
-require_once PIWIK_INCLUDE_PATH .'/tests/PHPUnit/IntegrationTestCase.php';
-require_once PIWIK_INCLUDE_PATH .'/tests/PHPUnit/FakeAccess.php';
-require_once PIWIK_INCLUDE_PATH .'/tests/PHPUnit/MockPiwikOption.php';
-require_once PIWIK_INCLUDE_PATH .'/tests/PHPUnit/MockEventDispatcher.php';
+require_once PIWIK_INCLUDE_PATH . '/libs/upgradephp/upgrade.php';
+require_once PIWIK_INCLUDE_PATH . '/core/testMinimumPhpVersion.php';
+require_once PIWIK_INCLUDE_PATH . '/core/Loader.php';
+require_once PIWIK_INCLUDE_PATH . '/core/FrontController.php';
+require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/DatabaseTestCase.php';
+require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/IntegrationTestCase.php';
+require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/FakeAccess.php';
+require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/MockPiwikOption.php';
+require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/MockEventDispatcher.php';
// required to build code coverage for uncovered files
-require_once PIWIK_INCLUDE_PATH .'/plugins/SecurityInfo/PhpSecInfo/PhpSecInfo.php';
+require_once PIWIK_INCLUDE_PATH . '/plugins/SecurityInfo/PhpSecInfo/PhpSecInfo.php';
// require test fixtures
-require_once PIWIK_INCLUDE_PATH.'/tests/PHPUnit/BaseFixture.php';
-foreach (glob(PIWIK_INCLUDE_PATH.'/tests/PHPUnit/Fixtures/*.php') as $file)
-{
- require_once $file;
+require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/BaseFixture.php';
+foreach (glob(PIWIK_INCLUDE_PATH . '/tests/PHPUnit/Fixtures/*.php') as $file) {
+ require_once $file;
}
// General requirement checks & help: a webserver must be running for tests to work!
@@ -49,31 +44,32 @@ checkPiwikSetupForTests();
function checkPiwikSetupForTests()
{
- if(empty($_SERVER['REQUEST_URI'])
- || $_SERVER['REQUEST_URI'] == '@REQUEST_URI@') {
- echo "WARNING: for tests to pass, you must first:
+ if (empty($_SERVER['REQUEST_URI'])
+ || $_SERVER['REQUEST_URI'] == '@REQUEST_URI@'
+ ) {
+ echo "WARNING: for tests to pass, you must first:
1) Install webserver on localhost, eg. apache
2) Make these Piwik files available on the webserver, at eg. http://localhost/dev/piwik/ - Piwik does need to be installed to run tests, but this URL must work.
3) Copy phpunit.xml.dist to phpunit.xml
4) Edit in phpunit.xml the @REQUEST_URI@ and replace with the webserver path to Piwik, eg. '/dev/piwik/'
Try again and now the tests should run!";
- exit(1);
- }
+ exit(1);
+ }
- // Now testing if the webserver is running
- $piwikServerUrl = Test_Piwik_BaseFixture::getRootUrl();
- try {
- $fetched = Piwik_Http::sendHttpRequest($piwikServerUrl, $timeout = 3);
- } catch(Exception $e) {
- $fetched = "ERROR fetching: " . $e->getMessage();
- }
- $expectedString = 'plugins/CoreHome/templates/images/favicon.ico';
+ // Now testing if the webserver is running
+ $piwikServerUrl = Test_Piwik_BaseFixture::getRootUrl();
+ try {
+ $fetched = Piwik_Http::sendHttpRequest($piwikServerUrl, $timeout = 3);
+ } catch (Exception $e) {
+ $fetched = "ERROR fetching: " . $e->getMessage();
+ }
+ $expectedString = 'plugins/CoreHome/templates/images/favicon.ico';
- if(strpos($fetched, $expectedString) === false) {
- echo "\nPiwik should be running at: " . $piwikServerUrl
- . "\nbut this URL returned an unexpected response: '"
- . substr($fetched,0,300) . "...'\n\n";
- exit;
- }
+ if (strpos($fetched, $expectedString) === false) {
+ echo "\nPiwik should be running at: " . $piwikServerUrl
+ . "\nbut this URL returned an unexpected response: '"
+ . substr($fetched, 0, 300) . "...'\n\n";
+ exit;
+ }
}
diff --git a/tests/PHPUnit/config.ini.travis.php b/tests/PHPUnit/config.ini.travis.php
index e4336bfdd1..54530281bd 100644
--- a/tests/PHPUnit/config.ini.travis.php
+++ b/tests/PHPUnit/config.ini.travis.php
@@ -3,15 +3,15 @@
; tests on Travis-CI. Do not use this in production.
[superuser]
-login = admin
-password = 098f6bcd4621d373cade4e832627b4f6
-email = hello@example.org
+login = admin
+password = 098f6bcd4621d373cade4e832627b4f6
+email = hello@example.org
[database]
-host = localhost
-username = root
-password =
-dbname = piwik_test
-adapter = PDO_MYSQL ; PDO_MYSQL, MYSQLI, or PDO_PGSQL
-tables_prefix = piwik_
-;charset = utf8
+host = localhost
+username = root
+password =
+dbname = piwik_test
+adapter = PDO_MYSQL ; PDO_MYSQL, MYSQLI, or PDO_PGSQL
+tables_prefix = piwik_
+;charset = utf8
diff --git a/tests/PHPUnit/proxy/index.php b/tests/PHPUnit/proxy/index.php
index e3034ccb1c..fd59a24554 100644
--- a/tests/PHPUnit/proxy/index.php
+++ b/tests/PHPUnit/proxy/index.php
@@ -2,8 +2,8 @@
/**
* Proxy to index.php, but will use the Test DB
* Currently only used only for the test: tests/PHPUnit/Integration/ImportLogsTest.php
- * since other integration tests do not call index.php via http but use the Piwik_API_Request object
- *
+ * since other integration tests do not call index.php via http but use the Piwik_API_Request object
+ *
*/
// Wrapping the request inside ob_start() calls to ensure that the Test
@@ -13,25 +13,26 @@ ob_start();
define('PIWIK_INCLUDE_PATH', '../../..');
define('PIWIK_USER_PATH', PIWIK_INCLUDE_PATH);
-require_once PIWIK_INCLUDE_PATH .'/libs/upgradephp/upgrade.php';
-require_once PIWIK_INCLUDE_PATH .'/core/Loader.php';
+require_once PIWIK_INCLUDE_PATH . '/libs/upgradephp/upgrade.php';
+require_once PIWIK_INCLUDE_PATH . '/core/Loader.php';
Piwik_Tracker::setTestEnvironment();
Piwik_Tracker_Cache::deleteTrackerCache();
-class Piwik_FrontController_Test extends Piwik_FrontController
+class Piwik_FrontController_Test extends Piwik_FrontController
{
- protected function createConfigObject()
- {
- // Config files forced to use the test database
- Piwik::createConfigObject();
- Piwik_Config::getInstance()->setTestEnvironment();
- }
- protected function createAccessObject()
- {
- parent::createAccessObject();
- Piwik::setUserIsSuperUser(true);
- }
+ protected function createConfigObject()
+ {
+ // Config files forced to use the test database
+ Piwik::createConfigObject();
+ Piwik_Config::getInstance()->setTestEnvironment();
+ }
+
+ protected function createAccessObject()
+ {
+ parent::createAccessObject();
+ Piwik::setUserIsSuperUser(true);
+ }
}
// Disable index.php dispatch since we do it manually below
@@ -41,5 +42,5 @@ include PIWIK_INCLUDE_PATH . '/index.php';
$controller = new Piwik_FrontController_Test;
$controller->init();
$controller->dispatch();
-
+
ob_flush();
diff --git a/tests/PHPUnit/proxy/piwik.php b/tests/PHPUnit/proxy/piwik.php
index b79fbc24b3..f70183ed16 100755
--- a/tests/PHPUnit/proxy/piwik.php
+++ b/tests/PHPUnit/proxy/piwik.php
@@ -1,12 +1,12 @@
<?php
/**
* Proxy to normal piwik.php, but in testing mode
- *
+ *
* - Use the tests database to record Tracking data
- * - Allows to overwrite the Visitor IP, and Server datetime
- *
+ * - Allows to overwrite the Visitor IP, and Server datetime
+ *
* @see Main.test.php
- *
+ *
*/
// Wrapping the request inside ob_start() calls to ensure that the Test
@@ -16,8 +16,8 @@ ob_start();
define('PIWIK_INCLUDE_PATH', '../../..');
define('PIWIK_USER_PATH', PIWIK_INCLUDE_PATH);
-require_once PIWIK_INCLUDE_PATH .'/libs/upgradephp/upgrade.php';
-require_once PIWIK_INCLUDE_PATH .'/core/Loader.php';
+require_once PIWIK_INCLUDE_PATH . '/libs/upgradephp/upgrade.php';
+require_once PIWIK_INCLUDE_PATH . '/core/Loader.php';
// Config files forced to use the test database
// Note that this also provides security for Piwik installs containing tests files:
diff --git a/tests/index.php b/tests/index.php
index 6a4e708988..c5acf9d64d 100644
--- a/tests/index.php
+++ b/tests/index.php
@@ -1,31 +1,38 @@
<html>
<body>
<p>Hello, world!</p>
+
<p>Today looks like an ideal day to write & run tests.</p>
<ul>
- <li><a href='lib/visualphpunit/'>Run unit & integration tests in the browser.</a> <br/><i>(If you're using apache, make sure the mod_rewrite module is enabled.)</i></li>
- <li><a href="javascript/">Run piwik.js Javascript unit & integration tests</a>. <br/><i>Note: the Javascript tests are not executed in Jenkins so must be run manually on major browsers after any change to piwik.js</i></li>
+ <li><a href='lib/visualphpunit/'>Run unit & integration tests in the browser.</a> <br/><i>(If you're using apache,
+ make sure the mod_rewrite module is enabled.)</i></li>
+ <li><a href="javascript/">Run piwik.js Javascript unit & integration tests</a>. <br/><i>Note: the Javascript tests
+ are not executed in Jenkins so must be run manually on major browsers after any change to piwik.js</i></li>
</ul>
<h4>Configuring VisualPHPUnit:</h4>
+
<p>You'll have to configure VisualPHPUnit before you can use it. To do so:
<ul>
- <li>In path-to-piwik/tests/lib/visualphpunit/app/config/bootstrap.php, set the value of 'pear_path' to the path where PEAR is located.</li>
- <li>If you want to use a phpunit.xml file, copy the phpunit.xml.dist file in path-to-piwik/tests/PHPUnit/phpunit.xml.dist & rename it to phpunit.xml. Then add the following to it:
+ <li>In path-to-piwik/tests/lib/visualphpunit/app/config/bootstrap.php, set the value of 'pear_path' to the path
+ where PEAR is located.
+ </li>
+ <li>If you want to use a phpunit.xml file, copy the phpunit.xml.dist file in
+ path-to-piwik/tests/PHPUnit/phpunit.xml.dist & rename it to phpunit.xml. Then add the following to it:
<pre>
<code>
- &lt;listeners&gt;
- &lt;listener class=&quot;PHPUnit_Util_Log_JSON&quot;&gt;&lt;/listener&gt;
- &lt;/listeners&gt;
- </code>
+ &lt;listeners&gt;
+ &lt;listener class=&quot;PHPUnit_Util_Log_JSON&quot;&gt;&lt;/listener&gt;
+ &lt;/listeners&gt;
+ </code>
</pre>
- </li>
+ </li>
</ul>
</p>
<p>If you are new to the wonderful world of testing, <a href='README.txt'>see the README</a> for an introduction.</p>
-
+
<img src='resources/disturbing-image.jpg' alt='I find your lack of tests disturbing'>
<br/><i><a href='http://www.flickr.com/photos/sebastian_bergmann/2282734669/'>Photo source & license</a></i>
</body>