Exemplo n.º 1
0
 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);
 }
 /**
  * Preparation work that is done before each test.
  * Test users, content types, nodes etc. are created.
  */
 function setUp($module = '')
 {
     if (empty($module)) {
         // Enable content access module
         parent::setUp('content_access');
     } else {
         // Enable content access module plus another module
         parent::setUp('content_access', $module);
         // Stop setup when module could not be enabled
         if (!module_exists($module)) {
             $this->pass('No ' . $module . ' module present, skipping test');
             return;
         }
     }
     // Create test user with seperate role
     $this->test_user = $this->backdropCreateUser();
     // Get the value of the new role
     // Needed in D7 because it's by default create two roles for new users
     // one role is Authenticated and the second is new default one
     // @see backdropCreateUser()
     foreach ($this->test_user->roles as $rid => $role) {
         if (!in_array($rid, array(BACKDROP_AUTHENTICATED_RID))) {
             $this->rid = $rid;
             break;
         }
     }
     // Create admin user
     $this->admin_user = $this->backdropCreateUser(array('access content', 'administer content types', 'grant content access', 'grant own content access', 'administer nodes', 'access administration pages'));
     $this->backdropLogin($this->admin_user);
     // Rebuild content access permissions
     node_access_rebuild();
     // Create test content type
     $this->content_type = $this->backdropCreateContentType();
 }
Exemplo n.º 3
0
 protected function setUp()
 {
     parent::setUp();
     node_access_test_add_field(NodeType::load('article'));
     node_access_rebuild();
     \Drupal::state()->set('node_access_test.private', TRUE);
 }
Exemplo n.º 4
0
 public function setUp()
 {
     parent::setUp();
     node_access_rebuild();
     $this->drupalCreateContentType(array('type' => 'page', 'name' => t('Basic page')));
     $this->container->get('comment.manager')->addDefaultField('node', 'page');
     $this->web_user = $this->drupalCreateUser(array('access content', 'access comments', 'node test view'));
 }
Exemplo n.º 5
0
 protected function setUp()
 {
     parent::setUp();
     node_access_rebuild();
     // Create a test user and log in.
     $this->testUser = $this->drupalCreateUser(array('access content', 'search content', 'use advanced search', 'access user profiles'));
     $this->drupalLogin($this->testUser);
 }
 protected function setUp()
 {
     parent::setUp();
     node_access_rebuild();
     $this->drupalCreateContentType(array('type' => 'page', 'name' => t('Basic page')));
     $this->addDefaultCommentField('node', 'page');
     $this->webUser = $this->drupalCreateUser(array('access content', 'access comments', 'node test view'));
 }
Exemplo n.º 7
0
 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);
 }
Exemplo n.º 8
0
 protected function setUp()
 {
     parent::setUp();
     node_access_rebuild();
     // Re-create user.
     $this->webUser = $this->drupalCreateUser(array('access comments', 'post comments', 'create article content', 'edit own comments', 'node test view', 'skip comment approval'));
     // Set the author of the created node to the web_user uid.
     $this->node->setOwnerId($this->webUser->id())->save();
 }
Exemplo n.º 9
0
 protected function setUp()
 {
     parent::setUp();
     node_access_rebuild();
     $this->drupalCreateContentType(array('type' => 'page'));
     node_access_test_add_field(NodeType::load('page'));
     $this->addDefaultCommentField('node', 'page', 'comment', CommentItemInterface::OPEN);
     \Drupal::state()->set('node_access_test.private', TRUE);
 }
Exemplo n.º 10
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     node_access_rebuild();
     // Create some content.
     $this->drupalCreateNode();
     $this->drupalCreateNode();
     $this->drupalCreateNode();
     $this->drupalCreateNode();
 }
Exemplo n.º 11
0
 function setUp()
 {
     parent::setUp();
     // node_access_test requires a node_access_rebuild().
     node_access_rebuild();
     // Create users.
     $this->book_author = $this->drupalCreateUser(array('create new books', 'create book content', 'edit own book content', 'add content to books'));
     $this->web_user = $this->drupalCreateUser(array('access printer-friendly version', 'node test view'));
     $this->admin_user = $this->drupalCreateUser(array('create new books', 'create book content', 'edit own book content', 'add content to books', 'administer blocks', 'administer permissions', 'administer book outlines', 'node test view', 'administer content types', 'administer site configuration'));
 }
Exemplo n.º 12
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     // Create Article node type.
     $this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article'));
     $this->accessHandler = \Drupal::entityManager()->getAccessControlHandler('node');
     node_access_test_add_field(NodeType::load('article'));
     // After enabling a node access module, the access table has to be rebuild.
     node_access_rebuild();
     // Enable the private node feature of the node_access_test module.
     \Drupal::state()->set('node_access_test.private', TRUE);
 }
Exemplo n.º 13
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->drupalPlaceBlock('system_breadcrumb_block');
     // node_access_test requires a node_access_rebuild().
     node_access_rebuild();
     // Create users.
     $this->bookAuthor = $this->drupalCreateUser(array('create new books', 'create book content', 'edit own book content', 'add content to books'));
     $this->webUser = $this->drupalCreateUser(array('access printer-friendly version', 'node test view'));
     $this->webUserWithoutNodeAccess = $this->drupalCreateUser(array('access printer-friendly version'));
     $this->adminUser = $this->drupalCreateUser(array('create new books', 'create book content', 'edit own book content', 'add content to books', 'administer blocks', 'administer permissions', 'administer book outlines', 'node test view', 'administer content types', 'administer site configuration'));
 }
 protected function setUp()
 {
     parent::setUp();
     // Create the 'private' field, which allows the node to be marked as private
     // (restricted access) in a given translation.
     $field_storage = FieldStorageConfig::create(array('field_name' => 'field_private', 'entity_type' => 'node', 'type' => 'boolean', 'cardinality' => 1));
     $field_storage->save();
     FieldConfig::create(['field_storage' => $field_storage, 'bundle' => 'page', 'widget' => array('type' => 'options_buttons'), 'settings' => array('on_label' => 'Private', 'off_label' => 'Not private')])->save();
     // After enabling a node access module, the access table has to be rebuild.
     node_access_rebuild();
     // Create a normal authenticated user.
     $this->webUser = $this->drupalCreateUser(array('access content'));
     // Load the user 1 user for later use as an admin user with permission to
     // see everything.
     $this->adminUser = User::load(1);
     // Add Hungarian and Catalan.
     ConfigurableLanguage::createFromLangcode('hu')->save();
     ConfigurableLanguage::createFromLangcode('ca')->save();
     // The node_access_test_language module allows individual translations of a
     // node to be marked private (not viewable by normal users).
     // Create six nodes:
     // 1. Four Hungarian nodes with Catalan translations
     //   - One with neither language marked as private.
     //   - One with only the Hungarian translation private.
     //   - One with only the Catalan translation private.
     //   - One with both the Hungarian and Catalan translations private.
     // 2. Two nodes with no language specified.
     //   - One public.
     //   - One private.
     $this->nodes['both_public'] = $node = $this->drupalCreateNode(array('body' => array(array()), 'langcode' => 'hu', 'field_private' => array(array('value' => 0))));
     $translation = $node->addTranslation('ca');
     $translation->title->value = $this->randomString();
     $translation->field_private->value = 0;
     $node->save();
     $this->nodes['ca_private'] = $node = $this->drupalCreateNode(array('body' => array(array()), 'langcode' => 'hu', 'field_private' => array(array('value' => 0))));
     $translation = $node->addTranslation('ca');
     $translation->title->value = $this->randomString();
     $translation->field_private->value = 1;
     $node->save();
     $this->nodes['hu_private'] = $node = $this->drupalCreateNode(array('body' => array(array()), 'langcode' => 'hu', 'field_private' => array(array('value' => 1))));
     $translation = $node->addTranslation('ca');
     $translation->title->value = $this->randomString();
     $translation->field_private->value = 0;
     $node->save();
     $this->nodes['both_private'] = $node = $this->drupalCreateNode(array('body' => array(array()), 'langcode' => 'hu', 'field_private' => array(array('value' => 1))));
     $translation = $node->addTranslation('ca');
     $translation->title->value = $this->randomString();
     $translation->field_private->value = 1;
     $node->save();
     $this->nodes['no_language_public'] = $this->drupalCreateNode(array('field_private' => array(array('value' => 0)), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED));
     $this->nodes['no_language_private'] = $this->drupalCreateNode(array('field_private' => array(array('value' => 1)), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED));
 }
