Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMatthieu Aubry <matt@piwik.org>2016-03-10 19:58:03 +0300
committerMatthieu Aubry <matt@piwik.org>2016-03-10 19:58:03 +0300
commit396675f86f59599f17e5389b25eb3f7553019306 (patch)
treeed0daaa776639ff280f64996a715be9a5a708a26 /tests
parent5d14d8a9100178d4c20af2715a9eb9d8c044034e (diff)
parent055839d047c1d0b3ba36a5447e40ebee507a0b74 (diff)
Merge pull request #9774 from piwik/offset_visitor_log
Apply offset and limit correctly to the Visitor Log SQL queries
Diffstat (limited to 'tests')
-rw-r--r--tests/PHPUnit/Integration/SegmentTest.php128
1 files changed, 124 insertions, 4 deletions
diff --git a/tests/PHPUnit/Integration/SegmentTest.php b/tests/PHPUnit/Integration/SegmentTest.php
index 7041c89202..9f626e7969 100644
--- a/tests/PHPUnit/Integration/SegmentTest.php
+++ b/tests/PHPUnit/Integration/SegmentTest.php
@@ -829,9 +829,129 @@ class SegmentTest extends IntegrationTestCase
AND
( log_link_visit_action.custom_var_k1 = ? )
ORDER BY NULL
- LIMIT 33
- ) AS log_inner
- LIMIT 33",
+ LIMIT 0, 33
+ ) AS log_inner",
+ "bind" => array(1, 'Test'));
+
+ $this->assertEquals($this->removeExtraWhiteSpaces($expected), $this->removeExtraWhiteSpaces($query));
+ }
+
+
+ public function test_getSelectQuery_whenLimitAndOffset_outerQueryShouldNotHaveOffset()
+ {
+ $select = 'sum(log_visit.visit_total_time) as sum_visit_length';
+ $from = 'log_visit';
+ $where = 'log_visit.idvisit = ?';
+ $bind = array(1);
+
+ $segment = 'customVariablePageName1==Test';
+ $segment = new Segment($segment, $idSites = array());
+
+ $orderBy = false;
+ $groupBy = false;
+ $limit = 33;
+ $offset = 10;
+
+ $query = $segment->getSelectQuery($select, $from, $where, $bind, $orderBy, $groupBy, $limit, $offset);
+
+ $expected = array(
+ "sql" => "
+ SELECT
+ sum(log_inner.visit_total_time) as sum_visit_length
+ FROM
+ (
+ SELECT
+ log_visit.visit_total_time
+ FROM
+ " . Common::prefixTable('log_visit') . " AS log_visit
+ LEFT JOIN " . Common::prefixTable('log_link_visit_action') . " AS log_link_visit_action ON log_link_visit_action.idvisit = log_visit.idvisit
+ WHERE
+ ( log_visit.idvisit = ? )
+ AND
+ ( log_link_visit_action.custom_var_k1 = ? )
+ ORDER BY NULL
+ LIMIT 10, 33
+ ) AS log_inner",
+ "bind" => array(1, 'Test'));
+
+ $this->assertEquals($this->removeExtraWhiteSpaces($expected), $this->removeExtraWhiteSpaces($query));
+ }
+
+ public function test_getSelectQuery_whenOffsetIsZero()
+ {
+ $select = 'sum(log_visit.visit_total_time) as sum_visit_length';
+ $from = 'log_visit';
+ $where = 'log_visit.idvisit = ?';
+ $bind = array(1);
+
+ $segment = 'customVariablePageName1==Test';
+ $segment = new Segment($segment, $idSites = array());
+
+ $orderBy = false;
+ $groupBy = false;
+ $limit = 33;
+ $offset = 0;
+
+ $query = $segment->getSelectQuery($select, $from, $where, $bind, $orderBy, $groupBy, $limit, $offset);
+
+ $expected = array(
+ "sql" => "
+ SELECT
+ sum(log_inner.visit_total_time) as sum_visit_length
+ FROM
+ (
+ SELECT
+ log_visit.visit_total_time
+ FROM
+ " . Common::prefixTable('log_visit') . " AS log_visit
+ LEFT JOIN " . Common::prefixTable('log_link_visit_action') . " AS log_link_visit_action ON log_link_visit_action.idvisit = log_visit.idvisit
+ WHERE
+ ( log_visit.idvisit = ? )
+ AND
+ ( log_link_visit_action.custom_var_k1 = ? )
+ ORDER BY NULL
+ LIMIT 0, 33
+ ) AS log_inner",
+ "bind" => array(1, 'Test'));
+
+ $this->assertEquals($this->removeExtraWhiteSpaces($expected), $this->removeExtraWhiteSpaces($query));
+ }
+
+ public function test_getSelectQuery_whenLimitIsZero()
+ {
+ $select = 'sum(log_visit.visit_total_time) as sum_visit_length';
+ $from = 'log_visit';
+ $where = 'log_visit.idvisit = ?';
+ $bind = array(1);
+
+ $segment = 'customVariablePageName1==Test';
+ $segment = new Segment($segment, $idSites = array());
+
+ $orderBy = false;
+ $groupBy = false;
+ $limit = 0;
+ $offset = 10;
+
+ $query = $segment->getSelectQuery($select, $from, $where, $bind, $orderBy, $groupBy, $limit, $offset);
+
+ $expected = array(
+ "sql" => "
+ SELECT
+ sum(log_inner.visit_total_time) as sum_visit_length
+ FROM
+ (
+ SELECT
+ log_visit.visit_total_time
+ FROM
+ " . Common::prefixTable('log_visit') . " AS log_visit
+ LEFT JOIN " . Common::prefixTable('log_link_visit_action') . " AS log_link_visit_action ON log_link_visit_action.idvisit = log_visit.idvisit
+ WHERE
+ ( log_visit.idvisit = ? )
+ AND
+ ( log_link_visit_action.custom_var_k1 = ? )
+ GROUP BY log_visit.idvisit
+ ORDER BY NULL
+ ) AS log_inner",
"bind" => array(1, 'Test'));
$this->assertEquals($this->removeExtraWhiteSpaces($expected), $this->removeExtraWhiteSpaces($query));
@@ -1233,7 +1353,7 @@ class SegmentTest extends IntegrationTestCase
$this->assertEquals($this->removeExtraWhiteSpaces($expected), $this->removeExtraWhiteSpaces($query));
}
- // se https://github.com/piwik/piwik/issues/9194
+ // see https://github.com/piwik/piwik/issues/9194
public function test_getSelectQuery_whenQueryingLogConversionWithSegmentThatUsesLogLinkVisitActionAndLogVisit_shouldUseSubselectGroupedByIdVisitAndBuster()
{
$select = 'log_conversion.idgoal AS `idgoal`,