Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/node/tests/src/Functional/NodeAccessLanguageAwareTest.php @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | c75dbcec494b |
children |
comparison
equal
deleted
inserted
replaced
4:a9cd425dd02b | 5:12f9dff5fda9 |
---|---|
1 <?php | 1 <?php |
2 | 2 |
3 namespace Drupal\Tests\node\Functional; | 3 namespace Drupal\Tests\node\Functional; |
4 | 4 |
5 use Drupal\Core\Database\Database; | |
5 use Drupal\Core\Language\LanguageInterface; | 6 use Drupal\Core\Language\LanguageInterface; |
6 use Drupal\field\Entity\FieldConfig; | 7 use Drupal\field\Entity\FieldConfig; |
7 use Drupal\language\Entity\ConfigurableLanguage; | 8 use Drupal\language\Entity\ConfigurableLanguage; |
8 use Drupal\user\Entity\User; | 9 use Drupal\user\Entity\User; |
9 use Drupal\field\Entity\FieldStorageConfig; | 10 use Drupal\field\Entity\FieldStorageConfig; |
190 // When no language is specified for a public node, access should be | 191 // When no language is specified for a public node, access should be |
191 // granted. | 192 // granted. |
192 $this->assertNodeAccess($expected_node_access, $this->nodes['no_language_public'], $this->webUser); | 193 $this->assertNodeAccess($expected_node_access, $this->nodes['no_language_public'], $this->webUser); |
193 | 194 |
194 // Query the node table with the node access tag in several languages. | 195 // Query the node table with the node access tag in several languages. |
195 | 196 $connection = Database::getConnection(); |
196 // Query with no language specified. The fallback (hu) will be used. | 197 // Query with no language specified. The fallback (hu) will be used. |
197 $select = db_select('node', 'n') | 198 $select = $connection->select('node', 'n') |
198 ->fields('n', ['nid']) | 199 ->fields('n', ['nid']) |
199 ->addMetaData('account', $this->webUser) | 200 ->addMetaData('account', $this->webUser) |
200 ->addTag('node_access'); | 201 ->addTag('node_access'); |
201 $nids = $select->execute()->fetchAllAssoc('nid'); | 202 $nids = $select->execute()->fetchAllAssoc('nid'); |
202 | 203 |
208 $this->assertTrue(array_key_exists($this->nodes['both_public']->id(), $nids), 'The node with both translations public is returned.'); | 209 $this->assertTrue(array_key_exists($this->nodes['both_public']->id(), $nids), 'The node with both translations public is returned.'); |
209 $this->assertTrue(array_key_exists($this->nodes['ca_private']->id(), $nids), 'The node with only the Catalan translation private is returned.'); | 210 $this->assertTrue(array_key_exists($this->nodes['ca_private']->id(), $nids), 'The node with only the Catalan translation private is returned.'); |
210 $this->assertTrue(array_key_exists($this->nodes['no_language_public']->id(), $nids), 'The node with no language is returned.'); | 211 $this->assertTrue(array_key_exists($this->nodes['no_language_public']->id(), $nids), 'The node with no language is returned.'); |
211 | 212 |
212 // Query with Hungarian (hu) specified. | 213 // Query with Hungarian (hu) specified. |
213 $select = db_select('node', 'n') | 214 $select = $connection->select('node', 'n') |
214 ->fields('n', ['nid']) | 215 ->fields('n', ['nid']) |
215 ->addMetaData('account', $this->webUser) | 216 ->addMetaData('account', $this->webUser) |
216 ->addMetaData('langcode', 'hu') | 217 ->addMetaData('langcode', 'hu') |
217 ->addTag('node_access'); | 218 ->addTag('node_access'); |
218 $nids = $select->execute()->fetchAllAssoc('nid'); | 219 $nids = $select->execute()->fetchAllAssoc('nid'); |
222 $this->assertEqual(count($nids), 2, 'db_select() returns 2 nodes when the hu langcode is specified.'); | 223 $this->assertEqual(count($nids), 2, 'db_select() returns 2 nodes when the hu langcode is specified.'); |
223 $this->assertTrue(array_key_exists($this->nodes['both_public']->id(), $nids), 'The node with both translations public is returned.'); | 224 $this->assertTrue(array_key_exists($this->nodes['both_public']->id(), $nids), 'The node with both translations public is returned.'); |
224 $this->assertTrue(array_key_exists($this->nodes['ca_private']->id(), $nids), 'The node with only the Catalan translation private is returned.'); | 225 $this->assertTrue(array_key_exists($this->nodes['ca_private']->id(), $nids), 'The node with only the Catalan translation private is returned.'); |
225 | 226 |
226 // Query with Catalan (ca) specified. | 227 // Query with Catalan (ca) specified. |
227 $select = db_select('node', 'n') | 228 $select = $connection->select('node', 'n') |
228 ->fields('n', ['nid']) | 229 ->fields('n', ['nid']) |
229 ->addMetaData('account', $this->webUser) | 230 ->addMetaData('account', $this->webUser) |
230 ->addMetaData('langcode', 'ca') | 231 ->addMetaData('langcode', 'ca') |
231 ->addTag('node_access'); | 232 ->addTag('node_access'); |
232 $nids = $select->execute()->fetchAllAssoc('nid'); | 233 $nids = $select->execute()->fetchAllAssoc('nid'); |
236 $this->assertEqual(count($nids), 2, 'db_select() returns 2 nodes when the hu langcode is specified.'); | 237 $this->assertEqual(count($nids), 2, 'db_select() returns 2 nodes when the hu langcode is specified.'); |
237 $this->assertTrue(array_key_exists($this->nodes['both_public']->id(), $nids), 'The node with both translations public is returned.'); | 238 $this->assertTrue(array_key_exists($this->nodes['both_public']->id(), $nids), 'The node with both translations public is returned.'); |
238 $this->assertTrue(array_key_exists($this->nodes['hu_private']->id(), $nids), 'The node with only the Hungarian translation private is returned.'); | 239 $this->assertTrue(array_key_exists($this->nodes['hu_private']->id(), $nids), 'The node with only the Hungarian translation private is returned.'); |
239 | 240 |
240 // Query with German (de) specified. | 241 // Query with German (de) specified. |
241 $select = db_select('node', 'n') | 242 $select = $connection->select('node', 'n') |
242 ->fields('n', ['nid']) | 243 ->fields('n', ['nid']) |
243 ->addMetaData('account', $this->webUser) | 244 ->addMetaData('account', $this->webUser) |
244 ->addMetaData('langcode', 'de') | 245 ->addMetaData('langcode', 'de') |
245 ->addTag('node_access'); | 246 ->addTag('node_access'); |
246 $nids = $select->execute()->fetchAllAssoc('nid'); | 247 $nids = $select->execute()->fetchAllAssoc('nid'); |
248 // There are no nodes with German translations, so no results are returned. | 249 // There are no nodes with German translations, so no results are returned. |
249 $this->assertTrue(empty($nids), 'db_select() returns an empty result when the de langcode is specified.'); | 250 $this->assertTrue(empty($nids), 'db_select() returns an empty result when the de langcode is specified.'); |
250 | 251 |
251 // Query the nodes table as admin user (full access) with the node access | 252 // Query the nodes table as admin user (full access) with the node access |
252 // tag and no specific langcode. | 253 // tag and no specific langcode. |
253 $select = db_select('node', 'n') | 254 $select = $connection->select('node', 'n') |
254 ->fields('n', ['nid']) | 255 ->fields('n', ['nid']) |
255 ->addMetaData('account', $this->adminUser) | 256 ->addMetaData('account', $this->adminUser) |
256 ->addTag('node_access'); | 257 ->addTag('node_access'); |
257 $nids = $select->execute()->fetchAllAssoc('nid'); | 258 $nids = $select->execute()->fetchAllAssoc('nid'); |
258 | 259 |
259 // All nodes are returned. | 260 // All nodes are returned. |
260 $this->assertEqual(count($nids), 6, 'db_select() returns all nodes.'); | 261 $this->assertEqual(count($nids), 6, 'db_select() returns all nodes.'); |
261 | 262 |
262 // Query the nodes table as admin user (full access) with the node access | 263 // Query the nodes table as admin user (full access) with the node access |
263 // tag and langcode de. | 264 // tag and langcode de. |
264 $select = db_select('node', 'n') | 265 $select = $connection->select('node', 'n') |
265 ->fields('n', ['nid']) | 266 ->fields('n', ['nid']) |
266 ->addMetaData('account', $this->adminUser) | 267 ->addMetaData('account', $this->adminUser) |
267 ->addMetaData('langcode', 'de') | 268 ->addMetaData('langcode', 'de') |
268 ->addTag('node_access'); | 269 ->addTag('node_access'); |
269 $nids = $select->execute()->fetchAllAssoc('nid'); | 270 $nids = $select->execute()->fetchAllAssoc('nid'); |