View source
<?php
namespace Drupal\Tests\wysiwyg_template\Kernel\Entity;
use Drupal\KernelTests\KernelTestBase;
use Drupal\node\Entity\NodeType;
use Drupal\wysiwyg_template\Entity\Template;
class TemplateTest extends KernelTestBase {
public static $modules = [
'wysiwyg_template',
'node',
'user',
'system',
];
protected $nodeTypes;
public function setUp() {
parent::setUp();
$this
->installEntitySchema('wysiwyg_template');
$this
->installEntitySchema('node_type');
foreach (range(1, 3) as $i) {
$this->nodeTypes[$i] = NodeType::create([
'type' => strtolower($this
->randomMachineName()),
'name' => $this
->randomString(),
]);
$this->nodeTypes[$i]
->save();
}
}
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();
$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());
self::assertEquals([], Template::loadByNodeType());
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]));
}
}