IngredientTest.php in Recipe 8.2
File
modules/ingredient/tests/src/Functional/IngredientTest.php
View source
<?php
namespace Drupal\Tests\ingredient\Functional;
use Drupal\Core\URL;
use Drupal\ingredient\Entity\Ingredient;
use Drupal\Tests\BrowserTestBase;
class IngredientTest extends BrowserTestBase {
protected static $modules = [
'block',
'ingredient',
'field_ui',
'views',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$this
->setupIngredientMenus();
$this
->drupalPlaceBlock('system_breadcrumb_block');
}
protected function setupIngredientMenus() {
$this
->drupalPlaceBlock('local_tasks_block', [
'region' => 'secondary_menu',
]);
$this
->drupalPlaceBlock('local_actions_block', [
'region' => 'content',
]);
$this
->drupalPlaceBlock('page_title_block', [
'region' => 'content',
]);
}
public function testIngredient() {
$web_user = $this
->drupalCreateUser([
'add ingredient',
'edit ingredient',
'view ingredient',
'delete ingredient',
'administer ingredient',
'administer ingredient display',
'administer ingredient fields',
'administer ingredient form display',
]);
$this
->drupalLogin($web_user);
$this
->drupalGet('admin/content/ingredient');
$this
->assertSession()
->linkExists('Add Ingredient');
$this
->clickLink('Add Ingredient');
$this
->assertSession()
->fieldExists('name[0][value]');
$edit = [
'name[0][value]' => 'test name',
];
$this
->drupalPostForm(NULL, $edit, 'Save');
$this
->assertSession()
->linkExists('Edit');
$this
->assertSession()
->linkExists('Delete');
$this
->clickLink('test name');
$this
->assertSession()
->pageTextContains('test name');
$this
->assertSession()
->pageTextContains('Edit');
$this
->assertSession()
->pageTextContains('Delete');
$expected_breadcrumb = [];
$expected_breadcrumb[] = URL::fromRoute('<front>')
->toString();
$expected_breadcrumb[] = URL::fromRoute('ingredient.landing_page')
->toString();
$links = $this
->xpath('//nav[@aria-labelledby="system-breadcrumb"]/ol/li/a');
$got_breadcrumb = [];
foreach ($links as $link) {
$got_breadcrumb[] = $link
->getAttribute('href');
}
$this
->assertSame($expected_breadcrumb, $got_breadcrumb, 'The breadcrumb is correctly displayed on the page.');
$this
->clickLink('Delete');
$this
->assertSession()
->linkExists('Cancel');
$this
->drupalPostForm(NULL, [], 'Delete');
$this
->assertSession()
->pageTextNotContains('test name');
$this
->drupalGet('admin/structure/ingredient_settings');
$this
->assertSession()
->pageTextContains('Ingredient Settings');
$this
->assertSession()
->linkExists('Settings');
$this
->assertSession()
->linkExists('Manage fields');
$this
->assertSession()
->linkExists('Manage form display');
$this
->assertSession()
->linkExists('Manage display');
}
}