View source
<?php
namespace Drupal\Tests\ga\Unit\AnalyticsCommand;
use Drupal\ga\AnalyticsCommand\Event;
use Drupal\Tests\UnitTestCase;
class EventTest extends UnitTestCase {
public function testDefaultPriority() {
$command = new Event('category', 'action');
$this
->assertEquals(-10, $command
->getPriority());
}
public function testBasicSettingCommands() {
$command = new Event('category', 'action');
$this
->assertEquals([
[
'send',
'event',
'category',
'action',
],
], $command
->getSettingCommands());
}
public function testWithLabelSettingCommands() {
$command = new Event('category', 'action', 'label');
$this
->assertEquals([
[
'send',
'event',
'category',
'action',
'label',
],
], $command
->getSettingCommands());
}
public function testWithLabelAndValueSettingCommands() {
$command = new Event('category', 'action', 'label', 1);
$this
->assertEquals([
[
'send',
'event',
'category',
'action',
'label',
1,
],
], $command
->getSettingCommands());
}
public function testWithLabelAndZeroValueSettingCommands() {
$command = new Event('category', 'action', 'label', 0);
$this
->assertEquals([
[
'send',
'event',
'category',
'action',
'label',
0,
],
], $command
->getSettingCommands());
}
public function testWithValueSettingCommands() {
$command = new Event('category', 'action', NULL, 1);
$this
->assertEquals([
[
'send',
'event',
'category',
'action',
[
'eventValue' => 1,
],
],
], $command
->getSettingCommands());
}
public function testWithZeroValueSettingCommands() {
$command = new Event('category', 'action', NULL, 0);
$this
->assertEquals([
[
'send',
'event',
'category',
'action',
[
'eventValue' => 0,
],
],
], $command
->getSettingCommands());
}
public function testWithFloatValue() {
$command = new Event('category', 'action', NULL, 1.5);
}
public function testWithNegativeIntegerValue() {
$command = new Event('category', 'action', NULL, -1);
}
public function testWithStringValue() {
$command = new Event('category', 'action', NULL, '1');
}
public function testWithFieldsObjectSettingCommmands() {
$command = new Event('category', 'action', NULL, NULL, [
'field1' => 'value1',
]);
$this
->assertEquals([
[
'send',
'event',
'category',
'action',
[
'field1' => 'value1',
],
],
], $command
->getSettingCommands());
}
public function testWithTrackerNameSettingCommands() {
$command = new Event('category', 'action', NULL, NULL, [], 'tracker');
$this
->assertEquals([
[
'tracker.send',
'event',
'category',
'action',
],
], $command
->getSettingCommands());
}
}