You are here

public function TemplateTest::testInterfaceMethods in Wysiwyg API template plugin 3.0.x

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/Entity/TemplateTest.php \Drupal\Tests\wysiwyg_template\Kernel\Entity\TemplateTest::testInterfaceMethods()

@covers ::id @covers ::label @covers ::getBody @covers ::getFormat @covers ::getNodeTypes @covers ::getWeight @covers ::loadByNodeType

File

tests/src/Kernel/Entity/TemplateTest.php, line 59

Class

TemplateTest
Tests the template config entity.

Namespace

Drupal\Tests\wysiwyg_template\Kernel\Entity

Code

public function testInterfaceMethods() {
  $values = [
    'id' => strtolower($this
      ->randomMachineName()),
    'label' => $this
      ->randomString(),
    'body' => [
      'value' => $this
        ->randomString(),
      'format' => $this
        ->randomMachineName(),
    ],
    'node_types' => [
      $this->nodeTypes[1]
        ->id(),
      $this->nodeTypes[2]
        ->id(),
    ],
    'weight' => -42,
  ];
  $template = Template::create($values);
  $template
    ->save();

  /** @var \Drupal\wysiwyg_template_core\TemplateInterface $template */
  $template = Template::load($values['id']);
  self::assertEquals($values['id'], $template
    ->id());
  self::assertEquals($values['label'], $template
    ->label());
  self::assertEquals($values['body']['value'], $template
    ->getBody());
  self::assertEquals($values['body']['format'], $template
    ->getFormat());
  self::assertEquals($values['node_types'], $template
    ->getNodeTypes());
  self::assertEquals($values['weight'], $template
    ->getWeight());

  // Since this template specifies node types, it should not be returned if
  // no node types are specified.
  self::assertEquals([], Template::loadByNodeType());

  // It should return for types 1 and 2, but not 3.
  self::assertEquals([
    $template
      ->id() => $template,
  ], Template::loadByNodeType($this->nodeTypes[1]));
  self::assertEquals([
    $template
      ->id() => $template,
  ], Template::loadByNodeType($this->nodeTypes[2]));
  self::assertEquals([], Template::loadByNodeType($this->nodeTypes[3]));
}