public function FieldCollectionBasicTestCase::testBasicUI in Field collection 8
Same name and namespace in other branches
- 8.3 tests/src/Functional/FieldCollectionBasicTestCase.php \Drupal\Tests\field_collection\Functional\FieldCollectionBasicTestCase::testBasicUI()
Make sure the basic UI and access checks are working.
File
- tests/
src/ Functional/ FieldCollectionBasicTestCase.php, line 164
Class
- FieldCollectionBasicTestCase
- Test basics.
Namespace
Drupal\Tests\field_collection\FunctionalCode
public function testBasicUI() {
$node = $this
->drupalCreateNode([
'type' => 'article',
]);
// Login with new user that has no privileges.
$user = $this
->drupalCreateUser([
'access content',
]);
$this
->drupalLogin($user);
// Make sure access is denied.
$path = "field_collection_item/add/field_test_collection/node/{$node->id()}";
$this
->drupalGet($path);
$this
->assertText(t('Access denied'), 'Access has been denied.');
// Login with new user that has basic edit rights.
$user_privileged = $this
->drupalCreateUser([
'access content',
'edit any article content',
]);
$this
->drupalLogin($user_privileged);
// Test field collection item add form.
$this
->drupalGet('admin/structure/types/manage/article/display');
$this
->drupalGet("node/{$node->id()}");
$this
->assertLinkByHref($path, 0, 'Add link is shown.');
$this
->drupalGet($path);
$this
->assertText(t($this->inner_field_definition['label']), 'Add form is shown.');
$edit = [
"{$this->inner_field_name}[0][value]" => rand(),
];
$this
->drupalPostForm(NULL, $edit, t('Save'));
$this
->assertText(t('Successfully added a @field.', [
'@field' => $this->field_collection_name,
]), 'Field collection saved.');
$this
->assertText($edit["{$this->inner_field_name}[0][value]"], 'Added field value is shown.');
$field_collection_item = FieldCollectionItem::load(1);
// Test field collection item edit form.
$edit["{$this->inner_field_name}[0][value]"] = rand();
$this
->drupalPostForm('field_collection_item/1/edit', $edit, t('Save'));
$this
->assertText(t('Successfully edited @field.', [
'@field' => $field_collection_item
->label(),
]), 'Field collection saved.');
$this
->assertText($edit["{$this->inner_field_name}[0][value]"], 'Field collection has been edited.');
$this
->drupalGet('field_collection_item/1');
$this
->assertText($edit["{$this->inner_field_name}[0][value]"], 'Field collection can be viewed.');
}