Exemplo n.º 15
0
 protected function setUp()
 {
     parent::setUp();
     node_access_test_add_field(NodeType::load('page'));
     // After enabling a node access module, the access table has to be rebuild.
     node_access_rebuild();
     // Enable the private node feature of the node_access_test module.
     \Drupal::state()->set('node_access_test.private', TRUE);
     // Add Hungarian, Catalan and Croatian.
     ConfigurableLanguage::createFromLangcode('hu')->save();
     ConfigurableLanguage::createFromLangcode('ca')->save();
     ConfigurableLanguage::createFromLangcode('hr')->save();
 }
Exemplo n.º 16
0
 protected function setUp()
 {
     parent::setUp();
     node_access_rebuild();
     // Create some users.
     $this->adminUser = $this->drupalCreateUser(array('access content', 'bypass node access'));
     $this->contentAdminUser = $this->drupalCreateUser(array('access content', 'administer content types', 'administer node fields'));
     // Add a custom field to the page content type.
     $this->fieldName = Unicode::strtolower($this->randomMachineName() . '_field_name');
     FieldStorageConfig::create(array('field_name' => $this->fieldName, 'entity_type' => 'node', 'type' => 'text'))->save();
     FieldConfig::create(['field_name' => $this->fieldName, 'entity_type' => 'node', 'bundle' => 'page'])->save();
     entity_get_display('node', 'page', 'default')->setComponent($this->fieldName)->save();
     entity_get_form_display('node', 'page', 'default')->setComponent($this->fieldName)->save();
 }
Exemplo n.º 17
0
 public function setUp()
 {
     parent::setUp();
     node_access_rebuild();
     // Create some users.
     $this->admin_user = $this->drupalCreateUser(array('access content', 'bypass node access'));
     $this->content_admin_user = $this->drupalCreateUser(array('access content', 'administer content types', 'administer node fields'));
     // Add a custom field to the page content type.
     $this->field_name = drupal_strtolower($this->randomName() . '_field_name');
     entity_create('field_storage_config', array('name' => $this->field_name, 'entity_type' => 'node', 'type' => 'text'))->save();
     entity_create('field_instance_config', array('field_name' => $this->field_name, 'entity_type' => 'node', 'bundle' => 'page'))->save();
     entity_get_display('node', 'page', 'default')->setComponent($this->field_name)->save();
     entity_get_form_display('node', 'page', 'default')->setComponent($this->field_name)->save();
 }
 public function setUp()
 {
     parent::setUp();
     // Create the 'private' field, which allows the node to be marked as private
     // (restricted access) in a given translation.
     $field_storage = entity_create('field_storage_config', array('name' => 'field_private', 'entity_type' => 'node', 'type' => 'boolean', 'cardinality' => 1, 'translatable' => TRUE, 'settings' => array('on_label' => 'Private', 'off_label' => 'Not private')));
     $field_storage->save();
     entity_create('field_instance_config', array('field_storage' => $field_storage, 'bundle' => 'page', 'widget' => array('type' => 'options_buttons')))->save();
     // After enabling a node access module, the access table has to be rebuild.
     node_access_rebuild();
     // Create a normal authenticated user.
     $this->web_user = $this->drupalCreateUser(array('access content'));
     // Load the user 1 user for later use as an admin user with permission to
     // see everything.
     $this->admin_user = user_load(1);
     // Add Hungarian and Catalan.
     $language = new Language(array('id' => 'hu'));
     language_save($language);
     $language = new Language(array('id' => 'ca'));
     language_save($language);
     // The node_access_test_language module allows individual translations of a
     // node to be marked private (not viewable by normal users).
     // Create six nodes:
     // 1. Four Hungarian nodes with Catalan translations
     //   - One with neither language marked as private.
     //   - One with only the Hungarian translation private.
     //   - One with only the Catalan translation private.
     //   - One with both the Hungarian and Catalan translations private.
     // 2. Two nodes with no language specified.
     //   - One public.
     //   - One private.
     $this->nodes['both_public'] = $node = $this->drupalCreateNode(array('body' => array(array()), 'langcode' => 'hu', 'field_private' => array(array('value' => 0))));
     $translation = $node->getTranslation('ca');
     $translation->field_private[0]->value = 0;
     $node->save();
     $this->nodes['ca_private'] = $node = $this->drupalCreateNode(array('body' => array(array()), 'langcode' => 'hu', 'field_private' => array(array('value' => 0))));
     $translation = $node->getTranslation('ca');
     $translation->field_private[0]->value = 1;
     $node->save();
     $this->nodes['hu_private'] = $node = $this->drupalCreateNode(array('body' => array(array()), 'langcode' => 'hu', 'field_private' => array(array('value' => 1))));
     $translation = $node->getTranslation('ca');
     $translation->field_private[0]->value = 0;
     $node->save();
     $this->nodes['both_private'] = $node = $this->drupalCreateNode(array('body' => array(array()), 'langcode' => 'hu', 'field_private' => array(array('value' => 1))));
     $translation = $node->getTranslation('ca');
     $translation->field_private[0]->value = 1;
     $node->save();
     $this->nodes['no_language_public'] = $this->drupalCreateNode(array('field_private' => array(array('value' => 0))));
     $this->nodes['no_language_private'] = $this->drupalCreateNode(array('field_private' => array(array('value' => 1))));
 }
 protected function setUp()
 {
     parent::setUp();
     node_access_rebuild();
     // Create some content.
     $this->drupalCreateNode();
     $this->drupalCreateNode();
     $this->drupalCreateNode();
     $this->drupalCreateNode();
     // Create user with simple node access permission. The 'node test view'
     // permission is implemented and granted by the node_access_test module.
     $this->accessUser = $this->drupalCreateUser(array('access content overview', 'access content', 'node test view'));
     $this->noAccessUser = $this->drupalCreateUser(array('access content overview', 'access content'));
     $this->noAccessUser2 = $this->drupalCreateUser(array('access content overview', 'access content'));
 }
