View source
<?php
namespace Drupal\Tests\acquia_contenthub\Functional;
use Drupal\Component\Serialization\Json;
use Drupal\field_permissions\Plugin\FieldPermissionTypeInterface;
class FieldPermissionsNodeTest extends ContentHubTestBase {
protected $adminUserPermissions = [
'bypass node access',
'administer acquia content hub',
'administer content types',
'access administration pages',
'administer node fields',
'administer field permissions',
'access private fields',
];
protected $adminRole;
public static $modules = [
'node',
'acquia_contenthub',
'field',
'field_ui',
'user',
'field_permissions',
];
public function testFieldPermissions() {
$this->adminRole = $this
->createAdminRole('administrator', 'Administrator');
$this
->drupalLogin($this->adminUser);
$entity = $this
->drupalCreateNode([
'type' => 'article',
'title' => 'Test Title',
'body' => [
[
'value' => 'Test Body',
'format' => filter_default_format(),
],
],
]);
$this
->configureContentHubContentTypes('node', [
'article',
]);
$output = $this
->drupalGetCdf('acquia-contenthub-cdf/' . $entity
->getEntityTypeId() . '/' . $entity
->id(), [
'query' => [
'include_references' => 'true',
],
]);
$this
->assertResponse(200);
$this
->assertEqual($output['entities']['0']['uuid'], $entity
->uuid());
$this
->assertEqual($output['entities']['0']['attributes']['title']['value']['en'], 'Test Title');
$json_body = $output['entities']['0']['attributes']['body']['value']['en'][0];
$body = Json::decode($json_body);
$this
->assertEqual($body['value'], 'Test Body');
$this
->drupalGet('admin/structure/types/manage/article/fields/node.article.body');
$this
->assertResponse(200);
$this
->assertText('Field visibility and permissions');
$perm = FieldPermissionTypeInterface::ACCESS_PRIVATE;
$edit = [
'type' => $perm,
];
$this
->drupalPostForm(NULL, $edit, $this
->t('Save settings'));
$this
->assertResponse(200);
$this
->assertText('Saved Body configuration');
$this
->drupalGet('admin/structure/types/manage/article/fields/node.article.body');
$this
->assertResponse(200);
$this
->assertFieldChecked('edit-type-private', 'Field visibility and permissions should be Private.');
drupal_flush_all_caches();
$output = $this
->drupalGetCdf('acquia-contenthub-cdf/' . $entity
->getEntityTypeId() . '/' . $entity
->id(), [
'query' => [
'include_references' => 'true',
],
]);
$this
->assertResponse(200);
$this
->assertEqual($output['entities']['0']['uuid'], $entity
->uuid());
$this
->assertEqual($output['entities']['0']['attributes']['title']['value']['en'], 'Test Title');
$this
->assertTrue(empty($output['entities']['0']['attributes']['body']), 'Body Field not present in CDF.');
$this
->setRoleFor($this->adminRole);
$output = $this
->drupalGetCdf('acquia-contenthub-cdf/' . $entity
->getEntityTypeId() . '/' . $entity
->id(), [
'query' => [
'include_references' => 'true',
],
]);
$this
->assertResponse(200);
$this
->assertEqual($output['entities']['0']['uuid'], $entity
->uuid());
$this
->assertEqual($output['entities']['0']['attributes']['title']['value']['en'], 'Test Title');
$json_body = $output['entities']['0']['attributes']['body']['value']['en'][0];
$body = Json::decode($json_body);
$this
->assertEqual($body['value'], 'Test Body');
}
}