class AlterEventDataEventTest in Commerce Google Tag Manager 8
Same name and namespace in other branches
- 8.2 tests/src/Unit/AlterEventDataEventTest.php \Drupal\Tests\commerce_google_tag_manager\Unit\AlterEventDataEventTest
@coversDefaultClass \Drupal\commerce_google_tag_manager\Event\AlterEventDataEvent
@group commerce @group commerce_google_tag_manager @group commerce_google_tag_manager_unit
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\commerce_google_tag_manager\Unit\AlterEventDataEventTest
Expanded class hierarchy of AlterEventDataEventTest
File
- tests/
src/ Unit/ AlterEventDataEventTest.php, line 16
Namespace
Drupal\Tests\commerce_google_tag_manager\UnitView source
class AlterEventDataEventTest extends UnitTestCase {
/**
* The event to tests against.
*
* @var \Drupal\commerce_google_tag_manager\Event\AlterEventDataEvent
*/
protected $alterEventData;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->alterEventData = new AlterEventDataEvent([]);
}
/**
* @covers ::setEventData
* @covers ::getEventData
*
* @dataProvider eventData
*/
public function testSetEventDetailViews($event_data) {
$this->alterEventData
->setEventData($event_data);
$this
->assertSame($event_data, $this->alterEventData
->getEventData());
}
/**
* List of supported event data.
*
* @return array
* Examples of event data structure by event types.
*/
public function eventData() {
return [
'Product detail views' => [
[
'event' => EventTrackerService::EVENT_PRODUCT_DETAIL_VIEWS,
'ecommerce' => [
'detail' => [
'actionField' => [
'list' => '',
],
'products' => [
0 => [
'name' => 'Lorem Ipsum',
'id' => '1',
'price' => '11.99',
'variant' => 'Lorem Ipsum',
],
],
],
],
],
],
// @todo add product impression example.
'Product impressions' => [
[
'event' => EventTrackerService::EVENT_PRODUCT_IMPRESSIONS,
'ecommerce' => [],
],
],
// @todo add product click example.
'Product click' => [
[
'event' => EventTrackerService::EVENT_PRODUCT_CLICK,
'ecommerce' => [],
],
],
'Add to cart' => [
[
'event' => EventTrackerService::EVENT_ADD_CART,
'ecommerce' => [
'currencyCode' => 'CHF',
'add' => [
'products' => [
0 => [
'name' => 'Lorem Ipsum',
'id' => '1',
'price' => '11.99',
'variant' => 'Lorem Ipsum',
'quantity' => 1,
],
],
],
],
],
],
'Remove to cart' => [
[
'event' => EventTrackerService::EVENT_REMOVE_CART,
'ecommerce' => [
'remove' => [
'products' => [
0 => [
'name' => 'Lorem Ipsum',
'id' => '1',
'price' => '11.99',
'variant' => 'Lorem Ipsum',
'quantity' => 1,
],
],
],
],
],
],
'Checkout' => [
[
'event' => EventTrackerService::EVENT_CHECKOUT,
'ecommerce' => [
'checkout' => [
'actionField' => [
'step' => 1,
],
'products' => [
0 => [
'name' => 'Lorem Ipsum',
'id' => '1',
'price' => '11.99',
'variant' => 'Lorem Ipsum',
'quantity' => 1,
],
],
],
],
],
],
// @todo add checkout option example.
'Checkout option' => [
[
'event' => EventTrackerService::EVENT_CHECKOUT_OPTION,
'ecommerce' => [],
],
],
'Purchase' => [
[
'event' => EventTrackerService::EVENT_PURCHASE,
'ecommerce' => [
'purchase' => [
'actionField' => [
'id' => '1',
'affiliation' => 'Commerce Website',
'revenue' => '11.99',
],
'products' => [
0 => [
'name' => 'Lorem Ipsum',
'id' => '1',
'price' => '11.99',
'variant' => 'Lorem Ipsum',
'quantity' => 1,
],
],
],
],
],
],
];
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AlterEventDataEventTest:: |
protected | property | The event to tests against. | |
AlterEventDataEventTest:: |
public | function | List of supported event data. | |
AlterEventDataEventTest:: |
protected | function |
Overrides UnitTestCase:: |
|
AlterEventDataEventTest:: |
public | function | @covers ::setEventData @covers ::getEventData | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |