DefaultContentTest.php in Wysiwyg API template plugin 8.2
File
src/Tests/DefaultContentTest.php
View source
<?php
namespace Drupal\wysiwyg_template\Tests;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\BrowserTestBase;
use Drupal\wysiwyg_template\Entity\Template;
class DefaultContentTest extends BrowserTestBase {
public static $modules = [
'node',
'wysiwyg_template',
];
protected $templates;
protected $nodeType;
protected $admin;
public function setUp() {
parent::setUp();
foreach (range(1, 2) as $i) {
$this->templates[$i] = Template::create([
'id' => strtolower($this
->randomMachineName()),
'label' => $this
->randomString(),
'body' => [
'value' => $this
->randomString(),
],
]);
$this->templates[$i]
->save();
}
$this->nodeType = $this
->createContentType([
'type' => strtolower($this
->randomMachineName()),
'name' => $this
->randomString(),
]);
$this->nodeType
->save();
$this->admin = $this
->createUser([], NULL, TRUE);
$this
->drupalLogin($this->admin);
}
public function testNodeTypeForm() {
$this
->drupalGet($this->nodeType
->toUrl('edit-form'));
$edit = [
'wysiwyg_template_default' => $this->templates[1]
->id(),
];
$this
->drupalPostForm(NULL, $edit, t('Save content type'));
$type = NodeType::load($this->nodeType
->id());
$this
->assertEqual($this->templates[1]
->id(), $type
->getThirdPartySetting('wysiwyg_template', 'default_template'));
$this
->drupalGet('node/add/' . $this->nodeType
->id());
$edit = [
'title[0][value]' => $this
->randomString(),
];
$this
->drupalPostForm(NULL, $edit, t('Save and publish'));
$node = $this
->drupalGetNodeByTitle($edit['title[0][value]']);
$this
->assertEqual($this->templates[1]
->getBody(), $node
->get('body')->value);
}
}