You are here

public function ProtectedNodeParagraphs::setUp in Protected Node 7

Same name and namespace in other branches
  1. 1.0.x tests/protected_node.paragraphs.test \ProtectedNodeParagraphs::setUp()

Prepare users for protected node's tests.

Overrides ProtectedNodeBaseTestCase::setUp

File

tests/protected_node.paragraphs.test, line 27
Test protected node behavior with paragraphs private files.

Class

ProtectedNodeParagraphs
Configure protected_node to use per node password and use private file field.

Code

public function setUp() {
  parent::setUp('paragraphs');

  // Log in an Admin.
  $this
    ->drupalLogin($this->adminUser);

  // Submit the configuration form.
  $protected_node_settings = array(
    'protected_node_use_global_password' => PROTECTED_NODE_PER_NODE_PASSWORD,
  );
  $this
    ->drupalPost('admin/config/content/protected_node', $protected_node_settings, t('Save configuration'));

  // Create a paragraph bundle.
  $this->paragraphs_bundle_name = 'test_protected_node';
  $paragraph_bundle_settings = array(
    'name' => 'test protected node',
    'bundle' => $this->paragraphs_bundle_name,
  );
  $this
    ->drupalPost('admin/structure/paragraphs/add', $paragraph_bundle_settings, t('Save Paragraph bundle'));

  // Create a paragraphs field to use for the tests.
  $this->paragraphs_field_name = 'field_test_paragraphs';
  $this->paragraphs_field = array(
    'field_name' => $this->paragraphs_field_name,
    'type' => 'paragraphs',
    // Cardinality of 1 ensure there is only one "Add new paragraph" button
    // for nested paragraphs.
    'cardinality' => 1,
  );
  $this->paragraphs_field = field_create_field($this->paragraphs_field);

  // Create a paragraphs field instance on basic page.
  $this->paragraphs_field_instance = array(
    'field_name' => $this->paragraphs_field_name,
    'entity_type' => 'node',
    'bundle' => 'page',
    'label' => $this
      ->randomName() . '_label',
    'description' => $this
      ->randomName() . '_description',
    'weight' => mt_rand(0, 127),
    'settings' => array(),
    'widget' => array(
      'type' => 'paragraphs_embed',
      'label' => 'Test',
      'settings' => array(),
    ),
  );
  $this->paragraphs_field_instance = field_create_instance($this->paragraphs_field_instance);

  // Create a paragraphs field instance on paragraphs to have nested
  // paragraphs.
  $this->paragraphs_field_instance = array(
    'field_name' => $this->paragraphs_field_name,
    'entity_type' => 'paragraphs_item',
    'bundle' => $this->paragraphs_bundle_name,
    'label' => $this
      ->randomName() . '_label',
    'description' => $this
      ->randomName() . '_description',
    'weight' => mt_rand(0, 127),
    'settings' => array(),
    'widget' => array(
      'type' => 'paragraphs_embed',
      'label' => 'Test',
      'settings' => array(),
    ),
  );
  $this->paragraphs_field_instance = field_create_instance($this->paragraphs_field_instance);

  // Private file system already set by simpletest.
  // Set private file field for basic page.
  $filefieldtestcase = new FileFieldTestCase();
  $this->private_file_field_name = 'private_file';

  // Create a private file field.
  $this->private_file_field = array(
    'field_name' => $this->private_file_field_name,
    'type' => 'file',
    'settings' => array(
      'uri_scheme' => 'private',
    ),
    'cardinality' => 1,
  );
  field_create_field($this->private_file_field);
  $filefieldtestcase
    ->attachFileField($this->private_file_field_name, 'paragraphs_item', $this->paragraphs_bundle_name);
}