AddAnotherTest.php in Add Another 8
File
tests/src/Functional/AddAnotherTest.php
View source
<?php
namespace Drupal\Tests\addanother\Functional;
use Drupal\Tests\BrowserTestBase;
class AddAnotherTest extends BrowserTestBase {
public static $modules = [
'addanother',
];
protected $profile = 'minimal';
public function testAddanother() {
$node_type = $this
->randomMachineName(8);
$config = \Drupal::service('config.factory')
->getEditable('addanother.settings');
$config
->set('button.' . $node_type, TRUE)
->set('message.' . $node_type, TRUE)
->set('tab.' . $node_type, TRUE)
->set('tab_edit.' . $node_type, TRUE)
->save();
$settings = [
'type' => $node_type,
'name' => $node_type,
];
$this
->drupalCreateContentType($settings);
$web_user = $this
->drupalCreateUser([
'bypass node access',
'administer content types',
'use add another',
'administer add another',
]);
$this
->drupalLogin($web_user);
$edit = [];
$edit['title[0][value]'] = $this
->randomMachineName(8);
$edit['body[0][value]'] = $this
->randomMachineName(16);
$this
->drupalGet("node/add/{$node_type}");
$this
->submitForm($edit, 'Save');
$this
->assertText(t('@post @title has been created.', [
'@post' => $node_type,
'@title' => $edit['title[0][value]'],
]), 'Node created.');
$this
->assertText(t('You may add another @type.', [
'@type' => $node_type,
]), 'Addanother message was presented.');
$this
->assertLink('Add another');
$edit = [];
$edit['title[0][value]'] = $this
->randomMachineName(8);
$edit['body[0][value]'] = $this
->randomMachineName(16);
$this
->drupalGet("node/add/{$node_type}");
$this
->submitForm($edit, 'Save and add another');
$this
->assertUrl("node/add/{$node_type}");
}
}