diff --git a/core/modules/forum/lib/Drupal/forum/Tests/ForumNodeAccessTest.php b/core/modules/forum/lib/Drupal/forum/Tests/ForumNodeAccessTest.php index 99f8b25..5e7ff26 100644 --- a/core/modules/forum/lib/Drupal/forum/Tests/ForumNodeAccessTest.php +++ b/core/modules/forum/lib/Drupal/forum/Tests/ForumNodeAccessTest.php @@ -32,6 +32,7 @@ public static function getInfo() { function setUp() { parent::setUp(); node_access_rebuild(); + node_access_test_add_field(entity_load('node_type', 'forum')); \Drupal::state()->set('node_access_test.private', TRUE); } @@ -54,7 +55,7 @@ function testForumNodeAccess() { $edit = array( 'title[0][value]' => $private_node_title, 'body[0][value]' => $this->randomName(200), - 'private' => TRUE, + 'private[0][value]' => TRUE, ); $this->drupalPostForm('node/add/forum', $edit, t('Save'), array('query' => array('forum_id' => 1))); $private_node = $this->drupalGetNodeByTitle($private_node_title); diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeAccessBaseTableTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeAccessBaseTableTest.php index e78b5bc..722d602 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeAccessBaseTableTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeAccessBaseTableTest.php @@ -39,6 +39,8 @@ public static function getInfo() { public function setUp() { parent::setUp(); + node_access_test_add_field(entity_load('node_type', 'article')); + node_access_rebuild(); \Drupal::state()->set('node_access_test.private', TRUE); } @@ -75,7 +77,7 @@ function testNodeAccessBasic() { 'title[0][value]' => t('@private_public Article created by @user', array('@private_public' => $type, '@user' => $this->webUser->getUsername())), ); if ($is_private) { - $edit['private'] = TRUE; + $edit['private[0][value]'] = TRUE; $edit['body[0][value]'] = 'private node'; $edit['field_tags'] = 'private'; } @@ -85,14 +87,13 @@ function testNodeAccessBasic() { } $this->drupalPostForm('node/add/article', $edit, t('Save')); - $nid = db_query('SELECT nid FROM {node_field_data} WHERE title = :title', array(':title' => $edit['title[0][value]']))->fetchField(); - $private_status = db_query('SELECT private FROM {node_access_test} where nid = :nid', array(':nid' => $nid))->fetchField(); - $this->assertTrue($is_private == $private_status, 'The private status of the node was properly set in the node_access_test table.'); + $node = $this->drupalGetNodeByTitle($edit['title[0][value]']); + $this->assertEqual($is_private, (int)$node->private->value, 'The private status of the node was properly set in the node_access_test table.'); if ($is_private) { - $private_nodes[] = $nid; + $private_nodes[] = $node->id(); } - $titles[$nid] = $edit['title[0][value]']; - $this->nodesByUser[$this->webUser->id()][$nid] = $is_private; + $titles[$node->id()] = $edit['title[0][value]']; + $this->nodesByUser[$this->webUser->id()][$node->id()] = $is_private; } } $this->publicTid = db_query('SELECT tid FROM {taxonomy_term_data} WHERE name = :name', array(':name' => 'public'))->fetchField(); diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageAwareCombinationTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageAwareCombinationTest.php index 4ea9fe8..46fdbbb 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageAwareCombinationTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageAwareCombinationTest.php @@ -53,6 +53,8 @@ public static function getInfo() { public function setUp() { parent::setUp(); + node_access_test_add_field(entity_load('node_type', 'page')); + // Create the 'private' field, which allows the node to be marked as private // (restricted access) in a given translation. $field_private = entity_create('field_config', array( diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageTest.php index feeae45..1de38ec 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageTest.php @@ -32,6 +32,8 @@ public static function getInfo() { function setUp() { parent::setUp(); + node_access_test_add_field(entity_load('node_type', 'page')); + // After enabling a node access module, the access table has to be rebuild. node_access_rebuild(); diff --git a/core/modules/node/tests/modules/node_access_test/node_access_test.install b/core/modules/node/tests/modules/node_access_test/node_access_test.install deleted file mode 100644 index 6b3ef5d..0000000 --- a/core/modules/node/tests/modules/node_access_test/node_access_test.install +++ /dev/null @@ -1,42 +0,0 @@ - 'The base table for node_access_test.', - 'fields' => array( - 'nid' => array( - 'description' => 'The {node}.nid this record affects.', - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - ), - 'private' => array( - 'description' => 'Boolean indicating whether the node is private (visible to administrator) or not (visible to non-administrators).', - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - ), - ), - 'indexes' => array( - 'nid' => array('nid'), - ), - 'primary key' => array('nid'), - 'foreign keys' => array( - 'versioned_node' => array( - 'table' => 'node', - 'columns' => array('nid' => 'nid'), - ), - ), - ); - - return $schema; -} \ No newline at end of file diff --git a/core/modules/node/tests/modules/node_access_test/node_access_test.module b/core/modules/node/tests/modules/node_access_test/node_access_test.module index 1229cb7..873921b 100644 --- a/core/modules/node/tests/modules/node_access_test/node_access_test.module +++ b/core/modules/node/tests/modules/node_access_test/node_access_test.module @@ -9,8 +9,7 @@ * a special 'node test view' permission. */ -use Drupal\Core\Entity\EntityTypeInterface; -use Drupal\Core\Field\FieldDefinition; +use Drupal\node\NodeTypeInterface; use Drupal\node\NodeInterface; /** @@ -79,74 +78,32 @@ function node_access_test_permission() { } /** - * Implements hook_entity_base_field_info(). + * Adds the private field to a node type + * + * @param \Drupal\node\NodeTypeInterface $type + * A node type object. */ -function node_access_test_entity_base_field_info(EntityTypeInterface $entity_type) { - if ($entity_type->id() === 'node') { - $fields['private'] = FieldDefinition::create('boolean') - ->setLabel(t('Private')) - ->setComputed(TRUE); - - return $fields; - } -} - -/** - * Implements hook_form_BASE_FORM_ID_alter(). - */ -function node_access_test_form_node_form_alter(&$form, $form_state) { - // Only show this checkbox for NodeAccessBaseTableTestCase. - if (\Drupal::state()->get('node_access_test.private')) { - $node = $form_state['controller']->getEntity($form_state); - $form['private'] = array( - '#type' => 'checkbox', - '#title' => t('Private'), - '#description' => t('Check here if this content should be set private and only shown to privileged users.'), - '#default_value' => $node->private->value, - ); - } -} - -/** - * Implements hook_ENTITY_TYPE_load_uncached(). - */ -function node_access_test_node_load_uncached($nodes) { - $result = db_query('SELECT nid, private FROM {node_access_test} WHERE nid IN(:nids)', array(':nids' => array_keys($nodes))); - foreach ($result as $record) { - $nodes[$record->nid]->private = $record->private; - } -} - -/** - * Implements hook_node_predelete(). - */ - -function node_access_test_node_predelete(NodeInterface $node) { - db_delete('node_access_test')->condition('nid', $node->id())->execute(); -} - -/** - * Implements hook_node_insert(). - */ -function node_access_test_node_insert(NodeInterface $node) { - _node_access_test_node_write($node); -} - -/** - * Implements hook_nodeapi_update(). - */ -function node_access_test_node_update(NodeInterface $node) { - _node_access_test_node_write($node); -} - -/** - * Helper for node insert/update. - */ -function _node_access_test_node_write(NodeInterface $node) { - db_merge('node_access_test') - ->key('nid', $node->id()) - ->fields(array('private' => (int) $node->private->value)) - ->execute(); +function node_access_test_add_field(NodeTypeInterface $type) { + $field = entity_create('field_config', array( + 'name' => 'private', + 'entity_type' => 'node', + 'type' => 'integer', + )); + $field->save(); + $instance = entity_create('field_instance_config', array( + 'field_name' => 'private', + 'entity_type' => 'node', + 'bundle' => $type->id(), + 'label' => 'Private', + )); + $instance->save(); + + // Assign widget settings for the 'default' form mode. + entity_get_form_display('node', $type->id(), 'default') + ->setComponent('private', array( + 'type' => 'number', + )) + ->save(); } /** diff --git a/core/modules/tracker/lib/Drupal/tracker/Tests/TrackerNodeAccessTest.php b/core/modules/tracker/lib/Drupal/tracker/Tests/TrackerNodeAccessTest.php index c50eed2..ed5f58e 100644 --- a/core/modules/tracker/lib/Drupal/tracker/Tests/TrackerNodeAccessTest.php +++ b/core/modules/tracker/lib/Drupal/tracker/Tests/TrackerNodeAccessTest.php @@ -34,6 +34,7 @@ public function setUp() { parent::setUp(); node_access_rebuild(); $this->drupalCreateContentType(array('type' => 'page')); + node_access_test_add_field(entity_load('node_type', 'page')); $this->container->get('comment.manager')->addDefaultField('node', 'page', 'comment', CommentItemInterface::OPEN); \Drupal::state()->set('node_access_test.private', TRUE); }