Skip to content

Commit

Permalink
Refs #4189, use new Omni test fixture for UI tests that combines all …
Browse files Browse the repository at this point in the history
…other fixtures.
  • Loading branch information
diosmosis committed Dec 14, 2013
1 parent 6a5c309 commit a68ed87
Show file tree
Hide file tree
Showing 32 changed files with 336 additions and 96 deletions.
12 changes: 11 additions & 1 deletion tests/PHPUnit/BaseFixture.php
Expand Up @@ -400,4 +400,14 @@ protected static function executeLogImporter($logFile, $options)

return $output;
}
}

public static function siteCreated($idSite)
{
return Db::fetchOne("SELECT COUNT(*) FROM " . Common::prefixTable('site') . " WHERE idsite = ?", array($idSite)) != 0;
}

public static function goalExists($idSite, $idGoal)
{
return Db::fetchOne("SELECT COUNT(*) FROM " . Common::prefixTable('goal') . " WHERE idgoal = ? AND idsite = ?", array($idGoal, $idSite)) != 0;
}
}
4 changes: 3 additions & 1 deletion tests/PHPUnit/Fixtures/FewVisitsWithSetVisitorId.php
Expand Up @@ -30,7 +30,9 @@ public function tearDown()
private function setUpWebsitesAndGoals()
{
// tests run in UTC, the Tracker in UTC
self::createWebsite($this->dateTime);
if (!self::siteCreated($idSite = 1)) {
self::createWebsite($this->dateTime);
}
}

private function trackVisits()
Expand Down
4 changes: 3 additions & 1 deletion tests/PHPUnit/Fixtures/InvalidVisits.php
Expand Up @@ -32,7 +32,9 @@ public function tearDown()

private function setUpWebsitesAndGoals()
{
self::createWebsite($this->dateTime);
if (!self::siteCreated($idSite = 1)) {
self::createWebsite($this->dateTime);
}
}

private function trackVisits()
Expand Down
16 changes: 12 additions & 4 deletions tests/PHPUnit/Fixtures/ManySitesImportedLogs.php
Expand Up @@ -47,10 +47,18 @@ public function tearDown()
public function setUpWebsitesAndGoals()
{
// for conversion testing
self::createWebsite($this->dateTime);
APIGoals::getInstance()->addGoal($this->idSite, 'all', 'url', 'http', 'contains', false, 5);
self::createWebsite($this->dateTime, $ecommerce = 0, $siteName = 'Piwik test two',
$siteUrl = 'http://example-site-two.com');
if (!self::siteCreated($idSite = 1)) {
self::createWebsite($this->dateTime);
}

if (!self::goalExists($idSite = 1, $idGoal = 1)) {
APIGoals::getInstance()->addGoal($this->idSite, 'all', 'url', 'http', 'contains', false, 5);
}

if (!self::siteCreated($idSite = 2)) {
self::createWebsite($this->dateTime, $ecommerce = 0, $siteName = 'Piwik test two',
$siteUrl = 'http://example-site-two.com');
}
}

public function getDefaultSegments()
Expand Down
21 changes: 14 additions & 7 deletions tests/PHPUnit/Fixtures/ManySitesImportedLogsWithXssAttempts.php
Expand Up @@ -49,13 +49,20 @@ public function setUp()
public function setUpWebsitesAndGoals()
{
// for conversion testing
$siteName = self::makeXssContent("site name", $sanitize = true);
self::createWebsite($this->dateTime, $ecommerce = 1, $siteName);
APIGoals::getInstance()->addGoal(
$this->idSite, self::makeXssContent("goal name"), 'url', 'http', 'contains', false, 5);

self::createWebsite($this->dateTime, $ecommerce = 0, $siteName = 'Piwik test two',
$siteUrl = 'http://example-site-two.com');
if (!self::siteCreated($idSite = 1)) {
$siteName = self::makeXssContent("site name", $sanitize = true);
self::createWebsite($this->dateTime, $ecommerce = 1, $siteName);
}

if (!self::goalExists($idSite = 1, $idGoal = 1)) {
APIGoals::getInstance()->addGoal(
$this->idSite, self::makeXssContent("goal name"), 'url', 'http', 'contains', false, 5);
}

if (!self::siteCreated($idSite = 2)) {
self::createWebsite($this->dateTime, $ecommerce = 0, $siteName = 'Piwik test two',
$siteUrl = 'http://example-site-two.com');
}
}