Exemplo n.º 20
0
 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();
     // Enable the private node feature of the node_access_test module.
     \Drupal::state()->set('node_access_test.private', TRUE);
     // Add Hungarian and Catalan.
     $language = new Language(array('id' => 'hu'));
     language_save($language);
     $language = new Language(array('id' => 'ca'));
     language_save($language);
     $language = new Language(array('id' => 'hr'));
     language_save($language);
 }
 /**
  * Tests rebuilding the node access permissions table with content.
  */
 public function testNodeAccessRebuildNodeGrants()
 {
     \Drupal::service('module_installer')->install(['node_access_test']);
     \Drupal::state()->set('node_access_test.private', TRUE);
     node_access_test_add_field(NodeType::load('page'));
     $this->resetAll();
     // Create 30 nodes so that _node_access_rebuild_batch_operation() has to run
     // more than once.
     for ($i = 0; $i < 30; $i++) {
         $nodes[] = $this->drupalCreateNode(array('uid' => $this->webUser->id(), 'private' => [['value' => 1]]));
     }
     /** @var \Drupal\node\NodeGrantDatabaseStorageInterface $grant_storage */
     $grant_storage = \Drupal::service('node.grant_storage');
     // Default realm access and node records are present.
     foreach ($nodes as $node) {
         $this->assertTrue($node->private->value);
         $this->assertTrue($grant_storage->access($node, 'view', $this->webUser)->isAllowed(), 'Prior to rebuilding node access the grant storage returns allowed for the node author.');
         $this->assertTrue($grant_storage->access($node, 'view', $this->adminUser)->isAllowed(), 'Prior to rebuilding node access the grant storage returns allowed for the admin user.');
     }
     $this->assertEqual(1, \Drupal::service('node.grant_storage')->checkAll($this->webUser), 'There is an all realm access record');
     $this->assertTrue(\Drupal::state()->get('node.node_access_needs_rebuild'), 'Node access permissions need to be rebuilt');
     // Rebuild permissions.
     $this->drupalGet('admin/reports/status');
     $this->clickLink(t('Rebuild permissions'));
     $this->drupalPostForm(NULL, array(), t('Rebuild permissions'));
     $this->assertText(t('The content access permissions have been rebuilt.'));
     // Test if the rebuild by user that cannot bypass node access and does not
     // have access to the nodes has been successful.
     $this->assertFalse($this->adminUser->hasPermission('bypass node access'));
     $this->assertNull(\Drupal::state()->get('node.node_access_needs_rebuild'), 'Node access permissions have been rebuilt');
     foreach ($nodes as $node) {
         $this->assertTrue($grant_storage->access($node, 'view', $this->webUser)->isAllowed(), 'After rebuilding node access the grant storage returns allowed for the node author.');
         $this->assertFalse($grant_storage->access($node, 'view', $this->adminUser)->isForbidden(), 'After rebuilding node access the grant storage returns forbidden for the admin user.');
     }
     $this->assertFalse(\Drupal::service('node.grant_storage')->checkAll($this->webUser), 'There is no all realm access record');
     // Test an anonymous node access rebuild from code.
     $this->drupalLogout();
     node_access_rebuild();
     foreach ($nodes as $node) {
         $this->assertTrue($grant_storage->access($node, 'view', $this->webUser)->isAllowed(), 'After rebuilding node access the grant storage returns allowed for the node author.');
         $this->assertFalse($grant_storage->access($node, 'view', $this->adminUser)->isForbidden(), 'After rebuilding node access the grant storage returns forbidden for the admin user.');
     }
     $this->assertFalse(\Drupal::service('node.grant_storage')->checkAll($this->webUser), 'There is no all realm access record');
 }
