Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/node/tests/src/Functional/NodeAccessLanguageTest.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\language\Entity\ConfigurableLanguage; | 7 use Drupal\language\Entity\ConfigurableLanguage; |
7 use Drupal\node\Entity\NodeType; | 8 use Drupal\node\Entity\NodeType; |
8 use Drupal\user\Entity\User; | 9 use Drupal\user\Entity\User; |
9 | 10 |
199 'private' => FALSE, | 200 'private' => FALSE, |
200 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, | 201 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, |
201 ]); | 202 ]); |
202 $this->assertTrue($node_no_language->language()->getId() == LanguageInterface::LANGCODE_NOT_SPECIFIED, 'Node created with not specified language.'); | 203 $this->assertTrue($node_no_language->language()->getId() == LanguageInterface::LANGCODE_NOT_SPECIFIED, 'Node created with not specified language.'); |
203 | 204 |
205 $connection = Database::getConnection(); | |
204 // Query the nodes table as the web user with the node access tag and no | 206 // Query the nodes table as the web user with the node access tag and no |
205 // specific langcode. | 207 // specific langcode. |
206 $select = db_select('node', 'n') | 208 $select = $connection->select('node', 'n') |
207 ->fields('n', ['nid']) | 209 ->fields('n', ['nid']) |
208 ->addMetaData('account', $web_user) | 210 ->addMetaData('account', $web_user) |
209 ->addTag('node_access'); | 211 ->addTag('node_access'); |
210 $nids = $select->execute()->fetchAllAssoc('nid'); | 212 $nids = $select->execute()->fetchAllAssoc('nid'); |
211 | 213 |
215 $this->assertTrue(array_key_exists($node_public->id(), $nids), 'Returned node ID is public node.'); | 217 $this->assertTrue(array_key_exists($node_public->id(), $nids), 'Returned node ID is public node.'); |
216 $this->assertTrue(array_key_exists($node_no_language->id(), $nids), 'Returned node ID is no language node.'); | 218 $this->assertTrue(array_key_exists($node_no_language->id(), $nids), 'Returned node ID is no language node.'); |
217 | 219 |
218 // Query the nodes table as the web user with the node access tag and | 220 // Query the nodes table as the web user with the node access tag and |
219 // langcode de. | 221 // langcode de. |
220 $select = db_select('node', 'n') | 222 $select = $connection->select('node', 'n') |
221 ->fields('n', ['nid']) | 223 ->fields('n', ['nid']) |
222 ->addMetaData('account', $web_user) | 224 ->addMetaData('account', $web_user) |
223 ->addMetaData('langcode', 'de') | 225 ->addMetaData('langcode', 'de') |
224 ->addTag('node_access'); | 226 ->addTag('node_access'); |
225 $nids = $select->execute()->fetchAllAssoc('nid'); | 227 $nids = $select->execute()->fetchAllAssoc('nid'); |
227 // Because no nodes are created in German, no nodes are returned. | 229 // Because no nodes are created in German, no nodes are returned. |
228 $this->assertTrue(empty($nids), 'db_select() returns an empty result.'); | 230 $this->assertTrue(empty($nids), 'db_select() returns an empty result.'); |
229 | 231 |
230 // Query the nodes table as admin user (full access) with the node access | 232 // Query the nodes table as admin user (full access) with the node access |
231 // tag and no specific langcode. | 233 // tag and no specific langcode. |
232 $select = db_select('node', 'n') | 234 $select = $connection->select('node', 'n') |
233 ->fields('n', ['nid']) | 235 ->fields('n', ['nid']) |
234 ->addMetaData('account', $admin_user) | 236 ->addMetaData('account', $admin_user) |
235 ->addTag('node_access'); | 237 ->addTag('node_access'); |
236 $nids = $select->execute()->fetchAllAssoc('nid'); | 238 $nids = $select->execute()->fetchAllAssoc('nid'); |
237 | 239 |
238 // All nodes are returned. | 240 // All nodes are returned. |
239 $this->assertEqual(count($nids), 3, 'db_select() returns all three nodes.'); | 241 $this->assertEqual(count($nids), 3, 'db_select() returns all three nodes.'); |
240 | 242 |
241 // Query the nodes table as admin user (full access) with the node access | 243 // Query the nodes table as admin user (full access) with the node access |
242 // tag and langcode de. | 244 // tag and langcode de. |
243 $select = db_select('node', 'n') | 245 $select = $connection->select('node', 'n') |
244 ->fields('n', ['nid']) | 246 ->fields('n', ['nid']) |
245 ->addMetaData('account', $admin_user) | 247 ->addMetaData('account', $admin_user) |
246 ->addMetaData('langcode', 'de') | 248 ->addMetaData('langcode', 'de') |
247 ->addTag('node_access'); | 249 ->addTag('node_access'); |
248 $nids = $select->execute()->fetchAllAssoc('nid'); | 250 $nids = $select->execute()->fetchAllAssoc('nid'); |