/** Creates two dashboards that split the widgets up into different groups. */
Expand Down
14 changes: 11 additions & 3 deletions tests/PHPUnit/Fixtures/ManyVisitsWithGeoIP.php
Expand Up @@ -65,9 +65,17 @@ public function tearDown()

private function setUpWebsitesAndGoals()
{
self::createWebsite($this->dateTime, 0, "Site 1");
$this->idGoal = API::getInstance()->addGoal($this->idSite, 'all', 'url', 'http', 'contains', false, 5);
$this->idGoal2 = API::getInstance()->addGoal($this->idSite, 'two', 'url', 'xxxxxxxxxxxxx', 'contains', false, 5);
if (!self::siteCreated($idSite = 1)) {
self::createWebsite($this->dateTime, 0, "Site 1");
}

if (!self::goalExists($idSite = 1, $idGoal = 1)) {
$this->idGoal = API::getInstance()->addGoal($this->idSite, 'all', 'url', 'http', 'contains', false, 5);
}

if (!self::goalExists($idSite = 1, $idGoal = 2)) {
$this->idGoal2 = API::getInstance()->addGoal($this->idSite, 'two', 'url', 'xxxxxxxxxxxxx', 'contains', false, 5);
}
}

private function trackVisits($visitorCount, $setIp = false, $useLocal = true, $doBulk = false)
Expand Down
Expand Up @@ -39,7 +39,9 @@ public function tearDown()

private function setUpWebsitesAndGoals()
{
self::createWebsite($this->dateTime);
if (!self::siteCreated($idSite = 1)) {
self::createWebsite($this->dateTime);
}
}

private function trackVisits()
Expand Down
Expand Up @@ -30,7 +30,9 @@ public function tearDown()

private function setUpWebsitesAndGoals()
{
self::createWebsite($this->dateTime);
if (!self::siteCreated($idSite = 1)) {
self::createWebsite($this->dateTime);
}
}

private function trackVisits()
Expand Down
81 changes: 81 additions & 0 deletions tests/PHPUnit/Fixtures/OmniFixture.php
@@ -0,0 +1,81 @@
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/

use Piwik\Date;
use Piwik\Tracker\Visit;

/**
* This fixture is the combination of every other fixture defined by Piwik. Should be used
* with year periods.
*/
class Test_Piwik_Fixture_OmniFixture extends Test_Piwik_BaseFixture
{
public $month = '2012-01';
public $idSite = 'all';
public $dateTime = '2012-02-01';
public $now = null;

public $fixtures = array();

/**
* Constructor.
*/
public function __construct()
{
$date = $this->month . '-01';

$classes = get_declared_classes();
foreach ($classes as $className) {
if (is_subclass_of($className, 'Test_Piwik_BaseFixture')
&& $className != __CLASS__
) {
$fixture = new $className();
if (!property_exists($fixture, 'dateTime')) {
continue;
}

$fixture->dateTime = $this->adjustDateTime($fixture->dateTime, $date);

$this->fixtures[$className] = $fixture;

$date = Date::factory($date)->addDay(1)->toString();
}
}

$this->now = $this->fixtures['Test_Piwik_Fixture_ManySitesImportedLogsWithXssAttempts']->now;

// make sure Test_Piwik_Fixture_ManySitesImportedLogsWithXssAttempts is the first fixture
$fixture = $this->fixtures['Test_Piwik_Fixture_ManySitesImportedLogsWithXssAttempts'];
unset($this->fixtures['Test_Piwik_Fixture_ManySitesImportedLogsWithXssAttempts']);
$this->fixtures = array_merge(array('Test_Piwik_Fixture_ManySitesImportedLogsWithXssAttempts' => $fixture), $this->fixtures);
}

private function adjustDateTime($dateTime, $adjustToDate)
{
$parts = explode(' ', $dateTime);

$result = $adjustToDate . ' ';
$result .= isset($parts[1]) ? $parts[1] : '11:22:33';

return $result;
}

public function setUp()
{
foreach ($this->fixtures as $name => $fixture) {
$fixture->setUp();
}
}

public function tearDown()
{
foreach ($this->fixtures as $fixture) {
$fixture->tearDown();
}
}
}
4 changes: 3 additions & 1 deletion tests/PHPUnit/Fixtures/OneVisitSeveralPageViews.php
Expand Up @@ -28,7 +28,9 @@ public function tearDown()

