diff options
author | diosmosis <benaka@piwik.pro> | 2015-05-12 14:02:16 +0300 |
---|---|---|
committer | diosmosis <benaka@piwik.pro> | 2015-06-11 09:42:04 +0300 |
commit | 98a7c117e4e9a0aaf6c7b32aef2dd15568736438 (patch) | |
tree | 1a4db006daac323a3c2af6241d7576a8e27a4c3c /tests | |
parent | 1223d1c892cccab917ca304614068e0140ea2e45 (diff) |
Move log inserting logic to new test helper class, LogInserter.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/PHPUnit/Framework/TestDataHelper/LogInserter.php | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/tests/PHPUnit/Framework/TestDataHelper/LogInserter.php b/tests/PHPUnit/Framework/TestDataHelper/LogInserter.php new file mode 100644 index 0000000000..ee49674c61 --- /dev/null +++ b/tests/PHPUnit/Framework/TestDataHelper/LogInserter.php @@ -0,0 +1,120 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +namespace Piwik\Tests\Framework\TestDataHelper; + +use Piwik\Common; +use Piwik\Network\IPUtils; +use Piwik\Db; + +/** + * TODO + * + * TODO: this also gets log data. rename to LogHelper? + */ +class LogInserter +{ + public function insertVisit($visit = array()) + { + $defaultProperties = array( + 'idsite' => 1, + 'idvisitor' => $this->getDummyVisitorId(), + 'visit_last_action_time' => '2012-01-01 00:00:00', + 'config_id' => $this->getDummyVisitorId(), + 'location_ip' => IPUtils::stringToBinaryIP('1.2.3.4'), + 'visitor_localtime' => '2012-01-01 00:00:00', + 'location_country' => 'xx', + 'config_os' => 'xxx', + 'visit_total_events' => 0, + 'visitor_days_since_last' => 0, + 'config_quicktime' => 0, + 'config_pdf' => 0, + 'config_realplayer' => 0, + 'config_silverlight' => 0, + 'config_windowsmedia' => 0, + 'config_java' => 0, + 'config_gears' => 0, + 'config_resolution' => 0, + 'config_resolution' => '', + 'config_cookie' => 0, + 'config_director' => 0, + 'config_flash' => 0, + 'config_browser_version' => '', + 'visitor_count_visits' => 1, + 'visitor_returning' => 0, + 'visit_total_time' => 123, + 'visit_entry_idaction_name' => 0, + 'visit_entry_idaction_url' => 0, + 'visitor_days_since_order' => 0, + 'visitor_days_since_first' => 0, + 'visit_first_action_time' => '2012-01-01 00:00:00', + 'visit_goal_buyer' => 0, + 'visit_goal_converted' => 0, + 'visit_exit_idaction_name' => 0, + 'referer_url' => '', + 'location_browser_lang' => 'xx', + 'config_browser_engine' => '', + 'config_browser_name' => '', + 'referer_type' => 0, + 'referer_name' => '', + 'visit_total_actions' => 0, + 'visit_total_searches' => 0 + ); + + $visit = array_merge($defaultProperties, $visit); + + $this->insertInto('log_visit', $visit); + + $idVisit = Db::fetchOne("SELECT LAST_INSERT_ID()"); + return $this->getVisit($idVisit, $allColumns = true); + } + + private function insertInto($table, $row) + { + $columns = implode(', ', array_keys($row)); + $columnsPlaceholders = Common::getSqlStringFieldsArray($row); + $values = array_values($row); + + Db::query("INSERT INTO " . Common::prefixTable($table) . " ($columns) VALUES ($columnsPlaceholders)", $values); + } + + public function getVisit($idVisit, $allColumns = false) + { + $columns = $allColumns ? "*" : "location_country, location_region, location_city, location_latitude, location_longitude"; + $visit = Db::fetchRow("SELECT $columns FROM " . Common::prefixTable('log_visit') . " WHERE idvisit = ?", array($idVisit)); + + return $visit; + } + + public function insertConversion($properties) + { + $defaultProperties = array( + 'idvisit' => 1, + 'idsite' => 1, + 'idvisitor' => $this->getDummyVisitorId(), + 'server_time' => '2012-01-01 00:00:00', + 'idgoal' => 1, + 'buster' => 1, + 'url' => '', + 'location_country' => 'xx', + 'visitor_count_visits' => 0, + 'visitor_returning' => 0, + 'visitor_days_since_order' => 0, + 'visitor_days_since_first' => 0 + ); + + $properties = array_merge($defaultProperties, $properties); + + $this->insertInto('log_conversion', $properties); + } + + private function getDummyVisitorId() + { + return Common::hex2bin('ea95f303f2165aa0'); + } +}
\ No newline at end of file |