You are here

public function ProtectedNodeFieldCollection::setUp in Protected Node 7

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

Prepare users for protected node's tests.

Overrides ProtectedNodeBaseTestCase::setUp

File

tests/protected_node.field_collection.test, line 27
Test protected node behavior with field collection private files.

Class

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

Code

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

  // 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 field_collection field to use for the tests.
  $this->field_collection_field_name = 'field_test_collection';
  $this->field_collection_field = array(
    'field_name' => $this->field_collection_field_name,
    'type' => 'field_collection',
    'cardinality' => -1,
  );
  $this->field_collection_field = field_create_field($this->field_collection_field);

  // Create a field_collection field instance.
  $this->field_collection_field_instance = array(
    'field_name' => $this->field_collection_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' => 'field_collection_embed',
      'label' => 'Test',
      'settings' => array(),
    ),
  );
  $this->field_collection_field_instance = field_create_instance($this->field_collection_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, 'field_collection_item', $this->field_collection_field_name);
}