View source
<?php
namespace Drupal\Tests\eck\Functional;
use Drupal\Core\Url;
class UITest extends FunctionalTestBase {
protected static $modules = [
'block',
];
public function setUp() {
parent::setUp();
$this
->drupalPlaceBlock('local_actions_block');
}
public function testAddEntityTypeActions() {
$this
->drupalGet(Url::fromRoute('eck.entity_type.list'));
$this
->assertSession()
->linkExists($this
->t('Add entity type'));
}
public function testListingTitles() {
$type = $this
->createEntityType();
$bundle = $this
->createEntityBundle($type['id']);
$this
->drupalPlaceBlock('page_title_block');
$this
->drupalGet(Url::fromRoute('eck.entity_type.list'));
$this
->assertSession()
->responseContains("ECK Entity Types");
$this
->drupalGet(Url::fromRoute("eck.entity.{$type['id']}_type.list"));
$this
->assertSession()
->responseContains((string) $this
->t('%type bundles', [
'%type' => ucfirst($type['label']),
]));
$this
->drupalGet(Url::fromRoute("eck.entity.{$type['id']}_type.add"));
$this
->assertSession()
->responseContains((string) $this
->t('Add %type bundle', [
'%type' => $type['label'],
]));
$this
->drupalGet(Url::fromRoute("entity.{$type['id']}_type.edit_form", [
"{$type['id']}_type" => $bundle['type'],
]));
$this
->assertSession()
->responseContains((string) $this
->t('Edit %type bundle', [
'%type' => $type['label'],
]));
$this
->drupalGet(Url::fromRoute("entity.{$type['id']}_type.delete_form", [
"{$type['id']}_type" => $bundle['type'],
]));
$this
->assertSession()
->responseContains((string) $this
->t('Are you sure you want to delete the entity bundle %type?', [
'%type' => $bundle['name'],
]));
$this
->drupalGet(Url::fromRoute("eck.entity.{$type['id']}.list"));
$this
->assertSession()
->responseContains((string) $this
->t('%type content', [
'%type' => ucfirst($type['label']),
]));
}
public function testEntityTypeListingOperations() {
$entityTypeManager = \Drupal::entityTypeManager();
$entity = $entityTypeManager
->getDefinition('eck_entity_type');
$this
->drupalGet(Url::fromRoute('eck.entity_type.list'));
$noEntitiesYetText = (string) $this
->t('There are no @label entities yet.', [
'@label' => strtolower($entity
->getLabel()),
]);
$this
->assertSession()
->responseContains($noEntitiesYetText);
$entityType = $this
->createEntityType();
$this
->drupalGet(Url::fromRoute('eck.entity_type.list'));
$this
->assertSession()
->responseNotContains($noEntitiesYetText);
foreach ([
'Add content',
'Content list',
] as $option) {
$this
->assertSession()
->linkNotExists($this
->t($option), $this
->t('No %option option is shown when there are no bundles.', [
'%option' => $this
->t($option),
]));
}
$this
->assertSession()
->linkExists($this
->t('Add bundle'));
$this
->assertSession()
->linkExists($this
->t('Bundle list'));
$this
->assertSession()
->linkExists($this
->t('Edit'));
$this
->assertSession()
->linkExists($this
->t('Delete'));
$bundles[] = $this
->createEntityBundle($entityType['id'], $entityType['id']);
$this
->drupalGet(Url::fromRoute('eck.entity_type.list'));
$this
->assertSession()
->responseNotContains($noEntitiesYetText);
$this
->assertSession()
->linkNotExists($this
->t('Content list'), $this
->t('No %option option is shown when there is no content.', [
'%option' => $this
->t('Content list'),
]));
$this
->assertSession()
->linkExists($this
->t('Add content'));
$this
->assertSession()
->linkExists($this
->t('Bundle list'));
$this
->assertSession()
->linkExists($this
->t('Edit'));
$this
->assertSession()
->linkExists($this
->t('Delete'));
$this
->clickLink($this
->t('Add content'));
$this
->submitForm([
'title[0][value]' => $this
->randomMachineName(),
], 'Save');
$this
->drupalGet(Url::fromRoute('eck.entity_type.list'));
$this
->assertSession()
->responseNotContains($noEntitiesYetText);
$this
->assertSession()
->linkExists($this
->t('Content list'));
$this
->assertSession()
->linkExists($this
->t('Add content'));
$this
->assertSession()
->linkExists($this
->t('Bundle list'));
$this
->assertSession()
->linkExists($this
->t('Edit'));
$this
->assertSession()
->linkExists($this
->t('Delete'));
$bundles[] = $this
->createEntityBundle($entityType['id']);
$this
->drupalGet(Url::fromRoute('eck.entity_type.list'));
$this
->clickLink($this
->t('Add content'));
foreach ($bundles as $bundle) {
$this
->assertSession()
->responseContains($bundle['name']);
}
}
public function testAddEntityActions() {
$entityType = $this
->createEntityType();
$this
->drupalGet(Url::fromRoute("eck.entity.{$entityType['id']}.list"));
$this
->assertSession()
->responseNotContains("Add {$entityType['label']}");
$bundles[] = $this
->createEntityBundle($entityType['id']);
$this
->drupalGet(Url::fromRoute("eck.entity.{$entityType['id']}.list"));
$this
->clickLink("Add {$entityType['label']}");
$this
->assertSession()
->fieldExists('title[0][value]');
$bundles[] = $this
->createEntityBundle($entityType['id']);
$this
->drupalGet(Url::fromRoute("eck.entity.{$entityType['id']}.list"));
$this
->clickLink("Add {$entityType['label']}");
foreach ($bundles as $bundle) {
$this
->assertSession()
->responseContains($bundle['name']);
}
$route = "entity.{$entityType['id']}_type.delete_form";
$routeArguments = [
"{$entityType['id']}_type" => $bundles[1]['type'],
];
$this
->drupalGet(Url::fromRoute($route, $routeArguments));
$this
->submitForm([], 'Delete');
$this
->drupalGet(Url::fromRoute("eck.entity.{$entityType['id']}.list"));
$this
->clickLink("Add {$entityType['label']}");
$this
->assertSession()
->fieldExists('title[0][value]');
}
public function testAdministrationEckThemeSettings() {
$admin_user = $this
->drupalCreateUser([
'administer eck entity types',
'administer eck entities',
'administer eck entity bundles',
'access administration pages',
'view the administration theme',
'administer themes',
]);
$this
->drupalLogin($admin_user);
$type = $this
->createEntityType();
$bundle = $this
->createEntityBundle($type['id']);
$this
->drupalGet(Url::fromRoute('eck.entity.add', [
'eck_entity_type' => $type['id'],
'eck_entity_bundle' => $bundle['type'],
]));
$this
->assertSession()
->responseContains('core/themes/classy');
$this->container
->get('theme_installer')
->install([
'seven',
]);
$edit = [
'admin_theme' => 'seven',
'eck_use_admin_theme' => TRUE,
];
$this
->drupalGet('admin/appearance');
$this
->submitForm($edit, 'Save configuration');
$this
->drupalGet(Url::fromRoute('eck.entity.add', [
'eck_entity_type' => $type['id'],
'eck_entity_bundle' => $bundle['type'],
]));
$this
->assertSession()
->responseContains('core/themes/seven');
}
}