You are here

public function CourierGlobalCollectionTest::testGlobalTemplateCollectionLiveImportTemplate in Courier 8

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

Ensure active config is loaded into template entity.

File

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

Class

CourierGlobalCollectionTest
Tests Courier global template collections interaction with local templates.

Namespace

Drupal\Tests\courier\Kernel

Code

public function testGlobalTemplateCollectionLiveImportTemplate() {
  $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();
  $gtc
    ->setTemplate('courier_test_message', [
    'message' => $new_message,
  ])
    ->save();

  // Reset entity cache so hook_entity_load is triggered again.
  \Drupal::entityTypeManager()
    ->getStorage('courier_test_message')
    ->resetCache();
  $template = TestMessage::load($template_id);
  $this
    ->assertEquals($new_message, $template
    ->getMessage());
}