public function CrudTest::testCrudUi in Wysiwyg API template plugin 3.0.x
Same name and namespace in other branches
- 8.2 src/Tests/Form/CrudTest.php \Drupal\wysiwyg_template\Tests\Form\CrudTest::testCrudUi()
Tests the CRUD UI.
File
- src/
Tests/ Form/ CrudTest.php, line 42
Class
- CrudTest
- Tests the template CRUD forms.
Namespace
Drupal\wysiwyg_template\Tests\FormCode
public function testCrudUi() {
// Add.
$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'));
// Node type selection should be hidden if there are less than 2 types.
$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']);
/** @var \Drupal\wysiwyg_template_core\TemplateInterface $template */
$template = Template::load($id);
$this
->assertEqual('filter_test', $template
->getFormat());
// Edit.
$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']);
// Delete.
$this
->drupalGet($template
->toUrl('delete-form'));
$this
->drupalPostForm(NULL, [], t('Delete'));
$this
->assertText(t('There are no WYSIWYG templates yet.'));
// Add a few node types.
$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'));
// Node type selection should be hidden if there are less than 2 types.
$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());
}