Exemplo n.º 22
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $io->newLine();
     $io->comment($this->trans('commands.node.access.rebuild.messages.rebuild'));
     $batch = $input->getOption('batch');
     try {
         node_access_rebuild($batch);
     } catch (\Exception $e) {
         $io->error($e->getMessage());
         return;
     }
     $needs_rebuild = $this->getState()->get('node.node_access_needs_rebuild') ?: false;
     if ($needs_rebuild) {
         $io->warning($this->trans('commands.node.access.rebuild.messages.failed'));
     } else {
         $io->success($this->trans('commands.node.access.rebuild.messages.completed'));
     }
 }
Exemplo n.º 23
0
/**
 * Custom form submission handler for system theme settings.
 *
 * Handles general settings plus enabling and disabling of content types throughtout the system.
 */
function sociale_platforme_settings_form_submit(&$form, $form_state)
{
    /**
     * General Settings
     */
    variable_set('site_name', $form_state['values']['site_name']);
    variable_set('site_mail', $form_state['values']['site_mail']);
    /**
     * Content Types
     */
    $content_types = $form_state["values"]["sp_content_types"];
    $browsing_widgets = ctools_export_crud_load_all('commons_bw_ui');
    // Enable or disable browsing widgets (Quicktabs).
    foreach ($browsing_widgets as $widget) {
        if (array_key_exists($widget->bundle, $content_types)) {
            $status = $content_types[$widget->bundle];
            if ($status === 0) {
                ctools_export_crud_disable('commons_bw_ui', $widget);
            } else {
                ctools_export_crud_enable('commons_bw_ui', $widget);
            }
        }
    }
    // Grant or remove content access view permissions.
    foreach ($content_types as $type_name => $status) {
        $settings = array();
        if ($status === 0) {
            $settings['view_own'] = array();
            $settings['view'] = array();
        } else {
            $settings['view_own'] = array(1, 2);
            $settings['view'] = array(1, 2);
        }
        content_access_set_settings($settings, $type_name);
    }
    node_access_rebuild();
}
 /**
  * Preparation work that is done before each test.
  * Test users, content types, nodes etc. are created.
  */
 function setUp($module = '')
 {
     if (empty($module)) {
         // Enable content access module
         parent::setUp('content_access');
     } else {
         // Enable content access module plus another module
         parent::setUp('content_access', $module);
         // Stop setup when module could not be enabled
         if (!module_exists($module)) {
             return;
         }
     }
     // Create test user with seperate role
     $this->test_user = $this->drupalCreateUser();
     // Create admin user
     $this->admin_user = $this->drupalCreateUser(array('access content', 'administer content types', 'grant content access', 'grant own content access', 'administer nodes', 'access administration pages'));
     $this->drupalLogin($this->admin_user);
     // Rebuild content access permissions
     node_access_rebuild();
     #$this->drupalPost('admin/reports/status/rebuild', array(), t('Rebuild permissions'));
     // Create test content type
     $this->content_type = $this->drupalCreateContentType();
 }
Exemplo n.º 25
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, array &$form_state)
 {
     node_access_rebuild(TRUE);
     $form_state['redirect_route'] = $this->getCancelUrl();
 }
