public function OrderEventTest::testTrackPurchase in Commerce Google Tag Manager 8
Same name and namespace in other branches
- 8.2 tests/src/Kernel/EventSubscriber/OrderEventTest.php \Drupal\Tests\commerce_google_tag_manager\Kernel\EventSubscriber\OrderEventTest::testTrackPurchase()
@covers ::trackPurchase
File
- tests/
src/ Kernel/ EventSubscriber/ OrderEventTest.php, line 103
Class
- OrderEventTest
- @coversDefaultClass \Drupal\commerce_google_tag_manager\EventSubscriber\CommerceEventsSubscriber
Namespace
Drupal\Tests\commerce_google_tag_manager\Kernel\EventSubscriberCode
public function testTrackPurchase() {
// Create a partial-mocked version of CommerceEventsSubscriber.
$subscriber = $this
->getMockBuilder(CommerceEventsSubscriber::class)
->disableOriginalConstructor()
->setMethods([
'trackPurchase',
])
->getMock();
// Assert the trackPurchase will be called only once.
$subscriber
->expects($this
->once())
->method('trackPurchase')
->with($this
->isInstanceOf(WorkflowTransitionEvent::class));
// Add the new mocked CommerceEventsSubscriber.
$this->eventDispatcher
->addSubscriber($subscriber);
// Place the order which should fire a commerce_order.place.post_transition.
$transition = $this->order
->getState()
->getTransitions();
$this->order
->getState()
->applyTransition($transition['place']);
$this->order
->save();
}