View source
<?php
namespace Drupal\Tests\eck\Functional;
use Drupal\Core\Url;
class DynamicBaseFieldTest extends FunctionalTestBase {
public function testBaseFieldCRUD() {
$type = $this
->createEntityType([
'uid',
'created',
'changed',
'status',
]);
$bundle = $this
->createEntityBundle($type['id']);
$route_args = [
'eck_entity_type' => $type['id'],
'eck_entity_bundle' => $bundle['type'],
];
$this
->drupalGet(Url::fromRoute('eck.entity.add', $route_args));
$this
->assertSession()
->fieldExists('uid[0][target_id]');
$this
->assertSession()
->fieldExists('created[0][value][date]');
$this
->assertSession()
->fieldExists('status[value]');
$edit = [
'title' => TRUE,
];
$this
->drupalGet(Url::fromRoute('entity.eck_entity_type.edit_form', [
'eck_entity_type' => $type['id'],
]));
$this
->submitForm($edit, 'Update ' . $type['label']);
$this
->assertSession()
->responseContains((string) $this
->t('Entity type %label has been updated.', [
'%label' => $type['label'],
]));
$this
->drupalGet(Url::fromRoute('eck.entity.add', $route_args));
$this
->assertSession()
->fieldExists('title[0][value]');
$edit = [
'created' => FALSE,
];
$this
->drupalGet(Url::fromRoute('entity.eck_entity_type.edit_form', [
'eck_entity_type' => $type['id'],
]));
$this
->submitForm($edit, 'Update ' . $type['label']);
$this
->assertSession()
->responseContains((string) $this
->t('Entity type %label has been updated.', [
'%label' => $type['label'],
]));
$this
->drupalGet(Url::fromRoute('eck.entity.add', $route_args));
$this
->assertSession()
->fieldNotExists('created[0][value][date]');
$edit = [
'status' => FALSE,
];
$this
->drupalGet(Url::fromRoute('entity.eck_entity_type.edit_form', [
'eck_entity_type' => $type['id'],
]));
$this
->submitForm($edit, t('Update @type', [
'@type' => $type['label'],
]));
$this
->assertSession()
->responseContains((string) t('Entity type %label has been updated.', [
'%label' => $type['label'],
]));
$this
->drupalGet(Url::fromRoute('eck.entity.add', $route_args));
$this
->assertSession()
->fieldNotExists('status[value]');
$edit = [
'title[0][value]' => $this
->randomMachineName(),
];
$this
->drupalGet(Url::fromRoute('eck.entity.add', $route_args));
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->responseContains($edit['title[0][value]']);
$this
->drupalGet(Url::fromRoute('entity.eck_entity_type.edit_form', [
'eck_entity_type' => $type['id'],
]));
$fields = $this
->xpath('//input[@type="checkbox"][@disabled]');
$this
->assertTrue(\count($fields) > 0);
}
public function testEntityEntityCreation() {
$type = $this
->createEntityType();
$bundle = $this
->createEntityBundle($type['id']);
$edit = [
'title[0][value]' => $this
->randomMachineName(),
];
$route_args = [
'eck_entity_type' => $type['id'],
'eck_entity_bundle' => $bundle['type'],
];
$this
->drupalGet(Url::fromRoute('eck.entity.add', $route_args));
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->responseContains($edit['title[0][value]']);
}
public function testTitlesDescriptionOverrides() {
$entity_type = $this
->createEntityType();
$bundle = $this
->createEntityBundle($entity_type['id']);
$new_eck_entity_page = Url::fromRoute('eck.entity.add', [
'eck_entity_type' => $entity_type['id'],
'eck_entity_bundle' => $bundle['type'],
]);
$this
->drupalGet($new_eck_entity_page);
$this
->assertSession()
->pageTextContains('Title');
$this
->assertSession()
->pageTextContains('The title of the entity.');
$edit['title_title_override'] = 'First name';
$edit['title_description_override'] = 'Please enter your first name.';
$this
->drupalGet(Url::fromRoute("entity.{$entity_type['id']}_type.edit_form", [
"{$entity_type['id']}_type" => $bundle['type'],
]));
$this
->submitForm($edit, 'Save bundle');
$this
->drupalGet($new_eck_entity_page);
$this
->assertSession()
->pageTextContains('First name');
$this
->assertSession()
->pageTextContains('Please enter your first name.');
}
}