You are here

public function EventStorageServiceTest::testAddEventShouldDispatchAlterOnlyOnce 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::testAddEventShouldDispatchAlterOnlyOnce()

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

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

@covers ::addEvent

File

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

Class

EventStorageServiceTest
@coversDefaultClass \Drupal\commerce_google_tag_manager\EventStorageService

Namespace

Drupal\Tests\commerce_google_tag_manager\Unit

Code

public function testAddEventShouldDispatchAlterOnlyOnce() {

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

  // 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
    ->never())
    ->method('dispatch');
  $this->eventStorage = new EventStorageService($this->tempStore, $this->eventDispatcher);
  $this->eventStorage
    ->addEvent($this->event);
}