You are here

public function AdminTest::setUp in Image Replace 7

Same name and namespace in other branches
  1. 8 src/Tests/AdminTest.php \Drupal\image_replace\Tests\AdminTest::setUp()

File

src/Tests/AdminTest.php, line 30

Class

AdminTest
Tests administrative interface for image replace.

Namespace

Drupal\image_replace\Tests

Code

public function setUp() {
  parent::setUp(array(
    'image',
    'image_replace',
  ));

  // Create an image style containing the replace effect.
  $this->styleName = 'image_replace_test';
  $this
    ->createImageStyle($this->styleName);

  // Add the replacement image field to the article bundle.
  $this
    ->createImageField('image_replacement', 'article');

  // Add the original image field to the article bundle and specify
  // the replacement image as replacement.
  $instance = $this
    ->createImageField('image_original', 'article');
  $instance['display']['teaser']['type'] = 'image';
  $instance['display']['teaser']['settings']['image_style'] = $this->styleName;
  $instance['display']['full']['type'] = 'image';
  $instance['display']['full']['settings']['image_style'] = NULL;
  field_update_instance($instance);
  field_bundle_settings('node', 'article', array(
    'view_modes' => array(
      'full' => array(
        'custom_settings' => TRUE,
      ),
      'teaser' => array(
        'custom_settings' => TRUE,
      ),
    ),
  ));
  $required_perms = array(
    'access content',
    'access administration pages',
    'administer site configuration',
    'administer content types',
    'administer nodes',
    'create article content',
    'edit any article content',
    'delete any article content',
    'administer image styles',
  );

  // The permission 'administer fields' is not available in all versions of
  // Drupal 7. See https://www.drupal.org/node/611294
  $available_perms = user_permission_get_modules();
  if (isset($available_perms['administer fields'])) {
    $required_perms[] = 'administer fields';
  }
  $this->adminUser = $this
    ->drupalCreateUser($required_perms);
}