You are here

public function CourierGlobalCollectionTest::testTemplateUpdatesGlobalTemplateCollection in Courier 2.x

Same name and namespace in other branches
  1. 8 tests/src/Kernel/CourierGlobalCollectionTest.php \Drupal\Tests\courier\Kernel\CourierGlobalCollectionTest::testTemplateUpdatesGlobalTemplateCollection()

Ensure individual template update saves to global template collection.

File

tests/src/Kernel/CourierGlobalCollectionTest.php, line 103

Class

CourierGlobalCollectionTest
Tests Courier global template collections interaction with local templates.

Namespace

Drupal\Tests\courier\Kernel

Code

public function testTemplateUpdatesGlobalTemplateCollection() {
  $old_message = $this
    ->randomString();
  $gtc = GlobalTemplateCollection::create([
    'id' => $this
      ->randomMachineName(),
  ])
    ->setTemplate('courier_test_message', [
    'message' => $old_message,
  ]);
  $gtc
    ->save();

  // Instantiate template collection.
  $tc = $this->gtcService
    ->getLocalCollection($gtc);
  $template_id = $tc
    ->getTemplate('courier_test_message')
    ->id();
  $new_message = $this
    ->randomString();
  TestMessage::load($template_id)
    ->setMessage($new_message)
    ->save();

  // Reload global template collection.
  $gtc = GlobalTemplateCollection::load($gtc
    ->id());
  $this
    ->assertEquals($new_message, $gtc
    ->getTemplate('courier_test_message')['message']);
}