Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions .github/workflows/matomo-tests.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Action for running tests
# This file has been automatically created.
# To recreate it you can run this command
# ./console generate:test-action --plugin="CustomVariables" --php-versions="matomo5_min_php,matomo5_max_php" --schedule-cron="0 3 * * 6"
# ./console generate:test-action --plugin="CustomVariables" --php-versions="8.1,8.5" --schedule-cron="0 3 * * 6"

name: Plugin CustomVariables Tests

Expand Down Expand Up @@ -37,8 +37,11 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ 'matomo5_min_php', 'matomo5_max_php' ]
php: [ '8.1', '8.5' ]
target: ['minimum_required_matomo', 'maximum_supported_matomo']
database:
- { engine: 'Mysql', version: '8.0' }
- { engine: 'Mariadb', version: '10.6' }
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -52,9 +55,11 @@ jobs:
plugin-name: 'CustomVariables'
php-version: ${{ matrix.php }}
test-type: 'PluginTests'
mysql-engine: ${{ matrix.database.engine }}
mysql-version: ${{ matrix.database.version }}
matomo-test-branch: ${{ matrix.target }}
artifacts-pass: ${{ secrets.ARTIFACTS_PASS }}
upload-artifacts: ${{ matrix.php == 'matomo5_min_php' && matrix.target == 'maximum_supported_matomo' }}
upload-artifacts: ${{ matrix.php == '8.1' && matrix.target == 'maximum_supported_matomo' && matrix.database.engine == 'Mysql' }}
UI:
runs-on: ubuntu-24.04
steps:
Expand All @@ -68,7 +73,9 @@ jobs:
plugin-name: 'CustomVariables'
matomo-test-branch: 'maximum_supported_matomo'
test-type: 'UI'
php-version: 'matomo5_min_php'
node-version: '16'
php-version: '8.1'
node-version: '24'
mysql-engine: 'Mysql'
mysql-version: '8.0'
artifacts-pass: ${{ secrets.ARTIFACTS_PASS }}
upload-artifacts: true
2 changes: 1 addition & 1 deletion .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.1'
tools: cs2pr
- name: Install dependencies
run:
Expand Down
4 changes: 2 additions & 2 deletions plugin.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "CustomVariables",
"description": "Categorise your visitors and actions with custom name-value pairs. Segment by these values and get more insights to draw the right conclusions.",
"version": "5.0.6",
"version": "6.0.0",
"keywords": ["custom variables"],
"license": "GPL v3+",
"homepage": "https://matomo.org",
"require": {
"matomo": ">=5.0.0-b4,<6.0.0-b1"
"matomo": ">=6.0.0-b1,<7.0.0-b1"
},
"support": {
"email": "hello@matomo.org",
Expand Down
5 changes: 4 additions & 1 deletion tests/Fixtures/TwoVisitsWithCustomVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ private function trackVisits()
$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');
// A custom variable with a non-string (array) name can no longer go through the
// type-safe setCustomVariable(); inject it straight into the cvar payload so we
// still verify a malformed custom variable is not tracked.
$visitorB->visitorCustomVar[6] = array(array('not tracked'), 'not tracked');
$visitorB->setUrl('http://example.org/homepage');
self::checkResponse($visitorB->doTrackGoal($idGoal, 1000));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace Piwik\Plugins\CustomVariables\tests\System;

use Piwik\Columns\Dimension;
use Piwik\Plugins\API\tests\System\AutoSuggestAPITest;
use Piwik\Tests\Framework\TestCase\SystemTestCase;
use Piwik\Plugins\CustomVariables\tests\Fixtures\TwoVisitsWithCustomVariables;
Expand Down Expand Up @@ -63,9 +64,15 @@ public function getSegmentToTest()
$this->assertGreaterThan($minimumExpectedSegmentsCount, count($segments));
$segmentExpression = array();

$temporalSegmentValues = self::getTemporalSegmentValues();

$seenVisitorId = false;
foreach ($segments as $segment) {
$value = 'campaign';
// Date/time segments can't be compared against an arbitrary string: MySQL 8.0 rejects
// e.g. "visitEndServerDate != 'campaign'" as an invalid DATE value (5.7 tolerated it).
// Give them a valid, type-appropriate value (a date for DATE() segments, a number for
// the HOUR()/MINUTE()/YEAR()/... integer extractions) so they stay covered.
$value = $temporalSegmentValues[$segment] ?? 'campaign';
if ($segment == 'visitorId') {
$seenVisitorId = true;
$value = '34c31e04394bdc63';
Expand Down Expand Up @@ -107,6 +114,42 @@ public static function getOutputPrefix()
return 'twoVisitsWithCustomVariables_segmentMatchNONE';
}

/**
* Returns a valid comparison value for every non-internal segment backed by a date/time typed
* dimension, keyed by segment name.
*
* These segments map to SQL that expects either a date (e.g. DATE(...)) or an integer (the
* HOUR()/MINUTE()/YEAR()/... extractions), so an arbitrary string like "campaign" produces an
* invalid DATE value error on MySQL 8.0. The returned values are valid for the respective
* comparison.
*/
private static function getTemporalSegmentValues(): array
{
$temporalTypes = [
Dimension::TYPE_DATE,
Dimension::TYPE_DATETIME,
Dimension::TYPE_TIME,
Dimension::TYPE_TIMESTAMP,
];

$values = [];
foreach (Dimension::getAllDimensions() as $dimension) {
if (!in_array($dimension->getType(), $temporalTypes, true)) {
continue;
}

foreach ($dimension->getSegments() as $segment) {
$isIntegerExtraction = (bool) preg_match(
'/^\s*(HOUR|MINUTE|SECOND|DAYOFWEEK|DAYOFMONTH|DAYOFYEAR|WEEKOFYEAR|WEEK|MONTH|QUARTER|YEAR)\s*\(/i',
$segment->getSqlSegment()
);
$values[$segment->getSegment()] = $isIntegerExtraction ? '99' : '2099-12-31';
}
}

return $values;
}

public static function getPathToTestDirectory()
{
return dirname(__FILE__);
Expand Down
Loading
Loading