You are here

function FreelinkingTest::setUp in Freelinking 7.3

Same name and namespace in other branches
  1. 6.3 freelinking.test \FreelinkingTest::setUp()

Prepares the testing environment enabling modules, creating a user and some test content.

Overrides DrupalWebTestCase::setUp

File

./freelinking.test, line 25
Unit tests for the freelinking Module.

Class

FreelinkingTest
@file Unit tests for the freelinking Module.

Code

function setUp() {
  parent::setUp('freelinking', 'search');

  // Create user
  $this->privileged_user = $this
    ->drupalCreateUser(array(
    'bypass node access',
    'administer filters',
    'access user profiles',
    'search content',
  ));
  $this
    ->drupalLogin($this->privileged_user);

  // Activate freelinking input filter
  $edit = array(
    'filters[freelinking][status]' => 1,
    'filters[freelinking][weight]' => 0,
    'filters[filter_url][weight]' => 1,
    'filters[filter_html][weight]' => 2,
    'filters[filter_autop][weight]' => 3,
    'filters[filter_htmlcorrector][weight]' => 4,
  );
  $this
    ->drupalPost('admin/config/content/formats/filtered_html', $edit, t('Save configuration'));
  $this
    ->assertText(t('The text format Filtered HTML has been updated.'));
  $this
    ->drupalGet('admin/config/content/formats/filtered_html');
  $this
    ->assertFieldChecked('edit-filters-freelinking-status', t('Freelinking input filter has been activated'));

  // Create a couple of pages which will be freelinked
  $edit = array();
  $edit['title'] = t('First page');
  $edit['body[und][0][value]'] = t('Body of first page');
  $this
    ->drupalPost('node/add/page', $edit, t('Save'));
  $this
    ->assertText(t('Basic page @title has been created.', array(
    '@title' => $edit['title'],
  )));
  $edit = array();
  $edit['title'] = t('Second page');
  $edit['body[und][0][value]'] = t('Body of second page');
  $this
    ->drupalPost('node/add/page', $edit, t('Save'));
  $this
    ->assertText(t('Basic page @title has been created.', array(
    '@title' => $edit['title'],
  )));
  $edit = array();
  $edit['title'] = t('Third page');
  $edit['body[und][0][value]'] = t('Body of third page');
  $this
    ->drupalPost('node/add/page', $edit, t('Save'));
  $this
    ->assertText(t('Basic page @title has been created.', array(
    '@title' => $edit['title'],
  )));

  // Upload Drupal logo to files directory to test file and image plugins
  $root_path = $_SERVER['DOCUMENT_ROOT'];
  $image = new stdClass();
  $image->uri = $root_path . '/themes/bartik/logo.png';
  file_copy($image);
  $this
    ->assertTrue(is_string(drupal_realpath('public://logo.png')), t('Image @image was saved successfully', array(
    '@image' => $image->uri,
  )));
}