You are here

public function EventStorageServiceTest::testAddEventDispatchAlter in Commerce Google Tag Manager 8.2

Same name and namespace in other branches
  1. 8 tests/src/Unit/EventStorageServiceTest.php \Drupal\Tests\commerce_google_tag_manager\Unit\EventStorageServiceTest::testAddEventDispatchAlter()

When addEvent called on a new event, we should fire an Event Alter.

This should occure only when the added event has not already been added. This will then dispatch EnhancedEcommerceEvents::ALTER_EVENT_DATA.

@covers ::addEvent

File

tests/src/Unit/EventStorageServiceTest.php, line 110

Class

EventStorageServiceTest
@coversDefaultClass \Drupal\commerce_google_tag_manager\EventStorageService

Namespace

Drupal\Tests\commerce_google_tag_manager\Unit

Code

public function testAddEventDispatchAlter() {

  // Mock stored events, make sure the event has never been added.
  $stored_events = $this
    ->getMockBuilder(PrivateTempStore::class)
    ->disableOriginalConstructor()
    ->getMock();
  $stored_events
    ->expects($this
    ->once())
    ->method('get')
    ->with('events')
    ->willReturn([]);

  // Re-Mock the Private Temp Store & The Symfony Event Dispatcher.
  $this->tempStore
    ->expects($this
    ->once())
    ->method('get')
    ->with('commerce_google_tag_manager')
    ->willReturn($stored_events);
  $this->eventDispatcher
    ->expects($this
    ->once())
    ->method('dispatch')
    ->with(EnhancedEcommerceEvents::ALTER_EVENT_DATA, $this->alterEventDataEvent);
  $this->eventStorage = new EventStorageService($this->tempStore, $this->eventDispatcher);
  $this->eventStorage
    ->addEvent($this->event);
}