View source
<?php
namespace Drupal\Tests\coffee\Kernel;
use Drupal\Core\Url;
use Drupal\KernelTests\KernelTestBase;
use Drupal\node\Entity\NodeType;
use Drupal\user\Entity\Role;
use Drupal\user\Entity\User;
class CoffeeCommandsTest extends KernelTestBase {
public static $modules = [
'coffee',
'coffee_test',
'system',
'node',
'user',
];
protected function setUp() {
parent::setUp();
$this
->installSchema('system', [
'sequences',
'router',
]);
$this
->installEntitySchema('user');
$this
->installConfig('coffee');
$node_type = NodeType::create([
'type' => 'page',
'name' => 'Basic page',
]);
$node_type
->save();
$role = Role::create([
'id' => 'page_creator',
'permissions' => [
'create page content',
],
]);
$role
->save();
$user = User::create([
'name' => $this
->randomMachineName(),
'roles' => [
$role
->id(),
],
]);
$user
->save();
\Drupal::currentUser()
->setAccount($user);
}
public function testHookCoffeeCommands() {
$expected_hook = [
'value' => Url::fromRoute('<front>')
->toString(),
'label' => t('Coffee hook fired!'),
'command' => ':test',
];
$expected_system = [
'value' => Url::fromRoute('<front>')
->toString(),
'label' => t('Go to front page'),
'command' => ':front',
];
$expected_node = [
'value' => Url::fromRoute('node.add', [
'node_type' => 'page',
])
->toString(),
'label' => 'Basic page',
'command' => ':add Basic page',
];
$commands = \Drupal::moduleHandler()
->invokeAll('coffee_commands');
$this
->assertContains($expected_hook, $commands);
$this
->assertContains($expected_system, $commands);
$this
->assertContains($expected_node, $commands);
}
}