private function setUpWebsitesAndGoals()
{
self::createWebsite($this->dateTime);
if (!self::siteCreated($idSite = 1)) {
self::createWebsite($this->dateTime);
}
}

private function trackVisits()
Expand Down
4 changes: 3 additions & 1 deletion tests/PHPUnit/Fixtures/OneVisitWithAbnormalPageviewUrls.php
Expand Up @@ -29,7 +29,9 @@ public function tearDown()

private function setUpWebsitesAndGoals()
{
self::createWebsite($this->dateTime);
if (!self::siteCreated($idSite = 1)) {
self::createWebsite($this->dateTime);
}
}

private function trackVisits()
Expand Down
23 changes: 18 additions & 5 deletions tests/PHPUnit/Fixtures/OneVisitorTwoVisits.php
Expand Up @@ -36,10 +36,17 @@ public function tearDown()

private function setUpWebsitesAndGoals()
{
self::createWebsite($this->dateTime);
if (!self::siteCreated($idSite = 1)) {
self::createWebsite($this->dateTime);
}

if (!self::siteCreated($idSite = 2)) {
$this->idSiteEmptyBis = $this->createWebsite($this->dateTime);
}

$this->idSiteEmptyBis = $this->createWebsite($this->dateTime);
$this->idSiteEmptyTer = $this->createWebsite($this->dateTime);
if (!self::siteCreated($idStie = 3)) {
$this->idSiteEmptyTer = $this->createWebsite($this->dateTime);
}
}

private function trackVisits()
Expand Down Expand Up @@ -109,7 +116,11 @@ private function trackVisits()
self::checkResponse($t->doTrackAction('http://dev.piwik.org/svn', 'link'));

// Create Goal 1: Triggered by JS, after 18 minutes
$idGoal = APIGoals::getInstance()->addGoal($idSite, 'triggered js', 'manually', '', '');
$idGoal = 1;
if (!self::goalExists($idSite, $idGoal)) {
$idGoal = APIGoals::getInstance()->addGoal($idSite, 'triggered js', 'manually', '', '');
}

$t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.3)->getDatetime());

// Change to Thai browser to ensure the conversion is credited to FR instead (the visitor initial country)
Expand Down Expand Up @@ -146,7 +157,9 @@ private function trackVisits()
// End of first visit: 24min

// Create Goal 2: Matching on URL
APIGoals::getInstance()->addGoal($idSite, 'matching purchase.htm', 'url', '(.*)store\/purchase\.(.*)', 'regex', false, $revenue = 1);
if (!self::goalExists($idSite, $idGoal = 2)) {
APIGoals::getInstance()->addGoal($idSite, 'matching purchase.htm', 'url', '(.*)store\/purchase\.(.*)', 'regex', false, $revenue = 1);
}

