1
0
قرینه از https://github.com/matomo-org/matomo.git synced 2025-08-25 00:17:37 +00:00
Files
matomo/tests/PHPUnit/Integration/Plugin/Dimension/ActionDimensionTest.php
Stefan Giehl d6d72d1fa7 [Coding Style] Enable rule PSR1.Methods.CamelCapsMethodName.NotCamelCaps (#22144)
* [Coding Style] Enable rule PSR1.Methods.CamelCapsMethodName.NotCamelCaps

* [Coding Style] Use camel case for method names in API plugin tests (#22145)

* [Coding Style] Use camel case for method names in Core* plugin tests (#22147)

* [Coding Style] Use camel case for method names in core Unit tests (#22149)

* [Coding Style] Use camel case for method names in Actions and BulkTracking plugin tests (#22146)

* [Coding Style] Use camel case for method names in CustomDimensions and CustomJSTracker plugin tests (#22148)

* [Coding Style] Use camel case for method names in core Integration tests (#22151)

* [Coding Style] Use camel case for method names in more core plugin tests (#22153)

* [Coding Style] Use camel case for method names in more core plugin tests (#22157)

* [Coding Style] Use camel case for method names in more core plugin tests

* Update plugins/Monolog/tests/Unit/Processor/ExceptionToTextProcessorTest.php

Co-authored-by: Michal Kleiner <michal@innocraft.com>

---------

Co-authored-by: Michal Kleiner <michal@innocraft.com>

* [Coding Style] Use camel case for method names in more core plugin tests (#22159)

* [Coding Style] Use camel case for method names in remaining tests (#22160)

* [Coding Style] Use camel case for method names in remaining tests

* rename expected test files

---------

Co-authored-by: Michal Kleiner <michal@innocraft.com>
2024-04-25 20:57:55 +02:00

171 خطوط
5.6 KiB
PHP

<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
// there is a test that requires the class to be defined in a plugin
namespace Piwik\Plugins\Test;
use Piwik\Columns\DimensionSegmentFactory;
use Piwik\Plugin\Dimension\ActionDimension;
use Piwik\Plugin\Segment;
use Piwik\Plugin\Manager;
use Piwik\Segment\SegmentsList;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
class FakeActionDimension extends ActionDimension
{
protected $columnName = 'fake_action_dimension_column';
protected $columnType = 'VARCHAR (255) DEFAULT 0';
public function set($param, $value)
{
$this->$param = $value;
}
public function configureSegments(SegmentsList $segmentsList, DimensionSegmentFactory $dimensionSegmentFactory)
{
$segment = new Segment();
$segment->setSegment('exitPageUrl');
$segment->setName('Actions_ColumnExitPageURL');
$segment->setCategory('General_Visit');
$segmentsList->addSegment($dimensionSegmentFactory->createSegment($segment));
// custom type and sqlSegment
$segment = new Segment();
$segment->setSegment('exitPageUrl');
$segment->setSqlSegment('customValue');
$segment->setType(Segment::TYPE_METRIC);
$segment->setName('Actions_ColumnExitPageURL');
$segment->setCategory('General_Visit');
$segmentsList->addSegment($dimensionSegmentFactory->createSegment($segment));
}
}
/**
* @group Core
*/
class ActionDimensionTest extends IntegrationTestCase
{
/**
* @var FakeActionDimension
*/
private $dimension;
public function setUp(): void
{
parent::setUp();
Manager::getInstance()->unloadPlugins();
Manager::getInstance()->doNotLoadAlwaysActivatedPlugins();
$this->dimension = new FakeActionDimension();
}
public function testInstallShouldNotReturnAnythingIfColumnTypeNotSpecified()
{
$this->dimension->set('columnType', '');
$this->assertEquals(array(), $this->dimension->install());
}
public function testInstallShouldNotReturnAnythingIfColumnNameNotSpecified()
{
$this->dimension->set('columnName', '');
$this->assertEquals(array(), $this->dimension->install());
}
public function testInstallShouldAlwaysInstallLogActionIfColumnNameAndTypeGiven()
{
$expected = array(
'log_link_visit_action' => array(
"ADD COLUMN `fake_action_dimension_column` VARCHAR (255) DEFAULT 0"
)
);
$this->assertEquals($expected, $this->dimension->install());
}
public function testUpdateShouldAlwaysUpdateLogVisitIfColumnNameAndTypeGiven()
{
$expected = array(
'log_link_visit_action' => array(
"MODIFY COLUMN `fake_action_dimension_column` VARCHAR (255) DEFAULT 0"
)
);
$this->assertEquals($expected, $this->dimension->update(array()));
}
public function testGetVersionShouldUseColumnTypeAsVersion()
{
$this->assertEquals('VARCHAR (255) DEFAULT 0', $this->dimension->getVersion());
}
public function testGetSegmentShouldReturnConfiguredSegments()
{
$list = new SegmentsList();
$this->dimension->configureSegments($list, new DimensionSegmentFactory($this->dimension));
$segments = $list->getSegments();
$this->assertCount(2, $segments);
$this->assertInstanceOf('\Piwik\Plugin\Segment', $segments[0]);
$this->assertInstanceOf('\Piwik\Plugin\Segment', $segments[1]);
}
public function testAddSegmentShouldPrefilSomeSegmentValuesIfNotDefinedYet()
{
$list = new SegmentsList();
$this->dimension->configureSegments($list, new DimensionSegmentFactory($this->dimension));
$segments = $list->getSegments();
$this->assertEquals('log_link_visit_action.fake_action_dimension_column', $segments[0]->getSqlSegment());
$this->assertEquals(Segment::TYPE_DIMENSION, $segments[0]->getType());
}
public function testAddSegmentShouldNotOverwritePreAssignedValues()
{
$list = new SegmentsList();
$this->dimension->configureSegments($list, new DimensionSegmentFactory($this->dimension));
$segments = $list->getSegments();
$this->assertEquals('customValue', $segments[1]->getSqlSegment());
$this->assertEquals(Segment::TYPE_METRIC, $segments[1]->getType());
}
public function testGetDimensionsShouldOnlyLoadAllActionDimensionsFromACertainPlugin()
{
Manager::getInstance()->loadPlugins(array('Actions'));
$plugin = Manager::getInstance()->loadPlugin('Actions');
$dimensions = ActionDimension::getDimensions($plugin);
$this->assertGreaterThan(5, count($dimensions));
foreach ($dimensions as $dimension) {
$this->assertInstanceOf('\Piwik\Plugin\Dimension\ActionDimension', $dimension);
$this->assertStringStartsWith('Piwik\Plugins\Actions\Columns', get_class($dimension));
}
}
public function testGetAllDimensionsShouldLoadAllDimensionsButOnlyIfLoadedPlugins()
{
Manager::getInstance()->loadPlugins(array('Actions', 'Events'));
$dimensions = ActionDimension::getAllDimensions();
$this->assertGreaterThan(8, count($dimensions));
foreach ($dimensions as $dimension) {
$this->assertInstanceOf('\Piwik\Plugin\Dimension\ActionDimension', $dimension);
$this->assertRegExp('/Piwik.Plugins.(Actions|Events).Columns/', get_class($dimension));
}
}
}