diff --git a/tests/PHPUnit/Integration/ApiGetReportMetadataTest.php b/tests/PHPUnit/Integration/ApiGetReportMetadataTest.php index eb19ba9df9ad7d00dfb1f728a6b8e1b862f8cbe9..488fe2e1f6d86278e9ae9f7451a3e396387a95d5 100755 --- a/tests/PHPUnit/Integration/ApiGetReportMetadataTest.php +++ b/tests/PHPUnit/Integration/ApiGetReportMetadataTest.php @@ -20,23 +20,26 @@ class Test_Piwik_Integration_ApiGetReportMetadata extends IntegrationTestCase protected static $idGoal2 = 2; protected static $idGoal3 = 3; - protected function setUpWebsitesAndGoals() - { - $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() + public static function setUpBeforeClass() { - parent::setUp(); + parent::setUpBeforeClass(); + self::setUpWebsitesAndGoals(); + self::trackVisits(); // From Piwik 1.5, we hide Goals.getConversions and other get* methods via @ignore, but we ensure that they still work // This hack allows the API proxy to let us generate example URLs for the ignored functions Piwik_API_Proxy::getInstance()->hideIgnoredFunctions = false; } + protected static function setUpWebsitesAndGoals() + { + self::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 getOutputPrefix() { return 'apiGetReportMetadata'; @@ -59,19 +62,19 @@ class Test_Piwik_Integration_ApiGetReportMetadata extends IntegrationTestCase $this->runApiTests($api, $params); } - protected function trackVisits() + protected static function trackVisits() { $idSite = self::$idSite; $dateTime = self::$dateTime; - $t = $this->getTracker($idSite, $dateTime, $defaultInit = true); + $t = self::getTracker($idSite, $dateTime, $defaultInit = true); // Record 1st page view $t->setUrl('http://example.org/index.htm'); - $this->checkResponse($t->doTrackPageView('incredible title!')); + self::checkResponse($t->doTrackPageView('incredible title!')); $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.3)->getDatetime()); - $this->checkResponse($t->doTrackGoal(self::$idGoal3, $revenue = 42.256)); + self::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 fe695f519f00f56b6c71294519790d24db6e172c..b04a7dff67892b698bd05fc4703018c227baf64c 100755 --- a/tests/PHPUnit/Integration/ApiGetReportMetadata_yearTest.php +++ b/tests/PHPUnit/Integration/ApiGetReportMetadata_yearTest.php @@ -16,12 +16,19 @@ class Test_Piwik_Integration_ApiGetReportMetadata_Year extends IntegrationTestCa protected static $idSite = 1; protected static $dateTime = '2009-01-04 00:11:42'; - protected function setUpWebsitesAndGoals() + public static function setUpBeforeClass() { - $this->createWebsite(self::$dateTime); + parent::setUpBeforeClass(); + self::setUpWebsitesAndGoals(); + self::trackVisits(); } - protected function trackVisits() + protected static function setUpWebsitesAndGoals() + { + self::createWebsite(self::$dateTime); + } + + protected static function trackVisits() { } diff --git a/tests/PHPUnit/Integration/CsvExportTest.php b/tests/PHPUnit/Integration/CsvExportTest.php index 6f6420031e1af440c7786893dd488855a1c59750..a89c0a8ef5a1dd129727f8509742a2ecd3cf3414 100755 --- a/tests/PHPUnit/Integration/CsvExportTest.php +++ b/tests/PHPUnit/Integration/CsvExportTest.php @@ -14,8 +14,20 @@ require_once dirname(__FILE__).'/TwoVisitsWithCustomVariablesTest.php'; */ class Test_Piwik_Integration_CsvExport extends Test_Piwik_Integration_TwoVisitsWithCustomVariables { - protected static $useEscapedQuotes = false; - protected static $doExtraQuoteTests = false; + + public static function setUpBeforeClass() + { + IntegrationTestCase::setUpBeforeClass(); + self::$visitorId = substr(md5(uniqid()), 0, 16); + self::setUpWebsitesAndGoals(); + self::trackVisits(); + } + + protected static function trackVisits() { + self::$useEscapedQuotes = false; + self::$doExtraQuoteTests = false; + parent::trackVisits(); + } public function getApiForTesting() { @@ -27,7 +39,8 @@ class Test_Piwik_Integration_CsvExport extends Test_Piwik_Integration_TwoVisitsW return array( array($apiToCall, array('idSite' => self::$idSite, - 'date' => self::$dateTime, 'format' => 'csv', + 'date' => self::$dateTime, + 'format' => 'csv', 'otherRequestParameters' => array('expanded' => 0, 'flat' => 0), 'testSuffix' => '_xp0')), diff --git a/tests/PHPUnit/Integration/EcommerceOrderWithItemsTest.php b/tests/PHPUnit/Integration/EcommerceOrderWithItemsTest.php index a440ced844a4803086bdeb8e489ed0458b9662f3..20465b2fd6139d6a6c959dcb621bfed0992654f6 100755 --- a/tests/PHPUnit/Integration/EcommerceOrderWithItemsTest.php +++ b/tests/PHPUnit/Integration/EcommerceOrderWithItemsTest.php @@ -17,6 +17,13 @@ class Test_Piwik_Integration_EcommerceOrderWithItems extends IntegrationTestCase protected static $idSite2 = 1; protected static $idGoalStandard = 1; + public static function setUpBeforeClass() + { + parent::setUpBeforeClass(); + self::setUpWebsitesAndGoals(); + self::trackVisits(); + } + /** * @dataProvider getApiForTesting * @group Integration @@ -166,20 +173,20 @@ class Test_Piwik_Integration_EcommerceOrderWithItems extends IntegrationTestCase return 'ecommerceOrderWithItems'; } - public function setUpWebsitesAndGoals() + public static function setUpWebsitesAndGoals() { - $this->createWebsite(self::$dateTime, $ecommerce = 1); - $this->createWebsite(self::$dateTime); + self::createWebsite(self::$dateTime, $ecommerce = 1); + self::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() + protected static function trackVisits() { $dateTime = self::$dateTime; $idSite = self::$idSite; $idSite2 = self::$idSite2; - $t = $this->getTracker($idSite, $dateTime, $defaultInit = true); + $t = self::getTracker($idSite, $dateTime, $defaultInit = true); // VISIT NO 1 $t->setUrl('http://example.org/index.htm'); $category = 'Electronics & Cameras'; @@ -189,25 +196,25 @@ class Test_Piwik_Integration_EcommerceOrderWithItems extends IntegrationTestCase $t->setEcommerceView('SKU2', 'PRODUCT name', $category, $price); $t->setCustomVariable(5, 'VisitorType', 'NewLoggedOut', 'visit'); $t->setCustomVariable(4, 'ValueIsZero', '0', 'visit'); - $this->assertTrue($t->getCustomVariable(3, 'page') == array('_pks', 'SKU2')); - $this->assertTrue($t->getCustomVariable(4, 'page') == array('_pkn', 'PRODUCT name')); - $this->assertTrue($t->getCustomVariable(5, 'page') == array('_pkc', $category)); - $this->assertTrue($t->getCustomVariable(2, 'page') == array('_pkp', $price)); - $this->assertTrue($t->getCustomVariable(5, 'visit') == array('VisitorType', 'NewLoggedOut')); - $this->checkResponse($t->doTrackPageView('incredible title!')); + self::assertTrue($t->getCustomVariable(3, 'page') == array('_pks', 'SKU2')); + self::assertTrue($t->getCustomVariable(4, 'page') == array('_pkn', 'PRODUCT name')); + self::assertTrue($t->getCustomVariable(5, 'page') == array('_pkc', $category)); + self::assertTrue($t->getCustomVariable(2, 'page') == array('_pkp', $price)); + self::assertTrue($t->getCustomVariable(5, 'visit') == array('VisitorType', 'NewLoggedOut')); + self::checkResponse($t->doTrackPageView('incredible title!')); $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.1)->getDatetime()); $t->setEcommerceView($sku = 'SKU VERY nice indeed', $name = 'PRODUCT name', $category, $price = 666); - $this->checkResponse($t->doTrackPageView('Another Product page')); + self::checkResponse($t->doTrackPageView('Another Product page')); // Note: here testing to pass a timestamp to the tracking API rather than the datetime string $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.2)->getTimestampUTC()); $t->setEcommerceView($sku = 'SKU VERY nice indeed', $name = 'PRODUCT name', ''); - $this->checkResponse($t->doTrackPageView('Another Product page with no category')); + self::checkResponse($t->doTrackPageView('Another Product page with no category')); $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.2)->getDatetime()); $t->setEcommerceView($sku = 'SKU VERY nice indeed', $name = 'PRODUCT name', $categories = array('Multiple Category 1', '', 0, 'Multiple Category 2', 'Electronics & Cameras', 'Multiple Category 4', 'Multiple Category 5', 'SHOULD NOT BE REPORTEDSSSSSSSSSSSSSSssssssssssssssssssssssssssstttttttttttttttttttttttuuuu!')); - $this->checkResponse($t->doTrackPageView('Another Product page with multiple categories')); + self::checkResponse($t->doTrackPageView('Another Product page with multiple categories')); // VISIT NO 2 @@ -217,17 +224,17 @@ class Test_Piwik_Integration_EcommerceOrderWithItems extends IntegrationTestCase // VIEW category page $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(1.6)->getDatetime()); $t->setEcommerceView('', '', $category); - $this->checkResponse($t->doTrackPageView('Looking at ' . $category . ' page with a page level custom variable')); + self::checkResponse($t->doTrackPageView('Looking at ' . $category . ' page with a page level custom variable')); // VIEW category page again $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(1.7)->getDatetime()); $t->setEcommerceView('', '', $category); - $this->checkResponse($t->doTrackPageView('Looking at ' . $category . ' page again')); + self::checkResponse($t->doTrackPageView('Looking at ' . $category . ' page again')); // VIEW product page $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(1.8)->getDatetime()); $t->setEcommerceView($sku = 'SKU VERY nice indeed', $name = 'PRODUCT name', $category = 'Electronics & Cameras', $price = 666); - $this->checkResponse($t->doTrackPageView('Looking at product page')); + self::checkResponse($t->doTrackPageView('Looking at product page')); // ADD TO CART $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(1.9)->getDatetime()); @@ -235,13 +242,13 @@ class Test_Piwik_Integration_EcommerceOrderWithItems extends IntegrationTestCase $t->addEcommerceItem($sku = 'SKU VERY nice indeed', $name = 'PRODUCT name', $category = 'Electronics & Cameras', $price = 500, $quantity = 1); $t->addEcommerceItem($sku = 'SKU VERY nice indeed', $name = 'PRODUCT name', $category = 'Electronics & Cameras', $price = 500, $quantity = 2); $t->addEcommerceItem($sku = 'SKU WILL BE DELETED', $name = 'BLABLA DELETED', $category = '', $price = 5000000, $quantity = 20); - $this->checkResponse($t->doTrackEcommerceCartUpdate($grandTotal = 1000)); + self::checkResponse($t->doTrackEcommerceCartUpdate($grandTotal = 1000)); // ORDER NO 1 $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(2)->getDatetime()); $t->addEcommerceItem($sku = 'SKU VERY nice indeed', $name = 'PRODUCT name', $categories, $price = 500, $quantity = 2); $t->addEcommerceItem($sku = 'ANOTHER SKU HERE', $name = 'PRODUCT name BIS', $category = '', $price = 100, $quantity = 6); - $this->checkResponse($t->doTrackEcommerceOrder($orderId = '937nsjusu 3894', $grandTotal = 1111.11, $subTotal = 1000, $tax = 111, $shipping = 0.11, $discount = 666)); + self::checkResponse($t->doTrackEcommerceOrder($orderId = '937nsjusu 3894', $grandTotal = 1111.11, $subTotal = 1000, $tax = 111, $shipping = 0.11, $discount = 666)); // ORDER NO 2 $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(2.1)->getDatetime()); @@ -254,7 +261,7 @@ class Test_Piwik_Integration_EcommerceOrderWithItems extends IntegrationTestCase // without passing the custom variable 1st party cookie along since it's not known by back office $visitorCustomVarSave = $t->visitorCustomVar; $t->visitorCustomVar = false; - $this->checkResponse($t->doTrackEcommerceOrder($orderId = '1037nsjusu4s3894', $grandTotal = 2000, $subTotal = 1500, $tax = 400, $shipping = 100, $discount = 0)); + self::checkResponse($t->doTrackEcommerceOrder($orderId = '1037nsjusu4s3894', $grandTotal = 2000, $subTotal = 1500, $tax = 400, $shipping = 100, $discount = 0)); $t->visitorCustomVar = $visitorCustomVarSave; // ORDER SHOULD DEDUPE @@ -262,13 +269,13 @@ class Test_Piwik_Integration_EcommerceOrderWithItems extends IntegrationTestCase // we test that both the order, and the products, are not updated on subsequent "Receipt" views $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(2.2)->getDatetime()); $t->addEcommerceItem($sku = 'SKU2', $name = 'Canon SLR NOT!', $category = 'Electronics & Cameras NOT!', $price = 15000000000, $quantity = 10000); - $this->checkResponse($t->doTrackEcommerceOrder($orderId = '1037nsjusu4s3894', $grandTotal = 20000000, $subTotal = 1500, $tax = 400, $shipping = 100, $discount = 0)); + self::checkResponse($t->doTrackEcommerceOrder($orderId = '1037nsjusu4s3894', $grandTotal = 20000000, $subTotal = 1500, $tax = 400, $shipping = 100, $discount = 0)); // Leave with an opened cart // No category $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(2.3)->getDatetime()); $t->addEcommerceItem($sku = 'SKU IN ABANDONED CART ONE', $name = 'PRODUCT ONE LEFT in cart', $category = '', $price = 500.11111112, $quantity = 2); - $this->checkResponse($t->doTrackEcommerceCartUpdate($grandTotal = 1000)); + self::checkResponse($t->doTrackEcommerceCartUpdate($grandTotal = 1000)); // Record the same visit leaving twice an abandoned cart foreach (array(0, 5, 24) as $offsetHour) { @@ -277,44 +284,44 @@ class Test_Piwik_Integration_EcommerceOrderWithItems extends IntegrationTestCase if ($offsetHour >= 24) { $t->setDebugStringAppend("&_idvc=1"); $t->addEcommerceItem($sku = 'SKU2', $name = 'Canon SLR', $category = 'Electronics & Cameras', $price = 1500, $quantity = 1); - $this->checkResponse($t->doTrackEcommerceOrder($orderId = '1037nsjusu4s3894', $grandTotal = 20000000, $subTotal = 1500, $tax = 400, $shipping = 100, $discount = 0)); + self::checkResponse($t->doTrackEcommerceOrder($orderId = '1037nsjusu4s3894', $grandTotal = 20000000, $subTotal = 1500, $tax = 400, $shipping = 100, $discount = 0)); } // VIEW PRODUCT PAGES $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour($offsetHour + 2.5)->getDatetime()); $t->setEcommerceView($sku = 'SKU VERY nice indeed', $name = 'PRODUCT THREE LEFT in cart', $category = '', $price = 999); - $this->checkResponse($t->doTrackPageView("View product left in cart")); + self::checkResponse($t->doTrackPageView("View product left in cart")); $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour($offsetHour + 2.55)->getDatetime()); $t->setEcommerceView($sku = 'SKU VERY nice indeed', $name = 'PRODUCT THREE LEFT in cart', $category = '', $price = 333); - $this->checkResponse($t->doTrackPageView("View product left in cart")); + self::checkResponse($t->doTrackPageView("View product left in cart")); $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour($offsetHour + 2.6)->getDatetime()); $t->setEcommerceView($sku = 'SKU IN ABANDONED CART TWO', $name = 'PRODUCT TWO LEFT in cart', $category = 'Category TWO LEFT in cart'); - $this->checkResponse($t->doTrackPageView("View product left in cart")); + self::checkResponse($t->doTrackPageView("View product left in cart")); // ABANDONED CART $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour($offsetHour + 2.7)->getDatetime()); $t->addEcommerceItem($sku = 'SKU IN ABANDONED CART ONE', $name = 'PRODUCT ONE LEFT in cart', $category = '', $price = 500.11111112, $quantity = 1); $t->addEcommerceItem($sku = 'SKU IN ABANDONED CART TWO', $name = 'PRODUCT TWO LEFT in cart', $category = 'Category TWO LEFT in cart', $price = 1000, $quantity = 2); $t->addEcommerceItem($sku = 'SKU VERY nice indeed', $name = 'PRODUCT THREE LEFT in cart', $category = 'Electronics & Cameras', $price = 10, $quantity = 1); - $this->checkResponse($t->doTrackEcommerceCartUpdate($grandTotal = 2510.11111112)); + self::checkResponse($t->doTrackEcommerceCartUpdate($grandTotal = 2510.11111112)); } // One more Ecommerce order to check weekly archiving works fine on orders $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(30.7)->getDatetime()); $t->addEcommerceItem($sku = 'TRIPOD SKU', $name = 'TRIPOD - bought day after', $category = 'Tools', $price = 100, $quantity = 2); - $this->checkResponse($t->doTrackEcommerceOrder($orderId = '666', $grandTotal = 240, $subTotal = 200, $tax = 20, $shipping = 20, $discount = 20)); + self::checkResponse($t->doTrackEcommerceOrder($orderId = '666', $grandTotal = 240, $subTotal = 200, $tax = 20, $shipping = 20, $discount = 20)); // One more Ecommerce order, without any product in it, because we still track orders without products $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(30.8)->getDatetime()); - $this->checkResponse($t->doTrackEcommerceOrder($orderId = '777', $grandTotal = 10000)); + self::checkResponse($t->doTrackEcommerceOrder($orderId = '777', $grandTotal = 10000)); // testing the same order in a different website should record - $t = $this->getTracker($idSite2, $dateTime, $defaultInit = true); + $t = self::getTracker($idSite2, $dateTime, $defaultInit = true); $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(30.9)->getDatetime()); $t->addEcommerceItem($sku = 'TRIPOD SKU', $name = 'TRIPOD - bought day after', $category = 'Tools', $price = 100, $quantity = 2); - $this->checkResponse($t->doTrackEcommerceOrder($orderId = '777', $grandTotal = 250)); + self::checkResponse($t->doTrackEcommerceOrder($orderId = '777', $grandTotal = 250)); //------------------------------------- End tracking } } diff --git a/tests/PHPUnit/Integration/FlattenReportsTest.php b/tests/PHPUnit/Integration/FlattenReportsTest.php index aa6cec28ca5923321516e7ee8cf299aeea89b1ec..796c6044e98b21c4011bd59143dee48dd733ab4f 100644 --- a/tests/PHPUnit/Integration/FlattenReportsTest.php +++ b/tests/PHPUnit/Integration/FlattenReportsTest.php @@ -15,6 +15,13 @@ class Test_Piwik_Integration_FlattenReports extends IntegrationTestCase protected static $dateTime = '2010-03-06 11:22:33'; protected static $idSite = 1; + public static function setUpBeforeClass() + { + parent::setUpBeforeClass(); + self::setUpWebsitesAndGoals(); + self::trackVisits(); + } + /** * @dataProvider getApiForTesting * @group Integration @@ -85,12 +92,12 @@ class Test_Piwik_Integration_FlattenReports extends IntegrationTestCase return 'FlattenReports'; } - protected function setUpWebsitesAndGoals() + protected static function setUpWebsitesAndGoals() { - $this->createWebsite(self::$dateTime); + self::createWebsite(self::$dateTime); } - protected function trackVisits() + protected static function trackVisits() { $dateTime = self::$dateTime; $idSite = self::$idSite; @@ -98,22 +105,22 @@ class Test_Piwik_Integration_FlattenReports extends IntegrationTestCase for ($referrerSite = 1; $referrerSite < 4; $referrerSite++) { for ($referrerPage = 1; $referrerPage < 3; $referrerPage++) { $offset = $referrerSite * 3 + $referrerPage; - $t = $this->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'); - $this->checkResponse($t->doTrackPageView('title')); + self::checkResponse($t->doTrackPageView('title')); } } } - $t = $this->getTracker($idSite, Piwik_Date::factory($dateTime)->addHour(24)->getDatetime()); + $t = self::getTracker($idSite, Piwik_Date::factory($dateTime)->addHour(24)->getDatetime()); $t->setCustomVariable(1, 'CustomVarVisit', 'CustomVarValue1', 'visit'); $t->setUrl('http://example.org/sub/dir/dir1/page1.html'); $t->setCustomVariable(1, 'CustomVarPage', 'CustomVarValue1', 'page'); - $this->checkResponse($t->doTrackPageView('title')); + self::checkResponse($t->doTrackPageView('title')); } } diff --git a/tests/PHPUnit/Integration/LabelFilterTest.php b/tests/PHPUnit/Integration/LabelFilterTest.php index 9a1b9f2cd72ca25118e4a3b4b12229dba7b7daa4..31ad78f0c2305df98b7b97a95e93d15a7eb880a2 100644 --- a/tests/PHPUnit/Integration/LabelFilterTest.php +++ b/tests/PHPUnit/Integration/LabelFilterTest.php @@ -16,6 +16,13 @@ class Test_Piwik_Integration_LabelFilter extends IntegrationTestCase protected static $dateTime = '2010-03-06 11:22:33'; protected static $idSite = 1; + public static function setUpBeforeClass() + { + parent::setUpBeforeClass(); + self::setUpWebsitesAndGoals(); + self::trackVisits(); + } + /** * @dataProvider getApiForTesting * @group Integration @@ -119,40 +126,40 @@ class Test_Piwik_Integration_LabelFilter extends IntegrationTestCase return 'LabelFilter'; } - protected function setUpWebsitesAndGoals() + protected static function setUpWebsitesAndGoals() { - $this->createWebsite(self::$dateTime); + self::createWebsite(self::$dateTime); } - protected function trackVisits() + protected static function trackVisits() { $dateTime = self::$dateTime; $idSite = self::$idSite; - $t = $this->getTracker($idSite, $dateTime, $defaultInit = true, $useThirdPartyCookie = 1); + $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!'); - $this->checkResponse($t->doTrackPageView('incredible title! <>,;')); + 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()); - $this->checkResponse($t->doTrackPageView('incredible title! <>,;')); + 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()); - $this->checkResponse($t->doTrackPageView('incredible parent title! <>,; / subtitle <>,;')); + 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()); - $this->checkResponse($t->doTrackPageView('incredible title! <>,;')); + 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()); - $this->checkResponse($t->doTrackPageView('incredible title! <>,;')); + self::checkResponse($t->doTrackPageView('incredible title! <>,;')); $t->setUrl('http://example.org/0'); $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.4)->getDatetime()); - $this->checkResponse($t->doTrackPageView('I am URL zero!')); + self::checkResponse($t->doTrackPageView('I am URL zero!')); } } diff --git a/tests/PHPUnit/Integration/NoVisitTest.php b/tests/PHPUnit/Integration/NoVisitTest.php index 325a29d743cc73735e0d6ad52632bbcb68b85c4c..e3d9bc449a89ca55e6d34a1a3ea9fbd9f5f6b6e0 100755 --- a/tests/PHPUnit/Integration/NoVisitTest.php +++ b/tests/PHPUnit/Integration/NoVisitTest.php @@ -17,10 +17,17 @@ class Test_Piwik_Integration_NoVisit extends IntegrationTestCase protected static $idSite = 1; protected static $dateTime = '2009-01-04 00:11:42'; + public static function setUpBeforeClass() + { + parent::setUpBeforeClass(); + self::setUpWebsitesAndGoals(); + self::trackVisits(); + } + /** * @dataProvider getApiForTesting * @group Integration - * @group NoVisits + * @group NoVisit */ public function testApi($api, $params) { @@ -46,38 +53,38 @@ class Test_Piwik_Integration_NoVisit extends IntegrationTestCase return 'noVisit'; } - public function setUpWebsitesAndGoals() + public static function setUpWebsitesAndGoals() { - $this->createWebsite(self::$dateTime); + self::createWebsite(self::$dateTime); } - protected function trackVisits() + protected static function trackVisits() { $dateTime = self::$dateTime; $idSite = self::$idSite; /* // Trigger invalid website - $trackerInvalidWebsite = $this->getTracker($idSiteFake = 0, $dateTime, $defaultInit = true); + $trackerInvalidWebsite = self::getTracker($idSiteFake = 0, $dateTime, $defaultInit = true); $response = Piwik_Http::fetchRemoteFile($trackerInvalidWebsite->getUrlTrackPageView()); - $this->assertTrue(strpos($response, 'Invalid idSite') !== false, 'invalid website ID'); + self::assertTrue(strpos($response, 'Invalid idSite') !== false, 'invalid website ID'); // Trigger wrong website - $trackerWrongWebsite = $this->getTracker($idSiteFake = 33, $dateTime, $defaultInit = true); + $trackerWrongWebsite = self::getTracker($idSiteFake = 33, $dateTime, $defaultInit = true); $response = Piwik_Http::fetchRemoteFile($trackerWrongWebsite->getUrlTrackPageView()); - $this->assertTrue(strpos($response, 'The requested website id = 33 couldn\'t be found') !== false, 'non-existent website ID'); + self::assertTrue(strpos($response, 'The requested website id = 33 couldn\'t be found') !== false, 'non-existent website ID'); */ // Trigger empty request - $trackerUrl = $this->getTrackerUrl(); + $trackerUrl = self::getTrackerUrl(); $response = Piwik_Http::fetchRemoteFile($trackerUrl); - $this->assertTrue(strpos($response, 'web analytics') !== false, 'Piwik empty request response not correct: ' . $response); + self::assertTrue(strpos($response, 'web analytics') !== false, 'Piwik empty request response not correct: ' . $response); - $t = $this->getTracker($idSite, $dateTime, $defaultInit = true); + $t = self::getTracker($idSite, $dateTime, $defaultInit = true); // test GoogleBot UA visitor $t->setUserAgent('Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'); - $this->checkResponse($t->doTrackPageView('bot visit, please do not record')); + self::checkResponse($t->doTrackPageView('bot visit, please do not record')); // Test IP Exclusion works with or without IP exclusion foreach (array(false, true) as $enable) { @@ -89,24 +96,24 @@ class Test_Piwik_Integration_NoVisit extends IntegrationTestCase $excludedIp = '154.1.12.34'; Piwik_SitesManager_API::getInstance()->updateSite($idSite, 'new site name', $url = array('http://site.com'), $ecommerce = 0, $excludedIp . ',1.2.3.4'); $t->setIp($excludedIp); - $this->checkResponse($t->doTrackPageView('visit from IP excluded')); + 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); $t->setIp($excludedIpBis); - $this->checkResponse($t->doTrackPageView('visit from IP globally excluded')); + self::checkResponse($t->doTrackPageView('visit from IP globally excluded')); } try { @$t->setAttributionInfo(array()); - $this->fail(); + self::fail(); } catch (Exception $e) { } try { $t->setAttributionInfo(json_encode('test')); - $this->fail(); + self::fail(); } catch (Exception $e) { } diff --git a/tests/PHPUnit/Integration/OneVisitorOneWebsite_SeveralDaysDateRangeTest.php b/tests/PHPUnit/Integration/OneVisitorOneWebsite_SeveralDaysDateRangeTest.php index c0f06953216d088791f09800b00a42faf1a4ff4c..72be17fad6ce9094cefde84eae59cf840dca1ab3 100755 --- a/tests/PHPUnit/Integration/OneVisitorOneWebsite_SeveralDaysDateRangeTest.php +++ b/tests/PHPUnit/Integration/OneVisitorOneWebsite_SeveralDaysDateRangeTest.php @@ -21,6 +21,13 @@ class Test_Piwik_Integration_OneVisitorOneWebsite_SeveralDaysDateRange extends I ); protected static $idSite = 1; + public static function setUpBeforeClass() + { + parent::setUpBeforeClass(); + self::setUpWebsitesAndGoals(); + self::trackVisits(); + } + /** * @dataProvider getApiForTesting * @group Integration @@ -53,12 +60,12 @@ class Test_Piwik_Integration_OneVisitorOneWebsite_SeveralDaysDateRange extends I return 'oneVisitor_oneWebsite_severalDays_DateRange'; } - protected function setUpWebsitesAndGoals() + protected static function setUpWebsitesAndGoals() { - $this->createWebsite(self::$dateTimes[0]); + self::createWebsite(self::$dateTimes[0]); } - protected function trackVisits() + protected static function trackVisits() { $dateTimes = self::$dateTimes; $idSite = self::$idSite; @@ -66,24 +73,24 @@ class Test_Piwik_Integration_OneVisitorOneWebsite_SeveralDaysDateRange extends I $i = 0; foreach ($dateTimes as $dateTime) { $i++; - $visitor = $this->getTracker($idSite, $dateTime, $defaultInit = true); + $visitor = self::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')); + self::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')); + self::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')); + self::checkResponse($visitor->doTrackPageView('ou pas')); } } } diff --git a/tests/PHPUnit/Integration/OneVisitorOneWebsite_SeveralDaysDateRange_ArchivingTestsTest.php b/tests/PHPUnit/Integration/OneVisitorOneWebsite_SeveralDaysDateRange_ArchivingTestsTest.php index 1cae72c06bf147c4f0e5a3d5f8b64a2092a6d2b0..771a0dd43050f503b32f641b845eb4c09b4c4afc 100755 --- a/tests/PHPUnit/Integration/OneVisitorOneWebsite_SeveralDaysDateRange_ArchivingTestsTest.php +++ b/tests/PHPUnit/Integration/OneVisitorOneWebsite_SeveralDaysDateRange_ArchivingTestsTest.php @@ -16,19 +16,49 @@ require_once dirname(__FILE__) . '/OneVisitorOneWebsite_SeveralDaysDateRangeTest class Test_Piwik_Integration_OneVisitorOneWebsite_SeveralDaysDateRange_ArchivingTests extends Test_Piwik_Integration_OneVisitorOneWebsite_SeveralDaysDateRange { /** + * @dataProvider getApiForTesting * @group Integration * @group OneVisitorOneWebsite_SeveralDaysDateRange_ArchivingTests */ - public function testApi() + public function testApi($api, $params) { - $testData = $this->getApiForTesting(); + $this->runApiTests($api, $params); + } - foreach ($testData AS $data) { - $api = $data[0]; - $params = $data[1]; - $this->runApiTests($api, $params); + 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; + } + + /** + * @depends testApi + * @group Integration + * @group OneVisitorOneWebsite_SeveralDaysDateRange_ArchivingTests + */ + public function testCheck() + { 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 @@ -55,30 +85,4 @@ class Test_Piwik_Integration_OneVisitorOneWebsite_SeveralDaysDateRange_Archiving } } - 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 index 60950393db103ff71c51e07a8513c223735d8057..01fc3b437463709e351c18f5f2a9eb8606156ae9 100755 --- a/tests/PHPUnit/Integration/OneVisitorTwoVisitsTest.php +++ b/tests/PHPUnit/Integration/OneVisitorTwoVisitsTest.php @@ -22,6 +22,13 @@ class Test_Piwik_Integration_OneVisitorTwoVisits extends IntegrationTestCase protected static $idSite = 1; protected static $dateTime = '2010-03-06 11:22:33'; + public static function setUpBeforeClass() + { + parent::setUpBeforeClass(); + self::setUpWebsitesAndGoals(); + self::trackVisits(); + } + /** * @dataProvider getApiForTesting * @group Integration @@ -59,19 +66,22 @@ class Test_Piwik_Integration_OneVisitorTwoVisits extends IntegrationTestCase ); } - protected function setUpWebsitesAndGoals() + protected static function setUpWebsitesAndGoals() { // tests run in UTC, the Tracker in UTC - $this->createWebsite(self::$dateTime); + self::createWebsite(self::$dateTime); } - protected function trackVisits() + protected static function trackVisits() { - $t = $this->getTracker(self::$idSite, self::$dateTime, $defaultInit = true); - $this->trackVisitsImpl($t); + $t = self::getTracker(self::$idSite, self::$dateTime, $defaultInit = true); + self::trackVisitsImpl($t); } - protected function trackVisitsImpl($t) + /** + * @param PiwikTracker $t + */ + protected static function trackVisitsImpl($t) { $dateTime = self::$dateTime; $idSite = self::$idSite; @@ -87,7 +97,7 @@ class Test_Piwik_Integration_OneVisitorTwoVisits extends IntegrationTestCase // 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!')); + self::checkResponse($t->doTrackPageView('incredible title!')); // testing that / and index.htm above record with different URLs // Recording the 2nd page after 3 minutes @@ -95,22 +105,22 @@ class Test_Piwik_Integration_OneVisitorTwoVisits extends IntegrationTestCase $urlPage2 = 'http://example.org/'; $t->setUrl($urlPage2); // $t->setUrlReferrer($urlPage1); - $this->checkResponse($t->doTrackPageView('Second page view - should be registered as URL /')); + self::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')); + self::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')); + self::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')); + self::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')); + self::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', '', ''); @@ -118,17 +128,17 @@ class Test_Piwik_Integration_OneVisitorTwoVisits extends IntegrationTestCase // 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)); + self::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)); + self::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)...')); + self::checkResponse($t->doTrackPageView('Looking at homepage (again)...')); // - // End of first visit: 24min @@ -145,7 +155,7 @@ class Test_Piwik_Integration_OneVisitorTwoVisits extends IntegrationTestCase $t->DEBUG_APPEND_URL = '&_idvc=2'; // Goal Tracking URL matching, testing custom referer including keyword - $this->checkResponse($t->doTrackPageView('Checkout/Purchasing...')); + self::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 index bfa661a33f360d6a175cf36a07252727dbf510eb..7660ac1ba4df4df19c65ee6533394227261f9e94 100755 --- a/tests/PHPUnit/Integration/OneVisitorTwoVisits_withCookieSupportTest.php +++ b/tests/PHPUnit/Integration/OneVisitorTwoVisits_withCookieSupportTest.php @@ -15,6 +15,13 @@ require_once dirname(__FILE__) . '/OneVisitorTwoVisitsTest.php'; */ class Test_Piwik_Integration_OneVisitorTwoVisits_WithCookieSupport extends Test_Piwik_Integration_OneVisitorTwoVisits { + public static function setUpBeforeClass() + { + IntegrationTestCase::setUpBeforeClass(); + self::setUpWebsitesAndGoals(); + self::trackVisits(); + } + /** * @dataProvider getApiForTesting * @group Integration @@ -42,10 +49,10 @@ class Test_Piwik_Integration_OneVisitorTwoVisits_WithCookieSupport extends Test_ return 'OneVisitorTwoVisits_withCookieSupport'; } - protected function trackVisits() + protected static function trackVisits() { - $t = $this->getTracker(self::$idSite, self::$dateTime, $defaultInit = true, $useThirdPartyCookie = 1); + $t = self::getTracker(self::$idSite, self::$dateTime, $defaultInit = true, $useThirdPartyCookie = 1); $t->DEBUG_APPEND_URL = '&forceUseThirdPartyCookie=1'; - $this->trackVisitsImpl($t); + self::trackVisitsImpl($t); } } diff --git a/tests/PHPUnit/Integration/OneVisitor_LongUrlsTruncatedTest.php b/tests/PHPUnit/Integration/OneVisitor_LongUrlsTruncatedTest.php index bc11be9e2e25fb3310f31fd2f7ee3ac722e87aa4..5242bfda801ef6f2119f569b0213f060b4ff0614 100644 --- a/tests/PHPUnit/Integration/OneVisitor_LongUrlsTruncatedTest.php +++ b/tests/PHPUnit/Integration/OneVisitor_LongUrlsTruncatedTest.php @@ -14,6 +14,13 @@ class Test_Piwik_Integration_OneVisitor_LongUrlsTruncated extends IntegrationTes protected static $dateTime = '2010-03-06 01:22:33'; protected static $idSite = 1; + public static function setUpBeforeClass() + { + parent::setUpBeforeClass(); + self::setUpWebsitesAndGoals(); + self::trackVisits(); + } + /** * @dataProvider getApiForTesting * @group Integration @@ -41,78 +48,78 @@ class Test_Piwik_Integration_OneVisitor_LongUrlsTruncated extends IntegrationTes return 'OneVisitor_LongUrlsTruncated'; } - protected function setUpWebsitesAndGoals() + protected static function setUpWebsitesAndGoals() { - $this->createWebsite(self::$dateTime); + self::createWebsite(self::$dateTime); } - protected function trackVisits() + protected static 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 = self::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')); + self::checkResponse($t->doTrackPageView('Hello')); $t->setUrl('http://example.org/category/Page2'); - $this->checkResponse($t->doTrackPageView('Hello')); + self::checkResponse($t->doTrackPageView('Hello')); $t->setUrl('http://example.org/category/Page3'); - $this->checkResponse($t->doTrackPageView('Hello')); + self::checkResponse($t->doTrackPageView('Hello')); $t->setUrl('http://example.org/category/Page3'); - $this->checkResponse($t->doTrackPageView('Hello')); + self::checkResponse($t->doTrackPageView('Hello')); $t->setUrl('http://example.org/category/Page4'); - $this->checkResponse($t->doTrackPageView('Hello')); + self::checkResponse($t->doTrackPageView('Hello')); $t->setUrl('http://example.org/category/Page4'); - $this->checkResponse($t->doTrackPageView('Hello')); + self::checkResponse($t->doTrackPageView('Hello')); $t->setUrl('http://example.org/category/Page4'); - $this->checkResponse($t->doTrackPageView('Hello')); + self::checkResponse($t->doTrackPageView('Hello')); $t->setUrl('http://example.org/category.htm'); - $this->checkResponse($t->doTrackPageView('Hello')); + self::checkResponse($t->doTrackPageView('Hello')); $t->setUrl('http://example.org/page.htm'); - $this->checkResponse($t->doTrackPageView('Hello')); + self::checkResponse($t->doTrackPageView('Hello')); $t->setUrl('http://example.org/index.htm'); - $this->checkResponse($t->doTrackPageView('Hello')); + self::checkResponse($t->doTrackPageView('Hello')); $t->setUrl('http://example.org/page.htm'); - $this->checkResponse($t->doTrackPageView('Hello')); + self::checkResponse($t->doTrackPageView('Hello')); $t->setUrl('http://example.org/page.htm'); - $this->checkResponse($t->doTrackPageView('Hello')); + self::checkResponse($t->doTrackPageView('Hello')); $t->setUrl('http://example.org/contact.htm'); - $this->checkResponse($t->doTrackPageView('Hello')); + self::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!')); + self::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!')); + self::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!')); + self::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!')); + self::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!')); + self::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!')); + self::checkResponse($t->doTrackPageView('incredible title!')); } } diff --git a/tests/PHPUnit/Integration/OneVisitor_NoKeywordSpecifiedTest.php b/tests/PHPUnit/Integration/OneVisitor_NoKeywordSpecifiedTest.php index 5a0056a43162a7bc12747ba59e07a246daba0770..97bd4a39d35363ff36755692c6003d803542e8ee 100755 --- a/tests/PHPUnit/Integration/OneVisitor_NoKeywordSpecifiedTest.php +++ b/tests/PHPUnit/Integration/OneVisitor_NoKeywordSpecifiedTest.php @@ -18,6 +18,13 @@ class Test_Piwik_Integration_OneVisitor_NoKeywordSpecified extends IntegrationTe protected static $dateTime = '2010-03-06 11:22:33'; protected static $idSite = 1; + public static function setUpBeforeClass() + { + parent::setUpBeforeClass(); + self::setUpWebsitesAndGoals(); + self::trackVisits(); + } + /** * @dataProvider getApiForTesting * @group Integration @@ -42,17 +49,17 @@ class Test_Piwik_Integration_OneVisitor_NoKeywordSpecified extends IntegrationTe return 'OneVisitor_NoKeywordSpecified'; } - protected function setUpWebsitesAndGoals() + protected static function setUpWebsitesAndGoals() { - $this->createWebsite(self::$dateTime); + self::createWebsite(self::$dateTime); } - protected function trackVisits() + protected static 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); + $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)'); @@ -62,17 +69,17 @@ class Test_Piwik_Integration_OneVisitor_NoKeywordSpecified extends IntegrationTe // 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!')); + self::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)); + self::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!')); + self::checkResponse($t->doTrackPageView('incredible title!')); } } diff --git a/tests/PHPUnit/Integration/PeriodIsRange_DateIsLastN_MetadataAndNormalAPITest.php b/tests/PHPUnit/Integration/PeriodIsRange_DateIsLastN_MetadataAndNormalAPITest.php index 02227a32575fe452e2fa6ec11ec161a09dbba032..264d1cbff984f6b910fa157f017560bde98f163b 100755 --- a/tests/PHPUnit/Integration/PeriodIsRange_DateIsLastN_MetadataAndNormalAPITest.php +++ b/tests/PHPUnit/Integration/PeriodIsRange_DateIsLastN_MetadataAndNormalAPITest.php @@ -16,8 +16,11 @@ class Test_Piwik_Integration_PeriodIsRange_DateIsLastN_MetadataAndNormalAPI exte { public static function setUpBeforeClass() { - parent::setUpBeforeClass(); + IntegrationTestCase::setUpBeforeClass(); + self::$visitorId = substr(md5(uniqid()), 0, 16); self::$dateTime = Piwik_Date::factory('now')->getDateTime(); + self::setUpWebsitesAndGoals(); + self::trackVisits(); } public function setUp() diff --git a/tests/PHPUnit/Integration/RowEvolutionTest.php b/tests/PHPUnit/Integration/RowEvolutionTest.php index 0d074643baf63b9624af93dd6722ed9bdfac9b43..ba36e5c602257824e42727d231262d12398ebf3b 100755 --- a/tests/PHPUnit/Integration/RowEvolutionTest.php +++ b/tests/PHPUnit/Integration/RowEvolutionTest.php @@ -20,6 +20,13 @@ class Test_Piwik_Integration_RowEvolution extends IntegrationTestCase 'justice )(&^#%$ NOT corruption!', ); + public static function setUpBeforeClass() + { + parent::setUpBeforeClass(); + self::setUpWebsitesAndGoals(); + self::trackVisits(); + } + /** * @dataProvider getApiForTesting * @group Integration @@ -110,12 +117,12 @@ class Test_Piwik_Integration_RowEvolution extends IntegrationTestCase return 'RowEvolution'; } - protected function setUpWebsitesAndGoals() + protected static function setUpWebsitesAndGoals() { - $this->createWebsite('2010-02-01 11:22:33'); + self::createWebsite('2010-02-01 11:22:33'); } - protected function trackVisits() + protected static function trackVisits() { $dateTime = self::$today; $idSite = self::$idSite; @@ -123,16 +130,16 @@ class Test_Piwik_Integration_RowEvolution extends IntegrationTestCase for ($daysIntoPast = 30; $daysIntoPast >= 0; $daysIntoPast--) { // Visit 1: referrer website + test page views $visitDateTime = Piwik_Date::factory($dateTime)->subDay($daysIntoPast)->getDatetime(); - $t = $this->getTracker($idSite, $visitDateTime, $defaultInit = true); + $t = self::getTracker($idSite, $visitDateTime, $defaultInit = true); $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); - $this->checkResponse($t->doTrackPageView('incredible title ' . ($daysIntoPast % 3))); + self::checkResponse($t->doTrackPageView('incredible title ' . ($daysIntoPast % 3))); // VISIT 2: search engine $t->setForceVisitDateTime(Piwik_Date::factory($visitDateTime)->addHour(3)->getDatetime()); $t->setUrlReferrer('http://google.com/search?q=' . urlencode(self::$keywords[$daysIntoPast % 3])); - $this->checkResponse($t->doTrackPageView('not an incredible title ')); + self::checkResponse($t->doTrackPageView('not an incredible title ')); } } } diff --git a/tests/PHPUnit/Integration/TrackCustomVariablesAndCampaigns_ForceUsingVisitIdNotHeuristicsTest.php b/tests/PHPUnit/Integration/TrackCustomVariablesAndCampaigns_ForceUsingVisitIdNotHeuristicsTest.php index c64c7acba83bc43647bdb307649b2c17120ff00e..cad91894e64d0f0574f061956805bfa5c1b1bfe8 100755 --- a/tests/PHPUnit/Integration/TrackCustomVariablesAndCampaigns_ForceUsingVisitIdNotHeuristicsTest.php +++ b/tests/PHPUnit/Integration/TrackCustomVariablesAndCampaigns_ForceUsingVisitIdNotHeuristicsTest.php @@ -17,6 +17,13 @@ class Test_Piwik_Integration_TrackCustomVariablesAndCampaigns_ForceUsingVisitIdN protected static $idSite = 1; protected static $idGoal = 1; + public static function setUpBeforeClass() + { + parent::setUpBeforeClass(); + self::setUpWebsitesAndGoals(); + self::trackVisits(); + } + /** * @dataProvider getApiForTesting * @group Integration @@ -42,65 +49,65 @@ class Test_Piwik_Integration_TrackCustomVariablesAndCampaigns_ForceUsingVisitIdN return 'PiwikTracker_trackForceUsingVisitId_insteadOfHeuristics_alsoTestsCampaignTracking'; } - public function setUpWebsitesAndGoals() + protected static function setUpWebsitesAndGoals() { - $this->createWebsite(self::$dateTime); + self::createWebsite(self::$dateTime); Piwik_Goals_API::getInstance()->addGoal(self::$idSite, 'triggered js', 'manually', '', ''); } - protected function trackVisits() + protected static function trackVisits() { $dateTime = self::$dateTime; $idSite = self::$idSite; $idGoal = self::$idGoal; - $t = $this->getTracker($idSite, $dateTime, $defaultInit = true); + $t = self::getTracker($idSite, $dateTime, $defaultInit = true); // Record 1st page view $t->setUrl('http://example.org/index.htm?utm_campaign=GA Campaign&piwik_kwd=Piwik kwd&utm_term=GA keyword SHOULD NOT DISPLAY#pk_campaign=NOT TRACKED!!&pk_kwd=NOT TRACKED!!'); - $this->checkResponse($t->doTrackPageView('incredible title!')); + self::checkResponse($t->doTrackPageView('incredible title!')); $visitorId = $t->getVisitorId(); - $this->assertTrue(strlen($visitorId) == 16); + 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_cvar_1_1fff'] = '{"1":["VAR 1 set, var 2 not set","yes"],"3":["var 3 set","yes!!!!"]}'; - $this->assertTrue($t->getVisitorId() == 'ca0afe7b6b692ff5'); - $this->assertTrue($t->getAttributionInfo() == $_COOKIE['_pk_ref_1_1fff']); - $this->assertTrue($t->getCustomVariable(1) == array("VAR 1 set, var 2 not set", "yes")); - $this->assertTrue($t->getCustomVariable(2) == false); - $this->assertTrue($t->getCustomVariable(3) == array("var 3 set", "yes!!!!")); - $this->assertTrue($t->getCustomVariable(4) == false); - $this->assertTrue($t->getCustomVariable(5) == false); - $this->assertTrue($t->getCustomVariable(6) == false); - $this->assertTrue($t->getCustomVariable(-1) == false); + self::assertTrue($t->getVisitorId() == 'ca0afe7b6b692ff5'); + self::assertTrue($t->getAttributionInfo() == $_COOKIE['_pk_ref_1_1fff']); + self::assertTrue($t->getCustomVariable(1) == array("VAR 1 set, var 2 not set", "yes")); + self::assertTrue($t->getCustomVariable(2) == false); + self::assertTrue($t->getCustomVariable(3) == array("var 3 set", "yes!!!!")); + self::assertTrue($t->getCustomVariable(4) == false); + self::assertTrue($t->getCustomVariable(5) == false); + self::assertTrue($t->getCustomVariable(6) == false); + self::assertTrue($t->getCustomVariable(-1) == false); unset($_COOKIE['_pk_id_1_1fff']); unset($_COOKIE['_pk_ref_1_1fff']); unset($_COOKIE['_pk_cvar_1_1fff']); // Create a new Tracker object, with different attributes - $t2 = $this->getTracker($idSite, $dateTime, $defaultInit = false); + $t2 = self::getTracker($idSite, $dateTime, $defaultInit = false); // Make sure the ID is different at first $visitorId2 = $t2->getVisitorId(); - $this->assertTrue($visitorId != $visitorId2); + self::assertTrue($visitorId != $visitorId2); // Then force the visitor ID $t2->setVisitorId($visitorId); // And Record a Goal: The previous visit should be updated rather than a new visit Created $t2->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.3)->getDatetime()); - $this->checkResponse($t2->doTrackGoal($idGoal, $revenue = 42.256)); + self::checkResponse($t2->doTrackGoal($idGoal, $revenue = 42.256)); // Yet another visitor, this time with a manual goal conversion, which should be credited to the campaign - $t3 = $this->getTracker($idSite, $dateTime); + $t3 = self::getTracker($idSite, $dateTime); $t3->setUrlReferrer('http://example.org/referrer'); $t3->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(1.3)->getDatetime()); // fake a website ref cookie, the campaign should be credited for conversion, not referrer.example.com nor example.org $t3->DEBUG_APPEND_URL = '&_ref=http%3A%2F%2Freferrer.example.com%2Fpage%2Fsub%3Fquery%3Dtest%26test2%3Dtest3'; $t3->setUrl('http://example.org/index.htm#pk_campaign=CREDITED TO GOAL PLEASE'); - $this->checkResponse($t3->doTrackGoal($idGoal, 42)); + self::checkResponse($t3->doTrackGoal($idGoal, 42)); } } diff --git a/tests/PHPUnit/Integration/TrackGoals_AllowMultipleConversionsPerVisitTest.php b/tests/PHPUnit/Integration/TrackGoals_AllowMultipleConversionsPerVisitTest.php index 712695ae095ce7cb52a1e9961d01638e190a1b7f..dee44b42f89434e776af7e8fb953174c6b859c5c 100755 --- a/tests/PHPUnit/Integration/TrackGoals_AllowMultipleConversionsPerVisitTest.php +++ b/tests/PHPUnit/Integration/TrackGoals_AllowMultipleConversionsPerVisitTest.php @@ -18,6 +18,13 @@ class Test_Piwik_Integration_TrackGoals_AllowMultipleConversionsPerVisit extends protected static $idGoal_OneConversionPerVisit = 1; protected static $idGoal_MultipleConversionPerVisit = 2; + public static function setUpBeforeClass() + { + parent::setUpBeforeClass(); + self::setUpWebsitesAndGoals(); + self::trackVisits(); + } + /** * @group Integration * @group TrackGoals_AllowMultipleConversionsPerVisit @@ -57,9 +64,9 @@ class Test_Piwik_Integration_TrackGoals_AllowMultipleConversionsPerVisit extends return 'trackGoals_allowMultipleConversionsPerVisit'; } - public function setUpWebsitesAndGoals() + public static function setUpWebsitesAndGoals() { - $this->createWebsite(self::$dateTime); + self::createWebsite(self::$dateTime); // First, a goal that is only recorded once per visit Piwik_Goals_API::getInstance()->addGoal(self::$idSite, 'triggered js ONCE', 'title', 'Thank you', 'contains', $caseSensitive = false, $revenue = 10, $allowMultipleConversions = false); @@ -68,37 +75,37 @@ class Test_Piwik_Integration_TrackGoals_AllowMultipleConversionsPerVisit extends Piwik_Goals_API::getInstance()->addGoal(self::$idSite, 'triggered js MULTIPLE ALLOWED', 'manually', '', '', $caseSensitive = false, $revenue = 10, $allowMultipleConversions = true); } - protected function trackVisits() + protected static function trackVisits() { $dateTime = self::$dateTime; $idSite = self::$idSite; $idGoal_OneConversionPerVisit = self::$idGoal_OneConversionPerVisit; $idGoal_MultipleConversionPerVisit = self::$idGoal_MultipleConversionPerVisit; - $t = $this->getTracker($idSite, $dateTime, $defaultInit = true); + $t = self::getTracker($idSite, $dateTime, $defaultInit = true); // Record 1st goal, should only have 1 conversion $t->setUrl('http://example.org/index.htm'); $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.3)->getDatetime()); - $this->checkResponse($t->doTrackPageView('Thank you mate')); + self::checkResponse($t->doTrackPageView('Thank you mate')); $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.4)->getDatetime()); - $this->checkResponse($t->doTrackGoal($idGoal_OneConversionPerVisit, $revenue = 10000000)); + self::checkResponse($t->doTrackGoal($idGoal_OneConversionPerVisit, $revenue = 10000000)); // Record 2nd goal, should record both conversions $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.5)->getDatetime()); - $this->checkResponse($t->doTrackGoal($idGoal_MultipleConversionPerVisit, $revenue = 300)); + self::checkResponse($t->doTrackGoal($idGoal_MultipleConversionPerVisit, $revenue = 300)); $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.6)->getDatetime()); - $this->checkResponse($t->doTrackGoal($idGoal_MultipleConversionPerVisit, $revenue = 366)); + self::checkResponse($t->doTrackGoal($idGoal_MultipleConversionPerVisit, $revenue = 366)); // Update & set to not allow multiple $goals = Piwik_Goals_API::getInstance()->getGoals($idSite); $goal = $goals[$idGoal_OneConversionPerVisit]; - $this->assertTrue($goal['allow_multiple'] == 0); + 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); - $this->assertTrue($goal['allow_multiple'] == 1); + self::assertTrue($goal['allow_multiple'] == 1); // 1st goal should Now be tracked $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.61)->getDatetime()); - $this->checkResponse($t->doTrackGoal($idGoal_OneConversionPerVisit, $revenue = 656)); + self::checkResponse($t->doTrackGoal($idGoal_OneConversionPerVisit, $revenue = 656)); } } diff --git a/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDaysTest.php b/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDaysTest.php index 4e2541a246e5a5d797ae40f813caaa04c3c5d9c7..4cb2ed162ea731da5113fd47fdb899f341a3f8da 100755 --- a/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDaysTest.php +++ b/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDaysTest.php @@ -25,6 +25,13 @@ class Test_Piwik_Integration_TwoVisitors_TwoWebsites_DifferentDays extends Integ protected static $dateTime = '2010-01-03 11:22:33'; protected static $allowConversions = false; + public static function setUpBeforeClass() + { + parent::setUpBeforeClass(); + self::setUpWebsitesAndGoals(); + self::trackVisits(); + } + /** * @dataProvider getApiForTesting * @group Integration @@ -57,16 +64,24 @@ class Test_Piwik_Integration_TwoVisitors_TwoWebsites_DifferentDays extends Integ $result = array( // Request data for the last 6 periods and idSite=all - array($apiToCall, array('idSite' => 'all', 'date' => self::$dateTime, 'periods' => $periods, + array($apiToCall, array('idSite' => 'all', + 'date' => self::$dateTime, + 'periods' => $periods, 'setDateLastN' => true)), // Request data for the last 6 periods and idSite=1 - array($apiToCall, array('idSite' => self::$idSite1, 'date' => self::$dateTime, 'periods' => $periods, - 'setDateLastN' => true, 'testSuffix' => '_idSiteOne_')), + array($apiToCall, array('idSite' => self::$idSite1, + 'date' => self::$dateTime, + 'periods' => $periods, + 'setDateLastN' => true, + 'testSuffix' => '_idSiteOne_')), // We also test a single period to check that this use case (Reports per idSite in the response) works - array($singlePeriodApi, array('idSite' => 'all', 'date' => self::$dateTime, 'periods' => array('day', 'month'), - 'setDateLastN' => false, 'testSuffix' => '_NotLastNPeriods')), + array($singlePeriodApi, array('idSite' => 'all', + 'date' => self::$dateTime, + 'periods' => array('day', 'month'), + 'setDateLastN' => false, + 'testSuffix' => '_NotLastNPeriods')), ); // testing metadata API for multiple periods @@ -75,10 +90,13 @@ class Test_Piwik_Integration_TwoVisitors_TwoWebsites_DifferentDays extends Integ list($apiModule, $apiAction) = explode(".", $api); $result[] = array( - 'API.getProcessedReport', array('idSite' => self::$idSite1, 'date' => self::$dateTime, - 'periods' => array('day'), 'setDateLastN' => true, - 'apiModule' => $apiModule, 'apiAction' => $apiAction, - 'testSuffix' => '_' . $api . '_firstSite_lastN') + 'API.getProcessedReport', array('idSite' => self::$idSite1, + 'date' => self::$dateTime, + 'periods' => array('day'), + 'setDateLastN' => true, + 'apiModule' => $apiModule, + 'apiAction' => $apiAction, + 'testSuffix' => '_' . $api . '_firstSite_lastN') ); } @@ -90,13 +108,13 @@ class Test_Piwik_Integration_TwoVisitors_TwoWebsites_DifferentDays extends Integ return 'TwoVisitors_twoWebsites_differentDays'; } - public function setUpWebsitesAndGoals() + public static function setUpWebsitesAndGoals() { // tests run in UTC, the Tracker in UTC $ecommerce = self::$allowConversions ? 1 : 0; - $this->createWebsite(self::$dateTime, $ecommerce, "Site 1"); - $this->createWebsite(self::$dateTime, 0, "Site 2"); + self::createWebsite(self::$dateTime, $ecommerce, "Site 1"); + self::createWebsite(self::$dateTime, 0, "Site 2"); if (self::$allowConversions) { Piwik_Goals_API::getInstance()->addGoal(self::$idSite1, 'all', 'url', 'http', 'contains', false, 5); @@ -104,7 +122,7 @@ class Test_Piwik_Integration_TwoVisitors_TwoWebsites_DifferentDays extends Integ } } - protected function trackVisits() + protected static function trackVisits() { $dateTime = self::$dateTime; $idSite = self::$idSite1; @@ -113,20 +131,20 @@ class Test_Piwik_Integration_TwoVisitors_TwoWebsites_DifferentDays extends Integ // - // First visitor on Idsite 1: two page views $datetimeSpanOverTwoDays = '2010-01-03 23:55:00'; - $visitorA = $this->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'); $visitorA->DEBUG_APPEND_URL = '&_idts=' . Piwik_Date::factory($datetimeSpanOverTwoDays)->getTimestamp(); - $this->checkResponse($visitorA->doTrackPageView('first page view')); + 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(' '); - $this->checkResponse($visitorA->doTrackPageView(' ')); + self::checkResponse($visitorA->doTrackPageView(' ')); // - // Second new visitor on Idsite 1: one page view - $visitorB = $this->getTracker($idSite, $dateTime, $defaultInit = true); + $visitorB = self::getTracker($idSite, $dateTime, $defaultInit = true); $visitorB->enableBulkTracking(); // calc token auth by hand in test environment $tokenAuth = md5( @@ -139,7 +157,7 @@ class Test_Piwik_Integration_TwoVisitors_TwoWebsites_DifferentDays extends Integ $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(); - $this->assertTrue($visitorB->doTrackPageView('first page view')); + self::assertTrue($visitorB->doTrackPageView('first page view')); // - // Second visitor again on Idsite 1: 2 page views 2 days later, 2010-01-05 @@ -150,40 +168,40 @@ class Test_Piwik_Integration_TwoVisitors_TwoWebsites_DifferentDays extends Integ $visitorB->setUrlReferrer('http://referer.com/Other_Page.htm'); $visitorB->setUrl('http://example.org/index.htm'); - $this->assertTrue($visitorB->doTrackPageView('second visitor/two days later/a new visit')); + 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'); - $this->assertTrue($visitorB->doTrackPageView('second visitor/two days later/second page view')); + self::assertTrue($visitorB->doTrackPageView('second visitor/two days later/second page view')); // testing a strange combination causing an error in r3767 $visitorB->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(48)->addHour(0.2)->getDatetime()); - $this->assertTrue($visitorB->doTrackAction('mailto:test@example.org', 'link')); + self::assertTrue($visitorB->doTrackAction('mailto:test@example.org', 'link')); $visitorB->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(48)->addHour(0.25)->getDatetime()); - $this->assertTrue($visitorB->doTrackAction('mailto:test@example.org/strangelink', 'link')); + self::assertTrue($visitorB->doTrackAction('mailto:test@example.org/strangelink', 'link')); // Actions.getPageTitle tested with this title $visitorB->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(48)->addHour(0.25)->getDatetime()); - $this->assertTrue($visitorB->doTrackPageView('Checkout / Purchasing...')); - $this->checkResponse($visitorB->doBulkTrack()); + self::assertTrue($visitorB->doTrackPageView('Checkout / Purchasing...')); + self::checkResponse($visitorB->doBulkTrack()); // - // First visitor on Idsite 2: one page view, with Website referer - $visitorAsite2 = $this->getTracker($idSite2, Piwik_Date::factory($dateTime)->addHour(24)->getDatetime(), $defaultInit = true); + $visitorAsite2 = self::getTracker($idSite2, Piwik_Date::factory($dateTime)->addHour(24)->getDatetime(), $defaultInit = true); $visitorAsite2->setUserAgent('Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0;)'); $visitorAsite2->setUrlReferrer('http://only-homepage-referer.com/'); $visitorAsite2->setUrl('http://example2.com/home'); $visitorAsite2->DEBUG_APPEND_URL = '&_idts=' . Piwik_Date::factory($dateTime)->addHour(24)->getTimestamp(); - $this->checkResponse($visitorAsite2->doTrackPageView('Website 2 page view')); + self::checkResponse($visitorAsite2->doTrackPageView('Website 2 page view')); // test with invalid URL $visitorAsite2->setUrl('this is invalid url'); // and an empty title - $this->checkResponse($visitorAsite2->doTrackPageView('')); + self::checkResponse($visitorAsite2->doTrackPageView('')); // Returning visitor on Idsite 2 1 day later, one page view, with chinese referer // $t2->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(48 + 10)->getDatetime()); // $t2->setUrlReferrer('http://www.baidu.com/s?wd=%D0%C2+%CE%C5&n=2'); // $t2->setUrl('http://example2.com/home'); -// $this->checkResponse($t2->doTrackPageView('I\'m a returning visitor...')); +// self::checkResponse($t2->doTrackPageView('I\'m a returning visitor...')); } } diff --git a/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDays_ArchivingDisabledTest.php b/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDays_ArchivingDisabledTest.php index 1a5dd71c0be91fa04c5c0eb672fd158bff856f0f..5f3e1296532428207b4f9e1583f5f0ccd960112d 100755 --- a/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDays_ArchivingDisabledTest.php +++ b/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDays_ArchivingDisabledTest.php @@ -14,21 +14,22 @@ require_once dirname(__FILE__) . '/TwoVisitors_TwoWebsites_DifferentDaysTest.php */ class Test_Piwik_Integration_TwoVisitors_TwoWebsites_DifferentDays_ArchivingDisabled extends Test_Piwik_Integration_TwoVisitors_TwoWebsites_DifferentDays { - protected static $allowConversions = true; + public static function setUpBeforeClass() + { + IntegrationTestCase::setUpBeforeClass(); + self::$allowConversions = true; + self::setUpWebsitesAndGoals(); + self::trackVisits(); + } /** + * @dataProvider getApiForTesting * @group Integration - * @group TwoWebsites_DifferentDays_ArchivingDisabled + * @group TwoVisitors_TwoWebsites_DifferentDays_ArchivingDisabled */ - public function testApi() + public function testApi($api, $params) { - $testData = $this->getApiForTesting(); - - foreach ($testData AS $data) { - $api = $data[0]; - $params = $data[1]; - $this->runApiTests($api, $params); - } + $this->runApiTests($api, $params); } public function getApiForTesting() diff --git a/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDays_ConversionsTest.php b/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDays_ConversionsTest.php index baa385f115bac36ff3768394dc9a8b7fb5c5e8a1..a3b01db9964922a60ec8560154286107f191a35e 100755 --- a/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDays_ConversionsTest.php +++ b/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDays_ConversionsTest.php @@ -16,7 +16,13 @@ require_once 'Goals/Goals.php'; */ class Test_Piwik_Integration_TwoVisitors_TwoWebsites_DifferentDays_Conversions extends Test_Piwik_Integration_TwoVisitors_TwoWebsites_DifferentDays { - protected static $allowConversions = true; + public static function setUpBeforeClass() + { + IntegrationTestCase::setUpBeforeClass(); + self::$allowConversions = true; + self::setUpWebsitesAndGoals(); + self::trackVisits(); + } /** * @dataProvider getApiForTesting diff --git a/tests/PHPUnit/Integration/TwoVisitsWithCustomVariablesTest.php b/tests/PHPUnit/Integration/TwoVisitsWithCustomVariablesTest.php index b29e2cc1791f7dad79e7f1030cb046541c4e4ad4..52bb3e580677f7b147c3bb55eb02d82e20a21e0d 100755 --- a/tests/PHPUnit/Integration/TwoVisitsWithCustomVariablesTest.php +++ b/tests/PHPUnit/Integration/TwoVisitsWithCustomVariablesTest.php @@ -28,6 +28,8 @@ class Test_Piwik_Integration_TwoVisitsWithCustomVariables extends IntegrationTes { parent::setUpBeforeClass(); self::$visitorId = substr(md5(uniqid()), 0, 16); + self::setUpWebsitesAndGoals(); + self::trackVisits(); } public function getApiForTesting() @@ -59,22 +61,22 @@ class Test_Piwik_Integration_TwoVisitsWithCustomVariables extends IntegrationTes return 'twoVisitsWithCustomVariables'; } - protected function setUpWebsitesAndGoals() + protected static function setUpWebsitesAndGoals() { // tests run in UTC, the Tracker in UTC - $this->createWebsite(self::$dateTime); + self::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() + protected static function trackVisits() { $dateTime = self::$dateTime; $idSite = self::$idSite; $idGoal = self::$idGoal1; $idGoal2 = self::$idGoal2; - $visitorA = $this->getTracker($idSite, $dateTime, $defaultInit = true); + $visitorA = self::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')); @@ -93,8 +95,8 @@ class Test_Piwik_Integration_TwoVisitsWithCustomVariables extends IntegrationTes $visitorA->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.1)->getDatetime()); $visitorA->setUrl('http://example.org/homepage'); $visitorA->setCustomVariable($id = 1, $name = 'VisitorType', $value = 'LoggedOut'); - $this->checkResponse($visitorA->doTrackPageView('Homepage')); - $this->checkResponse($visitorA->doTrackGoal($idGoal2, 0)); + self::checkResponse($visitorA->doTrackPageView('Homepage')); + self::checkResponse($visitorA->doTrackGoal($idGoal2)); // After login, set to LoggedIn, should overwrite previous value $visitorA->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.2)->getDatetime()); @@ -107,15 +109,15 @@ class Test_Piwik_Integration_TwoVisitsWithCustomVariables extends IntegrationTes $lookingAtProfile = 'looking at profile page'; } $visitorA->setCustomVariable($id = 5, $name = 'Status user', $value = $lookingAtProfile, $scope = 'page'); - $this->checkResponse($visitorA->doTrackPageView('Profile page')); + self::checkResponse($visitorA->doTrackPageView('Profile page')); $visitorA->setCustomVariable($id = 2, $name = 'SET WITH EMPTY VALUE', $value = ''); $visitorA->setCustomVariable($id = 1, $name = 'Language', $value = 'FR', $scope = 'page'); $visitorA->setCustomVariable($id = 2, $name = 'SET WITH EMPTY VALUE PAGE SCOPE', $value = '', $scope = 'page'); $visitorA->setCustomVariable($id = 4, $name = 'Status user', $value = "looking at \"profile page\"", $scope = 'page'); $visitorA->setCustomVariable($id = 3, $name = 'Value will be VERY long and truncated', $value = 'abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----'); - $this->checkResponse($visitorA->doTrackPageView('Profile page for user *_)%')); - $this->checkResponse($visitorA->doTrackGoal($idGoal, 0)); + self::checkResponse($visitorA->doTrackPageView('Profile page for user *_)%')); + self::checkResponse($visitorA->doTrackGoal($idGoal)); if (self::$doExtraQuoteTests) { $visitorA->setCustomVariable($id = 2, $name = 'var1', $value = 'looking at "profile page"', @@ -124,12 +126,12 @@ class Test_Piwik_Integration_TwoVisitsWithCustomVariables extends IntegrationTes $scope = 'page'); $visitorA->setCustomVariable($id = 4, $name = 'var3', $value = '\\looking at "\profile page"\\', $scope = 'page'); - $this->checkResponse($visitorA->doTrackPageView('Concurrent page views')); + self::checkResponse($visitorA->doTrackPageView('Concurrent page views')); } // - // Second new visitor on Idsite 1: one page view - $visitorB = $this->getTracker($idSite, $dateTime, $defaultInit = true); + $visitorB = self::getTracker($idSite, $dateTime, $defaultInit = true); $visitorB->setVisitorId(self::$visitorId); $visitorB->setUrlReferrer(''); @@ -149,14 +151,14 @@ class Test_Piwik_Integration_TwoVisitsWithCustomVariables extends IntegrationTes $visitorB->setCustomVariable($id = 6, $name = 'not tracked', $value = 'not tracked'); $visitorB->setCustomVariable($id = 6, $name = array('not tracked'), $value = 'not tracked'); $visitorB->setUrl('http://example.org/homepage'); - $this->checkResponse($visitorB->doTrackGoal($idGoal, 1000)); + self::checkResponse($visitorB->doTrackGoal($idGoal, 1000)); $visitorB->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(1.1)->getDatetime()); - $this->checkResponse($visitorB->doTrackPageView('Homepage')); + self::checkResponse($visitorB->doTrackPageView('Homepage')); // DIFFERENT test - // testing that starting the visit with an outlink works (doesn't trigger errors) $visitorB->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(2)->getDatetime()); - $this->checkResponse($visitorB->doTrackAction('http://test.com', 'link')); + self::checkResponse($visitorB->doTrackAction('http://test.com', 'link')); } } diff --git a/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentContainsTest.php b/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentContainsTest.php index 5c9c1a4f441004cbea02754f4571188f29a94d24..361f45a791a7ba8e35a930b7b81c7614290fc6b9 100755 --- a/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentContainsTest.php +++ b/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentContainsTest.php @@ -14,7 +14,14 @@ require_once dirname(__FILE__) . '/TwoVisitsWithCustomVariablesTest.php'; */ class Test_Piwik_Integration_TwoVisitsWithCustomVariables_SegmentContains extends Test_Piwik_Integration_TwoVisitsWithCustomVariables { - protected static $doExtraQuoteTests = false; + public static function setUpBeforeClass() + { + IntegrationTestCase::setUpBeforeClass(); + self::$visitorId = substr(md5(uniqid()), 0, 16); + self::$doExtraQuoteTests = false; + self::setUpWebsitesAndGoals(); + self::trackVisits(); + } /** * @dataProvider getApiForTesting diff --git a/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchALL_NoGoalDataTest.php b/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchALL_NoGoalDataTest.php index c7c43c2b86bf8fcab7704a8e6e4f2fad05babc20..6947ca7401ffa7feafc25f97fcfff105a5ed86ed 100755 --- a/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchALL_NoGoalDataTest.php +++ b/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchALL_NoGoalDataTest.php @@ -11,9 +11,16 @@ require_once dirname(__FILE__) . '/TwoVisitsWithCustomVariablesTest.php'; class Test_Piwik_Integration_TwoVisitsWithCustomVariables_SegmentMatchALL_NoGoalData extends Test_Piwik_Integration_TwoVisitsWithCustomVariables { - protected static $width = 1111; - protected static $height = 222; - protected static $doExtraQuoteTests = false; + public static function setUpBeforeClass() + { + IntegrationTestCase::setUpBeforeClass(); + self::$visitorId = substr(md5(uniqid()), 0, 16); + self::$width = 1111; + self::$height = 222; + self::$doExtraQuoteTests = false; + self::setUpWebsitesAndGoals(); + self::trackVisits(); + } /** * @dataProvider getApiForTesting diff --git a/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchNONETest.php b/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchNONETest.php index 199fa99c51ce1df3cb791872484ce2c87ebcb3a2..2d4e96447b881faab0db27e8f7d408080f5a0377 100755 --- a/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchNONETest.php +++ b/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchNONETest.php @@ -14,7 +14,14 @@ require_once dirname(__FILE__) . '/TwoVisitsWithCustomVariablesTest.php'; */ class Test_Piwik_Integration_TwoVisitsWithCustomVariables_SegmentMatchNONE extends Test_Piwik_Integration_TwoVisitsWithCustomVariables { - protected static $doExtraQuoteTests = false; + public static function setUpBeforeClass() + { + IntegrationTestCase::setUpBeforeClass(); + self::$visitorId = substr(md5(uniqid()), 0, 16); + self::$doExtraQuoteTests = false; + self::setUpWebsitesAndGoals(); + self::trackVisits(); + } /** * @dataProvider getApiForTesting diff --git a/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchVisitorTypeTest.php b/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchVisitorTypeTest.php index 9a73a20b8ecc94389cfaa544b45ce71ce55aef4b..dd0965d076b811f58fd9cc2557505a179da3b69a 100755 --- a/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchVisitorTypeTest.php +++ b/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchVisitorTypeTest.php @@ -14,23 +14,60 @@ require_once dirname(__FILE__) . '/TwoVisitsWithCustomVariablesTest.php'; */ class Test_Piwik_Integration_TwoVisitsWithCustomVariables_SegmentMatchVisitorType extends Test_Piwik_Integration_TwoVisitsWithCustomVariables { - protected static $doExtraQuoteTests = false; + public static function setUpBeforeClass() + { + IntegrationTestCase::setUpBeforeClass(); + self::$visitorId = substr(md5(uniqid()), 0, 16); + self::$doExtraQuoteTests = false; + self::setUpWebsitesAndGoals(); + self::trackVisits(); + } /** + * @dataProvider getApiForTesting * @group Integration * @group TwoVisitsWithCustomVariables_SegmentMatchVisitorType */ - public function testApi() + public function testApi($api, $params) + { + $this->runApiTests($api, $params); + } + + public function getApiForTesting() { - $testData = $this->getApiForTesting(); + // Segment matching some + $segments = array('customVariableName1==VisitorType;customVariableValue1==LoggedIn', + 'customVariableName1==VisitorType;customVariableValue1=@LoggedI'); + + $apiToCall = array('Referers.getKeywords', 'CustomVariables.getCustomVariables', 'VisitsSummary.get'); + + $periods = array('day', 'week'); - foreach ($testData AS $data) { - $api = $data[0]; - $params = $data[1]; - $this->runApiTests($api, $params); + // We run it twice just to check that running archiving twice for same input parameters doesn't create more records/overhead + $result = array(); + for ($i = 1; $i <= 2; $i++) { + foreach ($segments as $segment) { + $result[] = array( + $apiToCall, array('idSite' => 'all', + 'date' => self::$dateTime, + 'periods' => $periods, + 'setDateLastN' => true, + 'segment' => $segment) + ); + } } - // ---------------------------------------------- + return $result; + } + + /** + * @depends testApi + * @group Integration + * @group TwoVisitsWithCustomVariables_SegmentMatchVisitorType + */ + public function testCheck() + { + // ---------------------------------------------- // Implementation Checks // ---------------------------------------------- // Verify that, when a segment is specified, only the requested report is processed @@ -61,39 +98,11 @@ class Test_Piwik_Integration_TwoVisitsWithCustomVariables_SegmentMatchVisitorTyp foreach ($tests as $table => $expectedRows) { $sql = "SELECT count(*) FROM " . Piwik_Common::prefixTable($table); $countBlobs = Zend_Registry::get('db')->fetchOne($sql); - $this->assertEqual($expectedRows, $countBlobs, "$table: %s"); + $this->assertEquals($expectedRows, $countBlobs, "$table: %s"); } } } - public function getApiForTesting() - { - // Segment matching some - $segments = array('customVariableName1==VisitorType;customVariableValue1==LoggedIn', - 'customVariableName1==VisitorType;customVariableValue1=@LoggedI'); - - $apiToCall = array('Referers.getKeywords', 'CustomVariables.getCustomVariables', 'VisitsSummary.get'); - - $periods = array('day', 'week'); - - // We run it twice just to check that running archiving twice for same input parameters doesn't create more records/overhead - $result = array(); - for ($i = 1; $i <= 2; $i++) { - foreach ($segments as $segment) { - $result[] = array( - $apiToCall, array('idSite' => 'all', - 'date' => self::$dateTime, - 'periods' => $periods, - 'setDateLastN' => true, - 'segment' => $segment) - ); - } - } - - - return $result; - } - public function getOutputPrefix() { return 'twoVisitsWithCustomVariables_segmentMatchVisitorType'; diff --git a/tests/PHPUnit/Integration/VisitsInPast_InvalidateOldReportsTest.php b/tests/PHPUnit/Integration/VisitsInPast_InvalidateOldReportsTest.php index b260e2d914a87423bacdf8da5b78b97a7f5ea8d4..9e0df46e08618fab6ceed23d2fdca244fd9e78e1 100644 --- a/tests/PHPUnit/Integration/VisitsInPast_InvalidateOldReportsTest.php +++ b/tests/PHPUnit/Integration/VisitsInPast_InvalidateOldReportsTest.php @@ -20,6 +20,13 @@ class Test_Piwik_Integration_VisitsInPast_InvalidateOldReports extends Integrati protected static $idSite = 1; protected static $idSite2 = 2; + public static function setUpBeforeClass() + { + parent::setUpBeforeClass(); + self::setUpWebsitesAndGoals(); + self::trackVisits(); + } + /** * @dataProvider getApiForTesting * @group Integration @@ -112,69 +119,67 @@ class Test_Piwik_Integration_VisitsInPast_InvalidateOldReports extends Integrati return 'VisitsInPast_InvalidateOldReports'; } - public function setUpWebsitesAndGoals() + public static function setUpWebsitesAndGoals() { - $this->createWebsite(self::$dateTimeFirstDateWebsite1); - $this->createWebsite(self::$dateTimeFirstDateWebsite2); + self::createWebsite(self::$dateTimeFirstDateWebsite1); + self::createWebsite(self::$dateTimeFirstDateWebsite2); } - protected function trackVisits() + protected static function trackVisits() { /** * Track Visits normal date for the 2 websites */ - // WEBSITE 1 - $t = $this->getTracker(self::$idSite, self::$dateTimeFirstDateWebsite1, $defaultInit = true); + $t = self::getTracker(self::$idSite, self::$dateTimeFirstDateWebsite1, $defaultInit = true); $t->setUrl('http://example.org/category/Page1'); - $this->checkResponse($t->doTrackPageView('Hello')); + self::checkResponse($t->doTrackPageView('Hello')); $t->setUrl('http://example.org/category/Page2'); - $this->checkResponse($t->doTrackPageView('Hello')); + self::checkResponse($t->doTrackPageView('Hello')); $t->setUrl('http://example.org/category/Page3'); - $this->checkResponse($t->doTrackPageView('Hello')); + self::checkResponse($t->doTrackPageView('Hello')); $t->setUrl('http://example.org/Home'); - $this->checkResponse($t->doTrackPageView('Hello')); + self::checkResponse($t->doTrackPageView('Hello')); $t->setUrl('http://example.org/Contact'); - $this->checkResponse($t->doTrackPageView('Hello')); + self::checkResponse($t->doTrackPageView('Hello')); $t->setUrl('http://example.org/Contact/ThankYou'); - $this->checkResponse($t->doTrackPageView('Hello')); + self::checkResponse($t->doTrackPageView('Hello')); // WEBSITE 2 - $t = $this->getTracker(self::$idSite2, self::$dateTimeFirstDateWebsite2, $defaultInit = true); + $t = self::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')); + self::checkResponse($t->doTrackPageView('Hello')); $t->setUrl('http://example.org/category/Page2'); - $this->checkResponse($t->doTrackPageView('Hello')); + self::checkResponse($t->doTrackPageView('Hello')); $t->setUrl('http://example.org/category/Page3'); - $this->checkResponse($t->doTrackPageView('Hello')); + self::checkResponse($t->doTrackPageView('Hello')); $t->setUrl('http://example.org/Home'); - $this->checkResponse($t->doTrackPageView('Hello')); + self::checkResponse($t->doTrackPageView('Hello')); $t->setUrl('http://example.org/Contact'); - $this->checkResponse($t->doTrackPageView('Hello')); + self::checkResponse($t->doTrackPageView('Hello')); $t->setUrl('http://example.org/Contact/ThankYou'); - $this->checkResponse($t->doTrackPageView('Hello')); + self::checkResponse($t->doTrackPageView('Hello')); /** * Track visits in the past (before website creation date) for the 2 websites */ // WEBSITE1 - $t = $this->getTracker(self::$idSite, self::$dateTimeDateInPastWebsite1, $defaultInit = true); + $t = self::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')); + self::checkResponse($t->doTrackPageView('Hello')); $t->setUrl('http://example.org/category/Page2'); - $this->checkResponse($t->doTrackPageView('Hello')); + self::checkResponse($t->doTrackPageView('Hello')); $t->setUrl('http://example.org/category/Page3'); // WEBSITE2 - $t = $this->getTracker(self::$idSite2, self::$dateTimeDateInPastWebsite2, $defaultInit = true); + $t = self::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')); + self::checkResponse($t->doTrackPageView('Hello')); $t->setUrl('http://example.org/category/Page2'); - $this->checkResponse($t->doTrackPageView('Hello')); + self::checkResponse($t->doTrackPageView('Hello')); $t->setUrl('http://example.org/category/Page3'); } } - diff --git a/tests/PHPUnit/IntegrationTestCase.php b/tests/PHPUnit/IntegrationTestCase.php index 4f25ae8211a9023d56bf741a44ef373ef38363ee..83d81fd618aa5c11661d7d110c52d32227695bc8 100755 --- a/tests/PHPUnit/IntegrationTestCase.php +++ b/tests/PHPUnit/IntegrationTestCase.php @@ -14,7 +14,7 @@ require_once PIWIK_INCLUDE_PATH . '/libs/PiwikTracker/PiwikTracker.php'; * Provides helpers to track data and then call API get* methods to check outputs automatically. * */ -abstract class IntegrationTestCase extends DatabaseTestCase +abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase { /** @@ -24,15 +24,37 @@ abstract class IntegrationTestCase extends DatabaseTestCase */ protected $lastLanguage; - /** - * Initializes the test - * Load english translations to ensure API response have english text - * - * @see tests/core/Test_Database#setUp() - */ - public function setUp() + public static function setUpBeforeClass() { - parent::setUp(); + try { + Piwik::createConfigObject(); + Piwik_Config::getInstance()->setTestEnvironment(); + + $dbConfig = Piwik_Config::getInstance()->database; + $dbName = $dbConfig['dbname']; + $dbConfig['dbname'] = null; + + Piwik::createDatabaseObject($dbConfig); + + Piwik::dropDatabase(); + Piwik::createDatabase($dbName); + Piwik::disconnectDatabase(); + + Piwik::createDatabaseObject(); + Piwik::createTables(); + Piwik::createLogObject(); + + Piwik_PluginsManager::getInstance()->loadPlugins(array()); + + } catch(Exception $e) { + self::fail("TEST INITIALIZATION FAILED: " .$e->getMessage()); + } + + include "DataFiles/SearchEngines.php"; + include "DataFiles/Languages.php"; + include "DataFiles/Countries.php"; + include "DataFiles/Currencies.php"; + include "DataFiles/LanguageToCountry.php"; if (self::$widgetTestingLevel != self::NO_WIDGET_TESTING) { @@ -60,8 +82,8 @@ abstract class IntegrationTestCase extends DatabaseTestCase // 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. - $this->setApiNotToCall(self::$defaultApiNotToCall); - $this->setApiToCall( array()); + self::setApiNotToCall(self::$defaultApiNotToCall); + self::setApiToCall( array()); if (self::$widgetTestingLevel != self::NO_WIDGET_TESTING) { @@ -76,27 +98,44 @@ abstract class IntegrationTestCase extends DatabaseTestCase // disable shuffling of tag cloud visualization so output is consistent Piwik_Visualization_Cloud::$debugDisableShuffle = true; } - - $this->setUpWebsitesAndGoals(); - $this->trackVisits(); } - abstract protected function setUpWebsitesAndGoals(); - - abstract protected function trackVisits(); - - public function tearDown() + public static function tearDownAfterClass() { - parent::tearDown(); + try { + $plugins = Piwik_PluginsManager::getInstance()->getLoadedPlugins(); + foreach($plugins AS $plugin) { + $plugin->uninstall(); + } + Piwik_PluginsManager::getInstance()->unloadPlugins(); + } catch (Exception $e) {} + Piwik::dropDatabase(); + Piwik_DataTable_Manager::getInstance()->deleteAll(); + Piwik_Option::getInstance()->clearCache(); + Piwik_Site::clearCache(); + Piwik_Common::deleteTrackerCache(); + Piwik_Config::getInstance()->clear(); + Piwik_TablePartitioning::$tablesAlreadyInstalled = null; + Zend_Registry::_unsetInstance(); + $_GET = $_REQUEST = array(); Piwik_Translate::getInstance()->unloadEnglishTranslation(); // re-enable tag cloud shuffling Piwik_Visualization_Cloud::$debugDisableShuffle = true; + + } + + public function setUp() + { + } + + public function tearDown() + { } - protected $apiToCall = array(); - protected $apiNotToCall = array(); + protected static $apiToCall = array(); + protected static $apiNotToCall = array(); public static $defaultApiNotToCall = array( 'LanguagesManager', @@ -167,7 +206,7 @@ abstract class IntegrationTestCase extends DatabaseTestCase * @throws Exception * @return void */ - protected function setApiToCall( $apiToCall ) + protected static function setApiToCall( $apiToCall ) { if(func_num_args() != 1) { @@ -177,7 +216,7 @@ abstract class IntegrationTestCase extends DatabaseTestCase { $apiToCall = array($apiToCall); } - $this->apiToCall = $apiToCall; + self::$apiToCall = $apiToCall; } /** @@ -187,13 +226,13 @@ abstract class IntegrationTestCase extends DatabaseTestCase * * @return void */ - protected function setApiNotToCall( $apiNotToCall ) + protected static function setApiNotToCall( $apiNotToCall ) { if(!is_array($apiNotToCall)) { $apiNotToCall = array($apiNotToCall); } - $this->apiNotToCall = $apiNotToCall; + self::$apiNotToCall = $apiNotToCall; } /** @@ -205,9 +244,9 @@ abstract class IntegrationTestCase extends DatabaseTestCase * * @return PiwikTracker */ - protected function getTracker($idSite, $dateTime, $defaultInit = true ) + protected static function getTracker($idSite, $dateTime, $defaultInit = true ) { - $t = new PiwikTracker( $idSite, $this->getTrackerUrl()); + $t = new PiwikTracker( $idSite, self::getTrackerUrl()); $t->setForceVisitDateTime($dateTime); if($defaultInit) @@ -235,7 +274,7 @@ abstract class IntegrationTestCase extends DatabaseTestCase * * @return int idSite of website created */ - protected function createWebsite( $dateTime, $ecommerce = 0, $siteName = 'Piwik test' ) + protected static function createWebsite( $dateTime, $ecommerce = 0, $siteName = 'Piwik test' ) { $idSite = Piwik_SitesManager_API::getInstance()->addSite( $siteName, @@ -274,11 +313,11 @@ abstract class IntegrationTestCase extends DatabaseTestCase * * @param $response */ - protected function checkResponse($response) + protected static function checkResponse($response) { $trans_gif_64 = "R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="; $expectedResponse = base64_decode($trans_gif_64); - $this->assertEquals($expectedResponse, $response, "Expected GIF beacon, got: <br/>\n" . $response ."<br/>\n"); + self::assertEquals($expectedResponse, $response, "Expected GIF beacon, got: <br/>\n" . $response ."<br/>\n"); } /** @@ -287,7 +326,7 @@ abstract class IntegrationTestCase extends DatabaseTestCase * * @return string */ - protected function getTrackerUrl() + protected static function getTrackerUrl() { $piwikUrl = Piwik_Url::getCurrentUrlWithoutFileName(); @@ -391,9 +430,9 @@ abstract class IntegrationTestCase extends DatabaseTestCase $apiId = $moduleName.'.'.$methodName; // If Api to test were set, we only test these - if(!empty($this->apiToCall) - && in_array($moduleName, $this->apiToCall) === false - && in_array($apiId, $this->apiToCall) === false) + if(!empty(self::$apiToCall) + && in_array($moduleName, self::$apiToCall) === false + && in_array($apiId, self::$apiToCall) === false) { $skipped[] = $apiId; continue; @@ -401,8 +440,8 @@ abstract class IntegrationTestCase extends DatabaseTestCase // Excluded modules from test elseif( (strpos($methodName, 'get') !== 0 - || in_array($moduleName, $this->apiNotToCall) === true - || in_array($apiId, $this->apiNotToCall) === true + || in_array($moduleName, self::$apiNotToCall) === true + || in_array($apiId, self::$apiNotToCall) === true || $methodName == 'getLogoUrl' || $methodName == 'getHeaderLogoUrl' ) @@ -1074,8 +1113,8 @@ abstract class IntegrationTestCase extends DatabaseTestCase if ($api == 'all') { - $this->setApiToCall(array()); - $this->setApiNotToCall(self::$defaultApiNotToCall); + self::setApiToCall(array()); + self::setApiNotToCall(self::$defaultApiNotToCall); } else { @@ -1084,8 +1123,8 @@ abstract class IntegrationTestCase extends DatabaseTestCase $api = array($api); } - $this->setApiToCall($api); - $this->setApiNotToCall(array('API.getPiwikVersion')); + self::setApiToCall($api); + self::setApiNotToCall(array('API.getPiwikVersion')); } if (isset($params['disableArchiving']) && $params['disableArchiving'] === true) @@ -1139,6 +1178,8 @@ abstract class IntegrationTestCase extends DatabaseTestCase // deal w/ any language changing hacks if (isset($params['language'])) { $this->changeLanguage($params['language']); + } else { + $this->changeLanguage('en'); } // separate request parameters from function parameters @@ -1157,11 +1198,6 @@ abstract class IntegrationTestCase extends DatabaseTestCase $requestParams, isset($params['userTypes']) ? $params['userTypes'] : false, isset($params['testingLevelOverride']) ? $params['testingLevelOverride'] : false); - - // change the language back to en - if ($this->lastLanguage != 'en') { - $this->changeLanguage('en'); - } } /** @@ -1172,7 +1208,7 @@ abstract class IntegrationTestCase extends DatabaseTestCase */ protected function changeLanguage( $langId ) { - if (isset($this->lastLanguage) && $this->lastLanguage != $langId) + if ($this->lastLanguage != $langId) { $_GET['language'] = $langId; Piwik_Translate::reset();