View source
<?php
namespace Drupal\wysiwyg_template\Tests\Form;
use Drupal\Core\Url;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\BrowserTestBase;
use Drupal\wysiwyg_template\Entity\Template;
class CrudTest extends BrowserTestBase {
protected $admin;
public static $modules = [
'wysiwyg_template',
'filter_test',
'node',
];
public function setUp() {
parent::setUp();
$this->admin = $this
->drupalCreateUser([
'administer wysiwyg templates',
'administer filters',
]);
$this
->drupalLogin($this->admin);
}
public function testCrudUi() {
$this
->drupalGet(Url::fromRoute('entity.wysiwyg_template.collection'));
$this
->assertText(t('There are no WYSIWYG templates yet.'));
$this
->drupalGet(Url::fromRoute('entity.wysiwyg_template.add_form'));
$this
->assertNoText(t('Available for content types'));
$id = strtolower($this
->randomMachineName());
$edit = [
'id' => $id,
'label' => $this
->randomString(),
'description' => $this
->randomString(),
'body[value]' => $this
->randomString(),
];
$this
->drupalPostForm(NULL, $edit, t('Save'));
$this
->assertUrl(Url::fromRoute('entity.wysiwyg_template.collection'));
$this
->assertEscaped($id);
$this
->assertEscaped($edit['label']);
$template = Template::load($id);
$this
->assertEqual('filter_test', $template
->getFormat());
$this
->drupalGet($template
->toUrl('edit-form'));
$edit['label'] = $this
->randomString(12);
unset($edit['id']);
$this
->drupalPostForm(NULL, $edit, t('Save'));
$this
->assertUrl(Url::fromRoute('entity.wysiwyg_template.collection'));
$this
->assertEscaped($id);
$this
->assertEscaped($edit['label']);
$this
->drupalGet($template
->toUrl('delete-form'));
$this
->drupalPostForm(NULL, [], t('Delete'));
$this
->assertText(t('There are no WYSIWYG templates yet.'));
$type1 = NodeType::create([
'type' => $this
->randomMachineName(),
'label' => $this
->randomString(),
]);
$type1
->save();
$type2 = NodeType::create([
'type' => $this
->randomMachineName(),
'name' => $this
->randomString(),
]);
$type2
->save();
$this
->drupalGet(Url::fromRoute('entity.wysiwyg_template.add_form'));
$this
->assertText(t('Available for content types'));
$id = strtolower($this
->randomMachineName());
$edit = [
'id' => $id,
'label' => $this
->randomString(),
'description' => $this
->randomString(),
'body[value]' => $this
->randomString(),
'node_types[' . $type2
->id() . ']' => 1,
];
$this
->drupalPostForm(NULL, $edit, t('Save'));
$template = Template::load($id);
$this
->assertEqual([
$type2
->id(),
], $template
->getNodeTypes());
}
}