// -
// Start of returning visit, 1 hour after first page view
Expand Down
24 changes: 15 additions & 9 deletions tests/PHPUnit/Fixtures/SomeVisitsAllConversions.php
Expand Up @@ -31,19 +31,25 @@ public function tearDown()

private function setUpWebsitesAndGoals()
{
self::createWebsite($this->dateTime);
if (!self::siteCreated($idSite = 1)) {
self::createWebsite($this->dateTime);
}

// First, a goal that is only recorded once per visit
API::getInstance()->addGoal(
$this->idSite, 'triggered js ONCE', 'title', 'Thank you', 'contains', $caseSensitive = false,
$revenue = 10, $allowMultipleConversions = false
);
if (!self::goalExists($idSite = 1, $idGoal = 1)) {
API::getInstance()->addGoal(
$this->idSite, 'triggered js ONCE', 'title', 'Thank you', 'contains', $caseSensitive = false,
$revenue = 10, $allowMultipleConversions = false
);
}

// Second, a goal allowing multiple conversions
API::getInstance()->addGoal(
$this->idSite, 'triggered js MULTIPLE ALLOWED', 'manually', '', '', $caseSensitive = false,
$revenue = 10, $allowMultipleConversions = true
);
if (!self::goalExists($idSite = 1, $idGoal = 2)) {
API::getInstance()->addGoal(
$this->idSite, 'triggered js MULTIPLE ALLOWED', 'manually', '', '', $caseSensitive = false,
$revenue = 10, $allowMultipleConversions = true
);
}
}

private function trackVisits()
Expand Down
Expand Up @@ -31,8 +31,13 @@ public function tearDown()

private function setUpWebsitesAndGoals()
{
self::createWebsite($this->dateTime);
API::getInstance()->addGoal($this->idSite, 'triggered js', 'manually', '', '');
if (!self::siteCreated($idSite = 1)) {
self::createWebsite($this->dateTime);
}

if (!self::goalExists($idSite = 1, $idGoal = 1)) {
API::getInstance()->addGoal($this->idSite, 'triggered js', 'manually', '', '');
}
}

private function trackVisits()
Expand Down
Expand Up @@ -31,8 +31,10 @@ public function tearDown()

private function setUpWebsitesAndGoals()
{
self::createWebsite($this->dateTime, $ecommerce = 0, $siteName = 'Piwik test', $siteUrl = false,
$siteSearch = 1);
if (!self::siteCreated($idSite = 1)) {
self::createWebsite($this->dateTime, $ecommerce = 0, $siteName = 'Piwik test', $siteUrl = false,
$siteSearch = 1);
}
}

private function trackVisits()
Expand Down
4 changes: 3 additions & 1 deletion tests/PHPUnit/Fixtures/SomeVisitsWithLongUrls.php
Expand Up @@ -29,7 +29,9 @@ public function tearDown()

private function setUpWebsitesAndGoals()
{
self::createWebsite($this->dateTime);
if (!self::siteCreated($idSite = 1)) {
self::createWebsite($this->dateTime);
}
}

private function trackVisits()
Expand Down
Expand Up @@ -35,7 +35,10 @@ public function tearDown()
private function setUpWebsites()
{
API::getInstance()->setGlobalSearchParameters($searchKeywordParameters = 'gkwd', $searchCategoryParameters = 'gcat');
self::createWebsite(Date::factory($this->dateTime)->getDatetime(), 0, "Site 1 - Site search", $siteurl = false, $search = 1, $searchKwd = 'q,mykwd,p', $searchCat = 'cats');

if (!self::siteCreated($idSite = 1)) {
self::createWebsite(Date::factory($this->dateTime)->getDatetime(), 0, "Site 1 - Site search", $siteurl = false, $search = 1, $searchKwd = 'q,mykwd,p', $searchCat = 'cats');
}
}

private function trackVisits()
Expand Down

0 comments on commit a68ed87

Please sign in to comment.