You are here

class AlterEventDataEventTest in Commerce Google Tag Manager 8

Same name and namespace in other branches
  1. 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

Expanded class hierarchy of AlterEventDataEventTest

File

tests/src/Unit/AlterEventDataEventTest.php, line 16

Namespace

Drupal\Tests\commerce_google_tag_manager\Unit
View 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

Namesort descending Modifiers Type Description Overrides
AlterEventDataEventTest::$alterEventData protected property The event to tests against.
AlterEventDataEventTest::eventData public function List of supported event data.
AlterEventDataEventTest::setUp protected function Overrides UnitTestCase::setUp
AlterEventDataEventTest::testSetEventDetailViews public function @covers ::setEventData @covers ::getEventData
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.