Exemplo n.º 26
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     node_access_rebuild(TRUE);
     $form_state->setRedirectUrl($this->getCancelUrl());
 }
 protected function setUp()
 {
     parent::setUp();
     node_access_test_add_field(NodeType::load('page'));
     // Create the 'private' field, which allows the node to be marked as private
     // (restricted access) in a given translation.
     $field_storage = entity_create('field_storage_config', array('field_name' => 'field_private', 'entity_type' => 'node', 'type' => 'boolean', 'cardinality' => 1));
     $field_storage->save();
     entity_create('field_config', array('field_storage' => $field_storage, 'bundle' => 'page', 'widget' => array('type' => 'options_buttons'), 'settings' => array('on_label' => 'Private', 'off_label' => 'Not private')))->save();
     // After enabling a node access module, the access table has to be rebuild.
     node_access_rebuild();
     // Add Hungarian and Catalan.
     ConfigurableLanguage::createFromLangcode('hu')->save();
     ConfigurableLanguage::createFromLangcode('ca')->save();
     // Create a normal authenticated user.
     $this->webUser = $this->drupalCreateUser(array('access content'));
     // Load the user 1 user for later use as an admin user with permission to
     // see everything.
     $this->adminUser = User::load(1);
     // The node_access_test_language module allows individual translations of a
     // node to be marked private (not viewable by normal users), and the
     // node_access_test module allows whole nodes to be marked private. (In a
     // real-world implementation, hook_node_access_records_alter() might be
     // implemented by one or both modules to enforce that private nodes or
     // translations are always private, but we want to test the default,
     // additive behavior of node access).
     // Create six Hungarian nodes with Catalan translations:
     // 1. One public with neither language marked as private.
     // 2. One private with neither language marked as private.
     // 3. One public with only the Hungarian translation private.
     // 4. One public with only the Catalan translation private.
     // 5. One public with both the Hungarian and Catalan translations private.
     // 6. One private with both the Hungarian and Catalan translations private.
     $this->nodes['public_both_public'] = $node = $this->drupalCreateNode(array('body' => array(array()), 'langcode' => 'hu', 'field_private' => array(array('value' => 0)), 'private' => FALSE));
     $translation = $node->addTranslation('ca');
     $translation->title->value = $this->randomString();
     $translation->field_private->value = 0;
     $node->save();
     $this->nodes['private_both_public'] = $node = $this->drupalCreateNode(array('body' => array(array()), 'langcode' => 'hu', 'field_private' => array(array('value' => 0)), 'private' => TRUE));
     $translation = $node->addTranslation('ca');
     $translation->title->value = $this->randomString();
     $translation->field_private->value = 0;
     $node->save();
     $this->nodes['public_hu_private'] = $node = $this->drupalCreateNode(array('body' => array(array()), 'langcode' => 'hu', 'field_private' => array(array('value' => 1)), 'private' => FALSE));
     $translation = $node->addTranslation('ca');
     $translation->title->value = $this->randomString();
     $translation->field_private->value = 0;
     $node->save();
     $this->nodes['public_ca_private'] = $node = $this->drupalCreateNode(array('body' => array(array()), 'langcode' => 'hu', 'field_private' => array(array('value' => 0)), 'private' => FALSE));
     $translation = $node->addTranslation('ca');
     $translation->title->value = $this->randomString();
     $translation->field_private->value = 1;
     $node->save();
     $this->nodes['public_both_private'] = $node = $this->drupalCreateNode(array('body' => array(array()), 'langcode' => 'hu', 'field_private' => array(array('value' => 1)), 'private' => FALSE));
     $translation = $node->addTranslation('ca');
     $translation->title->value = $this->randomString();
     $translation->field_private->value = 1;
     $node->save();
     $this->nodes['private_both_private'] = $node = $this->drupalCreateNode(array('body' => array(array()), 'langcode' => 'hu', 'field_private' => array(array('value' => 1)), 'private' => TRUE));
     $translation = $node->addTranslation('ca');
     $translation->title->value = $this->randomString();
     $translation->field_private->value = 1;
     $node->save();
     $this->nodes['public_no_language_private'] = $this->drupalCreateNode(array('field_private' => array(array('value' => 1)), 'private' => FALSE, 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED));
     $this->nodes['public_no_language_public'] = $this->drupalCreateNode(array('field_private' => array(array('value' => 0)), 'private' => FALSE, 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED));
     $this->nodes['private_no_language_private'] = $this->drupalCreateNode(array('field_private' => array(array('value' => 1)), 'private' => TRUE, 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED));
     $this->nodes['private_no_language_public'] = $this->drupalCreateNode(array('field_private' => array(array('value' => 1)), 'private' => TRUE, 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED));
 }
