diff --git a/tests/PHPUnit/Integration/ApiGetReportMetadataTest.php b/tests/PHPUnit/Integration/ApiGetReportMetadataTest.php index 0f1e98f0ba0f3c402311a0278e2dcb7e9c08daef..eb19ba9df9ad7d00dfb1f728a6b8e1b862f8cbe9 100755 --- a/tests/PHPUnit/Integration/ApiGetReportMetadataTest.php +++ b/tests/PHPUnit/Integration/ApiGetReportMetadataTest.php @@ -14,18 +14,18 @@ */ class Test_Piwik_Integration_ApiGetReportMetadata extends IntegrationTestCase { - protected $dateTime = '2009-01-04 00:11:42'; - protected $idSite = 1; - protected $idGoal = 1; - protected $idGoal2 = 2; - protected $idGoal3 = 3; + protected static $dateTime = '2009-01-04 00:11:42'; + protected static $idSite = 1; + protected static $idGoal = 1; + protected static $idGoal2 = 2; + protected static $idGoal3 = 3; protected function setUpWebsitesAndGoals() { - $this->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); - Piwik_Goals_API::getInstance()->addGoal($this->idSite, 'Goal 2 - Hello', 'url', 'hellow', 'contains', $caseSensitive = false, $revenue = 10, $allowMultipleConversions = 0); - Piwik_Goals_API::getInstance()->addGoal($this->idSite, 'triggered js', 'manually', '', ''); + $this->createWebsite(self::$dateTime, $ecommerce = 1); + Piwik_Goals_API::getInstance()->addGoal(self::$idSite, 'Goal 1 - Thank you', 'title', 'Thank you', 'contains', $caseSensitive = false, $revenue = 10, $allowMultipleConversions = 1); + Piwik_Goals_API::getInstance()->addGoal(self::$idSite, 'Goal 2 - Hello', 'url', 'hellow', 'contains', $caseSensitive = false, $revenue = 10, $allowMultipleConversions = 0); + Piwik_Goals_API::getInstance()->addGoal(self::$idSite, 'triggered js', 'manually', '', ''); } public function setUp() @@ -45,7 +45,7 @@ class Test_Piwik_Integration_ApiGetReportMetadata extends IntegrationTestCase public function getApiForTesting() { return array( - array('API', array('idSite' => $this->idSite, 'date' => $this->dateTime)) + array('API', array('idSite' => self::$idSite, 'date' => self::$dateTime)) ); } @@ -61,8 +61,8 @@ class Test_Piwik_Integration_ApiGetReportMetadata extends IntegrationTestCase protected function trackVisits() { - $idSite = $this->idSite; - $dateTime = $this->dateTime; + $idSite = self::$idSite; + $dateTime = self::$dateTime; $t = $this->getTracker($idSite, $dateTime, $defaultInit = true); @@ -71,7 +71,7 @@ class Test_Piwik_Integration_ApiGetReportMetadata extends IntegrationTestCase $this->checkResponse($t->doTrackPageView('incredible title!')); $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.3)->getDatetime()); - $this->checkResponse($t->doTrackGoal($this->idGoal3, $revenue = 42.256)); + $this->checkResponse($t->doTrackGoal(self::$idGoal3, $revenue = 42.256)); } } diff --git a/tests/PHPUnit/Integration/ApiGetReportMetadata_yearTest.php b/tests/PHPUnit/Integration/ApiGetReportMetadata_yearTest.php index 69e8018f326f9d4e4b834bfb35d99f3516286d5b..fe695f519f00f56b6c71294519790d24db6e172c 100755 --- a/tests/PHPUnit/Integration/ApiGetReportMetadata_yearTest.php +++ b/tests/PHPUnit/Integration/ApiGetReportMetadata_yearTest.php @@ -13,12 +13,12 @@ */ class Test_Piwik_Integration_ApiGetReportMetadata_Year extends IntegrationTestCase { - protected $idSite = 1; - protected $dateTime = '2009-01-04 00:11:42'; + protected static $idSite = 1; + protected static $dateTime = '2009-01-04 00:11:42'; protected function setUpWebsitesAndGoals() { - $this->createWebsite($this->dateTime); + $this->createWebsite(self::$dateTime); } protected function trackVisits() @@ -27,8 +27,8 @@ class Test_Piwik_Integration_ApiGetReportMetadata_Year extends IntegrationTestCa public function getApiForTesting() { - $params = array('idSite' => $this->idSite, - 'date' => $this->dateTime, + $params = array('idSite' => self::$idSite, + 'date' => self::$dateTime, 'periods' => 'year', 'language' => 'fr'); return array( @@ -49,7 +49,7 @@ class Test_Piwik_Integration_ApiGetReportMetadata_Year extends IntegrationTestCa * @dataProvider getApiForTesting * @group Integration * @group ApiGetReportMetadata - * @group ApiGetReportMetadata_year + * @group ApiGetReportMetadata_Year */ public function testApi($api, $params) { diff --git a/tests/PHPUnit/Integration/CsvExportTest.php b/tests/PHPUnit/Integration/CsvExportTest.php index bf1a8ab839618fe361596380270fdc18976da347..6f6420031e1af440c7786893dd488855a1c59750 100755 --- a/tests/PHPUnit/Integration/CsvExportTest.php +++ b/tests/PHPUnit/Integration/CsvExportTest.php @@ -14,8 +14,8 @@ require_once dirname(__FILE__).'/TwoVisitsWithCustomVariablesTest.php'; */ class Test_Piwik_Integration_CsvExport extends Test_Piwik_Integration_TwoVisitsWithCustomVariables { - protected $useEscapedQuotes = false; - protected $doExtraQuoteTests = false; + protected static $useEscapedQuotes = false; + protected static $doExtraQuoteTests = false; public function getApiForTesting() { @@ -26,20 +26,20 @@ class Test_Piwik_Integration_CsvExport extends Test_Piwik_Integration_TwoVisitsW $deExtraParam = array('expanded' => 0, 'flat' => 1, 'include_aggregate_rows' => 1, 'translateColumnNames' => 1); return array( - array($apiToCall, array('idSite' => $this->idSite, - 'date' => $this->dateTime, 'format' => 'csv', + array($apiToCall, array('idSite' => self::$idSite, + 'date' => self::$dateTime, 'format' => 'csv', 'otherRequestParameters' => array('expanded' => 0, 'flat' => 0), 'testSuffix' => '_xp0')), - array($apiToCall, array('idSite' => $this->idSite, - 'date' => $this->dateTime, + array($apiToCall, array('idSite' => self::$idSite, + 'date' => self::$dateTime, 'format' => 'csv', 'otherRequestParameters' => $enExtraParam, 'language' => 'en', 'testSuffix' => '_xp1_inner0_trans-en')), - array($apiToCall, array('idSite' => $this->idSite, - 'date' => $this->dateTime, + array($apiToCall, array('idSite' => self::$idSite, + 'date' => self::$dateTime, 'format' => 'csv', 'otherRequestParameters' => $deExtraParam, 'language' => 'de', diff --git a/tests/PHPUnit/Integration/EcommerceOrderWithItemsTest.php b/tests/PHPUnit/Integration/EcommerceOrderWithItemsTest.php index f4a7efcf51bd40c15d5021c47d77cc3435608090..a440ced844a4803086bdeb8e489ed0458b9662f3 100755 --- a/tests/PHPUnit/Integration/EcommerceOrderWithItemsTest.php +++ b/tests/PHPUnit/Integration/EcommerceOrderWithItemsTest.php @@ -12,10 +12,10 @@ */ class Test_Piwik_Integration_EcommerceOrderWithItems extends IntegrationTestCase { - protected $dateTime = '2011-04-05 00:11:42'; - protected $idSite = 1; - protected $idSite2 = 1; - protected $idGoalStandard = 1; + protected static $dateTime = '2011-04-05 00:11:42'; + protected static $idSite = 1; + protected static $idSite2 = 1; + protected static $idGoalStandard = 1; /** * @dataProvider getApiForTesting @@ -42,121 +42,121 @@ class Test_Piwik_Integration_EcommerceOrderWithItems extends IntegrationTestCase // Normal standard goal return array( // day tests - array($dayApi, array('idSite' => $this->idSite, 'date' => $this->dateTime, 'periods' => array('day'), 'otherRequestParameters' => array('_leavePiwikCoreVariables' => 1))), + array($dayApi, array('idSite' => self::$idSite, 'date' => self::$dateTime, 'periods' => array('day'), 'otherRequestParameters' => array('_leavePiwikCoreVariables' => 1))), // goals API week tests - array($goalWeekApi, array('idSite' => $this->idSite, 'date' => $this->dateTime, 'periods' => array('week'))), + array($goalWeekApi, array('idSite' => self::$idSite, 'date' => self::$dateTime, 'periods' => array('week'))), // abandoned carts tests - array($goalItemApi, array('idSite' => $this->idSite, 'date' => $this->dateTime, + array($goalItemApi, array('idSite' => self::$idSite, 'date' => self::$dateTime, 'periods' => array('day', 'week'), 'abandonedCarts' => 1, 'testSuffix' => '_AbandonedCarts')), // multiple periods tests - array($goalItemApi, array('idSite' => $this->idSite, 'date' => $this->dateTime, 'periods' => array('day'), + array($goalItemApi, array('idSite' => self::$idSite, 'date' => self::$dateTime, 'periods' => array('day'), 'setDateLastN' => true, 'testSuffix' => 'multipleDates')), // multiple periods & multiple websites tests - array($goalItemApi, array('idSite' => "{$this->idSite},{$this->idSite2}", 'date' => $this->dateTime, + array($goalItemApi, array('idSite' => sprintf("%u,%u", self::$idSite, self::$idSite2), 'date' => self::$dateTime, 'periods' => array('day'), 'setDateLastN' => true, 'testSuffix' => 'multipleDates_andMultipleWebsites')), // test metadata products - array($processedReportApi, array('idSite' => $this->idSite, 'date' => $this->dateTime, + array($processedReportApi, array('idSite' => self::$idSite, 'date' => self::$dateTime, 'periods' => array('day'), 'apiModule' => 'Goals', 'apiAction' => 'getItemsSku', 'testSuffix' => '_Metadata_ItemsSku')), - array($processedReportApi, array('idSite' => $this->idSite, 'date' => $this->dateTime, + array($processedReportApi, array('idSite' => self::$idSite, 'date' => self::$dateTime, 'periods' => array('day'), 'apiModule' => 'Goals', 'apiAction' => 'getItemsCategory', 'testSuffix' => '_Metadata_ItemsCategory')), // test metadata Goals.get for Ecommerce orders & Carts - array($processedReportApi, array('idSite' => $this->idSite, 'date' => $this->dateTime, + array($processedReportApi, array('idSite' => self::$idSite, 'date' => self::$dateTime, 'periods' => array('day'), 'apiModule' => 'Goals', 'apiAction' => 'get', 'idGoal' => Piwik_Archive::LABEL_ECOMMERCE_ORDER, 'testSuffix' => '_Metadata_Goals.Get_Order')), - array($processedReportApi, array('idSite' => $this->idSite, 'date' => $this->dateTime, + array($processedReportApi, array('idSite' => self::$idSite, 'date' => self::$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' => $this->idSite, 'date' => $this->dateTime, + array($processedReportApi, array('idSite' => self::$idSite, 'date' => self::$dateTime, 'periods' => array('day'), 'apiModule' => 'Goals', 'apiAction' => 'get', - 'idGoal' => $this->idGoalStandard, + 'idGoal' => self::$idGoalStandard, 'testSuffix' => '_Metadata_Goals.Get_NormalGoal')), // non-existant goal test - array($processedReportApi, array('idSite' => $this->idSite, 'date' => $this->dateTime, + array($processedReportApi, array('idSite' => self::$idSite, 'date' => self::$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' => $this->idSite, 'date' => $this->dateTime, + array($processedReportApi, array('idSite' => self::$idSite, 'date' => self::$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' => $this->idSite, 'date' => $this->dateTime, + array('Goals.get', array('idSite' => self::$idSite, 'date' => self::$dateTime, 'periods' => array('day', 'week'), 'idGoal' => Piwik_Archive::LABEL_ECOMMERCE_CART, 'testSuffix' => '_GoalAbandonedCart')), - array('Goals.get', array('idSite' => $this->idSite, 'date' => $this->dateTime, + array('Goals.get', array('idSite' => self::$idSite, 'date' => self::$dateTime, 'periods' => array('day', 'week'), 'idGoal' => Piwik_Archive::LABEL_ECOMMERCE_ORDER, 'testSuffix' => '_GoalOrder')), - array('Goals.get', array('idSite' => $this->idSite, 'date' => $this->dateTime, + array('Goals.get', array('idSite' => self::$idSite, 'date' => self::$dateTime, 'periods' => array('day', 'week'), 'idGoal' => 1, 'testSuffix' => '_GoalMatchTitle')), - array('Goals.get', array('idSite' => $this->idSite, 'date' => $this->dateTime, + array('Goals.get', array('idSite' => self::$idSite, 'date' => self::$dateTime, 'periods' => array('day', 'week'), 'idGoal' => '', 'testSuffix' => '_GoalOverall')), - array('VisitsSummary.get', array('idSite' => $this->idSite, 'date' => $this->dateTime, + array('VisitsSummary.get', array('idSite' => self::$idSite, 'date' => self::$dateTime, 'periods' => array('day'), 'segment' => 'visitEcommerceStatus==none', 'testSuffix' => '_SegmentNoEcommerce')), - array('VisitsSummary.get', array('idSite' => $this->idSite, 'date' => $this->dateTime, + array('VisitsSummary.get', array('idSite' => self::$idSite, 'date' => self::$dateTime, 'periods' => array('day'), 'testSuffix' => '_SegmentOrderedSomething', 'segment' => 'visitEcommerceStatus==ordered,visitEcommerceStatus==orderedThenAbandonedCart')), - array('VisitsSummary.get', array('idSite' => $this->idSite, 'date' => $this->dateTime, + array('VisitsSummary.get', array('idSite' => self::$idSite, 'date' => self::$dateTime, 'periods' => array('day'), 'testSuffix' => '_SegmentAbandonedCart', 'segment' => 'visitEcommerceStatus==abandonedCart,visitEcommerceStatus==orderedThenAbandonedCart')), // test segment visitConvertedGoalId - array('VisitsSummary.get', array('idSite' => $this->idSite, 'date' => $this->dateTime, + array('VisitsSummary.get', array('idSite' => self::$idSite, 'date' => self::$dateTime, 'periods' => array('day', 'week'), 'testSuffix' => '_SegmentConvertedGoalId1', - 'segment' => "visitConvertedGoalId=={$this->idGoalStandard}")), - array('VisitsSummary.get', array('idSite' => $this->idSite, 'date' => $this->dateTime, + 'segment' => "visitConvertedGoalId==".self::$idGoalStandard)), + array('VisitsSummary.get', array('idSite' => self::$idSite, 'date' => self::$dateTime, 'periods' => array('day'), 'testSuffix' => '_SegmentDidNotConvertGoalId1', - 'segment' => "visitConvertedGoalId!={$this->idGoalStandard}")), + 'segment' => "visitConvertedGoalId!=".self::$idGoalStandard)), // test segment visitorType - array('VisitsSummary.get', array('idSite' => $this->idSite, 'date' => $this->dateTime, + array('VisitsSummary.get', array('idSite' => self::$idSite, 'date' => self::$dateTime, 'periods' => array('week'), 'segment' => 'visitorType==new', 'testSuffix' => '_SegmentNewVisitors')), - array('VisitsSummary.get', array('idSite' => $this->idSite, 'date' => $this->dateTime, + array('VisitsSummary.get', array('idSite' => self::$idSite, 'date' => self::$dateTime, 'periods' => array('week'), 'segment' => 'visitorType==returning', 'testSuffix' => '_SegmentReturningVisitors')), - array('VisitsSummary.get', array('idSite' => $this->idSite, 'date' => $this->dateTime, + array('VisitsSummary.get', array('idSite' => self::$idSite, 'date' => self::$dateTime, 'periods' => array('week'), 'segment' => 'visitorType==returningCustomer', 'testSuffix' => '_SegmentReturningCustomers')), // test segment pageTitle - array('VisitsSummary.get', array('idSite' => $this->idSite, 'date' => $this->dateTime, + array('VisitsSummary.get', array('idSite' => self::$idSite, 'date' => self::$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' => $this->idSite, - 'date' => Piwik_Date::factory($this->dateTime)->addHour(30.65)->getDatetime(), + array('Live.getLastVisitsDetails', array('idSite' => self::$idSite, + 'date' => Piwik_Date::factory(self::$dateTime)->addHour(30.65)->getDatetime(), 'periods' => array('day'), 'testSuffix' => '_LiveEcommerceStatusOrdered')), // test API.get method - array('API.get', array('idSite' => $this->idSite, 'date' => $this->dateTime, 'periods' => array('day', 'week'), + array('API.get', array('idSite' => self::$idSite, 'date' => self::$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' => $this->idSite2, 'date' => $this->dateTime, 'periods' => array('week'), + array($goalWeekApi, array('idSite' => self::$idSite2, 'date' => self::$dateTime, 'periods' => array('week'), 'testSuffix' => '_Website2')), ); } @@ -168,16 +168,16 @@ class Test_Piwik_Integration_EcommerceOrderWithItems extends IntegrationTestCase public function setUpWebsitesAndGoals() { - $this->createWebsite($this->dateTime, $ecommerce = 1); - $this->createWebsite($this->dateTime); - Piwik_Goals_API::getInstance()->addGoal($this->idSite, 'title match, triggered ONCE', 'title', 'incredible', 'contains', $caseSensitive = false, $revenue = 10, $allowMultipleConversions = true); + $this->createWebsite(self::$dateTime, $ecommerce = 1); + $this->createWebsite(self::$dateTime); + Piwik_Goals_API::getInstance()->addGoal(self::$idSite, 'title match, triggered ONCE', 'title', 'incredible', 'contains', $caseSensitive = false, $revenue = 10, $allowMultipleConversions = true); } protected function trackVisits() { - $dateTime = $this->dateTime; - $idSite = $this->idSite; - $idSite2 = $this->idSite2; + $dateTime = self::$dateTime; + $idSite = self::$idSite; + $idSite2 = self::$idSite2; $t = $this->getTracker($idSite, $dateTime, $defaultInit = true); // VISIT NO 1 diff --git a/tests/PHPUnit/Integration/FlattenReportsTest.php b/tests/PHPUnit/Integration/FlattenReportsTest.php index 743130345c1663997f0ba06ad52cf05bad8e1bb6..aa6cec28ca5923321516e7ee8cf299aeea89b1ec 100644 --- a/tests/PHPUnit/Integration/FlattenReportsTest.php +++ b/tests/PHPUnit/Integration/FlattenReportsTest.php @@ -12,8 +12,8 @@ */ class Test_Piwik_Integration_FlattenReports extends IntegrationTestCase { - protected $dateTime = '2010-03-06 11:22:33'; - protected $idSite = 1; + protected static $dateTime = '2010-03-06 11:22:33'; + protected static $idSite = 1; /** * @dataProvider getApiForTesting @@ -33,8 +33,8 @@ class Test_Piwik_Integration_FlattenReports extends IntegrationTestCase $return[] = array( 'Referers.getWebsites', array( - 'idSite' => $this->idSite, - 'date' => $this->dateTime, + 'idSite' => self::$idSite, + 'date' => self::$dateTime, 'otherRequestParameters' => array( 'flat' => '1', 'expanded' => '0' @@ -45,8 +45,8 @@ class Test_Piwik_Integration_FlattenReports extends IntegrationTestCase $return[] = array( 'Actions.getPageUrls', array( - 'idSite' => $this->idSite, - 'date' => $this->dateTime, + 'idSite' => self::$idSite, + 'date' => self::$dateTime, 'otherRequestParameters' => array( 'flat' => '1', 'expanded' => '0' @@ -55,8 +55,8 @@ class Test_Piwik_Integration_FlattenReports extends IntegrationTestCase $return[] = array( 'Actions.getPageUrls', array( - 'idSite' => $this->idSite, - 'date' => $this->dateTime, + 'idSite' => self::$idSite, + 'date' => self::$dateTime, 'testSuffix' => '_withAggregate', 'otherRequestParameters' => array( 'flat' => '1', @@ -67,8 +67,8 @@ class Test_Piwik_Integration_FlattenReports extends IntegrationTestCase // custom variables for multiple days $return[] = array('CustomVariables.getCustomVariables', array( - 'idSite' => $this->idSite, - 'date' => $this->dateTime, + 'idSite' => self::$idSite, + 'date' => self::$dateTime, 'otherRequestParameters' => array( 'date' => '2010-03-06,2010-03-08', 'flat' => '1', @@ -87,13 +87,13 @@ class Test_Piwik_Integration_FlattenReports extends IntegrationTestCase protected function setUpWebsitesAndGoals() { - $this->createWebsite($this->dateTime); + $this->createWebsite(self::$dateTime); } protected function trackVisits() { - $dateTime = $this->dateTime; - $idSite = $this->idSite; + $dateTime = self::$dateTime; + $idSite = self::$idSite; for ($referrerSite = 1; $referrerSite < 4; $referrerSite++) { for ($referrerPage = 1; $referrerPage < 3; $referrerPage++) { diff --git a/tests/PHPUnit/Integration/LabelFilterTest.php b/tests/PHPUnit/Integration/LabelFilterTest.php index fce3ced21a02c82937d567f3d6793b1050b7d991..9a1b9f2cd72ca25118e4a3b4b12229dba7b7daa4 100644 --- a/tests/PHPUnit/Integration/LabelFilterTest.php +++ b/tests/PHPUnit/Integration/LabelFilterTest.php @@ -13,8 +13,8 @@ */ class Test_Piwik_Integration_LabelFilter extends IntegrationTestCase { - protected $dateTime = '2010-03-06 11:22:33'; - protected $idSite = 1; + protected static $dateTime = '2010-03-06 11:22:33'; + protected static $idSite = 1; /** * @dataProvider getApiForTesting @@ -49,8 +49,8 @@ class Test_Piwik_Integration_LabelFilter extends IntegrationTestCase foreach ($labelsToTest as $suffix => $label) { $return[] = array('Actions.getPageUrls', array( 'testSuffix' => '_' . $suffix, - 'idSite' => $this->idSite, - 'date' => $this->dateTime, + 'idSite' => self::$idSite, + 'date' => self::$dateTime, 'otherRequestParameters' => array( 'label' => $label, 'expanded' => 0 @@ -61,8 +61,8 @@ class Test_Piwik_Integration_LabelFilter extends IntegrationTestCase $label = 'dir'; $return[] = array('Actions.getPageUrls', array( 'testSuffix' => '_' . $label . '_range', - 'idSite' => $this->idSite, - 'date' => $this->dateTime, + 'idSite' => self::$idSite, + 'date' => self::$dateTime, 'otherRequestParameters' => array( 'date' => '2010-03-06,2010-03-08', 'label' => $label, @@ -72,8 +72,8 @@ class Test_Piwik_Integration_LabelFilter extends IntegrationTestCase $return[] = array('Actions.getPageTitles', array( 'testSuffix' => '_titles', - 'idSite' => $this->idSite, - 'date' => $this->dateTime, + 'idSite' => self::$idSite, + 'date' => self::$dateTime, 'otherRequestParameters' => array( // encode once for test framework and once for the label filter. // note: title has no blank prefixed here. in the report it has. @@ -84,8 +84,8 @@ class Test_Piwik_Integration_LabelFilter extends IntegrationTestCase $return[] = array('Actions.getPageTitles', array( 'testSuffix' => '_titlesRecursive', - 'idSite' => $this->idSite, - 'date' => $this->dateTime, + 'idSite' => self::$idSite, + 'date' => self::$dateTime, 'otherRequestParameters' => array( 'label' => ' ' . // test trimming @@ -99,8 +99,8 @@ class Test_Piwik_Integration_LabelFilter extends IntegrationTestCase $keyword = '<>&\"the pdo extension is required for this adapter but the extension is not loaded'; $searchEngineTest = array( 'testSuffix' => '_keywords_html', - 'idSite' => $this->idSite, - 'date' => $this->dateTime, + 'idSite' => self::$idSite, + 'date' => self::$dateTime, 'otherRequestParameters' => array( 'label' => 'Google>' . urlencode($keyword), 'expanded' => 0 @@ -121,13 +121,13 @@ class Test_Piwik_Integration_LabelFilter extends IntegrationTestCase protected function setUpWebsitesAndGoals() { - $this->createWebsite($this->dateTime); + $this->createWebsite(self::$dateTime); } protected function trackVisits() { - $dateTime = $this->dateTime; - $idSite = $this->idSite; + $dateTime = self::$dateTime; + $idSite = self::$idSite; $t = $this->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'); diff --git a/tests/PHPUnit/Integration/NoVisitTest.php b/tests/PHPUnit/Integration/NoVisitTest.php index b9e721e6ce779da596b101e721debffa7cf31132..325a29d743cc73735e0d6ad52632bbcb68b85c4c 100755 --- a/tests/PHPUnit/Integration/NoVisitTest.php +++ b/tests/PHPUnit/Integration/NoVisitTest.php @@ -14,8 +14,8 @@ */ class Test_Piwik_Integration_NoVisit extends IntegrationTestCase { - protected $idSite = 1; - protected $dateTime = '2009-01-04 00:11:42'; + protected static $idSite = 1; + protected static $dateTime = '2009-01-04 00:11:42'; /** * @dataProvider getApiForTesting @@ -31,10 +31,10 @@ 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' => $this->idSite, - 'date' => $this->dateTime)), - array('all', array('idSite' => $this->idSite, - 'date' => $this->dateTime, + array('all', array('idSite' => self::$idSite, + 'date' => self::$dateTime)), + array('all', array('idSite' => self::$idSite, + 'date' => self::$dateTime, 'periods' => array('day', 'week'), 'setDateLastN' => true, 'testSuffix' => '_PeriodIsLast')), @@ -48,13 +48,13 @@ class Test_Piwik_Integration_NoVisit extends IntegrationTestCase public function setUpWebsitesAndGoals() { - $this->createWebsite($this->dateTime); + $this->createWebsite(self::$dateTime); } protected function trackVisits() { - $dateTime = $this->dateTime; - $idSite = $this->idSite; + $dateTime = self::$dateTime; + $idSite = self::$idSite; /* // Trigger invalid website diff --git a/tests/PHPUnit/Integration/OneVisitorOneWebsite_SeveralDaysDateRangeTest.php b/tests/PHPUnit/Integration/OneVisitorOneWebsite_SeveralDaysDateRangeTest.php new file mode 100755 index 0000000000000000000000000000000000000000..c0f06953216d088791f09800b00a42faf1a4ff4c --- /dev/null +++ b/tests/PHPUnit/Integration/OneVisitorOneWebsite_SeveralDaysDateRangeTest.php @@ -0,0 +1,90 @@ +<?php +/** + * Piwik - Open source web analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * @version $Id$ + */ + +/** + * testing period=range use case. Recording data before and after, checking that the requested range is processed correctly + */ +class Test_Piwik_Integration_OneVisitorOneWebsite_SeveralDaysDateRange extends IntegrationTestCase +{ + protected static $dateTimes = array( + '2010-12-14 01:00:00', + '2010-12-15 01:00:00', + '2010-12-25 01:00:00', + '2011-01-15 01:00:00', + '2011-01-16 01:00:00', + ); + protected static $idSite = 1; + + /** + * @dataProvider getApiForTesting + * @group Integration + * @group OneVisitorOneWebsite_SeveralDaysDateRange + */ + public function testApi($api, $params) + { + $this->runApiTests($api, $params); + } + + public function getApiForTesting() + { + return array( + // range test + array('MultiSites.getAll', array('idSite' => self::$idSite, + 'date' => '2010-12-15,2011-01-15', + 'periods' => array('range'))), + + // test several dates (tests use of IndexedByDate w/ 'date1,date2,etc.') + array('MultiSites.getAll', array('idSite' => self::$idSite, + 'date' => '2010-12-10', + 'periods' => array('day'), + 'setDateLastN' => true, + 'testSuffix' => '_IndexedByDate')) + ); + } + + public function getOutputPrefix() + { + return 'oneVisitor_oneWebsite_severalDays_DateRange'; + } + + protected function setUpWebsitesAndGoals() + { + $this->createWebsite(self::$dateTimes[0]); + } + + protected function trackVisits() + { + $dateTimes = self::$dateTimes; + $idSite = self::$idSite; + + $i = 0; + foreach ($dateTimes as $dateTime) { + $i++; + $visitor = $this->getTracker($idSite, $dateTime, $defaultInit = true); + // Fake the visit count cookie + $visitor->setDebugStringAppend("&_idvc=$i"); + + $visitor->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.1)->getDatetime()); + $visitor->setUrl('http://example.org/homepage'); + $this->checkResponse($visitor->doTrackPageView('ou pas')); + + // Test change the IP, the visit should not be split but recorded to the same idvisitor + $visitor->setIp('200.1.15.22'); + + $visitor->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.2)->getDatetime()); + $visitor->setUrl('http://example.org/news'); + $this->checkResponse($visitor->doTrackPageView('ou pas')); + + $visitor->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(1)->getDatetime()); + $visitor->setUrl('http://example.org/news'); + $this->checkResponse($visitor->doTrackPageView('ou pas')); + } + } +} + diff --git a/tests/PHPUnit/Integration/OneVisitorOneWebsite_SeveralDaysDateRange_ArchivingTestsTest.php b/tests/PHPUnit/Integration/OneVisitorOneWebsite_SeveralDaysDateRange_ArchivingTestsTest.php new file mode 100755 index 0000000000000000000000000000000000000000..1cae72c06bf147c4f0e5a3d5f8b64a2092a6d2b0 --- /dev/null +++ b/tests/PHPUnit/Integration/OneVisitorOneWebsite_SeveralDaysDateRange_ArchivingTestsTest.php @@ -0,0 +1,84 @@ +<?php +/** + * Piwik - Open source web analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * @version $Id$ + */ + +require_once dirname(__FILE__) . '/OneVisitorOneWebsite_SeveralDaysDateRangeTest.php'; + +/** + * Tests some API using range periods & makes sure the correct amount of blob/numeric + * archives are created. + */ +class Test_Piwik_Integration_OneVisitorOneWebsite_SeveralDaysDateRange_ArchivingTests extends Test_Piwik_Integration_OneVisitorOneWebsite_SeveralDaysDateRange +{ + /** + * @group Integration + * @group OneVisitorOneWebsite_SeveralDaysDateRange_ArchivingTests + */ + public function testApi() + { + $testData = $this->getApiForTesting(); + + foreach ($testData AS $data) { + $api = $data[0]; + $params = $data[1]; + $this->runApiTests($api, $params); + } + + if (IntegrationTestCase::$apiTestingLevel != IntegrationTestCase::NO_API_TESTING) { + // Check that requesting period "Range" means + // only processing the requested Plugin blob (Actions in this case), not all Plugins blobs + $tests = array( + // 4 blobs for the Actions plugin, 7 blobs for UserSettings, 2 blobs VisitTime + 'archive_blob_2010_12' => (4 + 7 + 2) * 3, + // (VisitsSummary 5 metrics + 1 flag - no Unique visitors for range) + // + 1 flag archive UserSettings + // + (Actions 1 flag + 2 metrics - pageviews, unique pageviews) + // + (Frequency 5 metrics + 1 flag) + // + 1 flag VisitTime + // * 3 segments + 'archive_numeric_2010_12' => (6 + 1 + 3 + 6 + 1) * 3, + + // all "Range" records are in December + 'archive_blob_2011_01' => 0, + 'archive_numeric_2011_01' => 0, + ); + foreach ($tests as $table => $expectedRows) { + $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"); + } + } + } + + public function getApiForTesting() + { + $apiToCall = array('Actions.getPageUrls', + '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( + false, + 'country!=aa', + 'pageUrl!=ThisIsNotKnownPageUrl', + ); + + // Running twice just as health check that second call also works + $result = array(); + for ($i = 0; $i <= 1; $i++) { + foreach ($segments as $segment) { + $result[] = array($apiToCall, array('idSite' => self::$idSite, 'date' => '2010-12-15,2011-01-15', + 'periods' => array('range'), 'segment' => $segment)); + } + } + + return $result; + } +} diff --git a/tests/PHPUnit/Integration/OneVisitorTwoVisitsTest.php b/tests/PHPUnit/Integration/OneVisitorTwoVisitsTest.php new file mode 100755 index 0000000000000000000000000000000000000000..60950393db103ff71c51e07a8513c223735d8057 --- /dev/null +++ b/tests/PHPUnit/Integration/OneVisitorTwoVisitsTest.php @@ -0,0 +1,152 @@ +<?php +/** + * Piwik - Open source web analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * @version $Id$ + */ + +/** + * This use case covers many simple tracking features. + * - Tracking Goal by manual trigger, and URL matching, with custom revenue + * - Tracking the same Goal twice only records it once + * - Tracks 4 page views: 3 clicks and a file download + * - URLs parameters exclude is tested + * - In a returning visit, tracks a Goal conversion + * URL matching, with custom referer and keyword + * NO cookie support + */ +class Test_Piwik_Integration_OneVisitorTwoVisits extends IntegrationTestCase +{ + protected static $idSite = 1; + protected static $dateTime = '2010-03-06 11:22:33'; + + /** + * @dataProvider getApiForTesting + * @group Integration + * @group OneVisitorTwoVisits + */ + public function testApi($api, $params) + { + $this->runApiTests($api, $params); + } + + public function getApiForTesting() + { + $enExtraParam = array('expanded' => 1, 'flat' => 1, 'include_aggregate_rows' => 0, 'translateColumnNames' => 1); + $bulkUrls = array( + "idSite=".self::$idSite."&date=2010-03-06&format=json&expanded=1&period=day&method=VisitsSummary.get", + "idSite=".self::$idSite."&date=2010-03-06&format=xml&expanded=1&period=day&method=VisitsSummary.get", + "idSite=".self::$idSite."&date=2010-03-06&format=json&expanded=1&period=day&method=" + . "VisitorInterest.getNumberOfVisitsPerVisitDuration" + ); + return array( + array('all', array('idSite' => self::$idSite, 'date' => self::$dateTime)), + + // test API.get (for bug that incorrectly reorders columns of CSV output) + // note: bug only affects rows after first + array('API.get', array('idSite' => self::$idSite, + 'date' => '2009-10-01', + 'format' => 'csv', + 'periods' => array('month'), + 'setDateLastN' => true, + 'otherRequestParameters' => $enExtraParam, + 'language' => 'en', + 'testSuffix' => '_csv')), + + array('API.getBulkRequest', array('otherRequestParameters' => array('urls' => $bulkUrls))), + ); + } + + protected function setUpWebsitesAndGoals() + { + // tests run in UTC, the Tracker in UTC + $this->createWebsite(self::$dateTime); + } + + protected function trackVisits() + { + $t = $this->getTracker(self::$idSite, self::$dateTime, $defaultInit = true); + $this->trackVisitsImpl($t); + } + + protected function trackVisitsImpl($t) + { + $dateTime = self::$dateTime; + $idSite = self::$idSite; + + $t->disableCookieSupport(); + + $t->setUrlReferrer('http://referer.com/page.htm?param=valuewith some spaces'); + + // testing URL excluded parameters + $parameterToExclude = 'excluded_parameter'; + Piwik_SitesManager_API::getInstance()->updateSite($idSite, 'new name', $url = array('http://site.com'), $ecommerce = 0, $excludedIps = null, $parameterToExclude . ',anotherParameter'); + + // Record 1st page view + $urlPage1 = 'http://example.org/index.htm?excluded_Parameter=SHOULD_NOT_DISPLAY¶meter=Should display'; + $t->setUrl($urlPage1); + $this->checkResponse($t->doTrackPageView('incredible title!')); + + // testing that / and index.htm above record with different URLs + // Recording the 2nd page after 3 minutes + $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.05)->getDatetime()); + $urlPage2 = 'http://example.org/'; + $t->setUrl($urlPage2); +// $t->setUrlReferrer($urlPage1); + $this->checkResponse($t->doTrackPageView('Second page view - should be registered as URL /')); + +// $t->setUrlReferrer($urlPage2); + // Click on external link after 6 minutes (3rd action) + $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.1)->getDatetime()); + $this->checkResponse($t->doTrackAction('http://dev.piwik.org/svn', 'link')); + + // Click on file download after 12 minutes (4th action) + $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.2)->getDatetime()); + $this->checkResponse($t->doTrackAction('http://piwik.org/path/again/latest.zip', 'download')); + + // Click on two more external links, one the same as before (5th & 6th actions) + $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.22)->getDateTime()); + $this->checkResponse($t->doTrackAction('http://outlinks.org/other_outlink', 'link')); + $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.25)->getDateTime()); + $this->checkResponse($t->doTrackAction('http://dev.piwik.org/svn', 'link')); + + // Create Goal 1: Triggered by JS, after 18 minutes + $idGoal = Piwik_Goals_API::getInstance()->addGoal($idSite, 'triggered js', 'manually', '', ''); + $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.3)->getDatetime()); + + // Change to Thai browser to ensure the conversion is credited to FR instead (the visitor initial country) + $t->setBrowserLanguage('th'); + $this->checkResponse($t->doTrackGoal($idGoal, $revenue = 42)); + + // Track same Goal twice (after 24 minutes), should only be tracked once + $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.4)->getDatetime()); + $this->checkResponse($t->doTrackGoal($idGoal, $revenue = 42)); + + $t->setBrowserLanguage('fr'); + // Final page view (after 27 min) + $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.45)->getDatetime()); + $t->setUrl('http://example.org/index.htm'); + $this->checkResponse($t->doTrackPageView('Looking at homepage (again)...')); + + // - + // End of first visit: 24min + + // Create Goal 2: Matching on URL + Piwik_Goals_API::getInstance()->addGoal($idSite, 'matching purchase.htm', 'url', '(.*)store\/purchase\.(.*)', 'regex', false, $revenue = 1); + + // - + // Start of returning visit, 1 hour after first page view + $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(1)->getDatetime()); + $t->setUrl('http://example.org/store/purchase.htm'); + $t->setUrlReferrer('http://search.yahoo.com/search?p=purchase'); + // Temporary, until we implement 1st party cookies in PiwikTracker + $t->DEBUG_APPEND_URL = '&_idvc=2'; + + // Goal Tracking URL matching, testing custom referer including keyword + $this->checkResponse($t->doTrackPageView('Checkout/Purchasing...')); + // - + // End of second visit + } +} diff --git a/tests/PHPUnit/Integration/OneVisitorTwoVisits_withCookieSupportTest.php b/tests/PHPUnit/Integration/OneVisitorTwoVisits_withCookieSupportTest.php new file mode 100755 index 0000000000000000000000000000000000000000..bfa661a33f360d6a175cf36a07252727dbf510eb --- /dev/null +++ b/tests/PHPUnit/Integration/OneVisitorTwoVisits_withCookieSupportTest.php @@ -0,0 +1,51 @@ +<?php +/** + * Piwik - Open source web analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * @version $Id$ + */ + +require_once dirname(__FILE__) . '/OneVisitorTwoVisitsTest.php'; + +/** + * Same as OneVisitorTwoVisits.test.php, but with cookie support, which incurs some slight changes + * in the reporting data (more accurate unique visitor count, better referer tracking for goals, etc.) + */ +class Test_Piwik_Integration_OneVisitorTwoVisits_WithCookieSupport extends Test_Piwik_Integration_OneVisitorTwoVisits +{ + /** + * @dataProvider getApiForTesting + * @group Integration + * @group OneVisitorTwoVisits_WithCookieSupport + */ + public function testApi($api, $params) + { + $this->runApiTests($api, $params); + } + + public function getApiForTesting() + { + $apiToCall = array( + 'VisitTime', 'VisitsSummary', 'VisitorInterest', 'VisitFrequency', 'UserSettings', + 'UserCountry', 'Referers', 'Provider', 'Goals', 'CustomVariables', 'CoreAdminHome', + 'Actions', 'Live.getLastVisitsDetails'); + + return array( + array($apiToCall, array('idSite' => self::$idSite, 'date' => self::$dateTime)) + ); + } + + public function getOutputPrefix() + { + return 'OneVisitorTwoVisits_withCookieSupport'; + } + + protected function trackVisits() + { + $t = $this->getTracker(self::$idSite, self::$dateTime, $defaultInit = true, $useThirdPartyCookie = 1); + $t->DEBUG_APPEND_URL = '&forceUseThirdPartyCookie=1'; + $this->trackVisitsImpl($t); + } +} diff --git a/tests/PHPUnit/Integration/OneVisitor_LongUrlsTruncatedTest.php b/tests/PHPUnit/Integration/OneVisitor_LongUrlsTruncatedTest.php new file mode 100644 index 0000000000000000000000000000000000000000..bc11be9e2e25fb3310f31fd2f7ee3ac722e87aa4 --- /dev/null +++ b/tests/PHPUnit/Integration/OneVisitor_LongUrlsTruncatedTest.php @@ -0,0 +1,118 @@ +<?php +/** + * Piwik - Open source web analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * @version $Id$ + */ +/** + * Tests that filter_truncate works recursively in Page URLs report AND in the case there are 2 different data Keywords -> search engine + */ +class Test_Piwik_Integration_OneVisitor_LongUrlsTruncated extends IntegrationTestCase +{ + protected static $dateTime = '2010-03-06 01:22:33'; + protected static $idSite = 1; + + /** + * @dataProvider getApiForTesting + * @group Integration + * @group OneVisitor_LongUrlsTruncated + */ + public function testApi($api, $params) + { + $this->runApiTests($api, $params); + } + + public function getApiForTesting() + { + $apiToCall = array('Referers.getKeywords', 'Actions.getPageUrls'); + + return array( + array($apiToCall, array('idSite' => self::$idSite, + 'date' => self::$dateTime, + 'language' => 'fr', + 'otherRequestParameters' => array('expanded' => 1, 'filter_truncate' => 2))) + ); + } + + public function getOutputPrefix() + { + return 'OneVisitor_LongUrlsTruncated'; + } + + protected function setUpWebsitesAndGoals() + { + $this->createWebsite(self::$dateTime); + } + + protected function trackVisits() + { + // tests run in UTC, the Tracker in UTC + $dateTime = self::$dateTime; + $idSite = self::$idSite; + + // Visit 1: keyword and few URLs + $t = $this->getTracker($idSite, $dateTime, $defaultInit = true, $useThirdPartyCookie = 1); + $t->setUrlReferrer('http://bing.com/search?q=Hello world'); + + // Generate a few page views that will be truncated + $t->setUrl('http://example.org/category/Page1'); + $this->checkResponse($t->doTrackPageView('Hello')); + $t->setUrl('http://example.org/category/Page2'); + $this->checkResponse($t->doTrackPageView('Hello')); + $t->setUrl('http://example.org/category/Page3'); + $this->checkResponse($t->doTrackPageView('Hello')); + $t->setUrl('http://example.org/category/Page3'); + $this->checkResponse($t->doTrackPageView('Hello')); + $t->setUrl('http://example.org/category/Page4'); + $this->checkResponse($t->doTrackPageView('Hello')); + $t->setUrl('http://example.org/category/Page4'); + $this->checkResponse($t->doTrackPageView('Hello')); + $t->setUrl('http://example.org/category/Page4'); + $this->checkResponse($t->doTrackPageView('Hello')); + $t->setUrl('http://example.org/category.htm'); + $this->checkResponse($t->doTrackPageView('Hello')); + $t->setUrl('http://example.org/page.htm'); + $this->checkResponse($t->doTrackPageView('Hello')); + $t->setUrl('http://example.org/index.htm'); + $this->checkResponse($t->doTrackPageView('Hello')); + $t->setUrl('http://example.org/page.htm'); + $this->checkResponse($t->doTrackPageView('Hello')); + $t->setUrl('http://example.org/page.htm'); + $this->checkResponse($t->doTrackPageView('Hello')); + $t->setUrl('http://example.org/contact.htm'); + $this->checkResponse($t->doTrackPageView('Hello')); + + // VISIT 2 = Another keyword + $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(1)->getDatetime()); + $t->setUrlReferrer('http://www.google.com.vn/url?q=Salut'); + $this->checkResponse($t->doTrackPageView('incredible title!')); + + // Visit 3 = Another keyword + $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(2)->getDatetime()); + $t->setUrlReferrer('http://www.google.com.vn/url?q=Kia Ora'); + $this->checkResponse($t->doTrackPageView('incredible title!')); + + // Visit 4 = Kia Ora again + $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(3)->getDatetime()); + $t->setUrlReferrer('http://www.google.com.vn/url?q=Kia Ora'); + $this->checkResponse($t->doTrackPageView('incredible title!')); + + // Visit 5 = Another search engine + $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(4)->getDatetime()); + $t->setUrlReferrer('http://nz.search.yahoo.com/search?p=Kia Ora'); + $this->checkResponse($t->doTrackPageView('incredible title!')); + + // Visit 6 = Another search engine + $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(5)->getDatetime()); + $t->setUrlReferrer('http://images.search.yahoo.com/search/images;_ylt=A2KcWcNKJzF?p=Kia%20Ora%20'); + $this->checkResponse($t->doTrackPageView('incredible title!')); + + // Visit 7 = Another search engine + $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(6)->getDatetime()); + $t->setUrlReferrer('http://nz.bing.com/images/search?q=+++Kia+ora+++'); + $this->checkResponse($t->doTrackPageView('incredible title!')); + } +} + diff --git a/tests/PHPUnit/Integration/OneVisitor_NoKeywordSpecifiedTest.php b/tests/PHPUnit/Integration/OneVisitor_NoKeywordSpecifiedTest.php new file mode 100755 index 0000000000000000000000000000000000000000..5a0056a43162a7bc12747ba59e07a246daba0770 --- /dev/null +++ b/tests/PHPUnit/Integration/OneVisitor_NoKeywordSpecifiedTest.php @@ -0,0 +1,79 @@ +<?php +/** + * Piwik - Open source web analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * @version $Id$ + */ + +/** + * 1) Tests empty google kwd works nicely in Live! output and Top keywords + * 2) Tests IP anonymization + * Also test that Live! will link to the search result page URL rather than the exact referrer URL + * when the referrer URL is google.XX/url.... which is a redirect to landing page rather than the search result URL + */ +class Test_Piwik_Integration_OneVisitor_NoKeywordSpecified extends IntegrationTestCase +{ + protected static $dateTime = '2010-03-06 11:22:33'; + protected static $idSite = 1; + + /** + * @dataProvider getApiForTesting + * @group Integration + * @group OneVisitor_NoKeywordSpecified + */ + public function testApi($api, $params) + { + $this->runApiTests($api, $params); + } + + public function getApiForTesting() + { + $apiToCall = array('Referers.getKeywords', 'Live.getLastVisitsDetails'); + + return array( + array($apiToCall, array('idSite' => self::$idSite, 'date' => self::$dateTime, 'language' => 'fr')) + ); + } + + public function getOutputPrefix() + { + return 'OneVisitor_NoKeywordSpecified'; + } + + protected function setUpWebsitesAndGoals() + { + $this->createWebsite(self::$dateTime); + } + + protected function trackVisits() + { + // tests run in UTC, the Tracker in UTC + $dateTime = self::$dateTime; + $idSite = self::$idSite; + $t = $this->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)'); + $t->DEBUG_APPEND_URL .= '&bots=1'; + $t->DEBUG_APPEND_URL .= '&forceIpAnonymization=1'; + // VISIT 1 = Referrer is "Keyword not defined" + // Alsotrigger goal to check that attribution goes to this keyword + $t->setUrlReferrer('http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CC&url=http%3A%2F%2Fpiwik.org%2F&ei=&usg='); + $t->setUrl('http://example.org/this%20is%20cool!'); + $this->checkResponse($t->doTrackPageView('incredible title!')); + $idGoal = Piwik_Goals_API::getInstance()->addGoal($idSite, 'triggered js', 'manually', '', ''); + $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.3)->getDatetime()); + $this->checkResponse($t->doTrackGoal($idGoal, $revenue = 42)); + + // VISIT 2 = Referrer has keyword, but the URL should be rewritten + // in Live Output to point to google search result page + $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'); + + $this->checkResponse($t->doTrackPageView('incredible title!')); + + } +} + diff --git a/tests/PHPUnit/Integration/PeriodIsRange_DateIsLastN_MetadataAndNormalAPITest.php b/tests/PHPUnit/Integration/PeriodIsRange_DateIsLastN_MetadataAndNormalAPITest.php new file mode 100755 index 0000000000000000000000000000000000000000..02227a32575fe452e2fa6ec11ec161a09dbba032 --- /dev/null +++ b/tests/PHPUnit/Integration/PeriodIsRange_DateIsLastN_MetadataAndNormalAPITest.php @@ -0,0 +1,87 @@ +<?php +/** + * Piwik - Open source web analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * @version $Id$ + */ + +require_once dirname(__FILE__) . '/TwoVisitsWithCustomVariablesTest.php'; + +/** + * test Metadata API + period=range&date=lastN + */ +class Test_Piwik_Integration_PeriodIsRange_DateIsLastN_MetadataAndNormalAPI extends Test_Piwik_Integration_TwoVisitsWithCustomVariables +{ + public static function setUpBeforeClass() + { + parent::setUpBeforeClass(); + self::$dateTime = Piwik_Date::factory('now')->getDateTime(); + } + + public function setUp() + { + if (date('G') == 23 || date('G') == 22) { + echo "SKIPPED test_periodIsRange_dateIsLastN_MetadataAndNormalAPI() since it fails around midnight..."; + $this->markTestSkipped(); + } + + parent::setUp(); + } + + /** + * @dataProvider getApiForTesting + * @group Integration + * @group PeriodIsRange_DateIsLastN_MetadataAndNormalAPI + */ + public function testApi($api, $params) + { + $this->runApiTests($api, $params); + } + + public function getApiForTesting() + { + $apiToCall = array( + 'API.getProcessedReport', + 'Actions.getPageUrls', + 'Goals.get', + 'CustomVariables.getCustomVariables', + 'Referers.getCampaigns', + 'Referers.getKeywords', + 'VisitsSummary.get', + 'Live'); + + $segments = array( + false, + 'daysSinceFirstVisit!=50', + 'visitorId!=33c31e01394bdc63', + // testing both filter on Actions table and visit table + 'visitorId!=33c31e01394bdc63;daysSinceFirstVisit!=50', + //'pageUrl!=http://unknown/not/viewed', + ); + $dates = array( + 'last7', + Piwik_Date::factory('now')->subDay(6)->toString() . ',today', + Piwik_Date::factory('now')->subDay(6)->toString() . ',now', + ); + + $result = array(); + foreach ($segments as $segment) { + foreach ($dates as $date) { + $result[] = array($apiToCall, array('idSite' => self::$idSite, 'date' => $date, + 'periods' => array('range'), 'segment' => $segment, + // testing getLastVisitsForVisitor requires a visitor ID + 'visitorId' => self::$visitorId)); + } + } + + return $result; + } + + public function getOutputPrefix() + { + return 'periodIsRange_dateIsLastN_MetadataAndNormalAPI'; + } +} + diff --git a/tests/PHPUnit/Integration/TwoVisitsWithCustomVariablesTest.php b/tests/PHPUnit/Integration/TwoVisitsWithCustomVariablesTest.php index 9aed0ddb3e8793e7e47471e5130622b28e3b1bbe..574f75b92501b67ecfaf817e13e25adf5f67a08f 100755 --- a/tests/PHPUnit/Integration/TwoVisitsWithCustomVariablesTest.php +++ b/tests/PHPUnit/Integration/TwoVisitsWithCustomVariablesTest.php @@ -12,17 +12,23 @@ */ class Test_Piwik_Integration_TwoVisitsWithCustomVariables extends IntegrationTestCase { - protected $dateTime = '2010-01-03 11:22:33'; - protected $width = 1111; - protected $height = 222; + protected static $dateTime = '2010-01-03 11:22:33'; + protected static $width = 1111; + protected static $height = 222; - protected $idSite = 1; - protected $idGoal1 = 1; - protected $idGoal2 = 2; - protected $visitorId = null; + protected static $idSite = 1; + protected static $idGoal1 = 1; + protected static $idGoal2 = 2; + protected static $visitorId = null; - protected $useEscapedQuotes = true; - protected $doExtraQuoteTests = true; + protected static $useEscapedQuotes = true; + protected static $doExtraQuoteTests = true; + + public static function setUpBeforeClass() + { + parent::setUpBeforeClass(); + self::$visitorId = substr(md5(uniqid()), 0, 16); + } public function getApiForTesting() { @@ -30,7 +36,7 @@ class Test_Piwik_Integration_TwoVisitsWithCustomVariables extends IntegrationTes $return = array( array($apiToCall, array('idSite' => 'all', - 'date' => $this->dateTime, + 'date' => self::$dateTime, 'periods' => array('day', 'week'), 'setDateLastN' => true)), ); @@ -56,19 +62,18 @@ class Test_Piwik_Integration_TwoVisitsWithCustomVariables extends IntegrationTes protected function setUpWebsitesAndGoals() { // tests run in UTC, the Tracker in UTC - $this->createWebsite($this->dateTime); - Piwik_Goals_API::getInstance()->addGoal($this->idSite, 'triggered js', 'manually', '', ''); - Piwik_Goals_API::getInstance()->addGoal($this->idSite, 'second goal', 'manually', '', ''); + $this->createWebsite(self::$dateTime); + Piwik_Goals_API::getInstance()->addGoal(self::$idSite, 'triggered js', 'manually', '', ''); + Piwik_Goals_API::getInstance()->addGoal(self::$idSite, 'second goal', 'manually', '', ''); } protected function trackVisits() { - $dateTime = $this->dateTime; - $idSite = $this->idSite; - $idGoal = $this->idGoal1; - $idGoal2 = $this->idGoal2; + $dateTime = self::$dateTime; + $idSite = self::$idSite; + $idGoal = self::$idGoal1; + $idGoal2 = self::$idGoal2; - ob_start(); $visitorA = $this->getTracker($idSite, $dateTime, $defaultInit = true); // Used to test actual referer + keyword position in Live! $visitorA->setUrlReferrer(urldecode('http://www.google.com/url?sa=t&source=web&cd=1&ved=0CB4QFjAA&url=http%3A%2F%2Fpiwik.org%2F&rct=j&q=this%20keyword%20should%20be%20ranked&ei=V8WfTePkKKLfiALrpZWGAw&usg=AFQjCNF_MGJRqKPvaKuUokHtZ3VvNG9ALw&sig2=BvKAdCtNixsmfNWXjsNyMw')); @@ -82,7 +87,7 @@ class Test_Piwik_Integration_TwoVisitsWithCustomVariables extends IntegrationTes ); $visitorA->setAttributionInfo(json_encode($attribution)); - $visitorA->setResolution($this->width, $this->height); + $visitorA->setResolution(self::$width, self::$height); // At first, visitor custom var is set to LoggedOut $visitorA->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.1)->getDatetime()); @@ -96,7 +101,7 @@ class Test_Piwik_Integration_TwoVisitsWithCustomVariables extends IntegrationTes $visitorA->setUrl('http://example.org/user/profile'); $visitorA->setCustomVariable($id = 1, $name = 'VisitorType', $value = 'LoggedIn'); $visitorA->setCustomVariable($id = 4, $name = 'Status user', $value = 'Loggedin', $scope = 'page'); - if ($this->useEscapedQuotes) { + if (self::$useEscapedQuotes) { $lookingAtProfile = 'looking at "profile page"'; } else { $lookingAtProfile = 'looking at profile page'; @@ -112,7 +117,7 @@ class Test_Piwik_Integration_TwoVisitsWithCustomVariables extends IntegrationTes $this->checkResponse($visitorA->doTrackPageView('Profile page for user *_)%')); $this->checkResponse($visitorA->doTrackGoal($idGoal, 0)); - if ($this->doExtraQuoteTests) { + if (self::$doExtraQuoteTests) { $visitorA->setCustomVariable($id = 2, $name = 'var1', $value = 'looking at "profile page"', $scope = 'page'); $visitorA->setCustomVariable($id = 3, $name = 'var2', $value = '\'looking at "\profile page"\'', @@ -134,7 +139,7 @@ class Test_Piwik_Integration_TwoVisitsWithCustomVariables extends IntegrationTes 'http://www.example.org/test/really?q=yes' ); $visitorB->setAttributionInfo(json_encode($attribution)); - $visitorB->setResolution($this->width, $this->height); + $visitorB->setResolution(self::$width, self::$height); $visitorB->setUserAgent('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6'); $visitorB->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(1)->getDatetime()); $visitorB->setCustomVariable($id = 1, $name = 'VisitorType', $value = 'LoggedOut'); @@ -151,9 +156,7 @@ class Test_Piwik_Integration_TwoVisitsWithCustomVariables extends IntegrationTes // DIFFERENT test - // testing that starting the visit with an outlink works (doesn't trigger errors) $visitorB->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(2)->getDatetime()); + $visitorB->setVisitorId(self::$visitorId); $this->checkResponse($visitorB->doTrackAction('http://test.com', 'link')); - - // hack - $this->visitorId = $visitorB->getVisitorId(); } } diff --git a/tests/PHPUnit/Integration/VisitsInPast_InvalidateOldReportsTest.php b/tests/PHPUnit/Integration/VisitsInPast_InvalidateOldReportsTest.php index e7b4a5ca793461f8985485a560749863b5056c42..b260e2d914a87423bacdf8da5b78b97a7f5ea8d4 100644 --- a/tests/PHPUnit/Integration/VisitsInPast_InvalidateOldReportsTest.php +++ b/tests/PHPUnit/Integration/VisitsInPast_InvalidateOldReportsTest.php @@ -8,17 +8,17 @@ */ /** - + * */ class Test_Piwik_Integration_VisitsInPast_InvalidateOldReports extends IntegrationTestCase { - protected $dateTimeFirstDateWebsite1 = '2010-03-06 01:22:33'; - protected $dateTimeDateInPastWebsite1 = '2010-01-06 01:22:33'; + protected static $dateTimeFirstDateWebsite1 = '2010-03-06 01:22:33'; + protected static $dateTimeDateInPastWebsite1 = '2010-01-06 01:22:33'; - protected $dateTimeFirstDateWebsite2 = '2010-01-03 20:22:33'; - protected $dateTimeDateInPastWebsite2 = '2009-10-30 01:22:33'; - protected $idSite = 1; - protected $idSite2 = 2; + protected static $dateTimeFirstDateWebsite2 = '2010-01-03 20:22:33'; + protected static $dateTimeDateInPastWebsite2 = '2009-10-30 01:22:33'; + protected static $idSite = 1; + protected static $idSite2 = 2; /** * @dataProvider getApiForTesting @@ -43,15 +43,15 @@ class Test_Piwik_Integration_VisitsInPast_InvalidateOldReports extends Integrati // Build tests for the 2 websites return array( - array($apiToCall, array('idSite' => $this->idSite, - 'testSuffix' => 'Website' . $this->idSite . '_OldReportsShouldNotAppear', - 'date' => $this->dateTimeDateInPastWebsite1, + array($apiToCall, array('idSite' => self::$idSite, + 'testSuffix' => 'Website' . self::$idSite . '_OldReportsShouldNotAppear', + 'date' => self::$dateTimeDateInPastWebsite1, 'periods' => 'month', 'setDateLastN' => 4, // 4months ahead 'otherRequestParameters' => array('expanded' => 1))), - array($apiToCall, array('idSite' => $this->idSite2, - 'testSuffix' => 'Website' . $this->idSite2 . '_OldReportsShouldNotAppear', - 'date' => $this->dateTimeDateInPastWebsite2, + array($apiToCall, array('idSite' => self::$idSite2, + 'testSuffix' => 'Website' . self::$idSite2 . '_OldReportsShouldNotAppear', + 'date' => self::$dateTimeDateInPastWebsite2, 'periods' => 'month', 'setDateLastN' => 4, // 4months ahead 'otherRequestParameters' => array('expanded' => 1))), @@ -70,13 +70,13 @@ class Test_Piwik_Integration_VisitsInPast_InvalidateOldReports extends Integrati $r = new Piwik_API_Request("module=API&method=CoreAdminHome.invalidateArchivedReports&idSites=4,5,6,55,-1,s',1&dates=2010-01-03"); ($r->process()); // Test invalidate comma separated dates - $r = new Piwik_API_Request("module=API&method=CoreAdminHome.invalidateArchivedReports&idSites=" . $this->idSite . "," . $this->idSite2 . "&dates=2010-01-06,2009-10-30"); + $r = new Piwik_API_Request("module=API&method=CoreAdminHome.invalidateArchivedReports&idSites=" . self::$idSite . "," . self::$idSite2 . "&dates=2010-01-06,2009-10-30"); ($r->process()); // test invalidate date in the past - $r = new Piwik_API_Request("module=API&method=CoreAdminHome.invalidateArchivedReports&idSites=" . $this->idSite2 . "&dates=2009-06-29"); + $r = new Piwik_API_Request("module=API&method=CoreAdminHome.invalidateArchivedReports&idSites=" . self::$idSite2 . "&dates=2009-06-29"); ($r->process()); // invalidate a date more recent to check the date is only updated when it's earlier than current - $r = new Piwik_API_Request("module=API&method=CoreAdminHome.invalidateArchivedReports&idSites=" . $this->idSite2 . "&dates=2010-03-03"); + $r = new Piwik_API_Request("module=API&method=CoreAdminHome.invalidateArchivedReports&idSites=" . self::$idSite2 . "&dates=2010-03-03"); ($r->process()); // 2) Call API again, with an older date, which should now return data @@ -92,15 +92,15 @@ class Test_Piwik_Integration_VisitsInPast_InvalidateOldReports extends Integrati $apiToCall = array('VisitsSummary.get', 'Actions.getPageUrls'); return array( - array($apiToCall, array('idSite' => $this->idSite, - 'testSuffix' => 'Website' . $this->idSite . '_OldReportsShouldAppear', - 'date' => $this->dateTimeDateInPastWebsite1, + array($apiToCall, array('idSite' => self::$idSite, + 'testSuffix' => 'Website' . self::$idSite . '_OldReportsShouldAppear', + 'date' => self::$dateTimeDateInPastWebsite1, 'periods' => 'month', 'setDateLastN' => 4, // 4months ahead 'otherRequestParameters' => array('expanded' => 1))), - array($apiToCall, array('idSite' => $this->idSite2, - 'testSuffix' => 'Website' . $this->idSite2 . '_OldReportsShouldAppear', - 'date' => $this->dateTimeDateInPastWebsite2, + array($apiToCall, array('idSite' => self::$idSite2, + 'testSuffix' => 'Website' . self::$idSite2 . '_OldReportsShouldAppear', + 'date' => self::$dateTimeDateInPastWebsite2, 'periods' => 'month', 'setDateLastN' => 4, // 4months ahead 'otherRequestParameters' => array('expanded' => 1))), @@ -114,8 +114,8 @@ class Test_Piwik_Integration_VisitsInPast_InvalidateOldReports extends Integrati public function setUpWebsitesAndGoals() { - $this->createWebsite($this->dateTimeFirstDateWebsite1); - $this->createWebsite($this->dateTimeFirstDateWebsite2); + $this->createWebsite(self::$dateTimeFirstDateWebsite1); + $this->createWebsite(self::$dateTimeFirstDateWebsite2); } protected function trackVisits() @@ -125,7 +125,7 @@ class Test_Piwik_Integration_VisitsInPast_InvalidateOldReports extends Integrati */ // WEBSITE 1 - $t = $this->getTracker($this->idSite, $this->dateTimeFirstDateWebsite1, $defaultInit = true); + $t = $this->getTracker(self::$idSite, self::$dateTimeFirstDateWebsite1, $defaultInit = true); $t->setUrl('http://example.org/category/Page1'); $this->checkResponse($t->doTrackPageView('Hello')); $t->setUrl('http://example.org/category/Page2'); @@ -140,7 +140,7 @@ class Test_Piwik_Integration_VisitsInPast_InvalidateOldReports extends Integrati $this->checkResponse($t->doTrackPageView('Hello')); // WEBSITE 2 - $t = $this->getTracker($this->idSite2, $this->dateTimeFirstDateWebsite2, $defaultInit = true); + $t = $this->getTracker(self::$idSite2, self::$dateTimeFirstDateWebsite2, $defaultInit = true); $t->setIp('156.15.13.12'); $t->setUrl('http://example.org/category/Page1'); $this->checkResponse($t->doTrackPageView('Hello')); @@ -159,7 +159,7 @@ class Test_Piwik_Integration_VisitsInPast_InvalidateOldReports extends Integrati * Track visits in the past (before website creation date) for the 2 websites */ // WEBSITE1 - $t = $this->getTracker($this->idSite, $this->dateTimeDateInPastWebsite1, $defaultInit = true); + $t = $this->getTracker(self::$idSite, self::$dateTimeDateInPastWebsite1, $defaultInit = true); $t->setIp('156.5.55.2'); $t->setUrl('http://example.org/category/Page1'); $this->checkResponse($t->doTrackPageView('Hello')); @@ -168,7 +168,7 @@ class Test_Piwik_Integration_VisitsInPast_InvalidateOldReports extends Integrati $t->setUrl('http://example.org/category/Page3'); // WEBSITE2 - $t = $this->getTracker($this->idSite2, $this->dateTimeDateInPastWebsite2, $defaultInit = true); + $t = $this->getTracker(self::$idSite2, self::$dateTimeDateInPastWebsite2, $defaultInit = true); $t->setIp('156.52.3.22'); $t->setUrl('http://example.org/category/Page1'); $this->checkResponse($t->doTrackPageView('Hello')); diff --git a/tests/PHPUnit/IntegrationTestCase.php b/tests/PHPUnit/IntegrationTestCase.php index 6f7943d6c380b771d84593d492913e1878039d43..91db60558ae027db521e7ecc88cce4b918001ae6 100755 --- a/tests/PHPUnit/IntegrationTestCase.php +++ b/tests/PHPUnit/IntegrationTestCase.php @@ -1033,19 +1033,6 @@ abstract class IntegrationTestCase extends DatabaseTestCase return array(); } - /** - * It is possible to run another set of API tests after the first one. - * For example, getApiForTesting() will test and record with a specific suffix - * Then we will call some API that invalidates a piece of the reports - * Then call all reports again and check that what is expected to have changed indeed has changed! - * - * @see getApiForTesting() for returned values, same signature - */ - public function getAnotherApiForTesting() - { - return array(); - } - /** * Returns an array describing the Controller actions to call & compare * with expected output.