CreateUITest.php in Entity API 8.0
File
tests/src/Functional/CreateUITest.php
View source
<?php
namespace Drupal\Tests\entity\Functional;
use Drupal\entity_module_test\Entity\EnhancedEntity;
use Drupal\entity_module_test\Entity\EnhancedEntityBundle;
use Drupal\simpletest\BrowserTestBase;
class CreateUITest extends BrowserTestBase {
public static $modules = [
'entity_module_test',
'user',
'entity',
];
protected function setUp() {
parent::setUp();
EnhancedEntityBundle::create([
'id' => 'first',
'label' => 'First',
'description' => 'The first bundle',
])
->save();
$account = $this
->drupalCreateUser([
'administer entity_test_enhanced',
]);
$this
->drupalLogin($account);
}
public function testAddPage() {
$this
->drupalGet('/entity_test_enhanced/add');
$this
->assertSession()
->addressEquals('/entity_test_enhanced/add/first');
EnhancedEntityBundle::create([
'id' => 'second',
'label' => 'Second',
'description' => 'The <b>second</b> bundle',
])
->save();
$this
->drupalGet('/entity_test_enhanced/add');
$assert = $this
->assertSession();
$assert
->addressEquals('/entity_test_enhanced/add');
$assert
->statusCodeEquals(200);
$assert
->elementTextContains('css', '.page-title', 'Add entity test with enhancements');
$assert
->responseContains('The first bundle');
$assert
->responseContains('The <b>second</b> bundle');
$link = $this
->getSession()
->getPage()
->findLink('First');
$this
->assertEquals('/entity_test_enhanced/add/first', $link
->getAttribute('href'));
$link = $this
->getSession()
->getPage()
->findLink('Second');
$this
->assertEquals('/entity_test_enhanced/add/second', $link
->getAttribute('href'));
}
public function testAddForm() {
$this
->drupalGet('/entity_test_enhanced/add/first');
$assert = $this
->assertSession();
$assert
->elementTextContains('css', '.page-title', 'Add entity test with enhancements');
$assert
->elementExists('css', 'form.entity-test-enhanced-first-add-form');
EnhancedEntityBundle::create([
'id' => 'second',
'label' => 'Second',
'description' => 'The <b>second</b> bundle',
])
->save();
$this
->drupalGet('/entity_test_enhanced/add/first');
$this
->assertSession()
->elementTextContains('css', '.page-title', 'Add First');
}
}
Classes
Name |
Description |
CreateUITest |
Tests the entity creation UI provided by EntityCreateController. |