Exemplo n.º 28
0
function _cobalt_rebuild_permissions()
{
    node_access_rebuild();
    drupal_goto();
}
Exemplo n.º 29
0
 /**
  * Tests the "private" node access functionality.
  *
  * - Create 2 users with "access content" and "create article" permissions.
  * - Each user creates one private and one not private article.
  *
  * - Test that each user can view the other user's non-private article.
  * - Test that each user cannot view the other user's private article.
  * - Test that each user finds only appropriate (non-private + own private)
  *   in taxonomy listing.
  * - Create another user with 'view any private content'.
  * - Test that user 4 can view all content created above.
  * - Test that user 4 can view all content on taxonomy listing.
  */
 function testNodeAccessBasic()
 {
     $num_simple_users = 2;
     $simple_users = array();
     // Nodes keyed by uid and nid: $nodes[$uid][$nid] = $is_private;
     $this->nodesByUser = array();
     // Titles keyed by nid.
     $titles = [];
     // Array of nids marked private.
     $private_nodes = [];
     for ($i = 0; $i < $num_simple_users; $i++) {
         $simple_users[$i] = $this->drupalCreateUser(array('access content', 'create article content'));
     }
     foreach ($simple_users as $this->webUser) {
         $this->drupalLogin($this->webUser);
         foreach (array(0 => 'Public', 1 => 'Private') as $is_private => $type) {
             $edit = array('title[0][value]' => t('@private_public Article created by @user', array('@private_public' => $type, '@user' => $this->webUser->getUsername())));
             if ($is_private) {
                 $edit['private[0][value]'] = TRUE;
                 $edit['body[0][value]'] = 'private node';
                 $edit['field_tags[target_id]'] = 'private';
             } else {
                 $edit['body[0][value]'] = 'public node';
                 $edit['field_tags[target_id]'] = 'public';
             }
             $this->drupalPostForm('node/add/article', $edit, t('Save'));
             $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[] = $node->id();
             }
             $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_field_data} WHERE name = :name AND default_langcode = 1', array(':name' => 'public'))->fetchField();
     $this->privateTid = db_query('SELECT tid FROM {taxonomy_term_field_data} WHERE name = :name AND default_langcode = 1', array(':name' => 'private'))->fetchField();
     $this->assertTrue($this->publicTid, 'Public tid was found');
     $this->assertTrue($this->privateTid, 'Private tid was found');
     foreach ($simple_users as $this->webUser) {
         $this->drupalLogin($this->webUser);
         // Check own nodes to see that all are readable.
         foreach ($this->nodesByUser as $uid => $data) {
             foreach ($data as $nid => $is_private) {
                 $this->drupalGet('node/' . $nid);
                 if ($is_private) {
                     $should_be_visible = $uid == $this->webUser->id();
                 } else {
                     $should_be_visible = TRUE;
                 }
                 $this->assertResponse($should_be_visible ? 200 : 403, strtr('A %private node by user %uid is %visible for user %current_uid.', array('%private' => $is_private ? 'private' : 'public', '%uid' => $uid, '%visible' => $should_be_visible ? 'visible' : 'not visible', '%current_uid' => $this->webUser->id())));
             }
         }
         // Check to see that the correct nodes are shown on taxonomy/private
         // and taxonomy/public.
         $this->assertTaxonomyPage(FALSE);
     }
     // Now test that a user with 'node test view' permissions can view content.
     $access_user = $this->drupalCreateUser(array('access content', 'create article content', 'node test view', 'search content'));
     $this->drupalLogin($access_user);
     foreach ($this->nodesByUser as $private_status) {
         foreach ($private_status as $nid => $is_private) {
             $this->drupalGet('node/' . $nid);
             $this->assertResponse(200);
         }
     }
     // This user should be able to see all of the nodes on the relevant
     // taxonomy pages.
     $this->assertTaxonomyPage(TRUE);
     // Rebuild the node access permissions, repeat the test. This is done to
     // ensure that node access is rebuilt correctly even if the current user
     // does not have the bypass node access permission.
     node_access_rebuild();
     foreach ($this->nodesByUser as $private_status) {
         foreach ($private_status as $nid => $is_private) {
             $this->drupalGet('node/' . $nid);
             $this->assertResponse(200);
         }
     }
     // This user should be able to see all of the nodes on the relevant
     // taxonomy pages.
     $this->assertTaxonomyPage(TRUE);
 }