comparison core/modules/node/tests/src/Kernel/NodeFieldAccessTest.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 4c8ae668cc8c
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
1 <?php 1 <?php
2 2
3 namespace Drupal\Tests\node\Kernel; 3 namespace Drupal\Tests\node\Kernel;
4 4
5 use Drupal\Component\Utility\SafeMarkup; 5 use Drupal\Component\Render\FormattableMarkup;
6 use Drupal\KernelTests\Core\Entity\EntityKernelTestBase; 6 use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
7 use Drupal\node\Entity\Node; 7 use Drupal\node\Entity\Node;
8 use Drupal\node\Entity\NodeType; 8 use Drupal\node\Entity\NodeType;
9 9
10 /** 10 /**
99 foreach ($this->administrativeFields as $field) { 99 foreach ($this->administrativeFields as $field) {
100 100
101 // Checks on view operations. 101 // Checks on view operations.
102 foreach ($test_users as $account) { 102 foreach ($test_users as $account) {
103 $may_view = $node1->{$field}->access('view', $account); 103 $may_view = $node1->{$field}->access('view', $account);
104 $this->assertTrue($may_view, SafeMarkup::format('Any user may view the field @name.', ['@name' => $field])); 104 $this->assertTrue($may_view, new FormattableMarkup('Any user may view the field @name.', ['@name' => $field]));
105 } 105 }
106 106
107 // Checks on edit operations. 107 // Checks on edit operations.
108 $may_update = $node1->{$field}->access('edit', $page_creator_user); 108 $may_update = $node1->{$field}->access('edit', $page_creator_user);
109 $this->assertFalse($may_update, SafeMarkup::format('Users with permission "edit own page content" is not allowed to the field @name.', ['@name' => $field])); 109 $this->assertFalse($may_update, new FormattableMarkup('Users with permission "edit own page content" is not allowed to the field @name.', ['@name' => $field]));
110 $may_update = $node2->{$field}->access('edit', $page_creator_user); 110 $may_update = $node2->{$field}->access('edit', $page_creator_user);
111 $this->assertFalse($may_update, SafeMarkup::format('Users with permission "edit own page content" is not allowed to the field @name.', ['@name' => $field])); 111 $this->assertFalse($may_update, new FormattableMarkup('Users with permission "edit own page content" is not allowed to the field @name.', ['@name' => $field]));
112 $may_update = $node2->{$field}->access('edit', $page_manager_user); 112 $may_update = $node2->{$field}->access('edit', $page_manager_user);
113 $this->assertFalse($may_update, SafeMarkup::format('Users with permission "edit any page content" is not allowed to the field @name.', ['@name' => $field])); 113 $this->assertFalse($may_update, new FormattableMarkup('Users with permission "edit any page content" is not allowed to the field @name.', ['@name' => $field]));
114 $may_update = $node1->{$field}->access('edit', $page_manager_user); 114 $may_update = $node1->{$field}->access('edit', $page_manager_user);
115 $this->assertFalse($may_update, SafeMarkup::format('Users with permission "edit any page content" is not allowed to the field @name.', ['@name' => $field])); 115 $this->assertFalse($may_update, new FormattableMarkup('Users with permission "edit any page content" is not allowed to the field @name.', ['@name' => $field]));
116 $may_update = $node2->{$field}->access('edit', $page_unrelated_user); 116 $may_update = $node2->{$field}->access('edit', $page_unrelated_user);
117 $this->assertFalse($may_update, SafeMarkup::format('Users not having permission "edit any page content" is not allowed to the field @name.', ['@name' => $field])); 117 $this->assertFalse($may_update, new FormattableMarkup('Users not having permission "edit any page content" is not allowed to the field @name.', ['@name' => $field]));
118 $may_update = $node1->{$field}->access('edit', $content_admin_user) && $node3->status->access('edit', $content_admin_user); 118 $may_update = $node1->{$field}->access('edit', $content_admin_user) && $node3->status->access('edit', $content_admin_user);
119 $this->assertTrue($may_update, SafeMarkup::format('Users with permission "administer nodes" may edit @name fields on all nodes.', ['@name' => $field])); 119 $this->assertTrue($may_update, new FormattableMarkup('Users with permission "administer nodes" may edit @name fields on all nodes.', ['@name' => $field]));
120 } 120 }
121 121
122 foreach ($this->readOnlyFields as $field) { 122 foreach ($this->readOnlyFields as $field) {
123 // Check view operation. 123 // Check view operation.
124 foreach ($test_users as $account) { 124 foreach ($test_users as $account) {
125 $may_view = $node1->{$field}->access('view', $account); 125 $may_view = $node1->{$field}->access('view', $account);
126 $this->assertTrue($may_view, SafeMarkup::format('Any user may view the field @name.', ['@name' => $field])); 126 $this->assertTrue($may_view, new FormattableMarkup('Any user may view the field @name.', ['@name' => $field]));
127 } 127 }
128 128
129 // Check edit operation. 129 // Check edit operation.
130 foreach ($test_users as $account) { 130 foreach ($test_users as $account) {
131 $may_view = $node1->{$field}->access('edit', $account); 131 $may_view = $node1->{$field}->access('edit', $account);
132 $this->assertFalse($may_view, SafeMarkup::format('No user is not allowed to edit the field @name.', ['@name' => $field])); 132 $this->assertFalse($may_view, new FormattableMarkup('No user is not allowed to edit the field @name.', ['@name' => $field]));
133 } 133 }
134 } 134 }
135 135
136 // Check the revision_log field on node 1 which has revisions disabled. 136 // Check the revision_log field on node 1 which has revisions disabled.
137 $may_update = $node1->revision_log->access('edit', $content_admin_user); 137 $may_update = $node1->revision_log->access('edit', $content_admin_user);