comparison core/modules/node/tests/src/Functional/NodeAccessLanguageAwareCombinationTest.php @ 18:af1871eacc83

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:33:08 +0100
parents 129ea1e6d783
children
comparison
equal deleted inserted replaced
17:129ea1e6d783 18:af1871eacc83
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\node\Entity\NodeType; 9 use Drupal\node\Entity\NodeType;
9 use Drupal\user\Entity\User; 10 use Drupal\user\Entity\User;
249 // No access for all languages as the non language aware node access module 250 // No access for all languages as the non language aware node access module
250 // denies access. 251 // denies access.
251 $this->assertNodeAccess($expected_node_access_no_access, $this->nodes['private_no_language_public'], $this->webUser); 252 $this->assertNodeAccess($expected_node_access_no_access, $this->nodes['private_no_language_public'], $this->webUser);
252 253
253 // Query the node table with the node access tag in several languages. 254 // Query the node table with the node access tag in several languages.
254 255 $connection = Database::getConnection();
255 // Query with no language specified. The fallback (hu or und) will be used. 256 // Query with no language specified. The fallback (hu or und) will be used.
256 $select = db_select('node', 'n') 257 $select = $connection->select('node', 'n')
257 ->fields('n', ['nid']) 258 ->fields('n', ['nid'])
258 ->addMetaData('account', $this->webUser) 259 ->addMetaData('account', $this->webUser)
259 ->addTag('node_access'); 260 ->addTag('node_access');
260 $nids = $select->execute()->fetchAllAssoc('nid'); 261 $nids = $select->execute()->fetchAllAssoc('nid');
261 262
266 $this->assertTrue(array_key_exists($this->nodes['public_ca_private']->id(), $nids), 'Returned node ID is Hungarian public only node.'); 267 $this->assertTrue(array_key_exists($this->nodes['public_ca_private']->id(), $nids), 'Returned node ID is Hungarian public only node.');
267 $this->assertTrue(array_key_exists($this->nodes['private_both_public']->id(), $nids), 'Returned node ID is both public non-language-aware private only node.'); 268 $this->assertTrue(array_key_exists($this->nodes['private_both_public']->id(), $nids), 'Returned node ID is both public non-language-aware private only node.');
268 $this->assertTrue(array_key_exists($this->nodes['public_no_language_public']->id(), $nids), 'Returned node ID is no language public node.'); 269 $this->assertTrue(array_key_exists($this->nodes['public_no_language_public']->id(), $nids), 'Returned node ID is no language public node.');
269 270
270 // Query with Hungarian (hu) specified. 271 // Query with Hungarian (hu) specified.
271 $select = db_select('node', 'n') 272 $select = $connection->select('node', 'n')
272 ->fields('n', ['nid']) 273 ->fields('n', ['nid'])
273 ->addMetaData('account', $this->webUser) 274 ->addMetaData('account', $this->webUser)
274 ->addMetaData('langcode', 'hu') 275 ->addMetaData('langcode', 'hu')
275 ->addTag('node_access'); 276 ->addTag('node_access');
276 $nids = $select->execute()->fetchAllAssoc('nid'); 277 $nids = $select->execute()->fetchAllAssoc('nid');
280 $this->assertTrue(array_key_exists($this->nodes['public_both_public']->id(), $nids), 'Returned node ID is both public node.'); 281 $this->assertTrue(array_key_exists($this->nodes['public_both_public']->id(), $nids), 'Returned node ID is both public node.');
281 $this->assertTrue(array_key_exists($this->nodes['public_ca_private']->id(), $nids), 'Returned node ID is Hungarian public only node.'); 282 $this->assertTrue(array_key_exists($this->nodes['public_ca_private']->id(), $nids), 'Returned node ID is Hungarian public only node.');
282 $this->assertTrue(array_key_exists($this->nodes['private_both_public']->id(), $nids), 'Returned node ID is both public non-language-aware private only node.'); 283 $this->assertTrue(array_key_exists($this->nodes['private_both_public']->id(), $nids), 'Returned node ID is both public non-language-aware private only node.');
283 284
284 // Query with Catalan (ca) specified. 285 // Query with Catalan (ca) specified.
285 $select = db_select('node', 'n') 286 $select = $connection->select('node', 'n')
286 ->fields('n', ['nid']) 287 ->fields('n', ['nid'])
287 ->addMetaData('account', $this->webUser) 288 ->addMetaData('account', $this->webUser)
288 ->addMetaData('langcode', 'ca') 289 ->addMetaData('langcode', 'ca')
289 ->addTag('node_access'); 290 ->addTag('node_access');
290 $nids = $select->execute()->fetchAllAssoc('nid'); 291 $nids = $select->execute()->fetchAllAssoc('nid');
294 $this->assertTrue(array_key_exists($this->nodes['public_both_public']->id(), $nids), 'Returned node ID is both public node.'); 295 $this->assertTrue(array_key_exists($this->nodes['public_both_public']->id(), $nids), 'Returned node ID is both public node.');
295 $this->assertTrue(array_key_exists($this->nodes['public_hu_private']->id(), $nids), 'Returned node ID is Catalan public only node.'); 296 $this->assertTrue(array_key_exists($this->nodes['public_hu_private']->id(), $nids), 'Returned node ID is Catalan public only node.');
296 $this->assertTrue(array_key_exists($this->nodes['private_both_public']->id(), $nids), 'Returned node ID is both public non-language-aware private only node.'); 297 $this->assertTrue(array_key_exists($this->nodes['private_both_public']->id(), $nids), 'Returned node ID is both public non-language-aware private only node.');
297 298
298 // Query with German (de) specified. 299 // Query with German (de) specified.
299 $select = db_select('node', 'n') 300 $select = $connection->select('node', 'n')
300 ->fields('n', ['nid']) 301 ->fields('n', ['nid'])
301 ->addMetaData('account', $this->webUser) 302 ->addMetaData('account', $this->webUser)
302 ->addMetaData('langcode', 'de') 303 ->addMetaData('langcode', 'de')
303 ->addTag('node_access'); 304 ->addTag('node_access');
304 $nids = $select->execute()->fetchAllAssoc('nid'); 305 $nids = $select->execute()->fetchAllAssoc('nid');
306 // There are no nodes with German translations, so no results are returned. 307 // There are no nodes with German translations, so no results are returned.
307 $this->assertTrue(empty($nids), 'db_select() returns an empty result.'); 308 $this->assertTrue(empty($nids), 'db_select() returns an empty result.');
308 309
309 // Query the nodes table as admin user (full access) with the node access 310 // Query the nodes table as admin user (full access) with the node access
310 // tag and no specific langcode. 311 // tag and no specific langcode.
311 $select = db_select('node', 'n') 312 $select = $connection->select('node', 'n')
312 ->fields('n', ['nid']) 313 ->fields('n', ['nid'])
313 ->addMetaData('account', $this->adminUser) 314 ->addMetaData('account', $this->adminUser)
314 ->addTag('node_access'); 315 ->addTag('node_access');
315 $nids = $select->execute()->fetchAllAssoc('nid'); 316 $nids = $select->execute()->fetchAllAssoc('nid');
316 317
317 // All nodes are returned. 318 // All nodes are returned.
318 $this->assertEqual(count($nids), 10, 'db_select() returns all nodes.'); 319 $this->assertEqual(count($nids), 10, 'db_select() returns all nodes.');
319 320
320 // Query the nodes table as admin user (full access) with the node access 321 // Query the nodes table as admin user (full access) with the node access
321 // tag and langcode de. 322 // tag and langcode de.
322 $select = db_select('node', 'n') 323 $select = $connection->select('node', 'n')
323 ->fields('n', ['nid']) 324 ->fields('n', ['nid'])
324 ->addMetaData('account', $this->adminUser) 325 ->addMetaData('account', $this->adminUser)
325 ->addMetaData('langcode', 'de') 326 ->addMetaData('langcode', 'de')
326 ->addTag('node_access'); 327 ->addTag('node_access');
327 $nids = $select->execute()->fetchAllAssoc('nid'); 328 $nids = $select->execute()->fetchAllAssoc('nid');