diff --git a/tests/integration/ApiGetReportMetadata.test.php b/tests/integration/ApiGetReportMetadata.test.php deleted file mode 100755 index 42fa77b39557bf8ea090340ae63e9545e6febe24..0000000000000000000000000000000000000000 --- a/tests/integration/ApiGetReportMetadata.test.php +++ /dev/null @@ -1,74 +0,0 @@ -<?php -if(!defined('PIWIK_CONFIG_TEST_INCLUDED')) -{ - require_once dirname(__FILE__)."/../../tests/config_test.php"; -} - -require_once PIWIK_INCLUDE_PATH . '/tests/integration/Integration.php'; - -/** - * This tests the output of the API plugin API - * It will return metadata about all API reports from all plugins - * as well as the data itself, pre-processed and ready to be displayed - * @return - */ -class Test_Piwik_Integration_ApiGetReportMetadata extends Test_Integration_Facade -{ - protected $dateTime = '2009-01-04 00:11:42'; - protected $idSite = null; - protected $idGoal = null; - protected $idGoal2 = null; - - public function getApiToTest() - { - return array( - array('API', array('idSite' => $this->idSite, 'date' => $this->dateTime)), - - // test w/ hideMetricsDocs=true - array('API.getMetadata', array('idSite' => $this->idSite, 'date' => $this->dateTime, - 'apiModule' => 'Actions', 'apiAction' => 'get', - 'testSuffix' => '_hideMetricsDoc', - 'otherRequestParameters' => array('hideMetricsDoc' => 1)) ), - array('API.getProcessedReport', array('idSite' => $this->idSite, 'date' => $this->dateTime, - 'apiModule' => 'Actions', 'apiAction' => 'get', - 'testSuffix' => '_hideMetricsDoc', - 'otherRequestParameters' => array('hideMetricsDoc' => 1)) ), - ); - } - - public function getControllerActionsToTest() - { - return array(); - } - - public function getOutputPrefix() - { - return 'apiGetReportMetadata'; - } - - public function setUp() - { - parent::setUp(); - - $this->idSite = $this->createWebsite($this->dateTime, $ecommerce = 1); - $this->idGoal = Piwik_Goals_API::getInstance()->addGoal($this->idSite, 'Goal 1 - Thank you', 'title', 'Thank you', 'contains', $caseSensitive=false, $revenue=10, $allowMultipleConversions = 1); - $this->idGoal2 = Piwik_Goals_API::getInstance()->addGoal($this->idSite, 'Goal 2 - Hello', 'url', 'hellow', 'contains', $caseSensitive=false, $revenue=10, $allowMultipleConversions = 0); - $this->idGoal3 = Piwik_Goals_API::getInstance()->addGoal($this->idSite, 'triggered js', 'manually', '', ''); - } - - protected function trackVisits() - { - $idSite = $this->idSite; - $dateTime = $this->dateTime; - - $t = $this->getTracker($idSite, $dateTime, $defaultInit = true); - - // Record 1st page view - $t->setUrl( 'http://example.org/index.htm' ); - $this->checkResponse($t->doTrackPageView( 'incredible title!')); - - $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.3)->getDatetime()); - $this->checkResponse($t->doTrackGoal($this->idGoal3, $revenue = 42.256)); - } -} - diff --git a/tests/integration/ApiGetReportMetadata_year.test.php b/tests/integration/ApiGetReportMetadata_year.test.php deleted file mode 100755 index 02e5f8f09dd2463e29db7957f332340521476dae..0000000000000000000000000000000000000000 --- a/tests/integration/ApiGetReportMetadata_year.test.php +++ /dev/null @@ -1,54 +0,0 @@ -<?php -if(!defined('PIWIK_CONFIG_TEST_INCLUDED')) -{ - require_once dirname(__FILE__)."/../../tests/config_test.php"; -} - -require_once PIWIK_INCLUDE_PATH . '/tests/integration/Integration.php'; - -/** - * test the Yearly metadata API response, - * with no visits, with custom response language - */ -class Test_Piwik_Integration_ApiGetReportMetadata_Year extends Test_Integration_Facade -{ - protected $idSite = null; - protected $dateTime = null; - - public function getApiToTest() - { - $apiToCall = array('API.getProcessedReport', - //FIXME TODO re-enable me! -// 'API.getReportMetadata', - 'LanguagesManager.getTranslationsForLanguage', - 'LanguagesManager.getAvailableLanguageNames', - 'SitesManager.getJavascriptTag'); - return array( - array($apiToCall, array('idSite' => $this->idSite, 'date' => $this->dateTime, 'periods' => 'year', - 'language' => 'fr')), - ); - } - - public function getOutputPrefix() - { - return 'apiGetReportMetadata_year'; - } - - public function getControllerActionsToTest() - { - return array(); - } - - public function setUp() - { - parent::setUp(); - - $this->dateTime = '2009-01-04 00:11:42'; - $this->idSite = $this->createWebsite($this->dateTime); - } - - protected function trackVisits() - { - // empty - } -} diff --git a/tests/integration/CsvExport.test.php b/tests/integration/CsvExport.test.php deleted file mode 100755 index 83276c651eac64eb52dafd0cec8a7b7a9dd04693..0000000000000000000000000000000000000000 --- a/tests/integration/CsvExport.test.php +++ /dev/null @@ -1,59 +0,0 @@ -<?php -if(!defined('PIWIK_CONFIG_TEST_INCLUDED')) -{ - require_once dirname(__FILE__)."/../../tests/config_test.php"; -} - -require_once PIWIK_INCLUDE_PATH . '/tests/integration/TwoVisitsWithCustomVariables.test.php'; - -/** - * Test CSV export with Expanded rows, Translated labels, Different languages - */ -class Test_Piwik_Integration_CsvExport extends Test_Piwik_Integration_TwoVisitsWithCustomVariables -{ - public function __construct( $testName = '' ) - { - parent::__construct($testName); - $this->useEscapedQuotes = false; - $this->doExtraQuoteTests = false; - } - - public function getApiToTest() - { - $apiToCall = array('VisitsSummary.get', 'CustomVariables.getCustomVariables'); - - $enExtraParam = array('expanded' => 0, 'flat' => 1, 'include_aggregate_rows' => 0, 'translateColumnNames' => 1); - - $deExtraParam = array('expanded' => 0, 'flat' => 1, 'include_aggregate_rows' => 1, 'translateColumnNames' => 1); - - return array( - array($apiToCall, array('idSite' => $this->idSite, 'date' => $this->dateTime, 'format' => 'csv', - 'otherRequestParameters' => array('expanded' => 0, 'flat' => 0), - 'testSuffix' => '_xp0')), - - array($apiToCall, array('idSite' => $this->idSite, 'date' => $this->dateTime, 'format' => 'csv', - 'otherRequestParameters' => $enExtraParam, 'language' => 'en', - 'testSuffix' => '_xp1_inner0_trans-en')), - - array($apiToCall, array('idSite' => $this->idSite, 'date' => $this->dateTime, 'format' => 'csv', - 'otherRequestParameters' => $deExtraParam, 'language' => 'de', - 'testSuffix' => '_xp1_inner1_trans-de')), - ); - } - - public function getAnotherApiToTest() - { - return array(); - } - - public function getControllerActionsToTest() - { - return array(); - } - - public function getOutputPrefix() - { - return 'csvExport'; - } -} - diff --git a/tests/integration/EcommerceOrderWithItems.test.php b/tests/integration/EcommerceOrderWithItems.test.php deleted file mode 100755 index 90b3171867bdf8f84ab95ffb0290429dd896c56d..0000000000000000000000000000000000000000 --- a/tests/integration/EcommerceOrderWithItems.test.php +++ /dev/null @@ -1,319 +0,0 @@ -<?php -if(!defined('PIWIK_CONFIG_TEST_INCLUDED')) -{ - require_once dirname(__FILE__)."/../../tests/config_test.php"; -} - -require_once PIWIK_INCLUDE_PATH . '/tests/integration/Integration.php'; - -/** - * Tests API methods after ecommerce orders are tracked. - */ -class Test_Piwik_Integration_EcommerceOrderWithItems extends Test_Integration_Facade -{ - protected $dateTime = null; - protected $idSite = null; - protected $idSite2 = null; - protected $idGoalStandard = null; - - public function getApiToTest() - { - $dayApi = array('VisitsSummary.get', 'VisitTime', 'CustomVariables.getCustomVariables', - 'Live.getLastVisitsDetails', 'UserCountry', 'API.getProcessedReport', 'Goals.get', - 'Goals.getConversions', 'Goals.getItemsSku', 'Goals.getItemsName', 'Goals.getItemsCategory'); - - $goalWeekApi = array('Goals.get', 'Goals.getItemsSku', 'Goals.getItemsName', 'Goals.getItemsCategory'); - - $goalItemApi = array('Goals.getItemsSku', 'Goals.getItemsName', 'Goals.getItemsCategory'); - - $processedReportApi = array('API.getProcessedReport'); - - // Normal standard goal - return array( - // day tests - array($dayApi, array('idSite' => $this->idSite, 'date' => $this->dateTime, 'periods' => array('day'), 'otherRequestParameters' => array('_leavePiwikCoreVariables' => 1))), - - // goals API week tests - array($goalWeekApi, array('idSite' => $this->idSite, 'date' => $this->dateTime, 'periods' => array('week'))), - - // abandoned carts tests - array($goalItemApi, array('idSite' => $this->idSite, 'date' => $this->dateTime, - 'periods' => array('day', 'week'), 'abandonedCarts' => 1, - 'testSuffix' => '_AbandonedCarts')), - - // multiple periods tests - array($goalItemApi, array('idSite' => $this->idSite, 'date' => $this->dateTime, 'periods' => array('day'), - 'setDateLastN' => true, 'testSuffix' => 'multipleDates')), - - // multiple periods & multiple websites tests - array($goalItemApi, array('idSite' => "{$this->idSite},{$this->idSite2}", 'date' => $this->dateTime, - 'periods' => array('day'), 'setDateLastN' => true, - 'testSuffix' => 'multipleDates_andMultipleWebsites')), - - // test metadata products - array($processedReportApi, array('idSite' => $this->idSite, 'date' => $this->dateTime, - 'periods' => array('day'), 'apiModule' => 'Goals', - 'apiAction' => 'getItemsSku', 'testSuffix' => '_Metadata_ItemsSku')), - array($processedReportApi, array('idSite' => $this->idSite, 'date' => $this->dateTime, - 'periods' => array('day'), 'apiModule' => 'Goals', - 'apiAction' => 'getItemsCategory', 'testSuffix' => '_Metadata_ItemsCategory')), - - // test metadata Goals.get for Ecommerce orders & Carts - array($processedReportApi, array('idSite' => $this->idSite, 'date' => $this->dateTime, - 'periods' => array('day'), 'apiModule' => 'Goals', 'apiAction' => 'get', - 'idGoal' => Piwik_Archive::LABEL_ECOMMERCE_ORDER, - 'testSuffix' => '_Metadata_Goals.Get_Order')), - array($processedReportApi, array('idSite' => $this->idSite, 'date' => $this->dateTime, - 'periods' => array('day'), 'apiModule' => 'Goals', 'apiAction' => 'get', - 'idGoal' => Piwik_Archive::LABEL_ECOMMERCE_CART, - 'testSuffix' => '_Metadata_Goals.Get_AbandonedCart')), - - // normal standard goal test - array($processedReportApi, array('idSite' => $this->idSite, 'date' => $this->dateTime, - 'periods' => array('day'), 'apiModule' => 'Goals', 'apiAction' => 'get', - 'idGoal' => $this->idGoalStandard, - 'testSuffix' => '_Metadata_Goals.Get_NormalGoal')), - - // non-existant goal test - array($processedReportApi, array('idSite' => $this->idSite, 'date' => $this->dateTime, - 'periods' => array('day'), 'apiModule' => 'Goals', 'apiAction' => 'get', - 'idGoal' => 'FAKE IDGOAL', - 'testSuffix' => '_Metadata_Goals.Get_NotExistingGoal')), - - // While we're at it, test for a standard Metadata report with zero entries - array($processedReportApi, array('idSite' => $this->idSite, 'date' => $this->dateTime, - 'periods' => array('day'), 'apiModule' => 'VisitTime', - 'apiAction' => 'getVisitInformationPerServerTime', - 'testSuffix' => '_Metadata_VisitTime.getVisitInformationPerServerTime')), - - // Standard non metadata Goals.get - // test Goals.get with idGoal=ecommerceOrder and ecommerceAbandonedCart - array('Goals.get', array('idSite' => $this->idSite, 'date' => $this->dateTime, - 'periods' => array('day', 'week'), 'idGoal' => Piwik_Archive::LABEL_ECOMMERCE_CART, - 'testSuffix' => '_GoalAbandonedCart')), - array('Goals.get', array('idSite' => $this->idSite, 'date' => $this->dateTime, - 'periods' => array('day', 'week'), 'idGoal' => Piwik_Archive::LABEL_ECOMMERCE_ORDER, - 'testSuffix' => '_GoalOrder')), - array('Goals.get', array('idSite' => $this->idSite, 'date' => $this->dateTime, - 'periods' => array('day', 'week'), 'idGoal' => 1, 'testSuffix' => '_GoalMatchTitle')), - array('Goals.get', array('idSite' => $this->idSite, 'date' => $this->dateTime, - 'periods' => array('day', 'week'), 'idGoal' => '', 'testSuffix' => '_GoalOverall')), - - array('VisitsSummary.get', array('idSite' => $this->idSite, 'date' => $this->dateTime, - 'periods' => array('day'), 'segment' => 'visitEcommerceStatus==none', - 'testSuffix' => '_SegmentNoEcommerce')), - array('VisitsSummary.get', array('idSite' => $this->idSite, 'date' => $this->dateTime, - 'periods' => array('day'), 'testSuffix' => '_SegmentOrderedSomething', - 'segment' => 'visitEcommerceStatus==ordered,visitEcommerceStatus==orderedThenAbandonedCart')), - array('VisitsSummary.get', array('idSite' => $this->idSite, 'date' => $this->dateTime, - 'periods' => array('day'), 'testSuffix' => '_SegmentAbandonedCart', - 'segment' => 'visitEcommerceStatus==abandonedCart,visitEcommerceStatus==orderedThenAbandonedCart')), - - // test segment visitConvertedGoalId - array('VisitsSummary.get', array('idSite' => $this->idSite, 'date' => $this->dateTime, - 'periods' => array('day', 'week'), 'testSuffix' => '_SegmentConvertedGoalId1', - 'segment' => "visitConvertedGoalId=={$this->idGoalStandard}")), - array('VisitsSummary.get', array('idSite' => $this->idSite, 'date' => $this->dateTime, - 'periods' => array('day'), 'testSuffix' => '_SegmentDidNotConvertGoalId1', - 'segment' => "visitConvertedGoalId!={$this->idGoalStandard}")), - - // test segment visitorType - array('VisitsSummary.get', array('idSite' => $this->idSite, 'date' => $this->dateTime, - 'periods' => array('week'), 'segment' => 'visitorType==new', - 'testSuffix' => '_SegmentNewVisitors')), - array('VisitsSummary.get', array('idSite' => $this->idSite, 'date' => $this->dateTime, - 'periods' => array('week'), 'segment' => 'visitorType==returning', - 'testSuffix' => '_SegmentReturningVisitors')), - array('VisitsSummary.get', array('idSite' => $this->idSite, 'date' => $this->dateTime, - 'periods' => array('week'), 'segment' => 'visitorType==returningCustomer', - 'testSuffix' => '_SegmentReturningCustomers')), - - // test segment pageTitle - array('VisitsSummary.get', array('idSite' => $this->idSite, 'date' => $this->dateTime, - 'periods' => array('day'), 'segment' => 'pageTitle==incredible title!', - 'testSuffix' => '_SegmentPageTitleMatch')), - - // test Live! output is OK also for the visit that just bought something (other visits leave an abandoned cart) - array('Live.getLastVisitsDetails', array('idSite' => $this->idSite, - 'date' => Piwik_Date::factory($this->dateTime)->addHour( 30.65 )->getDatetime(), - 'periods' => array('day'), 'testSuffix' => '_LiveEcommerceStatusOrdered')), - - // test API.get method - array('API.get', array('idSite' => $this->idSite, 'date' => $this->dateTime, 'periods' => array('day', 'week'), - 'otherRequestParameters' => array( - 'columns' => 'nb_pageviews,nb_visits,avg_time_on_site,nb_visits_converted'), - 'testSuffix' => '_API_get')), - - // Website2 - array($goalWeekApi, array('idSite' => $this->idSite2, 'date' => $this->dateTime, 'periods' => array('week'), - 'testSuffix' => '_Website2')), - ); - } - - public function getOutputPrefix() - { - return 'ecommerceOrderWithItems'; - } - - public function getControllerActionsToTest() - { - return array(); - } - - public function setUp() - { - parent::setUp(); - - $this->dateTime = '2011-04-05 00:11:42'; - $this->idSite = $this->createWebsite($this->dateTime, $ecommerce=1); - $this->idSite2 = $this->createWebsite($this->dateTime); - $this->idGoalStandard = Piwik_Goals_API::getInstance()->addGoal($this->idSite, 'title match, triggered ONCE', 'title', 'incredible', 'contains', $caseSensitive=false, $revenue=10, $allowMultipleConversions = true); - } - - protected function trackVisits() - { - $dateTime = $this->dateTime; - $idSite = $this->idSite; - $idSite2 = $this->idSite2; - - $t = $this->getTracker($idSite, $dateTime, $defaultInit = true); - // VISIT NO 1 - $t->setUrl( 'http://example.org/index.htm' ); - $category = 'Electronics & Cameras'; - $price = 1111.11111; - - // VIEW product page - $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!')); - - $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')); - - // 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')); - - $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')); - - // VISIT NO 2 - - // Fake the returning visit cookie - $t->setDebugStringAppend("&_idvc=2"); - - // 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')); - - // 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')); - - // 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')); - - // ADD TO CART - $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(1.9)->getDatetime()); - $t->setCustomVariable(3, 'VisitorName', 'Great name!', 'visit'); - $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)); - - // 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)); - - // ORDER NO 2 - $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(2.1)->getDatetime()); - $t->addEcommerceItem($sku = 'SKU2', $name = 'Canon SLR' , $category = 'Electronics & Cameras', $price = 1500, $quantity = 1); - // Product bought with empty category - $t->addEcommerceItem($sku = 'SKU VERY nice indeed', $name = 'PRODUCT name' , '', $price = 11.22, $quantity = 1); - - // test to delete all custom vars, they should be copied from visits - // This is a frequent use case: ecommerce shops tracking the order from backoffice - // without passing the custom variable 1st party cookie along since it's not known by back office - $visitorCustomVarSave = $t->visitorCustomVar; - $t->visitorCustomVar = false; - $this->checkResponse($t->doTrackEcommerceOrder($orderId = '1037nsjusu4s3894', $grandTotal = 2000, $subTotal = 1500, $tax = 400, $shipping = 100, $discount = 0)); - $t->visitorCustomVar = $visitorCustomVarSave; - - // ORDER SHOULD DEDUPE - // Refresh the page with the receipt for the second order, should be ignored - // 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)); - - // 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)); - - // Record the same visit leaving twice an abandoned cart - foreach(array(0, 5, 24) as $offsetHour) - { - $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour($offsetHour + 2.4)->getDatetime()); - // Also recording an order the day after - 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)); - } - - // 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")); - - $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")); - - $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")); - - // 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)); - } - - // 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)); - - // 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)); - - // testing the same order in a different website should record - $t = $this->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)); - //------------------------------------- End tracking - } -} diff --git a/tests/integration/FlattenReports.test.php b/tests/integration/FlattenReports.test.php deleted file mode 100644 index 2d3c27350fe6ac3356434666154ccb11bf513e37..0000000000000000000000000000000000000000 --- a/tests/integration/FlattenReports.test.php +++ /dev/null @@ -1,110 +0,0 @@ -<?php -if(!defined('PIWIK_CONFIG_TEST_INCLUDED')) -{ - require_once dirname(__FILE__)."/../../tests/config_test.php"; -} - -require_once PIWIK_INCLUDE_PATH . '/tests/integration/Integration.php'; - -/** - * Tests the flattening of reports. - */ -class Test_Piwik_Integration_FlattenReports extends Test_Integration_Facade -{ - protected $dateTime = '2010-03-06 11:22:33'; - protected $idSite = null; - - public function getApiToTest() - { - $return = array(); - - // referrers - $return[] = array('Referers.getWebsites', array( - 'idSite' => $this->idSite, - 'date' => $this->dateTime, - 'otherRequestParameters' => array( - 'flat' => '1', - 'expanded' => '0' - ) - )); - - // urls - $return[] = array('Actions.getPageUrls', array( - 'idSite' => $this->idSite, - 'date' => $this->dateTime, - 'otherRequestParameters' => array( - 'flat' => '1', - 'expanded' => '0' - ) - )); - $return[] = array('Actions.getPageUrls', array( - 'idSite' => $this->idSite, - 'date' => $this->dateTime, - 'testSuffix' => '_withAggregate', - 'otherRequestParameters' => array( - 'flat' => '1', - 'include_aggregate_rows' => '1', - 'expanded' => '0' - ) - )); - - // custom variables for multiple days - $return[] = array('CustomVariables.getCustomVariables', array( - 'idSite' => $this->idSite, - 'date' => $this->dateTime, - 'otherRequestParameters' => array( - 'date' => '2010-03-06,2010-03-08', - 'flat' => '1', - 'include_aggregate_rows' => '1', - 'expanded' => '0' - ) - )); - - return $return; - } - - public function getControllerActionsToTest() - { - return array(); - } - - public function getOutputPrefix() - { - return 'FlattenReports'; - } - - public function setUp() - { - parent::setUp(); - $this->idSite = $this->createWebsite($this->dateTime); - } - - protected function trackVisits() - { - $dateTime = $this->dateTime; - $idSite = $this->idSite; - - 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->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')); - } - } - } - - $t = $this->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')); - } -} - diff --git a/tests/integration/ImportLogs.test.php b/tests/integration/ImportLogs.test.php deleted file mode 100755 index 408bc6247b810b85d3e10e8f7f5ccbd05d8cae48..0000000000000000000000000000000000000000 --- a/tests/integration/ImportLogs.test.php +++ /dev/null @@ -1,81 +0,0 @@ -<?php -if(!defined('PIWIK_CONFIG_TEST_INCLUDED')) -{ - require_once dirname(__FILE__)."/../../tests/config_test.php"; -} - -require_once PIWIK_INCLUDE_PATH . '/tests/integration/Integration.php'; - -/** - * Tests the log importer. - */ -class Test_Piwik_Integration_ImportLogs extends Test_Integration_Facade -{ - protected $dateTime = '2010-03-06 11:22:33'; - protected $idSite = null; - protected $idGoal = null; - - public function getApiToTest() - { - return array( - //FIXME! -// array('all', array('idSite' => $this->idSite, 'date' => '2012-08-09', 'periods' => 'month')), - ); - } - - public function getControllerActionsToTest() - { - return array(); - } - - public function getOutputPrefix() - { - return 'ImportLogs'; - } - - public function setUp() - { - parent::setUp(); - $this->idSite = $this->createWebsite($this->dateTime); - - // for conversion testing - $this->idGoal = Piwik_Goals_API::getInstance()->addGoal($this->idSite, 'all', 'url', 'http', 'contains', false, 5); - } - - - /** - * Logs a couple visits for Aug 9, Aug 10, Aug 11 of 2012. - */ - protected function trackVisits() - { - //FIXMETODO - return; - $pwd = Zend_Registry::get('config')->superuser->password; - if(strlen($pwd) != 32) $pwd = md5($pwd); - - $token_auth = Piwik_UsersManager_API::getInstance()->getTokenAuth(Zend_Registry::get('config')->superuser->login, $pwd); - $python = Piwik_Common::isWindows() ? "C:\Python27\python.exe" : 'python'; - $cmd = $python . ' "' - . PIWIK_INCLUDE_PATH.'/misc/log-analytics/import_logs.py" ' # script loc -// . '-ddd ' // debug - . '--url="'.$this->getRootUrl().'tests/PHPUnit/proxy/" ' # proxy so that piwik uses test config files - . '--idsite='.$this->idSite.' ' - . '--token-auth="'.$token_auth.'" ' - . '--recorders=4 ' - . '--enable-http-errors ' - . '--enable-http-redirects ' - . '--enable-static ' - . '--enable-bots "' - . PIWIK_INCLUDE_PATH.'/tests/resources/fake_logs.log" ' # log file - . '2>&1' - ; - echo $cmd; - - exec($cmd, $output, $result); - if ($result !== 0) - { - echo "<pre>command: $cmd\nresult: $result\noutput: ".implode("\n", $output)."</pre>"; - throw new Exception("log importer failed"); - } - } -} diff --git a/tests/integration/Integration.php b/tests/integration/Integration.php deleted file mode 100644 index 26dcfe596af76dc831c03a7d49245fb1dd633a9f..0000000000000000000000000000000000000000 --- a/tests/integration/Integration.php +++ /dev/null @@ -1,1315 +0,0 @@ -<?php -if(!defined('PIWIK_CONFIG_TEST_INCLUDED')) -{ - require_once dirname(__FILE__)."/../../tests/config_test.php"; -} - -require_once PIWIK_INCLUDE_PATH . '/libs/PiwikTracker/PiwikTracker.php'; -require_once PIWIK_INCLUDE_PATH . '/tests/core/Database.test.php'; - -Mock::generate('Piwik_Auth'); - -/** - * Base class for Integration tests. Runs integration / acceptance tests - * - * The tests call the Piwik tracker with known sets of data, expected errors, - * and can _test the output of the tracker beacon, as well as calling - * all API functions and compare their XML output with the 'expected output'. - * - * If an algorithm changes in the Tracker or in the Archiving, tests can easily be run to check that - * the output changes as expected (eg. More accurate browser detection, adding a new metric in the - * API results, etc. - * - * @see Ideas for improvements http://dev.piwik.org/trac/ticket/1465 - */ -abstract class Test_Integration extends Test_Database_Base -{ - public static $defaultApiNotToCall = array( - 'LanguagesManager', - 'DBStats', - 'UsersManager', - 'SitesManager', - 'ExampleUI', - 'Live', - 'SEO', - 'ExampleAPI', - 'PDFReports', - 'API', - 'ImageGraph', - ); - - /** - * Widget testing level constant. If Test_Integration::$widgetTestingLevel is - * set to this, controller actions will not be tested. - */ - const NO_WIDGET_TESTING = 'none'; - - /** - * Widget testing level constant. If Test_Integration::$widgetTestingLevel is - * set to this, controller actions will be checked for non-fatal errors, but - * the output will be ignored. - */ - const CHECK_WIDGET_ERRORS = 'check_errors'; - - /** - * Widget testing level constant. If Test_Integration::$widgetTestingLevel is - * set to this, controller actions will be run & their output will be checked with - * expected output files. - */ - const COMPARE_WIDGET_OUTPUT = 'compare_output'; - - /** - * Determines how much of controller actions are tested (if at all). - */ - static public $widgetTestingLevel = self::NO_WIDGET_TESTING; - - /** - * API testing level constant. If Test_Integration::$apiTestingLevel is - * set to this, API methods will not be tested. - */ - const NO_API_TESTING = 'none'; - - /** - * API testing level constant. If Test_Integration::$apiTestingLevel is - * set to this, API methods will be run & their output will be checked with - * expected output files. - */ - const COMPARE_API_OUTPUT = 'compare_output'; - - /** - * Determines how much testing API methods are subjected to (if any). - */ - static public $apiTestingLevel = self::COMPARE_API_OUTPUT; - - const DEFAULT_USER_PASSWORD = 'nopass'; - - /** - * Whether to send tracking requests through CURL or to the Tracker directly. - */ - static public $useLocalTracking = false; - - /** - * Path where expected/processed output files are stored. Can be overridden. - */ - public function getPathToTestDirectory() - { - return PIWIK_INCLUDE_PATH . '/tests/integration'; - } - - /** - * Load english translations to ensure API response have english text - * @see tests/core/Test_Database#setUp() - */ - function setUp() - { - parent::setUp(); - Piwik_Config::getInstance()->setTestEnvironment(); - - $_GET = $_REQUEST = array(); - $_SERVER['HTTP_REFERER'] = ''; - - // Make sure translations are loaded to check messages in English - Piwik_Translate::getInstance()->loadEnglishTranslation(); - - // 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()); - - if (self::$widgetTestingLevel != self::NO_WIDGET_TESTING) - { - Piwik::setUserIsSuperUser(); - - // create users for controller testing - $usersApi = Piwik_UsersManager_API::getInstance(); - $usersApi->addUser('anonymous', self::DEFAULT_USER_PASSWORD, 'anonymous@anonymous.com'); - $usersApi->addUser('test_view', self::DEFAULT_USER_PASSWORD, 'view@view.com'); - $usersApi->addUser('test_admin', self::DEFAULT_USER_PASSWORD, 'admin@admin.com'); - - // disable shuffling of tag cloud visualization so output is consistent - Piwik_Visualization_Cloud::$debugDisableShuffle = true; - } - } - - function tearDown() - { - parent::tearDown(); - $_GET = $_REQUEST = array(); - Piwik_Translate::getInstance()->unloadEnglishTranslation(); - - // re-enable tag cloud shuffling - Piwik_Visualization_Cloud::$debugDisableShuffle = true; - } - - protected $apiToCall = array(); - protected $apiNotToCall = array(); - - /** - * Forces the test to only call and fetch XML for the specified plugins, - * or exact API methods. - * - * If not called, all default tests will be executed. - * - * @param $apiToCall array( 'ExampleAPI', 'Plugin.getData' ) - * @return void - */ - protected function setApiToCall( $apiToCall ) - { - if(func_num_args() != 1) - { - throw new Exception('setApiToCall expects an array'); - } - if(!is_array($apiToCall)) - { - $apiToCall = array($apiToCall); - } - $this->apiToCall = $apiToCall; - } - - /** - * Sets a list of API methods to not call during the test - * @param $apiNotToCall eg. 'ExampleAPI.getPiwikVersion' - * @return void - */ - protected function setApiNotToCall( $apiNotToCall ) - { - if(!is_array($apiNotToCall)) - { - $apiNotToCall = array($apiNotToCall); - } - $this->apiNotToCall = $apiNotToCall; - } - - /** - * Returns a PiwikTracker object that you can then use to track pages or goals. - * - * @param $idSite - * @param $dateTime - * @param $defaultInit If set to true, the tracker object will have default IP, user agent, time, resolution, etc. - * @return PiwikTracker - */ - protected function getTracker($idSite, $dateTime, $defaultInit = true ) - { - if (self::$useLocalTracking) - { - require_once PIWIK_INCLUDE_PATH.'/tests/LocalTracker.php'; - $t = new Piwik_LocalTracker($idSite, $this->getTrackerUrl()); - } - else - { - $t = new PiwikTracker( $idSite, $this->getTrackerUrl()); - } - - $t->setForceVisitDateTime($dateTime); - - if($defaultInit) - { - $t->setIp('156.5.3.2'); - - // Optional tracking - $t->setUserAgent( "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 (.NET CLR 3.5.30729)"); - $t->setBrowserLanguage('fr'); - $t->setLocalTime( '12:34:06' ); - $t->setResolution( 1024, 768 ); - $t->setBrowserHasCookies(true); - $t->setPlugins($flash = true, $java = true, $director = false); - } - return $t; - } - - /** - * Creates a website, then sets its creation date to a day earlier than specified dateTime - * Useful to create a website now, but force data to be archived back in the past. - * - * @param $dateTime eg '2010-01-01 12:34:56' - * @return $idSite of website created - */ - protected function createWebsite( $dateTime, $ecommerce = 0, $siteName = 'Piwik test' ) - { - $idSite = Piwik_SitesManager_API::getInstance()->addSite( - $siteName, - "http://piwik.net/", - $ecommerce, - $ips = null, - $excludedQueryParameters = null, - $timezone = null, - $currency = null - ); - - // Manually set the website creation date to a day earlier than the earliest day we record stats for - Zend_Registry::get('db')->update(Piwik_Common::prefixTable("site"), - array('ts_created' => Piwik_Date::factory($dateTime)->subDay(1)->getDatetime()), - "idsite = $idSite" - ); - - // Clear the memory Website cache - Piwik_Site::clearCache(); - - // add access to all test users if doing controller tests - if (self::$widgetTestingLevel != self::NO_WIDGET_TESTING) - { - $usersApi = Piwik_UsersManager_API::getInstance(); - $usersApi->setUserAccess('anonymous', 'view', array($idSite)); - $usersApi->setUserAccess('test_view', 'view', array($idSite)); - $usersApi->setUserAccess('test_admin', 'admin', array($idSite)); - } - - return $idSite; - } - - /** - * Checks that the response is a GIF image as expected. - * @return Will fail the test if the response is not the expected GIF - */ - protected function checkResponse($response) - { - $trans_gif_64 = "R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="; - $expectedResponse = base64_decode($trans_gif_64); - $this->assertEqual($expectedResponse, $response, ""); - if($response == $expectedResponse) - { - $this->pass(); - return; - } - echo "Expected GIF beacon, got: <br/>\n" . $response ."<br/>\n"; - } - - /** - * Returns URL to Piwik root. - * - * @return string - */ - protected function getRootUrl() - { - $piwikUrl = Piwik_Url::getCurrentUrlWithoutFileName(); - - $pathBeforeRoot = 'tests'; - // Running from a plugin - if(strpos($piwikUrl, 'plugins/') !== false) - { - $pathBeforeRoot = 'plugins'; - } - - $piwikUrl = substr($piwikUrl, 0, strpos($piwikUrl, $pathBeforeRoot.'/')); - return $piwikUrl; - } - - /** - * Returns URL to the proxy script, used to ensure piwik.php - * uses the test environment, and allows variable overwriting - * - * @return string - */ - protected function getTrackerUrl() - { - return $this->getRootUrl().'tests/PHPUnit/proxy/piwik.php'; - } - - /** - * Initializes the test - * @param $title - * @return void - */ - function __construct($title = '') - { - parent::__construct($title); - - if (Test_Integration::$widgetTestingLevel != self::NO_WIDGET_TESTING) - { - self::initializeControllerTesting(); - } - - Piwik::createAccessObject(); - Piwik_PostEvent('FrontController.initAuthenticationObject'); - - // We need to be SU to create websites for tests - Piwik::setUserIsSuperUser(); - - // Load and install plugins - $pluginsManager = Piwik_PluginsManager::getInstance(); - $plugins = Piwik_Config::getInstance()->Plugins['Plugins']; - - $pluginsManager->loadPlugins( $plugins ); - $pluginsManager->installLoadedPlugins(); - } - - /** - * Initializes parts of Piwik so controller actions can be called & tested. - */ - public static function initializeControllerTesting() - { - static $initialized = false; - - if (!$initialized) - { - Zend_Registry::set('timer', new Piwik_Timer); - - $pluginsManager = Piwik_PluginsManager::getInstance(); - $pluginsToLoad = Piwik_Config::getInstance()->Plugins['Plugins']; - $pluginsManager->loadPlugins( $pluginsToLoad ); - - $initialized = true; - } - } - - public static function processRequestArgs() - { - // set the widget testing level - if (isset($_GET['widgetTestingLevel'])) - { - self::setWidgetTestingLevel($_GET['widgetTestingLevel']); - } - - // set the API testing level - if (isset($_GET['apiTestingLevel'])) - { - self::setApiTestingLevel($_GET['apiTestingLevel']); - } - - if (isset($_GET['useLocalTracking']) && strtolower($_GET['useLocalTracking']) == 'true') - { - self::$useLocalTracking = true; - } - } - - public static function setWidgetTestingLevel($level) - { - if (!$level) return; - - if ($level != Test_Integration::NO_WIDGET_TESTING && - $level != Test_Integration::CHECK_WIDGET_ERRORS && - $level != Test_Integration::COMPARE_WIDGET_OUTPUT) - { - echo "<p>Invalid option for 'widgetTestingLevel', ignoring.</p>\n"; - return; - } - - self::$widgetTestingLevel = $level; - } - - public function setApiTestingLevel($level) - { - if (!$level) return; - - if ($level != Test_Integration::NO_API_TESTING && - $level != Test_Integration::COMPARE_API_OUTPUT) - { - echo "<p>Invalid option for 'apiTestingLevel', ignoring.</p>"; - return; - } - - self::$apiTestingLevel = $level; - } - - /** - * Given a list of default parameters to set, returns the URLs of APIs to call - * If any API was specified in setApiToCall() we ensure only these are tested. - * If any API is set as excluded (see list below) then it will be ignored. - * - * @param $parametersToSet - * @param $formats Array of 'format' to fetch from API - * @param $periods Array of 'period' to query API - * @param $setDateLastN If set to true, the 'date' parameter will be rewritten to query instead a range of dates, rather than one period only. - * @param $language 2 letter language code, defaults to default piwik language - * @return array of API URLs query strings - */ - protected function generateUrlsApi( $parametersToSet, $formats, $periods, $setDateLastN = false, $language = false, $segment = false ) - { - // Get the URLs to query against the API for all functions starting with get* - $skipped = $requestUrls = array(); - $apiMetadata = new Piwik_API_DocumentationGenerator; - foreach(Piwik_API_Proxy::getInstance()->getMetadata() as $class => $info) - { - $moduleName = Piwik_API_Proxy::getInstance()->getModuleNameFromClassName($class); - foreach($info as $methodName => $infoMethod) - { - $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) - { - $skipped[] = $apiId; - continue; - } - // Excluded modules from test - elseif( - (strpos($methodName, 'get') !== 0 - || in_array($moduleName, $this->apiNotToCall) === true - || in_array($apiId, $this->apiNotToCall) === true - || $methodName == 'getLogoUrl' - || $methodName == 'getHeaderLogoUrl' - ) - ) - { - $skipped[] = $apiId; - continue; - } - - foreach($periods as $period) - { - $parametersToSet['period'] = $period; - - // If date must be a date range, we process this date range by adding 6 periods to it - if($setDateLastN) - { - if(!isset($parametersToSet['dateRewriteBackup'])) - { - $parametersToSet['dateRewriteBackup'] = $parametersToSet['date']; - } - - $lastCount = (int)$setDateLastN; - if($setDateLastN === true) - { - $lastCount = 6; - } - $firstDate = $parametersToSet['dateRewriteBackup']; - $secondDate = date('Y-m-d', strtotime("+$lastCount " . $period . "s", strtotime($firstDate))); - $parametersToSet['date'] = $firstDate . ',' . $secondDate; - } - - // Set response language - if($language !== false) - { - $parametersToSet['language'] = $language; - } - // Generate for each specified format - foreach($formats as $format) - { - $parametersToSet['format'] = $format; - $parametersToSet['hideIdSubDatable'] = 1; - $parametersToSet['serialize'] = 1; - - $exampleUrl = $apiMetadata->getExampleUrl($class, $methodName, $parametersToSet); - if($exampleUrl === false) - { - $skipped[] = $apiId; - continue; - } - - // Remove the first ? in the query string - $exampleUrl = substr($exampleUrl, 1); - $apiRequestId = $apiId; - if(strpos($exampleUrl, 'period=') !== false) - { - $apiRequestId .= '_' . $period; - } - - $apiRequestId .= '.' . $format; - - $requestUrls[$apiRequestId] = $exampleUrl; - } - } - } - } -// var_dump($skipped); -// var_dump($requestUrls); -// exit; - return $requestUrls; - } - - /** - * Will call all get* methods on authorized modules, - * force the archiving, - * record output in XML files - * and compare with the expected outputs. - * - * @param $testName Used to write the output in a file, used as filename prefix - * @param $formats String or array of formats to fetch from API - * @param $idSite Id site - * @param $dateTime Date time string of reports to request - * @param $periods String or array of strings of periods (day, week, month, year) - * @param $setDateLastN When set to true, 'date' parameter passed to API request will be rewritten to query a range of dates rather than 1 date only - * @param $language 2 letter language code to request data in - * @param $segment Custom Segment to query the data for - * @param $visitorId Only used for Live! API testing - * @param $abandonedCarts Only used in Goals API testing - * - * @return bool Passed or failed - */ - function callGetApiCompareOutput($testName, $formats = 'xml', $idSite = false, $dateTime = false, $periods = false, - $setDateLastN = false, $language = false, $segment = false, $visitorId = false, $abandonedCarts = false, - $idGoal = false, $apiModule = false, $apiAction = false, $otherRequestParameters = array()) - { - if (self::$apiTestingLevel == Test_Integration::NO_API_TESTING) - { - return; - } - - $pass = true; - - list($pathProcessed, $pathExpected) = $this->getProcessedAndExpectedDirs(); - - if($periods === false) - { - $periods = 'day'; - } - if(!is_array($periods)) - { - $periods = array($periods); - } - if(!is_array($formats)) - { - $formats = array($formats); - } - if(!is_writable($pathProcessed)) - { - $this->fail('To run the tests, you need to give write permissions to the following directory (create it if it doesn\'t exist).<code><br/>mkdir '. $pathProcessed.'<br/>chmod 777 -R '.$pathProcessed.'</code><br/>'); - } - $parametersToSet = array( - 'idSite' => $idSite, - 'date' => $periods == array('range') ? $dateTime : date('Y-m-d', strtotime($dateTime)), - 'expanded' => '1', - 'piwikUrl' => 'http://example.org/piwik/', - // Used in getKeywordsForPageUrl - 'url' => 'http://example.org/store/purchase.htm', - - // Used in Actions.getPageUrl, .getDownload, etc. - // tied to Main.test.php doTest_oneVisitorTwoVisits - // will need refactoring when these same API functions are tested in a new function - 'downloadUrl' => 'http://piwik.org/path/again/latest.zip?phpsessid=this is ignored when searching', - 'outlinkUrl' => 'http://dev.piwik.org/svn', - 'pageUrl' => 'http://example.org/index.htm?sessionid=this is also ignored by default', - 'pageName' => ' Checkout / Purchasing... ', - - // do not show the millisec timer in response or tests would always fail as value is changing - 'showTimer' => 0, - - 'language' => $language ? $language : 'en', - 'abandonedCarts' => $abandonedCarts ? 1 : 0, - 'idSites' => $idSite, - ); - $parametersToSet = array_merge($parametersToSet, $otherRequestParameters); - if(!empty($visitorId )) - { - $parametersToSet['visitorId'] = $visitorId; - } - if(!empty($apiModule )) - { - $parametersToSet['apiModule'] = $apiModule; - } - if(!empty($apiAction)) - { - $parametersToSet['apiAction'] = $apiAction; - } - if(!empty($segment)) - { - $parametersToSet['segment'] = $segment; - } - if($idGoal !== false) - { - $parametersToSet['idGoal'] = $idGoal; - } - - $requestUrls = $this->generateUrlsApi($parametersToSet, $formats, $periods, $setDateLastN, $language, $segment); - - foreach($requestUrls as $apiId => $requestUrl) - { -// echo "$requestUrl <br>"; - $isLiveMustDeleteDates = strpos($requestUrl, 'Live.getLastVisits') !== false; - $request = new Piwik_API_Request($requestUrl); - - list($processedFilePath, $expectedFilePath) = $this->getProcessedAndExpectedPaths($testName, $apiId); - - // Cast as string is important. For example when calling - // with format=original, objects or php arrays can be returned. - // we also hide errors to prevent the 'headers already sent' in the ResponseBuilder (which sends Excel headers multiple times eg.) - $response = (string)$request->process(); - - if($isLiveMustDeleteDates) - { - $response = $this->removeAllLiveDatesFromXml($response); - } - - file_put_contents( $processedFilePath, $response ); - - $expected = $this->loadExpectedFile($expectedFilePath); - if (empty($expected)) - { - continue; - } - - // When tests run on Windows EOL delimiters are not the same as UNIX default EOL used in the renderers - $expected = str_replace("\r\n", "\n", $expected); - $response = str_replace("\r\n", "\n", $response); - - // @todo This should not vary between systems AFAIK... "idsubdatatable can differ" - $expected = $this->removeXmlElement($expected, 'idsubdatatable',$testNotSmallAfter = false); - $response = $this->removeXmlElement($response, 'idsubdatatable',$testNotSmallAfter = false); - - $removeEndOfLines = false; - if($isLiveMustDeleteDates) - { - $expected = $this->removeAllLiveDatesFromXml($expected); - } - // If date=lastN the <prettyDate> element will change each day, we remove XML element before comparison - elseif(strpos($dateTime, 'last') !== false - || strpos($dateTime, 'today') !== false - || strpos($dateTime, 'now') !== false - ) - { - if(strpos($requestUrl, 'API.getProcessedReport') !== false) - { - $expected = $this->removePrettyDateFromXml($expected); - $response = $this->removePrettyDateFromXml($response); - } - // avoid build failure when running just before midnight, generating visits in the future - $expected = $this->removeXmlElement($expected, 'sum_daily_nb_uniq_visitors'); - $response = $this->removeXmlElement($response, 'sum_daily_nb_uniq_visitors'); - $expected = $this->removeXmlElement($expected, 'nb_visits_converted'); - $response = $this->removeXmlElement($response, 'nb_visits_converted'); - $expected = $this->removeXmlElement($expected, 'imageGraphUrl'); - $response = $this->removeXmlElement($response, 'imageGraphUrl'); - $removeEndOfLines =true; - } - - // is there a better way to test for the current DB type in use? - if(Zend_Registry::get('db') instanceof Piwik_Db_Adapter_Mysqli) - { - // Do not test for TRUNCATE(SUM()) returning .00 on mysqli since this is not working - // http://bugs.php.net/bug.php?id=54508 - $expected = str_replace('.00</revenue>', '</revenue>', $expected); - $response = str_replace('.00</revenue>', '</revenue>', $response); - $expected = str_replace('.1</revenue>', '</revenue>', $expected); - $expected = str_replace('.11</revenue>', '</revenue>', $expected); - $response = str_replace('.11</revenue>', '</revenue>', $response); - $response = str_replace('.1</revenue>', '</revenue>', $response); - } - - // Hack so we dont file_put_contents (see below) the files with the end of lines removed (not readable) - $responseToTest = $response; - $expectedToTest = $expected; - if($removeEndOfLines) - { - $responseToTest = str_replace("\n", "", $response); - $expectedToTest = str_replace("\n", "", $expected); - } - $pass = $pass && $this->assertEqual(trim($responseToTest), trim($expectedToTest), "<br/>\nDifferences with expected in: $processedFilePath %s "); - if(trim($response) != trim($expected)) - { - var_dump('ERROR FOR ' . $apiId . ' -- FETCHED RESPONSE, then EXPECTED RESPONSE - '.$requestUrl); - echo "\n"; - var_dump($response); - echo "\n"; - var_dump($expected); - echo "\n"; - } - else - { - file_put_contents( $processedFilePath, $response ); - } - } - if($pass) { - $this->pass(); - } else { - $this->fail(); - } - return $pass; - } - - /** - * Calls a set of controller actions & either checks the result against - * expected output or just checks if errors occurred when called. - * - * The behavior of this function can be modified by setting - * Test_Integration::$widgetTestingLevel (or $testingLevelOverride): - * <ul> - * <li>If set to <b>NO_WIDGET_TESTING</b> this function simply returns.<li> - * <li>If set to <b>CHECK_WIDGET_ERRORS</b> controller actions are called & - * this function will just check for errors.</li> - * <li>If set to <b>COMPARE_WIDGET_OUTPUT</b> controller actions are - * called & the output is checked against expected output.</li> - * </ul> - * - * @param string $testName Unique name of this test group. Expected/processed - * file names use this as a prefix. - * @param array $actions Array of controller actions to call. Each element - * must be in the following format: 'Controller.action' - * @param array $requestParameters The request parameters to set. - * @param array $userTypes The user types to test the controller with. Can contain - * these values: 'anonymous', 'view', 'admin', 'superuser'. - * Defaults to all four. - * @param int $testingLevelOverride Overrides Test_Integration::$widgetTestingLevel. - */ - public function callWidgetsCompareOutput( - $testName, $actions, $requestParameters, $userTypes = false, $testingLevelOverride = false) - { - // deal with the testing level - if (Test_Integration::$widgetTestingLevel == self::NO_WIDGET_TESTING) - { - return; - } - - if ($testingLevelOverride === false) - { - $testingLevelOverride = self::$widgetTestingLevel; - } - - // process $userTypes argument - if (!$userTypes) - { - $userTypes = array('anonymous', 'view', 'admin', 'superuser'); - } - else if (!is_array($userTypes)) - { - $userTypes = array($userTypes); - } - - $oldGet = $_GET; - - // get all testable controller actions if necessary - $actionParams = array(); - if ($actions == 'all') - { - // Goals.addWidgets requires idSite to be set - $_GET['idSite'] = isset($requestParameters['idSite']) ? $requestParameters['idSite'] : '0'; - - list($actions, $actionParams) = $this->findAllWidgets(); - - $_GET = $oldGet; - } - else if (!is_array($actions)) - { - $actions = array($actions); - } - - // run the tests - foreach ($actions as $controllerAction) - { - $customParams = isset($actionParams[$controllerAction]) ? $actionParams[$controllerAction] : array(); - list($controllerName, $actionName) = explode('.', $controllerAction); - - foreach ($userTypes as $userType) - { - $this->setUserType($userType); - - try - { - // set request parameters - $_GET = array(); - foreach ($customParams as $key => $value) - { - $_GET[$key] = $value; - } - foreach ($requestParameters as $key => $value) - { - $_GET[$key] = $value; - } - - $_GET['module'] = $controllerName; - $_GET['action'] = $actionName; - - if ($testingLevelOverride == self::CHECK_WIDGET_ERRORS) - { - $this->errorsOccurredInTest = array(); - set_error_handler(array($this, "customErrorHandler")); - } - - // call controller action - $response = Piwik_FrontController::getInstance()->fetchDispatch(); - - list($processedFilePath, $expectedFilePath) = $this->getProcessedAndExpectedPaths( - $testName . '_' . $userType, $controllerAction, 'html'); - - if ($testingLevelOverride == self::CHECK_WIDGET_ERRORS) - { - restore_error_handler(); - - if (!empty($this->errorsOccurredInTest)) - { - // write processed (only if there are errors) - file_put_contents($processedFilePath, $response); - - $this->fail("PHP Errors occurred in calling controller action '$controllerAction':"); - foreach ($this->errorsOccurredInTest as $error) - { - echo " $error<br/>\n"; - } - } - else - { - $this->pass(); - } - } - else // check against expected - { - // write raw processed response - file_put_contents($processedFilePath, $response); - - // load expected - $expected = $this->loadExpectedFile($expectedFilePath); - if (!$expected) - { - continue; - } - - // normalize eol delimeters - $expected = str_replace("\r\n", "\n", $expected); - $response = str_replace("\r\n", "\n", $response); - - // check against expected - $passed = $this->assertEqual(trim($expected), trim($response), - "<br/>\nDifferences with expected in: $processedFilePath %s "); - - if (!$passed) - { - var_dump('ERROR FOR ' . $controllerAction . ' -- FETCHED RESPONSE, then EXPECTED RESPONSE - '); - echo "<br/>\n"; - var_dump(htmlspecialchars($response)); - echo "<br/>\n"; - var_dump(htmlspecialchars($expected)); - echo "<br/>\n"; - } - } - } - catch (Exception $e) - { - $this->fail("EXCEPTION THROWN IN $controllerAction: ".$e->getTraceAsString()); - } - } - } - - // reset $_GET to old values - $_GET = array(); - foreach ($oldGet as $key => $value) - { - $_GET[$key] = $value; - } - - // set user type - $this->setUserType('superuser'); - } - - /** - * Sets the access privilegs of the current user to the specified user type. - * - * @param $userType string Can be 'superuser', 'admin', 'view' or 'anonymous'. - */ - protected function setUserType( $userType ) - { - if ($userType == 'superuser') - { - $code = Piwik_Auth_Result::SUCCESS_SUPERUSER_AUTH_CODE; - $login = 'superUserLogin'; - } - else - { - $code = 0; - - $login = $userType; - if ($login != 'anonymous') - { - $login = 'test_' . $login; - } - } - - $authResultObj = new Piwik_Auth_Result($code, $login, 'dummyTokenAuth'); - $authObj = new MockPiwik_Auth(); - $authObj->setReturnValue('getName', 'Login'); - $authObj->setReturnValue('authenticate', $authResultObj); - - Zend_Registry::get('access')->reloadAccess($authObj); - } - - /** - * Set of messages for errors that occurred during the invocation of a - * controller action. If not empty, there was an error in the controller. - */ - private $errorsOccurredInTest = array(); - - /** - * A custom error handler used with <code>set_error_handler</code>. If - * an error occurs, a message describing it is saved in an array. - */ - public function customErrorHandler($errno, $errstr, $errfile, $errline) - { - if (strpos(strtolower($errstr), 'cannot modify header information - headers already sent')) // HACK - { - $this->errorsOccurredInTest[] = "$errfile($errline): - $errstr"; - } - } - - /** - * Returns a list of all available widgets. - */ - protected function findAllWidgets() - { - $widgetList = Piwik_GetWidgetsList(); - - $actions = array(); - $customParams = array(); - - foreach($widgetList as $widgetCategory => $widgets) - { - foreach($widgets as $widgetInfo) - { - $module = $widgetInfo['parameters']['module']; - $moduleAction = $widgetInfo['parameters']['action']; - $wholeAction = "$module.$moduleAction"; - - // FIXME: can't test Referers.getKeywordsForPage since it tries to make a request to - // localhost w/ the wrong url. Piwik_Url::getCurrentUrlWithoutFileName - // returns /tests/integration/?... when used within a test. - if ($wholeAction == "Referers.getKeywordsForPage") - { - continue; - } - - // rss widgets depends on feedburner URL. don't test the widget just in case - // feedburner is down. - if ($module == "ExampleRssWidget" - || $module == "ExampleFeedburner") - { - continue; - } - - unset($widgetInfo['parameters']['module']); - unset($widgetInfo['parameters']['action']); - - $actions[] = $wholeAction; - $customParams[$wholeAction] = $widgetInfo['parameters']; - } - } - - return array($actions, $customParams); - } - - protected function removeAllLiveDatesFromXml($input) - { - $toRemove = array( - 'serverDate', - 'firstActionTimestamp', - 'lastActionTimestamp', - 'lastActionDateTime', - 'serverTimestamp', - 'serverTimePretty', - 'serverDatePretty', - 'serverDatePrettyFirstAction', - 'serverTimePrettyFirstAction', - 'goalTimePretty', - 'serverTimePretty', - 'visitorId' - ); - foreach($toRemove as $xml) { - $input = $this->removeXmlElement($input, $xml); - } - return $input; - } - - protected function removePrettyDateFromXml($input) - { - return $this->removeXmlElement($input, 'prettyDate'); - } - - protected function removeXmlElement($input, $xmlElement, $testNotSmallAfter = true) - { - $input = preg_replace('/(<'.$xmlElement.'>.+?<\/'.$xmlElement.'>)/', '', $input); - //check we didn't delete the whole string - if($testNotSmallAfter) - { - $this->assertTrue(strlen($input) > 100); - } - return $input; - } - - private function getProcessedAndExpectedDirs() - { - $path = $this->getPathToTestDirectory(); - return array($path . '/processed/', $path . '/expected/'); - } - - private function getProcessedAndExpectedPaths($testName, $testId, $format = null) - { - $filename = $testName . '__' . $testId; - if ($format) - { - $filename .= ".$format"; - } - - list($processedDir, $expectedDir) = $this->getProcessedAndExpectedDirs(); - - return array($processedDir . $filename, $expectedDir . $filename); - } - - private function loadExpectedFile($filePath) - { - $result = @file_get_contents($filePath); - if(empty($result)) - { - $expectedDir = dirname($filePath); - $this->fail(" ERROR: Could not find expected API output '$filePath'. For new tests, to pass the test, you can copy files from the processed/ directory into $expectedDir after checking that the output is valid. %s "); - return null; - } - return $result; - } - - /** Identifies the last language used in an API/Controller call. */ - protected $lastLanguage; - - /** - * changing the language within one request is a bit fancy - * in order to keep the core clean, we need a little hack here - */ - protected function changeLanguage( $langId ) - { - if (empty($this->lastLanguage) - || $this->lastLanguage != $langId) - { - $_GET['language'] = $langId; - Piwik_Translate::reset(); - Piwik_Translate::getInstance()->reloadLanguage($langId); - } - - $this->lastLanguage = $langId; - } -} - -/** - * Facade type that can be used to create more readable integration tests. - * - * Derived types must be prefixed with Test_Integration_Facade_. - */ -abstract class Test_Integration_Facade extends Test_Integration -{ - /** - * Returns an array describing the API methods to call & compare with - * expected output. - * - * The returned array must be of the following format: - * <code> - * array( - * array('SomeAPI.method', array('testOption1' => 'value1', 'testOption2' => 'value2'), - * array(array('SomeAPI.method', 'SomeOtherAPI.method'), array(...)), - * . - * . - * . - * ) - * </code> - * - * Valid test options: - * <ul> - * <li><b>testSuffix</b> The suffix added to the test name. Helps determine - * the filename of the expected output.</li> - * <li><b>format</b> The desired format of the output. Defaults to 'xml'.</li> - * <li><b>idSite</b> The id of the website to get data for.</li> - * <li><b>date</b> The date to get data for.</li> - * <li><b>periods</b> The period or periods to get data for. Can be an array.</li> - * <li><b>setDateLastN</b> Flag describing whether to query for a set of - * dates or not.</li> - * <li><b>language</b> The language to use.</li> - * <li><b>segment</b> The segment to use.</li> - * <li><b>visitorId</b> The visitor ID to use.</li> - * <li><b>abandonedCarts</b> Whether to look for abandoned carts or not.</li> - * <li><b>idGoal</b> The goal ID to use.</li> - * <li><b>apiModule</b> The value to use in the apiModule request parameter.</li> - * <li><b>apiAction</b> The value to use in the apiAction request parameter.</li> - * <li><b>otherRequestParameters</b> An array of extra request parameters to use.</li> - * <li><b>disableArchiving</b> Disable archiving before running tests.</li> - * </ul> - * - * All test options are optional, except 'idSite' & 'date'. - */ - abstract public function getApiToTest(); - - /** - * It is possible to run another set of API tests after the first one. - * For example, getApiToTest() will test and record with a specific suffix - * Then we will call some API that invalidates a piece of the reports - * Then call all reports again and check that what is expected to have changed indeed has changed! - * - * @see getApiToTest() for returned values, same signature - */ - public function getAnotherApiToTest() - { - return array(); - } - /** - * Returns an array describing the Controller actions to call & compare - * with expected output. - * - * The returned array must be of the following format: - * <code> - * array( - * array('Controller.action', array('testOption1' => 'value1', 'testOption2' => 'value2'), - * array(array('Controller.action', 'OtherController.action'), array(...)), - * . - * . - * . - * ) - * </code> - * - * Valid test options: - * <ul> - * <li><b>UNIMPLEMENTED</b></li> - * </ul> - */ - abstract public function getControllerActionsToTest(); - - /** - * Called before running any tests. Overriding classes must log any - * visits/conversions in this method. - */ - abstract protected function trackVisits(); - - /** - * The main test case. Runs API & Controller tests. - * - * This can be overriden to add more testing logic (or a new test case - * can be added). - */ - public function test_RunAllTests() - { - $this->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; - - $this->runApiTests(); - $this->runControllerTests(); - $this->runApiAnotherTests(); - } - - /** - * Gets the string prefix used in the name of the expected/processed output files. - */ - public function getOutputPrefix() - { - return str_replace('Test_Piwik_Integration_', '', get_class($this)); - } - - /* - * When there 2 distinct sets of APIs to call, call it - */ - private function runApiAnotherTests() - { - $apiToTest = $this->getAnotherApiToTest(); - if(!empty($apiToTest)) - { - $this->runApiTests( $apiToTest ); - } - } - - /** - * Runs API tests. - */ - private function runApiTests($apiToTest = false) - { - if($apiToTest === false) - { - $apiToTest = $this->getApiToTest(); - } - $testName = 'test_' . $this->getOutputPrefix(); - - foreach ($apiToTest as $test) - { - list($api, $params) = $test; - - if ($api == 'all') - { - $this->setApiToCall(array()); - $this->setApiNotToCall(Test_Integration::$defaultApiNotToCall); - } - else - { - if (!is_array($api)) - { - $api = array($api); - } - - $this->setApiToCall($api); - $this->setApiNotToCall(array('API.getPiwikVersion')); - } - - if (isset($params['disableArchiving']) && $params['disableArchiving'] === true) - { - Piwik_ArchiveProcessing::$forceDisableArchiving = true; - } - else - { - Piwik_ArchiveProcessing::$forceDisableArchiving = false; - } - - if (isset($params['language'])) - { - $this->changeLanguage($params['language']); - } - - $testSuffix = isset($params['testSuffix']) ? $params['testSuffix'] : ''; - - $this->callGetApiCompareOutput( - $testName . $testSuffix, - isset($params['format']) ? $params['format'] : 'xml', - isset($params['idSite']) ? $params['idSite'] : false, - isset($params['date']) ? $params['date'] : false, - isset($params['periods']) ? $params['periods'] : false, - isset($params['setDateLastN']) ? $params['setDateLastN'] : false, - isset($params['language']) ? $params['language'] : false, - isset($params['segment']) ? $params['segment'] : false, - isset($params['visitorId']) ? $params['visitorId'] : false, - isset($params['abandonedCarts']) ? $params['abandonedCarts'] : false, - isset($params['idGoal']) ? $params['idGoal'] : false, - isset($params['apiModule']) ? $params['apiModule'] : false, - isset($params['apiAction']) ? $params['apiAction'] : false, - isset($params['otherRequestParameters']) ? $params['otherRequestParameters'] : array()); - - // change the language back to en - if ($this->lastLanguage != 'en') - { - $this->changeLanguage('en'); - } - } - } - - /** - * Runs controller tests. - */ - protected function runControllerTests() - { - static $nonRequestParameters = array('testingLevelOverride' => null, 'userTypes' => null); - - $testGroups = $this->getControllerActionsToTest(); - $testName = 'test_' . $this->getOutputPrefix(); - - foreach ($testGroups as $test) - { - list($actions, $params) = $test; - - // deal w/ any language changing hacks - if (isset($params['language'])) - { - $this->changeLanguage($params['language']); - } - - // separate request parameters from function parameters - $requestParams = array(); - foreach ($params as $key => $value) - { - if (!isset($nonRequestParameters[$key])) - { - $requestParams[$key] = $value; - } - } - - $testSuffix = isset($params['testSuffix']) ? $params['testSuffix'] : ''; - - $this->callWidgetsCompareOutput( - $testName . $testSuffix, - $actions, - $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'); - } - } - } -} - -// process testing level request args -Test_Integration::processRequestArgs(); - diff --git a/tests/integration/LabelFilter.test.php b/tests/integration/LabelFilter.test.php deleted file mode 100644 index f2e76dfb02a85278c876f57f6cb717ab65afc21c..0000000000000000000000000000000000000000 --- a/tests/integration/LabelFilter.test.php +++ /dev/null @@ -1,155 +0,0 @@ -<?php -if(!defined('PIWIK_CONFIG_TEST_INCLUDED')) -{ - require_once dirname(__FILE__)."/../../tests/config_test.php"; -} - -require_once PIWIK_INCLUDE_PATH . '/tests/integration/Integration.php'; - -/** - * Tests the class Piwik_API_DataTableManipulator_LabelFilter. - * This is not possible as unit test, since it loads data from the archive. - */ -class Test_Piwik_Integration_LabelFilter extends Test_Integration_Facade -{ - protected $dateTime = '2010-03-06 11:22:33'; - protected $idSite = null; - - public function getApiToTest() - { - $labelsToTest = array( - // first level - 'shouldBeNoData' => 'nonExistent', - 'dir' => ' dir ', - '0' => urlencode('/0'), - - // TODO the label in the API output is ...&#039;... why does it only work this way? - 'thisiscool' => urlencode('/ééé"'... <this is cool>!'), - - // second level - 'dirnonExistent' => 'dir>nonExistent', - 'dirfilephpfoobarfoo2bar' => 'dir>'.urlencode('/file.php?foo=bar&foo2=bar'), - - // 4 levels - 'dir2sub0filephp' => 'dir2>sub>0>'.urlencode('/file.php') - ); - - $return = array(); - foreach ($labelsToTest as $suffix => $label) - { - $return[] = array('Actions.getPageUrls', array( - 'testSuffix' => '_'.$suffix, - 'idSite' => $this->idSite, - 'date' => $this->dateTime, - 'otherRequestParameters' => array( - 'label' => $label, - 'expanded' => 0 - ) - )); - } - - $label = 'dir'; - $return[] = array('Actions.getPageUrls', array( - 'testSuffix' => '_'.$label.'_range', - 'idSite' => $this->idSite, - 'date' => $this->dateTime, - 'otherRequestParameters' => array( - 'date' => '2010-03-06,2010-03-08', - 'label' => $label, - 'expanded' => 0 - ) - )); - - $return[] = array('Actions.getPageTitles', array( - 'testSuffix' => '_titles', - 'idSite' => $this->idSite, - 'date' => $this->dateTime, - 'otherRequestParameters' => array( - // encode once for test framework and once for the label filter. - // note: title has no blank prefixed here. in the report it has. - 'label' => urlencode('incredible title! <>,;'), - 'expanded' => 0 - ) - )); - - $return[] = array('Actions.getPageTitles', array( - 'testSuffix' => '_titlesRecursive', - 'idSite' => $this->idSite, - 'date' => $this->dateTime, - 'otherRequestParameters' => array( - 'label' => - ' '. // test trimming - urlencode('incredible parent title! <>,;'). - '>'. - urlencode('subtitle <>,;'), - 'expanded' => 0 - ) - )); - - $keyword = '<>&\"the pdo extension is required for this adapter but the extension is not loaded'; - $searchEngineTest = array( - 'testSuffix' => '_keywords_html', - 'idSite' => $this->idSite, - 'date' => $this->dateTime, - 'otherRequestParameters' => array( - 'label' => 'Google>'.urlencode($keyword), - 'expanded' => 0 - ) - ); - $return[] = array('Referers.getSearchEngines', $searchEngineTest); - - $searchEngineTest['otherRequestParameters']['label'] = 'Google>'.urlencode(html_entity_decode($keyword)); - $return[] = array('Referers.getSearchEngines', $searchEngineTest); - - return $return; - } - - public function getControllerActionsToTest() - { - return array(); - } - - public function getOutputPrefix() - { - return 'LabelFilter'; - } - - public function setUp() - { - parent::setUp(); - $this->idSite = $this->createWebsite($this->dateTime); - } - - protected function trackVisits() - { - $dateTime = $this->dateTime; - $idSite = $this->idSite; - $t = $this->getTracker($idSite, $dateTime, $defaultInit = true); - - $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! <>,;')); - - $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! <>,;')); - - $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 <>,;')); - - $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! <>,;')); - - $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! <>,;')); - - $t->setUrl('http://example.org/0'); - $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.4)->getDatetime()); - $this->checkResponse($t->doTrackPageView('I am URL zero!')); - - } -} - diff --git a/tests/integration/NoVisit.test.php b/tests/integration/NoVisit.test.php deleted file mode 100755 index bf2d623903c825dc8b011534fb5663adb5bb53d2..0000000000000000000000000000000000000000 --- a/tests/integration/NoVisit.test.php +++ /dev/null @@ -1,108 +0,0 @@ -<?php -if(!defined('PIWIK_CONFIG_TEST_INCLUDED')) -{ - require_once dirname(__FILE__)."/../../tests/config_test.php"; -} - -require_once PIWIK_INCLUDE_PATH . '/tests/integration/Integration.php'; - -/** - * testing various wrong Tracker requests and check that they behave as expected: - * not throwing errors and not recording data. - * - * API will archive and output empty stats. - */ -class Test_Piwik_Integration_NoVisit extends Test_Integration_Facade -{ - protected $idSite = null; - protected $dateTime = null; - - public function getApiToTest() - { - // this will output empty XML result sets as no visit was tracked - return array( - array('all', array('idSite' => $this->idSite, 'date' => $this->dateTime)), - array('all', array('idSite' => $this->idSite, 'date' => $this->dateTime, 'periods' => array('day', 'week'), - 'setDateLastN' => true, 'testSuffix' => '_PeriodIsLast')), - ); - } - - public function getControllerActionsToTest() - { - return array(); - } - - public function getOutputPrefix() - { - return 'noVisit'; - } - - public function setUp() - { - parent::setUp(); - - $this->dateTime = '2009-01-04 00:11:42'; - $this->idSite = $this->createWebsite($this->dateTime); - } - - protected function trackVisits() - { - $dateTime = $this->dateTime; - $idSite = $this->idSite; - -/* - // Trigger invalid website - $trackerInvalidWebsite = $this->getTracker($idSiteFake = 0, $dateTime, $defaultInit = true); - $response = Piwik_Http::fetchRemoteFile($trackerInvalidWebsite->getUrlTrackPageView()); - $this->assertTrue(strpos($response, 'Invalid idSite') !== false, 'invalid website ID'); - - // Trigger wrong website - $trackerWrongWebsite = $this->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'); - */ - - // Trigger empty request - $trackerUrl = $this->getTrackerUrl(); - $response = Piwik_Http::fetchRemoteFile($trackerUrl); - $this->assertTrue(strpos($response, 'is a free open source web') !== false, 'Piwik empty request response not correct: ' . $response); - - $t = $this->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')); - - // Test IP Exclusion works with or without IP exclusion - foreach(array(false, true) as $enable) - { - // Enable IP Anonymization - $t->DEBUG_APPEND_URL = '&forceIpAnonymization=' . (int)$enable; - - // test with excluded IP - $t->setUserAgent('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 (.NET CLR 3.5.30729)'); // restore normal user agent - $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')); - - // 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')); - } - - try { - @$t->setAttributionInfo(array()); - $this->fail(); - } catch(Exception $e) {} - - try { - $t->setAttributionInfo(json_encode('test')); - $this->fail(); - } catch(Exception $e) {} - - $t->setAttributionInfo(json_encode(array())); - } -} diff --git a/tests/integration/OneVisitorOneWebsite_SeveralDaysDateRange.test.php b/tests/integration/OneVisitorOneWebsite_SeveralDaysDateRange.test.php deleted file mode 100755 index 3e609b1ac37695212c3aa9999a7c1e5a39079ed3..0000000000000000000000000000000000000000 --- a/tests/integration/OneVisitorOneWebsite_SeveralDaysDateRange.test.php +++ /dev/null @@ -1,84 +0,0 @@ -<?php -if(!defined('PIWIK_CONFIG_TEST_INCLUDED')) -{ - require_once dirname(__FILE__)."/../../tests/config_test.php"; -} - -require_once PIWIK_INCLUDE_PATH . '/tests/integration/Integration.php'; - -/** - * testing period=range use case. Recording data before and after, checking that the requested range is processed correctly - */ -class Test_Piwik_Integration_OneVisitorOneWebsite_SeveralDaysDateRange extends Test_Integration_Facade -{ - protected $dateTimes = array( - '2010-12-14 01:00:00', - '2010-12-15 01:00:00', - '2010-12-25 01:00:00', - '2011-01-15 01:00:00', - '2011-01-16 01:00:00', - ); - protected $idSite = null; - - public function getApiToTest() - { - return array( - // range test - array('MultiSites.getAll', array('idSite' => $this->idSite, 'date' => '2010-12-15,2011-01-15', - 'periods' => array('range'))), - - // test several dates (tests use of IndexedByDate w/ 'date1,date2,etc.') - array('MultiSites.getAll', array('idSite' => $this->idSite, 'date' => '2010-12-10', - 'periods' => array('day'), 'setDateLastN' => true, - 'testSuffix' => '_IndexedByDate')) - ); - } - - public function getControllerActionsToTest() - { - return array(); - } - - public function getOutputPrefix() - { - return 'oneVisitor_oneWebsite_severalDays_DateRange'; - } - - public function setUp() - { - parent::setUp(); - - $this->idSite = $this->createWebsite($this->dateTimes[0]); - } - - protected function trackVisits() - { - $dateTimes = $this->dateTimes; - $idSite = $this->idSite; - - $i = 0; - foreach($dateTimes as $dateTime) - { - $i++; - $visitor = $this->getTracker($idSite, $dateTime, $defaultInit = true); - // Fake the visit count cookie - $visitor->setDebugStringAppend("&_idvc=$i"); - - $visitor->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.1)->getDatetime()); - $visitor->setUrl('http://example.org/homepage'); - $this->checkResponse($visitor->doTrackPageView('ou pas')); - - // Test change the IP, the visit should not be split but recorded to the same idvisitor - $visitor->setIp('200.1.15.22'); - - $visitor->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.2)->getDatetime()); - $visitor->setUrl('http://example.org/news'); - $this->checkResponse($visitor->doTrackPageView('ou pas')); - - $visitor->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(1)->getDatetime()); - $visitor->setUrl('http://example.org/news'); - $this->checkResponse($visitor->doTrackPageView('ou pas')); - } - } -} - diff --git a/tests/integration/OneVisitorOneWebsite_SeveralDaysDateRange_ArchivingTests.test.php b/tests/integration/OneVisitorOneWebsite_SeveralDaysDateRange_ArchivingTests.test.php deleted file mode 100755 index 1c9617353e074613b749c706aa77b5e9d5b6eaa2..0000000000000000000000000000000000000000 --- a/tests/integration/OneVisitorOneWebsite_SeveralDaysDateRange_ArchivingTests.test.php +++ /dev/null @@ -1,117 +0,0 @@ -<?php -if(!defined('PIWIK_CONFIG_TEST_INCLUDED')) -{ - require_once dirname(__FILE__)."/../../tests/config_test.php"; -} - -require_once PIWIK_INCLUDE_PATH . '/tests/integration/OneVisitorOneWebsite_SeveralDaysDateRange.test.php'; - -/** - * Tests some API using range periods & makes sure the correct amount of blob/numeric - * archives are created. - */ -class Test_Piwik_Integration_OneVisitorOneWebsite_SeveralDaysDateRange_ArchivingTests extends Test_Piwik_Integration_OneVisitorOneWebsite_SeveralDaysDateRange -{ - public function getApiToTest() - { - $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' => $this->idSite, 'date' => '2010-12-15,2011-01-15', - 'periods' => array('range'), 'segment' => $segment)); - } - } - - return $result; - } - - public function getControllerActionsToTest() - { - return array(); - } - - public function test_RunAllTests() - { - parent::test_RunAllTests(); - - if (Test_Integration::$apiTestingLevel != Test_Integration::NO_API_TESTING) - { - $this->_checkExpectedRowsInArchiveTable(); - - // Force Purge to happen again this table (since it was called at end of archiving) - Piwik_SetOption( Piwik_ArchiveProcessing_Period::FLAG_TABLE_PURGED . Piwik_Common::prefixTable('archive_blob_2010_12'), '2010-01-01'); - Piwik_SetOption( Piwik_ArchiveProcessing_Period::FLAG_TABLE_PURGED . Piwik_Common::prefixTable('archive_blob_2011_01'), '2010-01-01'); - - foreach(array('archive_numeric_2010_12','archive_blob_2010_12','archive_numeric_2011_01','archive_blob_2011_01') as $table ) - { - // INSERT some ERROR records. - // We use period=range since the test below is restricted to these - Piwik_Query(" INSERT INTO `" - . Piwik_Common::prefixTable($table) - ."` (`idarchive` ,`name` ,`idsite` ,`date1` ,`date2` ,`period` ,`ts_archived` ,`value`) - VALUES (10000, 'done', '1', '2010-12-06', '2010-12-06', '".Piwik::$idPeriods['range']."', '2010-12-06' , '".Piwik_ArchiveProcessing::DONE_ERROR."'), - (20000, 'doneX', '2', '2012-07-06', '2012-07-06', '".Piwik::$idPeriods['range']."', '' , '".Piwik_ArchiveProcessing::DONE_ERROR."')" - ); - } - - // We've added error rows which should fail the following test - $this->_checkExpectedRowsInArchiveTable( $expectPass = false ); - - // Test Scheduled tasks Table Optimize, and Delete old reports - Piwik_CoreAdminHome::purgeOutdatedArchives(); - Piwik_CoreAdminHome::optimizeArchiveTable(); - - // Check that only the good reports were not deleted: - $this->_checkExpectedRowsInArchiveTable(); - } - } - - // Check that requesting period "Range" means - protected function _checkExpectedRowsInArchiveTable( $expectPass = true ) - { - // only processing the requested Plugin blob (Actions in this case), not all Plugins blobs - $tests = array( - // 4 blobs for the Actions plugin, 7 blobs for UserSettings, 2 blobs VisitTime - 'archive_blob_2010_12' => (4 + 7 + 2) * 3, - // (VisitsSummary 5 metrics + 1 flag - no Unique visitors for range) - // + 1 flag archive UserSettings - // + (Actions 1 flag + 2 metrics - pageviews, unique pageviews) - // + (Frequency 5 metrics + 1 flag) - // + 1 flag VisitTime - // * 3 segments - 'archive_numeric_2010_12' => (6 + 1 + 3 + 6 + 1 ) * 3, - - // all "Range" records are in December - 'archive_blob_2011_01' => 0, - 'archive_numeric_2011_01' => 0, - ); - foreach($tests as $table => $expectedRows) - { - $sql = "SELECT count(*) FROM " . Piwik_Common::prefixTable($table) . " WHERE period = ".Piwik::$idPeriods['range']; - $countBlobs = Zend_Registry::get('db')->fetchOne($sql); - if($expectPass) { - $this->assertEqual( $expectedRows, $countBlobs, "$table expected $expectedRows, got $countBlobs" ); - } else { - $this->assertTrue( $expectedRows < $countBlobs, "$table expected $expectedRows < $countBlobs" ); - } - } - - } -} - diff --git a/tests/integration/OneVisitorTwoVisits.test.php b/tests/integration/OneVisitorTwoVisits.test.php deleted file mode 100755 index 952508779050a38ede6e22d04b0e89a8bdc34d47..0000000000000000000000000000000000000000 --- a/tests/integration/OneVisitorTwoVisits.test.php +++ /dev/null @@ -1,147 +0,0 @@ -<?php -if(!defined('PIWIK_CONFIG_TEST_INCLUDED')) -{ - require_once dirname(__FILE__)."/../../tests/config_test.php"; -} - -require_once PIWIK_INCLUDE_PATH . '/tests/integration/Integration.php'; - -/** - * This use case covers many simple tracking features. - * - Tracking Goal by manual trigger, and URL matching, with custom revenue - * - Tracking the same Goal twice only records it once - * - Tracks 4 page views: 3 clicks and a file download - * - URLs parameters exclude is tested - * - In a returning visit, tracks a Goal conversion - * URL matching, with custom referer and keyword - * - * NO cookie support - */ -class Test_Piwik_Integration_OneVisitorTwoVisits extends Test_Integration_Facade -{ - protected $idSite = null; - protected $dateTime = null; - - public function getApiToTest() - { - $enExtraParam = array('expanded' => 1, 'flat' => 1, 'include_aggregate_rows' => 0, 'translateColumnNames' => 1); - $bulkUrls = array( - "idSite={$this->idSite}&date=2010-03-06&format=json&expanded=1&period=day&method=VisitsSummary.get", - "idSite={$this->idSite}&date=2010-03-06&format=xml&expanded=1&period=day&method=VisitsSummary.get", - "idSite={$this->idSite}&date=2010-03-06&format=json&expanded=1&period=day&method=" - ."VisitorInterest.getNumberOfVisitsPerVisitDuration" - ); - return array( - array('all', array('idSite' => $this->idSite, 'date' => $this->dateTime)), - - // test API.get (for bug that incorrectly reorders columns of CSV output) - // note: bug only affects rows after first - array('API.get', array('idSite' => $this->idSite, 'date' => '2009-10-01', 'format' => 'csv', - 'periods' => array('month'), 'setDateLastN' => true, - 'otherRequestParameters' => $enExtraParam, 'language' => 'en', - 'testSuffix' => '_csv')), - - array('API.getBulkRequest', array('otherRequestParameters' => array('urls' => $bulkUrls))), - ); - } - - public function getControllerActionsToTest() - { - return array(); - } - - public function setUp() - { - parent::setUp(); - - // tests run in UTC, the Tracker in UTC - $this->dateTime = '2010-03-06 11:22:33'; - $this->idSite = $this->createWebsite($this->dateTime); - } - - protected function trackVisits() - { - $t = $this->getTracker($this->idSite, $this->dateTime, $defaultInit = true); - $this->trackVisitsImpl($t); - } - - protected function trackVisitsImpl($t) - { - $dateTime = $this->dateTime; - $idSite = $this->idSite; - - $t->disableCookieSupport(); - - $t->setUrlReferrer( 'http://referer.com/page.htm?param=valuewith some spaces'); - - // testing URL excluded parameters - $parameterToExclude = 'excluded_parameter'; - Piwik_SitesManager_API::getInstance()->updateSite($idSite, 'new name', $url=array('http://site.com'),$ecommerce = 0, $excludedIps = null, $parameterToExclude . ',anotherParameter'); - - // Record 1st page view - $urlPage1 = 'http://example.org/index.htm?excluded_Parameter=SHOULD_NOT_DISPLAY¶meter=Should display'; - $t->setUrl( $urlPage1 ); - $this->checkResponse($t->doTrackPageView( 'incredible title!')); - - // testing that / and index.htm above record with different URLs - // Recording the 2nd page after 3 minutes - $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.05)->getDatetime()); - $urlPage2 = 'http://example.org/' ; - $t->setUrl( $urlPage2 ); -// $t->setUrlReferrer($urlPage1); - $this->checkResponse($t->doTrackPageView( 'Second page view - should be registered as URL /')); - -// $t->setUrlReferrer($urlPage2); - // Click on external link after 6 minutes (3rd action) - $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.1)->getDatetime()); - $this->checkResponse($t->doTrackAction( 'http://dev.piwik.org/svn', 'link' )); - - // Click on file download after 12 minutes (4th action) - $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.2)->getDatetime()); - $this->checkResponse($t->doTrackAction( 'http://piwik.org/path/again/latest.zip', 'download' )); - - // Click on two more external links, one the same as before (5th & 6th actions) - $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.22)->getDateTime()); - $this->checkResponse($t->doTrackAction('http://outlinks.org/other_outlink', 'link')); - $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.25)->getDateTime()); - $this->checkResponse($t->doTrackAction('http://dev.piwik.org/svn', 'link')); - - // Create Goal 1: Triggered by JS, after 18 minutes - $idGoal = Piwik_Goals_API::getInstance()->addGoal($idSite, 'triggered js', 'manually', '', ''); - $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.3)->getDatetime()); - - // Change to Thai browser to ensure the conversion is credited to FR instead (the visitor initial country) - $t->setBrowserLanguage('th'); - $this->checkResponse($t->doTrackGoal($idGoal, $revenue = 42)); - - // Track same Goal twice (after 24 minutes), should only be tracked once - $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.4)->getDatetime()); - $this->checkResponse($t->doTrackGoal($idGoal, $revenue = 42)); - - $t->setBrowserLanguage('fr'); - // Final page view (after 27 min) - $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.45)->getDatetime()); - $t->setUrl( 'http://example.org/index.htm' ); - $this->checkResponse($t->doTrackPageView( 'Looking at homepage (again)...')); - - // - - // End of first visit: 24min - - // Create Goal 2: Matching on URL - Piwik_Goals_API::getInstance()->addGoal($idSite, 'matching purchase.htm', 'url', '(.*)store\/purchase\.(.*)', 'regex', false, $revenue = 1); - - // - - // Start of returning visit, 1 hour after first page view - $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(1)->getDatetime()); - $t->setUrl( 'http://example.org/store/purchase.htm' ); - $t->setUrlReferrer( 'http://search.yahoo.com/search?p=purchase'); - // Temporary, until we implement 1st party cookies in PiwikTracker - $t->DEBUG_APPEND_URL = '&_idvc=2'; - - // Goal Tracking URL matching, testing custom referer including keyword - $this->checkResponse($t->doTrackPageView( 'Checkout/Purchasing...')); - // - - // End of second visit - - } -} diff --git a/tests/integration/OneVisitorTwoVisits_withCookieSupport.test.php b/tests/integration/OneVisitorTwoVisits_withCookieSupport.test.php deleted file mode 100755 index 5271682aa0dbbc29fa8010678a16d932d7ddf833..0000000000000000000000000000000000000000 --- a/tests/integration/OneVisitorTwoVisits_withCookieSupport.test.php +++ /dev/null @@ -1,43 +0,0 @@ -<?php -if(!defined('PIWIK_CONFIG_TEST_INCLUDED')) -{ - require_once dirname(__FILE__)."/../../tests/config_test.php"; -} - -require_once PIWIK_INCLUDE_PATH . '/tests/integration/OneVisitorTwoVisits.test.php'; - -/** - * Same as OneVisitorTwoVisits.test.php, but with cookie support, which incurs some slight changes - * in the reporting data (more accurate unique visitor count, better referer tracking for goals, etc.) - */ -class Test_Piwik_Integration_OneVisitorTwoVisits_WithCookieSupport extends Test_Piwik_Integration_OneVisitorTwoVisits -{ - public function getApiToTest() - { - $apiToCall = array( - 'VisitTime', 'VisitsSummary', 'VisitorInterest', 'VisitFrequency', 'UserSettings', - 'UserCountry', 'Referers', 'Provider', 'Goals', 'CustomVariables', 'CoreAdminHome', - 'Actions', 'Live.getLastVisitsDetails'); - - return array( - array($apiToCall, array('idSite' => $this->idSite, 'date' => $this->dateTime)) - ); - } - - public function getControllerActionsToTest() - { - return array(); - } - - public function getOutputPrefix() - { - return 'OneVisitorTwoVisits_withCookieSupport'; - } - - protected function trackVisits() - { - $t = $this->getTracker($this->idSite, $this->dateTime, $defaultInit = true); - $t->DEBUG_APPEND_URL = '&forceUseThirdPartyCookie=1'; - $this->trackVisitsImpl($t); - } -} diff --git a/tests/integration/OneVisitor_LongUrlsTruncated.test.php b/tests/integration/OneVisitor_LongUrlsTruncated.test.php deleted file mode 100644 index 8b40546a14e80e8a5d0df8bb19cf9ba2f3020e78..0000000000000000000000000000000000000000 --- a/tests/integration/OneVisitor_LongUrlsTruncated.test.php +++ /dev/null @@ -1,112 +0,0 @@ -<?php -if(!defined('PIWIK_CONFIG_TEST_INCLUDED')) -{ - require_once dirname(__FILE__)."/../../tests/config_test.php"; -} - -require_once PIWIK_INCLUDE_PATH . '/tests/integration/Integration.php'; - -/** - * Tests that filter_truncate works recursively in Page URLs report AND in the case there are 2 different data Keywords -> search engine - */ -class Test_Piwik_Integration_OneVisitor_LongUrlsTruncated extends Test_Integration_Facade -{ - protected $dateTime = '2010-03-06 01:22:33'; - protected $idSite = null; - public function getApiToTest() - { - $apiToCall = array('Referers.getKeywords', 'Actions.getPageUrls'); - - return array( - array($apiToCall, array('idSite' => $this->idSite, 'date' => $this->dateTime, 'language' => 'fr', - 'otherRequestParameters' => array('expanded' => 1, 'filter_truncate' => 2))) - ); - } - - public function getControllerActionsToTest() - { - return array(); - } - - public function getOutputPrefix() - { - return 'OneVisitor_LongUrlsTruncated'; - } - - public function setUp() - { - parent::setUp(); - - $this->idSite = $this->createWebsite($this->dateTime); - } - - protected function trackVisits() - { - // tests run in UTC, the Tracker in UTC - $dateTime = $this->dateTime; - $idSite = $this->idSite; - - // Visit 1: keyword and few URLs - $t = $this->getTracker($idSite, $dateTime, $defaultInit = true); - $t->setUrlReferrer( 'http://bing.com/search?q=Hello world'); - - // Generate a few page views that will be truncated - $t->setUrl( 'http://example.org/category/Page1'); - $this->checkResponse($t->doTrackPageView( 'Hello')); - $t->setUrl( 'http://example.org/category/Page2'); - $this->checkResponse($t->doTrackPageView( 'Hello')); - $t->setUrl( 'http://example.org/category/Page3'); - $this->checkResponse($t->doTrackPageView( 'Hello')); - $t->setUrl( 'http://example.org/category/Page3'); - $this->checkResponse($t->doTrackPageView( 'Hello')); - $t->setUrl( 'http://example.org/category/Page4'); - $this->checkResponse($t->doTrackPageView( 'Hello')); - $t->setUrl( 'http://example.org/category/Page4'); - $this->checkResponse($t->doTrackPageView( 'Hello')); - $t->setUrl( 'http://example.org/category/Page4'); - $this->checkResponse($t->doTrackPageView( 'Hello')); - $t->setUrl( 'http://example.org/category.htm'); - $this->checkResponse($t->doTrackPageView( 'Hello')); - $t->setUrl( 'http://example.org/page.htm'); - $this->checkResponse($t->doTrackPageView( 'Hello')); - $t->setUrl( 'http://example.org/index.htm'); - $this->checkResponse($t->doTrackPageView( 'Hello')); - $t->setUrl( 'http://example.org/page.htm'); - $this->checkResponse($t->doTrackPageView( 'Hello')); - $t->setUrl( 'http://example.org/page.htm'); - $this->checkResponse($t->doTrackPageView( 'Hello')); - $t->setUrl( 'http://example.org/contact.htm'); - $this->checkResponse($t->doTrackPageView( 'Hello')); - - // VISIT 2 = Another keyword - $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(1)->getDatetime()); - $t->setUrlReferrer( 'http://www.google.com.vn/url?q=Salut'); - $this->checkResponse($t->doTrackPageView( 'incredible title!')); - - // Visit 3 = Another keyword - $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(2)->getDatetime()); - $t->setUrlReferrer( 'http://www.google.com.vn/url?q=Kia Ora'); - $this->checkResponse($t->doTrackPageView( 'incredible title!')); - - // Visit 4 = Kia Ora again - $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(3)->getDatetime()); - $t->setUrlReferrer( 'http://www.google.com.vn/url?q=Kia Ora'); - $this->checkResponse($t->doTrackPageView( 'incredible title!')); - - // Visit 5 = Another search engine - $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(4)->getDatetime()); - $t->setUrlReferrer( 'http://nz.search.yahoo.com/search?p=Kia Ora'); - $this->checkResponse($t->doTrackPageView( 'incredible title!')); - - // Visit 6 = Another search engine - $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(5)->getDatetime()); - $t->setUrlReferrer( 'http://images.search.yahoo.com/search/images;_ylt=A2KcWcNKJzF?p=Kia%20Ora%20'); - $this->checkResponse($t->doTrackPageView( 'incredible title!')); - - // Visit 7 = Another search engine - $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(6)->getDatetime()); - $t->setUrlReferrer( 'http://nz.bing.com/images/search?q=+++Kia+ora+++'); - $this->checkResponse($t->doTrackPageView( 'incredible title!')); - } -} - diff --git a/tests/integration/OneVisitor_NoKeywordSpecified.test.php b/tests/integration/OneVisitor_NoKeywordSpecified.test.php deleted file mode 100755 index f5daa8cda88c0c27a31d71a45e603f7a6de2702e..0000000000000000000000000000000000000000 --- a/tests/integration/OneVisitor_NoKeywordSpecified.test.php +++ /dev/null @@ -1,76 +0,0 @@ -<?php -if(!defined('PIWIK_CONFIG_TEST_INCLUDED')) -{ - require_once dirname(__FILE__)."/../../tests/config_test.php"; -} - -require_once PIWIK_INCLUDE_PATH . '/tests/integration/Integration.php'; - -/** - * 1) Tests empty google kwd works nicely in Live! output and Top keywords - * 2) Tests IP anonymization - * - * Also test that Live! will link to the search result page URL rather than the exact referrer URL - * when the referrer URL is google.XX/url.... which is a redirect to landing page rather than the search result URL - */ -class Test_Piwik_Integration_OneVisitor_NoKeywordSpecified extends Test_Integration_Facade -{ - protected $dateTime = '2010-03-06 11:22:33'; - protected $idSite = null; - - public function getApiToTest() - { - $apiToCall = array('Referers.getKeywords', 'Live.getLastVisitsDetails'); - - return array( - array($apiToCall, array('idSite' => $this->idSite, 'date' => $this->dateTime, 'language' => 'fr')) - ); - } - - public function getControllerActionsToTest() - { - return array(); - } - - public function getOutputPrefix() - { - return 'OneVisitor_NoKeywordSpecified'; - } - - public function setUp() - { - parent::setUp(); - - $this->idSite = $this->createWebsite($this->dateTime); - } - - protected function trackVisits() - { - // tests run in UTC, the Tracker in UTC - $dateTime = $this->dateTime; - $idSite = $this->idSite; - $t = $this->getTracker($idSite, $dateTime, $defaultInit = true, $useThirdPartyCookie = 1); - - // Also testing to record this as a bot while specifically allowing bots - $t->setUserAgent('Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'); - $t->DEBUG_APPEND_URL .= '&bots=1'; - $t->DEBUG_APPEND_URL .= '&forceIpAnonymization=1'; - // VISIT 1 = Referrer is "Keyword not defined" - // Alsotrigger goal to check that attribution goes to this keyword - $t->setUrlReferrer( 'http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CC&url=http%3A%2F%2Fpiwik.org%2F&ei=&usg='); - $t->setUrl( 'http://example.org/this%20is%20cool!'); - $this->checkResponse($t->doTrackPageView( 'incredible title!')); - $idGoal = Piwik_Goals_API::getInstance()->addGoal($idSite, 'triggered js', 'manually', '', ''); - $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.3)->getDatetime()); - $this->checkResponse($t->doTrackGoal($idGoal, $revenue = 42)); - - // VISIT 2 = Referrer has keyword, but the URL should be rewritten - // in Live Output to point to google search result page - $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(2)->getDatetime()); - $t->setUrlReferrer( 'http://www.google.com.vn/url?sa=t&rct=j&q=%3C%3E%26%5C%22the%20pdo%20extension%20is%20required%20for%20this%20adapter%20but%20the%20extension%20is%20not%20loaded&source=web&cd=4&ved=0FjAD&url=http%3A%2F%2Fforum.piwik.org%2Fread.php%3F2%2C1011&ei=y-HHAQ&usg=AFQjCN2-nt5_GgDeg&cad=rja'); - - $this->checkResponse($t->doTrackPageView( 'incredible title!')); - - } -} - diff --git a/tests/integration/PeriodIsRange_DateIsLastN_MetadataAndNormalAPI.test.php b/tests/integration/PeriodIsRange_DateIsLastN_MetadataAndNormalAPI.test.php deleted file mode 100755 index c68c20d76e17e926b6564a466ae226a095d2d39a..0000000000000000000000000000000000000000 --- a/tests/integration/PeriodIsRange_DateIsLastN_MetadataAndNormalAPI.test.php +++ /dev/null @@ -1,93 +0,0 @@ -<?php -if(!defined('PIWIK_CONFIG_TEST_INCLUDED')) -{ - require_once dirname(__FILE__)."/../../tests/config_test.php"; -} - -require_once PIWIK_INCLUDE_PATH . '/tests/integration/TwoVisitsWithCustomVariables.test.php'; - -/** - * test Metadata API + period=range&date=lastN - */ -class Test_Piwik_Integration_PeriodIsRange_DateIsLastN_MetadataAndNormalAPI extends Test_Piwik_Integration_TwoVisitsWithCustomVariables -{ - public function __construct($title = '') - { - parent::__construct($title); - $this->doExtraQuoteTests = false; - } - - public function getApiToTest() - { - $apiToCall = array( 'API.getProcessedReport', - 'Actions.getPageUrls', - 'Goals.get', - 'CustomVariables.getCustomVariables', - 'Referers.getCampaigns', - 'Referers.getKeywords', - 'VisitsSummary.get', - 'Live'); - - $segments = array( - false, - 'daysSinceFirstVisit!=50', - 'visitorId!=33c31e01394bdc63', - // testing both filter on Actions table and visit table - 'visitorId!=33c31e01394bdc63;daysSinceFirstVisit!=50', - //'pageUrl!=http://unknown/not/viewed', - ); - $dates = array( - 'last7', - Piwik_Date::factory('now')->subDay(6)->toString() . ',today', - Piwik_Date::factory('now')->subDay(6)->toString() . ',now', - ); - - $result = array(); - foreach($segments as $segment) - { - foreach($dates as $date) - { - $result[] = array($apiToCall, array('idSite' => $this->idSite, 'date' => $date, - 'periods' => array('range'), 'segment' => $segment, - // testing getLastVisitsForVisitor requires a visitor ID - 'visitorId' => $this->visitorId)); - } - } - - return $result; - } - - public function getAnotherApiToTest() - { - return array(); - } - - public function getControllerActionsToTest() - { - return array(); - } - - public function getOutputPrefix() - { - return 'periodIsRange_dateIsLastN_MetadataAndNormalAPI'; - } - - public function setUp() - { - $this->dateTime = Piwik_Date::factory('now')->getDateTime(); - - parent::setUp(); - } - - public function test_RunAllTests() - { - if(date('G') == 23 || date('G') == 22) { - echo "SKIPPED test_periodIsRange_dateIsLastN_MetadataAndNormalAPI() since it fails around midnight..."; - $this->pass(); - return; - } - - parent::test_RunAllTests(); - } -} - diff --git a/tests/integration/RowEvolution.test.php b/tests/integration/RowEvolution.test.php deleted file mode 100644 index 9439af41fc856b2de9c65389d56a1df5b441d5ec..0000000000000000000000000000000000000000 --- a/tests/integration/RowEvolution.test.php +++ /dev/null @@ -1,135 +0,0 @@ -<?php -if(!defined('PIWIK_CONFIG_TEST_INCLUDED')) -{ - require_once dirname(__FILE__)."/../../tests/config_test.php"; -} - -require_once PIWIK_INCLUDE_PATH . '/tests/integration/Integration.php'; - -/** - * Tests the method API.getRowEvolution - */ -class Test_Piwik_Integration_RowEvolution extends Test_Integration_Facade -{ - protected $today = '2010-03-06 11:22:33'; - protected $idSite = null; - - public function getApiToTest() - { - $return = array(); - - $config = array( - 'testSuffix' => '_referrer1', - 'idSite' => $this->idSite, - 'date' => $this->today, - 'otherRequestParameters' => array( - 'date' => '2010-02-06,2010-03-06', - 'period' => 'day', - 'apiModule' => 'Referers', - 'apiAction' => 'getWebsites', - 'label' => 'www.referrer2.com', - 'expanded' => 0 - ) - ); - - $return[] = array('API.getRowEvolution', $config); - - // Websites, hierarchical - $config['testSuffix'] = '_referrer2'; - $referrerLabel = urlencode('www.referrer0.com').'>'.urlencode('theReferrerPage1.html'); - $config['otherRequestParameters']['label'] = $referrerLabel; - $return[] = array('API.getRowEvolution', $config); - - // Websites, multiple labels including one hierarchical - $config['testSuffix'] = '_referrerMulti1'; - $referrerLabel = urlencode($referrerLabel).','.urlencode('www.referrer2.com'); - $config['otherRequestParameters']['label'] = $referrerLabel; - $return[] = array('API.getRowEvolution', $config); - - // Keywords, label containing > and , - $config['otherRequestParameters']['apiAction'] = 'getKeywords'; - $config['testSuffix'] = '_LabelReservedCharacters'; - $keywords = urlencode($this->keywords[0]).','.urlencode($this->keywords[1]); - $config['otherRequestParameters']['label'] = $keywords; - $return[] = array('API.getRowEvolution', $config); - - // Keywords, hierarchical - $config['otherRequestParameters']['apiAction'] = 'getSearchEngines'; - $config['testSuffix'] = '_LabelReservedCharactersHierarchical'; - $keywords = "Google>".urlencode(strtolower($this->keywords[0])) - .',Google>'.urlencode(strtolower($this->keywords[1])) - .',Google>'.urlencode(strtolower($this->keywords[2])); - // Test multiple labels search engines, Google should also have a 'logo' entry - $config['otherRequestParameters']['label'] = $keywords . ",Google"; - $return[] = array('API.getRowEvolution', $config); - - // Actions > Pages titles, standard label - $config['testSuffix'] = '_pageTitles'; - $config['periods'] = array('day', 'week'); - $config['otherRequestParameters']['apiModule'] = 'Actions'; - $config['otherRequestParameters']['apiAction'] = 'getPageTitles'; - $config['otherRequestParameters']['label'] = 'incredible title 0'; - $return[] = array('API.getRowEvolution', $config); - - // Actions > Page titles, multiple labels - $config['testSuffix'] = '_pageTitlesMulti'; - $label = urlencode('incredible title 0').','.urlencode('incredible title 2'); - $config['otherRequestParameters']['label'] = $label; - $return[] = array('API.getRowEvolution', $config); - - // Actions > Page URLS, hierarchical label - $config['testSuffix'] = '_pageUrls'; - $config['periods'] = array('range'); - $config['otherRequestParameters']['date'] = '2010-03-01,2010-03-06'; - $config['otherRequestParameters']['apiModule'] = 'Actions'; - $config['otherRequestParameters']['apiAction'] = 'getPageUrls'; - $config['otherRequestParameters']['label'] = 'my>dir>'.urlencode('/page3?foo=bar&baz=bar'); - $return[] = array('API.getRowEvolution', $config); - - return $return; - } - - public function getControllerActionsToTest() - { - return array(); - } - - public function getOutputPrefix() - { - return 'RowEvolution'; - } - - public function setUp() - { - parent::setUp(); - $this->idSite = $this->createWebsite('2010-02-01 11:22:33'); - } - - protected function trackVisits() - { - $dateTime = $this->today; - $idSite = $this->idSite; - - $this->keywords = array( - 'free > proprietary', // BUG! testing a keyword containing > - 'peace "," not war', // testing a keyword containing , - 'justice )(&^#%$ NOT corruption!', - ); - 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->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))); - - // VISIT 2: search engine - $t->setForceVisitDateTime(Piwik_Date::factory($visitDateTime)->addHour(3)->getDatetime()); - $t->setUrlReferrer('http://google.com/search?q='.urlencode($this->keywords[$daysIntoPast%3])); - $this->checkResponse($t->doTrackPageView('not an incredible title ')); - } - } -} - diff --git a/tests/integration/TrackCustomVariablesAndCampaigns_ForceUsingVisitIdNotHeuristics.test.php b/tests/integration/TrackCustomVariablesAndCampaigns_ForceUsingVisitIdNotHeuristics.test.php deleted file mode 100755 index 8d9fe5be9f200f89b553c872cb27811e2bfb0439..0000000000000000000000000000000000000000 --- a/tests/integration/TrackCustomVariablesAndCampaigns_ForceUsingVisitIdNotHeuristics.test.php +++ /dev/null @@ -1,103 +0,0 @@ -<?php -if(!defined('PIWIK_CONFIG_TEST_INCLUDED')) -{ - require_once dirname(__FILE__)."/../../tests/config_test.php"; -} - -require_once PIWIK_INCLUDE_PATH . '/tests/integration/Integration.php'; - -/** - * Test tracker & API when forcing the use of visit ID instead of heuristics. Also - * tests campaign tracking. - */ -class Test_Piwik_Integration_TrackCustomVariablesAndCampaigns_ForceUsingVisitIdNotHeuristics extends Test_Integration_Facade -{ - protected $dateTime = '2009-01-04 00:11:42'; - protected $idSite = null; - protected $idGoal = null; - - public function getApiToTest() - { - $apiToCall = array('VisitsSummary.get', 'Referers.getCampaigns', 'Referers.getWebsites'); - - return array( - // TOTAL should be: 1 visit, 1 converted goal, 1 page view - array($apiToCall, array('idSite' => $this->idSite, 'date' => $this->dateTime)) - ); - } - - public function getControllerActionsToTest() - { - return array(); - } - - public function getOutputPrefix() - { - return 'PiwikTracker_trackForceUsingVisitId_insteadOfHeuristics_alsoTestsCampaignTracking'; - } - - public function setUp() - { - parent::setUp(); - - $this->idSite = $this->createWebsite($this->dateTime); - $this->idGoal = Piwik_Goals_API::getInstance()->addGoal($this->idSite, 'triggered js', 'manually', '', ''); - } - - protected function trackVisits() - { - $dateTime = $this->dateTime; - $idSite = $this->idSite; - $idGoal = $this->idGoal; - - $t = $this->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!')); - - $visitorId = $t->getVisitorId(); - $this->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); - 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); - - // Make sure the ID is different at first - $visitorId2 = $t2->getVisitorId(); - $this->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)); - - // Yet another visitor, this time with a manual goal conversion, which should be credited to the campaign - $t3 = $this->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)); - } -} - diff --git a/tests/integration/TrackGoals_AllowMultipleConversionsPerVisit.test.php b/tests/integration/TrackGoals_AllowMultipleConversionsPerVisit.test.php deleted file mode 100755 index ae4cefaaa7c9e1a1eae41a6193e16b2ca228d66b..0000000000000000000000000000000000000000 --- a/tests/integration/TrackGoals_AllowMultipleConversionsPerVisit.test.php +++ /dev/null @@ -1,101 +0,0 @@ -<?php -if(!defined('PIWIK_CONFIG_TEST_INCLUDED')) -{ - require_once dirname(__FILE__)."/../../tests/config_test.php"; -} - -require_once PIWIK_INCLUDE_PATH . '/tests/integration/Integration.php'; - -/** - * Tests API methods with goals that do and don't allow multiple - * conversions per visit. - */ -class Test_Piwik_Integration_TrackGoals_AllowMultipleConversionsPerVisit extends Test_Integration_Facade -{ - protected $dateTime = null; - protected $idSite = null; - protected $idGoal_OneConversionPerVisit = null; - protected $idGoal_MultipleConversionPerVisit = null; - - public function getApiToTest() - { - $apiToCall = array('VisitTime.getVisitInformationPerServerTime', 'VisitsSummary.get'); - - return array( - array($apiToCall, array('idSite' => $this->idSite, 'date' => $this->dateTime)) - ); - } - - public function getControllerActionsToTest() - { - return array(); - } - - public function getOutputPrefix() - { - return 'trackGoals_allowMultipleConversionsPerVisit'; - } - - public function setUp() - { - parent::setUp(); - - $this->dateTime = '2009-01-04 00:11:42'; - $this->idSite = $this->createWebsite($this->dateTime); - - // First, a goal that is only recorded once per visit - $this->idGoal_OneConversionPerVisit = Piwik_Goals_API::getInstance()->addGoal($this->idSite, 'triggered js ONCE', 'title', 'Thank you', 'contains', $caseSensitive=false, $revenue=10, $allowMultipleConversions = false); - - // Second, a goal allowing multiple conversions - $this->idGoal_MultipleConversionPerVisit = Piwik_Goals_API::getInstance()->addGoal($this->idSite, 'triggered js MULTIPLE ALLOWED', 'manually', '', '', $caseSensitive=false, $revenue=10, $allowMultipleConversions = true); - } - - public function test_RunAllTests() - { - $idSite = $this->idSite; - - parent::test_RunAllTests(); - - // test delete is working as expected - $goals = Piwik_Goals_API::getInstance()->getGoals($idSite); - $this->assertTrue( 2 == count($goals) ); - Piwik_Goals_API::getInstance()->deleteGoal($idSite, $this->idGoal_OneConversionPerVisit); - Piwik_Goals_API::getInstance()->deleteGoal($idSite, $this->idGoal_MultipleConversionPerVisit); - $goals = Piwik_Goals_API::getInstance()->getGoals($idSite); - $this->assertTrue( empty($goals) ); - } - - protected function trackVisits() - { - $dateTime = $this->dateTime; - $idSite = $this->idSite; - $idGoal_OneConversionPerVisit = $this->idGoal_OneConversionPerVisit; - $idGoal_MultipleConversionPerVisit = $this->idGoal_MultipleConversionPerVisit; - - $t = $this->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')); - $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.4)->getDatetime()); - $this->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)); - $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.6)->getDatetime()); - $this->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); - 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); - - // 1st goal should Now be tracked - $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.61)->getDatetime()); - $this->checkResponse($t->doTrackGoal($idGoal_OneConversionPerVisit, $revenue = 656)); - } -} diff --git a/tests/integration/TwoVisitors_TwoWebsites_DifferentDays.test.php b/tests/integration/TwoVisitors_TwoWebsites_DifferentDays.test.php deleted file mode 100755 index 1fde27e36cffe6175cdaea67d1531a47b63d8273..0000000000000000000000000000000000000000 --- a/tests/integration/TwoVisitors_TwoWebsites_DifferentDays.test.php +++ /dev/null @@ -1,188 +0,0 @@ -<?php -if(!defined('PIWIK_CONFIG_TEST_INCLUDED')) -{ - require_once dirname(__FILE__)."/../../tests/config_test.php"; -} - -require_once PIWIK_INCLUDE_PATH . '/tests/integration/Integration.php'; - -/** - * tests Tracker several websites, different days. - * tests API for period=day/week/month/year, requesting data for both websites, - * and requesting data for last N periods. - * Also tests a visit that spans over 2 days. - * And testing empty URL and empty Page name request - * Also testing a click on a mailto counted as outlink - * Also testing metadata API for multiple periods - */ -class Test_Piwik_Integration_TwoVisitors_TwoWebsites_DifferentDays extends Test_Integration_Facade -{ - protected $idSite1 = null; - protected $idSite2 = null; - protected $idGoal1 = null; - protected $idGoal2 = null; - protected $dateTime = null; - protected $allowConversions = false; - - protected function getApiToCall() - { - return array('VisitFrequency.get', - 'VisitsSummary.get', - 'Referers.getWebsites', - 'Actions.getPageUrls', - 'Actions.getPageTitles', - 'Actions.getOutlinks', - 'Actions.getPageTitle', - 'Actions.getPageUrl', - 'VisitorInterest.getNumberOfVisitsByDaysSinceLast'); - } - - public function getApiToTest() - { - $apiToCall = $this->getApiToCall(); - $singlePeriodApi = array('VisitsSummary.get', 'Goals.get'); - - $periods = array('day', 'week', 'month', 'year'); - - $result = array( - // Request data for the last 6 periods and idSite=all - array($apiToCall, array('idSite' => 'all', 'date' => $this->dateTime, 'periods' => $periods, - 'setDateLastN' => true)), - - // Request data for the last 6 periods and idSite=1 - array($apiToCall, array('idSite' => $this->idSite1, 'date' => $this->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' => $this->dateTime, 'periods' => array('day', 'month'), - 'setDateLastN' => false, 'testSuffix' => '_NotLastNPeriods')), - ); - - // testing metadata API for multiple periods - $apiToCall = array_diff($apiToCall, array('Actions.getPageTitle', 'Actions.getPageUrl')); - foreach($apiToCall as $api) - { - list($apiModule, $apiAction) = explode(".", $api); - - $result[] = array( - 'API.getProcessedReport', array('idSite' => $this->idSite1, 'date' => $this->dateTime, - 'periods' => array('day'), 'setDateLastN' => true, - 'apiModule' => $apiModule, 'apiAction' => $apiAction, - 'testSuffix' => '_'.$api.'_firstSite_lastN') - ); - } - - return $result; - } - - public function getControllerActionsToTest() - { - return array(); - } - - public function getOutputPrefix() - { - return 'TwoVisitors_twoWebsites_differentDays'; - } - - public function setUp() - { - parent::setUp(); - - // tests run in UTC, the Tracker in UTC - $this->dateTime = '2010-01-03 11:22:33'; - $ecommerce = $this->allowConversions ? 1 : 0; - - $this->idSite1 = $this->createWebsite($this->dateTime, $ecommerce, "Site 1"); - $this->idSite2 = $this->createWebsite($this->dateTime, 0, "Site 2"); - } - - protected function trackVisits() - { - $dateTime = $this->dateTime; - $idSite = $this->idSite1; - $idSite2 = $this->idSite2; - - if ($this->allowConversions) - { - $this->idGoal1 = Piwik_Goals_API::getInstance()->addGoal($idSite, 'all', 'url', 'http', 'contains', false, 5); - $this->idGoal2 = Piwik_Goals_API::getInstance()->addGoal($idSite2, 'all', 'url', 'http', 'contains'); - } - - // - - // First visitor on Idsite 1: two page views - $datetimeSpanOverTwoDays = '2010-01-03 23:55:00'; - $visitorA = $this->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')); - - $visitorA->setForceVisitDateTime(Piwik_Date::factory($datetimeSpanOverTwoDays)->addHour(0.1)->getDatetime()); - // testing with empty URL and empty page title - $visitorA->setUrl(' '); - $this->checkResponse($visitorA->doTrackPageView(' ')); - - // - - // Second new visitor on Idsite 1: one page view - $visitorB = $this->getTracker($idSite, $dateTime, $defaultInit = true); - $visitorB->enableBulkTracking(); - // calc token auth by hand in test environment - $tokenAuth = md5( - Piwik_Config::getInstance()->superuser['login'].Piwik_Config::getInstance()->superuser['password']); - $visitorB->setTokenAuth($tokenAuth); - $visitorB->setIp('100.52.156.83'); - $visitorB->setResolution(800, 300); - $visitorB->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(1)->getDatetime()); - $visitorB->setUrlReferrer( '' ); - $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')); - - // - - // Second visitor again on Idsite 1: 2 page views 2 days later, 2010-01-05 - $visitorB->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(48)->getDatetime()); - // visitor_returning is set to 1 only when visit count more than 1 - // Temporary, until we implement 1st party cookies in PiwikTracker - $visitorB->DEBUG_APPEND_URL .= '&_idvc=2&_viewts='.Piwik_Date::factory($dateTime)->getTimestamp(); - - $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')); - // 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')); - - // 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')); - $visitorB->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(48)->addHour(0.25)->getDatetime()); - $this->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()); - - // - - // 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->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')); - // test with invalid URL - $visitorAsite2->setUrl('this is invalid url'); - // and an empty title - $this->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...')); - } -} diff --git a/tests/integration/TwoVisitors_TwoWebsites_DifferentDays_ArchivingDisabled.test.php b/tests/integration/TwoVisitors_TwoWebsites_DifferentDays_ArchivingDisabled.test.php deleted file mode 100755 index 58cc10c59cd8e65d2065e6fcecb05eaffb779a2b..0000000000000000000000000000000000000000 --- a/tests/integration/TwoVisitors_TwoWebsites_DifferentDays_ArchivingDisabled.test.php +++ /dev/null @@ -1,48 +0,0 @@ -<?php -if(!defined('PIWIK_CONFIG_TEST_INCLUDED')) -{ - require_once dirname(__FILE__)."/../../tests/config_test.php"; -} - -require_once PIWIK_INCLUDE_PATH . '/tests/integration/TwoVisitors_TwoWebsites_DifferentDays.test.php'; - -/** - * TODO - */ -class Test_Piwik_Integration_TwoVisitors_TwoWebsites_DifferentDays_ArchivingDisabled extends Test_Piwik_Integration_TwoVisitors_TwoWebsites_DifferentDays -{ - public function __construct($title = '') - { - parent::__construct($title); - $this->allowConversions = true; - } - - public function getApiToTest() - { - $periods = array('day', 'week', 'month', 'year'); - - return array( - // disable archiving & check that there is no archive data - array('VisitsSummary.get', array('idSite' => 'all', 'date' => $this->dateTime, 'periods' => $periods, - 'disableArchiving' => true, 'testSuffix' => '_disabledBefore')), - - // re-enable archiving & check the output - array('VisitsSummary.get', array('idSite' => 'all', 'date' => $this->dateTime, 'periods' => $periods, - 'disableArchiving' => false, 'testSuffix' => '_enabled')), - - // diable archiving again & check the output - array('VisitsSummary.get', array('idSite' => 'all', 'date' => $this->dateTime, 'periods' => $periods, - 'disableArchiving' => true, 'testSuffix' => '_disabledAfter')), - ); - } - - public function getControllerActionsToTest() - { - return array(); - } - - public function getOutputPrefix() - { - return 'TwoVisitors_twoWebsites_differentDays_ArchivingDisabled'; - } -} diff --git a/tests/integration/TwoVisitors_TwoWebsites_DifferentDays_Conversions.test.php b/tests/integration/TwoVisitors_TwoWebsites_DifferentDays_Conversions.test.php deleted file mode 100755 index f59803e05535fb22658fac1658ee70f721c43d12..0000000000000000000000000000000000000000 --- a/tests/integration/TwoVisitors_TwoWebsites_DifferentDays_Conversions.test.php +++ /dev/null @@ -1,59 +0,0 @@ -<?php -if(!defined('PIWIK_CONFIG_TEST_INCLUDED')) -{ - require_once dirname(__FILE__)."/../../tests/config_test.php"; -} - -require_once PIWIK_INCLUDE_PATH . '/tests/integration/TwoVisitors_TwoWebsites_DifferentDays.test.php'; - -/** - * Same as TwoVisitors_twoWebsites_differentDays but with goals that convert - * on every url. - */ -class Test_Piwik_Integration_TwoVisitors_TwoWebsites_DifferentDays_Conversions extends Test_Piwik_Integration_TwoVisitors_TwoWebsites_DifferentDays -{ - public function __construct($title = '') - { - parent::__construct($title); - $this->allowConversions = true; - } - - protected function getApiToCall() - { - return array('Goals.getDaysToConversion', 'MultiSites.getAll'); - } - - public function getApiToTest() - { - $result = parent::getApiToTest(); - - // Tests that getting a visits summary metric (nb_visits) & a Goal's metric (Goal_revenue) - // at the same time works. - $dateTime = '2010-01-03,2010-01-06'; - $columns = 'nb_visits,'.Piwik_Goals::getRecordName('conversion_rate'); - - $result[] = array( - 'VisitsSummary.get', array('idSite' => 'all', 'date' => $dateTime, 'periods' => 'range', - 'otherRequestParameters' => array('columns' => $columns), - 'testSuffix' => '_getMetricsFromDifferentReports') - ); - - return $result; - } - - public function getControllerActionsToTest() - { - return array( - // test MultiSites.index using default testing level - array('MultiSites.index', array('date' => $this->dateTime, 'period' => 'month', 'idSite' => $this->idSite1)), - - // test all widgets using default testing level - array('all', array('date' => $this->dateTime, 'period' => 'day', 'idSite' => $this->idSite1)), - ); - } - - public function getOutputPrefix() - { - return 'TwoVisitors_twoWebsites_differentDays_Conversions'; - } -} diff --git a/tests/integration/TwoVisitsWithCustomVariables.test.php b/tests/integration/TwoVisitsWithCustomVariables.test.php deleted file mode 100755 index da4c42f4ee78558152198ce123e755212664e0c0..0000000000000000000000000000000000000000 --- a/tests/integration/TwoVisitsWithCustomVariables.test.php +++ /dev/null @@ -1,172 +0,0 @@ -<?php -if(!defined('PIWIK_CONFIG_TEST_INCLUDED')) -{ - require_once dirname(__FILE__)."/../../tests/config_test.php"; -} - -require_once PIWIK_INCLUDE_PATH . '/tests/integration/Integration.php'; - -/** - * Tests w/ two visits & custom variables. - */ -class Test_Piwik_Integration_TwoVisitsWithCustomVariables extends Test_Integration_Facade -{ - protected $dateTime = '2010-01-03 11:22:33'; - protected $width = 1111; - protected $height = 222; - - protected $idSite = null; - protected $idGoal1 = null; - protected $idGoal2 = null; - protected $visitorId = null; - - protected $useEscapedQuotes = true; - protected $doExtraQuoteTests = true; - - public function getApiToTest() - { - $apiToCall = array('VisitsSummary.get', 'CustomVariables.getCustomVariables'); - - $return = array( - array($apiToCall, array('idSite' => 'all', 'date' => $this->dateTime, 'periods' => array('day', 'week'), - 'setDateLastN' => true)), - ); - - return $return; - } - - public function getAnotherApiToTest() - { - $table = Piwik_CustomVariables_API::getInstance()->getCustomVariables($this->idSite, 'day', '2010-01-03'); - $idsubtable = reset($table->getRows())->getIdSubDataTable(); - - // test getProcessedReport w/ custom variables - return array( - array('API.getProcessedReport', array('idSite' => $this->idSite, 'date' => $this->dateTime, - 'periods' => 'day', 'apiModule' => 'CustomVariables', - 'apiAction' => 'getCustomVariablesValuesFromNameId', - 'testSuffix' => '__subtable', - 'otherRequestParameters' => array('idSubtable' => $idsubtable) )), - ); - } - - public function getControllerActionsToTest() - { - return array(); - } - - public function getOutputPrefix() - { - return 'twoVisitsWithCustomVariables'; - } - - public function setUp() - { - parent::setUp(); - - // tests run in UTC, the Tracker in UTC - $this->idSite = $this->createWebsite($this->dateTime); - $this->idGoal1 = Piwik_Goals_API::getInstance()->addGoal($this->idSite, 'triggered js', 'manually', '', ''); - $this->idGoal2 = Piwik_Goals_API::getInstance()->addGoal($this->idSite, 'second goal', 'manually', '', ''); - } - - protected function trackVisits() - { - $dateTime = $this->dateTime; - $idSite = $this->idSite; - $idGoal = $this->idGoal1; - $idGoal2 = $this->idGoal2; - - ob_start(); - $visitorA = $this->getTracker($idSite, $dateTime, $defaultInit = true); - // Used to test actual referer + keyword position in Live! - $visitorA->setUrlReferrer(urldecode('http://www.google.com/url?sa=t&source=web&cd=1&ved=0CB4QFjAA&url=http%3A%2F%2Fpiwik.org%2F&rct=j&q=this%20keyword%20should%20be%20ranked&ei=V8WfTePkKKLfiALrpZWGAw&usg=AFQjCNF_MGJRqKPvaKuUokHtZ3VvNG9ALw&sig2=BvKAdCtNixsmfNWXjsNyMw')); - - // no campaign, but a search engine to attribute the goal conversion to - $attribution = array( - '', - '', - 1302306504, - 'http://www.google.com/search?q=piwik&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-GB:official&client=firefox-a' - ); - $visitorA->setAttributionInfo(json_encode($attribution)); - - $visitorA->setResolution($this->width, $this->height); - - // At first, visitor custom var is set to LoggedOut - $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)); - - // After login, set to LoggedIn, should overwrite previous value - $visitorA->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.2)->getDatetime()); - $visitorA->setUrl('http://example.org/user/profile'); - $visitorA->setCustomVariable($id = 1, $name = 'VisitorType', $value = 'LoggedIn'); - $visitorA->setCustomVariable($id = 4, $name = 'Status user', $value = 'Loggedin', $scope = 'page'); - if ($this->useEscapedQuotes) - { - $lookingAtProfile = 'looking at "profile page"'; - } - else - { - $lookingAtProfile = 'looking at profile page'; - } - $visitorA->setCustomVariable($id = 5, $name = 'Status user', $value = $lookingAtProfile, $scope = 'page'); - $this->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)); - - if ($this->doExtraQuoteTests) - { - $visitorA->setCustomVariable($id = 2, $name = 'var1', $value = 'looking at "profile page"', - $scope = 'page'); - $visitorA->setCustomVariable($id = 3, $name = 'var2', $value = '\'looking at "\profile page"\'', - $scope = 'page'); - $visitorA->setCustomVariable($id = 4, $name = 'var3', $value = '\\looking at "\profile page"\\', - $scope = 'page'); - $this->checkResponse($visitorA->doTrackPageView('Concurrent page views')); - } - - // - - // Second new visitor on Idsite 1: one page view - $visitorB = $this->getTracker($idSite, $dateTime, $defaultInit = true); - $visitorB->setUrlReferrer(''); - - $attribution = array( - ' CAMPAIGN NAME -%20YEAH! ', - ' CAMPAIGN%20KEYWORD - RIGHT... ', - 1302306504, - 'http://www.example.org/test/really?q=yes' - ); - $visitorB->setAttributionInfo(json_encode($attribution)); - $visitorB->setResolution($this->width, $this->height); - $visitorB->setUserAgent('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6'); - $visitorB->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(1)->getDatetime()); - $visitorB->setCustomVariable($id = 1, $name = 'VisitorType', $value = 'LoggedOut'); - $visitorB->setCustomVariable($id = 2, $name = 'Othercustom value which should be truncated abcdefghijklmnopqrstuvwxyz', $value = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz'); - $visitorB->setCustomVariable($id = -2, $name = 'not tracked', $value = 'not tracked'); - $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)); - - $visitorB->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(1.1)->getDatetime()); - $this->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')); - - // hack - $this->visitorId = $visitorB->getVisitorId(); - } -} diff --git a/tests/integration/TwoVisitsWithCustomVariables_SegmentContains.test.php b/tests/integration/TwoVisitsWithCustomVariables_SegmentContains.test.php deleted file mode 100644 index 1825a63464617507e8393d3c806724d8b33c2f2b..0000000000000000000000000000000000000000 --- a/tests/integration/TwoVisitsWithCustomVariables_SegmentContains.test.php +++ /dev/null @@ -1,58 +0,0 @@ -<?php -if(!defined('PIWIK_CONFIG_TEST_INCLUDED')) -{ - require_once dirname(__FILE__)."/../../tests/config_test.php"; -} - -require_once PIWIK_INCLUDE_PATH . '/tests/integration/TwoVisitsWithCustomVariables.test.php'; - -/** - * Tests use of custom variable segments. - */ -class Test_Piwik_Integration_TwoVisitsWithCustomVariables_SegmentContains extends Test_Piwik_Integration_TwoVisitsWithCustomVariables -{ - public function __construct($title = '') - { - parent::__construct($title); - $this->doExtraQuoteTests = false; - } - - public function getApiToTest() - { - $return = array(); - - $api = array('Actions.getPageUrls', 'Actions.getPageTitles', 'VisitsSummary.get'); - $segmentsToTest = array( - // array( SegmentString , TestSuffix , Array of API to test) - array("pageTitle=@*_)%", '_SegmentPageTitleContainsStrangeCharacters', array('Actions.getPageTitles', 'VisitsSummary.get')), - array("pageUrl=@user/profile", '_SegmentPageUrlContains', $api), - array("pageTitle=@Profile pa", '_SegmentPageTitleContains', $api), - array("pageUrl!@user/profile", '_SegmentPageUrlExcludes', $api), - array("pageTitle!@Profile pa", '_SegmentPageTitleExcludes', $api), - ); - - foreach($segmentsToTest as $segment) - { - // Also test "Page URL / Page title CONTAINS string" feature - $return[] = array($segment[2], - array('idSite' => $this->idSite, 'date' => $this->dateTime, 'periods' => array('day'), - 'setDateLastN' => false, - 'segment' => $segment[0], - 'testSuffix' => $segment[1]) - ); - } - return $return; - } - - public function getAnotherApiToTest() - { - return array(); - } - - public function getControllerActionsToTest() - { - return array(); - } - -} - diff --git a/tests/integration/TwoVisitsWithCustomVariables_SegmentMatchALL_NoGoalData.test.php b/tests/integration/TwoVisitsWithCustomVariables_SegmentMatchALL_NoGoalData.test.php deleted file mode 100755 index 073fed65d0e64759bc9ddedf731b5acabd6b650a..0000000000000000000000000000000000000000 --- a/tests/integration/TwoVisitsWithCustomVariables_SegmentMatchALL_NoGoalData.test.php +++ /dev/null @@ -1,50 +0,0 @@ -<?php -if(!defined('PIWIK_CONFIG_TEST_INCLUDED')) -{ - require_once dirname(__FILE__)."/../../tests/config_test.php"; -} - -require_once PIWIK_INCLUDE_PATH . '/tests/integration/TwoVisitsWithCustomVariables.test.php'; - -class Test_Piwik_Integration_TwoVisitsWithCustomVariables_SegmentMatchALL_NoGoalData extends Test_Piwik_Integration_TwoVisitsWithCustomVariables -{ - public function __construct($title = '') - { - parent::__construct($title); - - $this->width = 1111; - $this->height = 222; - $this->doExtraQuoteTests = false; - } - - public function getApiToTest() - { - $apiToCall = array('VisitsSummary.get', 'CustomVariables.getCustomVariables'); - - // Segment matching ALL - // + adding DOES NOT CONTAIN segment always matched, to test this particular operator - $resolution = $this->width.'x'.$this->height; - $segment = 'resolution=='.$resolution.';customVariableName1!@randomvalue does not exist'; - - return array( - array($apiToCall, array('idSite' => 'all', 'date' => $this->dateTime, 'periods' => array('day', 'week'), - 'setDateLastN' => true, 'segment' => $segment)) - ); - } - - public function getAnotherApiToTest() - { - return array(); - } - - public function getControllerActionsToTest() - { - return array(); - } - - public function getOutputPrefix() - { - return 'twoVisitsWithCustomVariables_segmentMatchALL_noGoalData'; - } -} - diff --git a/tests/integration/TwoVisitsWithCustomVariables_SegmentMatchNONE.test.php b/tests/integration/TwoVisitsWithCustomVariables_SegmentMatchNONE.test.php deleted file mode 100755 index 51fb22b68aafa972d166b8cfdbbe088ef2fd694e..0000000000000000000000000000000000000000 --- a/tests/integration/TwoVisitsWithCustomVariables_SegmentMatchNONE.test.php +++ /dev/null @@ -1,94 +0,0 @@ -<?php -if(!defined('PIWIK_CONFIG_TEST_INCLUDED')) -{ - require_once dirname(__FILE__)."/../../tests/config_test.php"; -} - -require_once PIWIK_INCLUDE_PATH . '/tests/integration/TwoVisitsWithCustomVariables.test.php'; - -/** - * testing a segment containing all supported fields - */ -class Test_Piwik_Integration_TwoVisitsWithCustomVariables_SegmentMatchNONE extends Test_Piwik_Integration_TwoVisitsWithCustomVariables -{ - // set lazily so when testing, asserts can be run - private $segment = null; - - public function __construct($title = '') - { - parent::__construct($title); - $this->doExtraQuoteTests = false; - } - - public function getApiToTest() - { - $apiToCall = array('VisitsSummary.get', 'CustomVariables.getCustomVariables'); - - return array( - array($apiToCall, array('idSite' => 'all', 'date' => $this->dateTime, 'periods' => array('day', 'week'), - 'setDateLastN' => true, 'segment' => $this->getSegmentToTest(false))) - ); - } - - public function getSegmentToTest($calledDuringTest) - { - if ($this->segment) - { - return $this->segment; - } - - // Segment matching NONE - $segments = Piwik_API_API::getInstance()->getSegmentsMetadata($this->idSite); - $segmentExpression = array(); - - $seenVisitorId = false; - foreach($segments as $segment) { - $value = 'campaign'; - if($segment['segment'] == 'visitorId') - { - $seenVisitorId = true; - $value = '34c31e04394bdc63'; - } - if($segment['segment'] == 'visitEcommerceStatus') - { - $value = 'none'; - } - $segmentExpression[] = $segment['segment'] .'!='.$value; - } - - $this->segment = implode(";", $segmentExpression); - - // just checking that this segment was tested (as it has the only visible to admin flag) - if ($calledDuringTest) - { - $this->assertTrue($seenVisitorId); - $this->assertTrue(strlen($this->segment) > 100); - } - - return $this->segment; - } - - public function getAnotherApiToTest() - { - return array(); - } - - public function getControllerActionsToTest() - { - return array(); - } - - public function getOutputPrefix() - { - return 'twoVisitsWithCustomVariables_segmentMatchNONE'; - } - - public function test_RunAllTests() - { - // get the segment used & make sure to do some extra tests before testing the API - $this->getSegmentToTest(true); - - parent::test_RunAllTests(); - } -} - diff --git a/tests/integration/TwoVisitsWithCustomVariables_SegmentMatchVisitorType.test.php b/tests/integration/TwoVisitsWithCustomVariables_SegmentMatchVisitorType.test.php deleted file mode 100755 index ef57ca66916178720fca4f81805b33cba404f313..0000000000000000000000000000000000000000 --- a/tests/integration/TwoVisitsWithCustomVariables_SegmentMatchVisitorType.test.php +++ /dev/null @@ -1,104 +0,0 @@ -<?php -if(!defined('PIWIK_CONFIG_TEST_INCLUDED')) -{ - require_once dirname(__FILE__)."/../../tests/config_test.php"; -} - -require_once PIWIK_INCLUDE_PATH . '/tests/integration/TwoVisitsWithCustomVariables.test.php'; - -/** - * Tests use of custom variable segments. - */ -class Test_Piwik_Integration_TwoVisitsWithCustomVariables_SegmentMatchVisitorType extends Test_Piwik_Integration_TwoVisitsWithCustomVariables -{ - public function __construct($title = '') - { - parent::__construct($title); - $this->doExtraQuoteTests = false; - } - - public function getApiToTest() - { - // 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' => $this->dateTime, 'periods' => $periods, - 'setDateLastN' => true, 'segment' => $segment) - ); - } - } - - - return $result; - } - - public function getControllerActionsToTest() - { - return array(); - } - - public function getAnotherApiToTest() - { - return array(); - } - - public function getOutputPrefix() - { - return 'twoVisitsWithCustomVariables_segmentMatchVisitorType'; - } - - public function test_RunAllTests() - { - parent::test_RunAllTests(); - - // ---------------------------------------------- - // Implementation Checks - // ---------------------------------------------- - // Verify that, when a segment is specified, only the requested report is processed - // In this case, check that only the Custom Variables blobs have been processed - - if (Test_Integration::$apiTestingLevel != Test_Integration::NO_API_TESTING) - { - $tests = array( - // 1) CHECK 'day' archive stored in January - // We expect 2 segments * (1 custom variable name + 2 ref metrics + 6 subtable for the custom var values + 5 Referers blob) - 'archive_blob_2010_01' => 28, - // This contains all 'last N' weeks & days, - // (1 metrics - // + 2 referer metrics - // + 3 done flag ) - // * 2 segments - // + 1 Done flag per Plugin, for each "Last N" date - 'archive_numeric_2010_01' => 138, - - // 2) CHECK 'week' archive stored in December (week starts the month before) - // We expect 2 segments * (1 custom variable name + 2 ref metrics + 6 subtable for the values of the name + 5 referers blob) - 'archive_blob_2009_12' => 28, - // 6 metrics, - // 2 Referer metrics (Referers_distinctSearchEngines/Referers_distinctKeywords), - // 3 done flag (referers, CustomVar, VisitsSummary), - // X * 2 segments - 'archive_numeric_2009_12' => (6 + 2 + 3) * 2, - ); - 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"); - } - } - } -} - diff --git a/tests/integration/UrlNormalization.test.php b/tests/integration/UrlNormalization.test.php deleted file mode 100644 index bae8c2b4babcc700018882e8a4ea51423f539fc6..0000000000000000000000000000000000000000 --- a/tests/integration/UrlNormalization.test.php +++ /dev/null @@ -1,129 +0,0 @@ -<?php -if(!defined('PIWIK_CONFIG_TEST_INCLUDED')) -{ - require_once dirname(__FILE__)."/../../tests/config_test.php"; -} - -require_once PIWIK_INCLUDE_PATH . '/tests/integration/Integration.php'; - -/** - * Tests the URL normalization. - */ -class Test_Piwik_Integration_UrlNormalization extends Test_Integration_Facade -{ - protected $dateTime = '2010-03-06 11:22:33'; - protected $idSite = null; - - public function getApiToTest() - { - $return = array(); - $return[] = array('Actions.getPageUrls', array( - 'testSuffix' => '_urls', - 'idSite' => $this->idSite, - 'date' => $this->dateTime, - )); - $return[] = array('Actions.getPageTitles', array( - 'testSuffix' => '_titles', - 'idSite' => $this->idSite, - 'date' => $this->dateTime, - )); - $return[] = array('Actions.getPageUrls', array( - 'testSuffix' => '_pagesSegmented', - 'idSite' => $this->idSite, - 'date' => $this->dateTime, - 'segment' => 'pageUrl==https://WWw.example.org/foo/bar2.html', - )); - $return[] = array('Actions.getPageUrls', array( - 'testSuffix' => '_pagesSegmented', - 'idSite' => $this->idSite, - 'date' => $this->dateTime, - 'segment' => 'pageUrl==example.org/foo/bar2.html', - )); - $return[] = array('Actions.getPageUrls', array( - 'testSuffix' => '_pagesSegmentedRef', - 'idSite' => $this->idSite, - 'date' => $this->dateTime, - 'segment' => 'referrerUrl==http://www.google.com/search?q=piwik', - )); - $return[] = array('Referers.getKeywordsForPageUrl', array( - 'testSuffix' => '_keywords', - 'idSite' => $this->idSite, - 'date' => $this->dateTime, - 'otherRequestParameters' => array( - 'url' => 'http://WWW.example.org/foo/bar.html' - ) - )); - return $return; - } - - public function getControllerActionsToTest() - { - return array(); - } - - public function getOutputPrefix() - { - return 'UrlNormalization'; - } - - public function setUp() - { - parent::setUp(); - $this->idSite = $this->createWebsite($this->dateTime); - } - - protected function trackVisits() - { - $dateTime = $this->dateTime; - $idSite = $this->idSite; - $t = $this->getTracker($idSite, $dateTime, $defaultInit = true, $useThirdPartyCookie = 1); - - $t->setUrlReferrer('http://www.google.com/search?q=piwik'); - $t->setUrl('http://example.org/foo/bar.html'); - $this->checkResponse($t->doTrackPageView('http://incredible.title/')); - - $t->setUrl('https://example.org/foo/bar.html'); - $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.2)->getDatetime()); - $this->checkResponse($t->doTrackPageView('https://incredible.title/')); - - $t->setUrl('https://wWw.example.org/foo/bar2.html'); - $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.3)->getDatetime()); - $this->checkResponse($t->doTrackPageView('http://www.incredible.title/')); - - $t->setUrl('http://WwW.example.org/foo/bar2.html'); - $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.4)->getDatetime()); - $this->checkResponse($t->doTrackPageView('https://www.incredible.title/')); - - $t->setUrl('http://www.example.org/foo/bar3.html'); - $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.5)->getDatetime()); - $this->checkResponse($t->doTrackPageView('incredible.title/')); - - $t->setUrl('https://example.org/foo/bar4.html'); - $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.6)->getDatetime()); - $this->checkResponse($t->doTrackPageView('incredible.title/')); - } - - public function test_RunAllTests() - { - parent::test_RunAllTests(); - - $sql = "SELECT count(*) FROM " . Piwik_Common::prefixTable('log_action'); - $count = Zend_Registry::get('db')->fetchOne($sql); - $expected = 9; // 4 urls + 5 titles - $this->assertEqual( $expected, $count, "only $expected actions expected" ); - - $sql = "SELECT name, url_prefix FROM " . Piwik_Common::prefixTable('log_action') - . " WHERE type = " . Piwik_Tracker_Action::TYPE_ACTION_URL - . " ORDER BY idaction ASC"; - $urls = Zend_Registry::get('db')->fetchAll($sql); - $expected = array( - array('name' => 'example.org/foo/bar.html', 'url_prefix' => 0), - array('name' => 'example.org/foo/bar2.html', 'url_prefix' => 3), - array('name' => 'example.org/foo/bar3.html', 'url_prefix' => 1), - array('name' => 'example.org/foo/bar4.html', 'url_prefix' => 2) - ); - $this->assertEqual( $expected, $urls, "normalization went wrong" ); - } - -} - diff --git a/tests/integration/VisitsInPast_InvalidateOldReports.test.php b/tests/integration/VisitsInPast_InvalidateOldReports.test.php deleted file mode 100644 index 7a3be3ab85da1255a29e2248232d06db54128359..0000000000000000000000000000000000000000 --- a/tests/integration/VisitsInPast_InvalidateOldReports.test.php +++ /dev/null @@ -1,175 +0,0 @@ -<?php -if(!defined('PIWIK_CONFIG_TEST_INCLUDED')) -{ - require_once dirname(__FILE__)."/../../tests/config_test.php"; -} - -require_once PIWIK_INCLUDE_PATH . '/tests/integration/Integration.php'; - -/** - * - */ -class Test_Piwik_Integration_VisitsInPast_InvalidateOldReports extends Test_Integration_Facade -{ - protected $dateTimeFirstDateWebsite1 = '2010-03-06 01:22:33'; - protected $dateTimeDateInPastWebsite1 = '2010-01-06 01:22:33'; - - protected $dateTimeFirstDateWebsite2 = '2010-01-03 20:22:33'; - protected $dateTimeDateInPastWebsite2 = '2009-10-30 01:22:33'; - protected $idSite = null; - protected $idSite2 = null; - - /** - * This should NOT return data for old dates before website creation - */ - public function getApiToTest() - { - // We test a typical Numeric and a Recursive blob reports - $apiToCall = array('VisitsSummary.get', 'Actions.getPageUrls'); - - // We also test a segment - //TODO - - // Build tests for the 2 websites - $test = array($apiToCall, array('idSite' => $this->idSite, - 'testSuffix' => 'Website'.$this->idSite.'_OldReportsShouldNotAppear', - 'date' => $this->dateTimeDateInPastWebsite1, - 'periods' => 'month', - 'setDateLastN' => 4, // 4months ahead - 'otherRequestParameters' => array('expanded' => 1))); - $testWebsite2 = $test; - $testWebsite2[1]['idSite'] = $this->idSite2; - $testWebsite2[1]['testSuffix'] = 'Website'.$this->idSite2.'_OldReportsShouldNotAppear'; - $testWebsite2[1]['date'] = $this->dateTimeDateInPastWebsite2; - - $this->tests = array( - $test, - $testWebsite2 - ); - return $this->tests; - } - - /** - * This is called after getApiToTest() - * WE invalidate old reports and check that data is now returned for old dates - */ - public function getAnotherApiToTest() - { - // 1) Invalidate old reports for the 2 websites - // Test invalidate 1 date only - $r = new Piwik_API_Request("module=API&method=CoreAdminHome.invalidateArchivedReports - &idSites=4,5,6,55,-1,s',1&dates=2010-01-03"); - $r->process(); - - // Test invalidate comma separated dates - $r = new Piwik_API_Request("module=API&method=CoreAdminHome.invalidateArchivedReports - &idSites=".$this->idSite.",".$this->idSite2."&dates=2010-01-06,2009-10-30"); - $r->process(); - - // test invalidate date in the past - $r = new Piwik_API_Request("module=API&method=CoreAdminHome.invalidateArchivedReports - &idSites=".$this->idSite2."&dates=2009-06-29"); - $r->process(); - - // invalidate a date more recent to check the date is only updated when it's earlier than current - $r = new Piwik_API_Request("module=API&method=CoreAdminHome.invalidateArchivedReports - &idSites=".$this->idSite2."&dates=2010-03-03"); - $r->process(); - - // 2) Call API again, with an older date, which should now return data - // website 1 - $this->tests[0][1]['testSuffix'] = 'Website'.$this->idSite.'_OldReportsShouldAppear'; - // website2 - $this->tests[1][1]['testSuffix'] = 'Website'.$this->idSite2.'_OldReportsShouldAppear'; - - return $this->tests; - } - - public function getControllerActionsToTest() - { - return array(); - } - - public function getOutputPrefix() - { - return 'VisitsInPast_InvalidateOldReports'; - } - - public function setUp() - { - parent::setUp(); - - // Create 2 websites - $this->idSite = $this->createWebsite($this->dateTimeFirstDateWebsite1); - $this->idSite2 = $this->createWebsite($this->dateTimeFirstDateWebsite2); - } - - protected function trackVisits() - { - /** - * Track Visits normal date for the 2 websites - */ - - // WEBSITE 1 - $t = $this->getTracker($this->idSite, $this->dateTimeFirstDateWebsite1, $defaultInit = true); - $t->setUrl( 'http://example.org/category/Page1'); - $this->checkResponse($t->doTrackPageView( 'Hello')); - $t->setUrl( 'http://example.org/category/Page2'); - $this->checkResponse($t->doTrackPageView( 'Hello')); - $t->setUrl( 'http://example.org/category/Page3'); - $this->checkResponse($t->doTrackPageView( 'Hello')); - $t->setUrl( 'http://example.org/Home'); - $this->checkResponse($t->doTrackPageView( 'Hello')); - $t->setUrl( 'http://example.org/Contact'); - $this->checkResponse($t->doTrackPageView( 'Hello')); - $t->setUrl( 'http://example.org/Contact/ThankYou'); - $this->checkResponse($t->doTrackPageView( 'Hello')); - - // WEBSITE 2 - $t = $this->getTracker($this->idSite2, $this->dateTimeFirstDateWebsite2, $defaultInit = true); - $t->setIp('156.15.13.12'); - $t->setUrl( 'http://example.org/category/Page1'); - $this->checkResponse($t->doTrackPageView( 'Hello')); - $t->setUrl( 'http://example.org/category/Page2'); - $this->checkResponse($t->doTrackPageView( 'Hello')); - $t->setUrl( 'http://example.org/category/Page3'); - $this->checkResponse($t->doTrackPageView( 'Hello')); - $t->setUrl( 'http://example.org/Home'); - $this->checkResponse($t->doTrackPageView( 'Hello')); - $t->setUrl( 'http://example.org/Contact'); - $this->checkResponse($t->doTrackPageView( 'Hello')); - $t->setUrl( 'http://example.org/Contact/ThankYou'); - $this->checkResponse($t->doTrackPageView( 'Hello')); - - /** - * Track visits in the past (before website creation date) for the 2 websites - */ - // WEBSITE1 - $t = $this->getTracker($this->idSite, $this->dateTimeDateInPastWebsite1, $defaultInit = true); - $t->setIp('156.5.55.2'); - $t->setUrl( 'http://example.org/category/Page1'); - $this->checkResponse($t->doTrackPageView( 'Hello')); - $t->setUrl( 'http://example.org/category/Page1'); - $this->checkResponse($t->doTrackPageView( 'Hello')); - $t->setUrl( 'http://example.org/category/Page2'); - $this->checkResponse($t->doTrackPageView( 'Hello')); - $t->setUrl( 'http://example.org/category/Pagexx'); - $this->checkResponse($t->doTrackPageView( 'Blabla')); - - // WEBSITE2 - $t = $this->getTracker($this->idSite2, $this->dateTimeDateInPastWebsite2, $defaultInit = true); - $t->setIp('156.52.3.22'); - $t->setUrl( 'http://example.org/category/Page1'); - $this->checkResponse($t->doTrackPageView( 'Hello')); - $t->setUrl( 'http://example.org/category/Page1'); - $this->checkResponse($t->doTrackPageView( 'Hello')); - $t->setUrl( 'http://example.org/category/Page2'); - $this->checkResponse($t->doTrackPageView( 'Hello')); - $t->setUrl( 'http://example.org/category/Pageyy'); - $this->checkResponse($t->doTrackPageView( 'Blabla')); - $t->setForceVisitDateTime(Piwik_Date::factory($this->dateTimeDateInPastWebsite2)->addHour(0.1)->getDatetime()); - $t->setUrl( 'http://example.org/category/Pageyy'); - $this->checkResponse($t->doTrackPageView( 'Blabla')); - } -} - diff --git a/tests/integration/compareExpectedAndProcessedFiles.WinMerge b/tests/integration/compareExpectedAndProcessedFiles.WinMerge deleted file mode 100644 index e45988ed3c88a04190de284f5fcc413a2003d8ea..0000000000000000000000000000000000000000 --- a/tests/integration/compareExpectedAndProcessedFiles.WinMerge +++ /dev/null @@ -1,12 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="yes"?> - -<project> - <paths> - <left>expected\</left> - <right>processed\</right> - <filter>*</filter> - <subfolders>0</subfolders> - <left-readonly>0</left-readonly> - <right-readonly>0</right-readonly> - </paths> -</project>