You are here

freelinking.test in Freelinking 6.3

Same filename and directory in other branches
  1. 7.3 freelinking.test

Unit tests for the freelinking Module.

File

freelinking.test
View source
<?php

/**
 * @file
 * Unit tests for the freelinking Module.
 */
class FreelinkingTest extends DrupalWebTestCase {

  /*
   * The getInfo() method provides information about the test.
   * In order for the test to be run, the getInfo() method needs
   * to be implemented.
   */
  public static function getInfo() {
    return array(
      'name' => t('Feelinking tests'),
      'description' => t('Tests main module functionality.'),
      'group' => t('Freelinking'),
    );
  }

  /**
   * Prepares the testing environment enabling modules, creating a user and some test content.
   */
  function setUp() {

    // Check that we have the right version of simpletest
    if (!method_exists($this, 'assertLinkByHref')) {
      $this
        ->fail(t('You must install a newer version of Simpletest. ' . 'Go to !link and download the latest development release.', array(
        '!link' => 'http://drupal.org/project/simpletest',
      )));
    }
    parent::setUp('freelinking', 'search');

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

    // Activate freelinking input filter
    $edit = array(
      'filters[freelinking/0]' => 1,
    );
    $this
      ->drupalPost('admin/settings/filters/1', $edit, t('Save configuration'));
    $this
      ->assertText(t('The input format settings have been updated.'));
    $this
      ->drupalGet('admin/settings/filters/1');
    $this
      ->assertFieldChecked('edit-filters-freelinking/0', 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'] = t('Body of first page');
    $this
      ->drupalPost('node/add/page', $edit, t('Save'));
    $this
      ->assertText(t('Page @title has been created.', array(
      '@title' => $edit['title'],
    )));
    $edit = array();
    $edit['title'] = t('Second page');
    $edit['body'] = t('Body of second page');
    $this
      ->drupalPost('node/add/page', $edit, t('Save'));
    $this
      ->assertText(t('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 = $root_path . '/themes/garland/logo.png';
    file_copy($image);
    $this
      ->assertTrue(is_string(file_check_location('logo.png')), t('Image @image was saved successfully', array(
      '@image' => $image,
    )));
  }

  /**
   * Tests all plugins
   */
  public function testFreelinkingPlugins() {

    // Create node that will contain a sample of each plugin
    $edit = array();
    $edit['title'] = t('Testing all freelinking plugins');
    $edit['body'] = '<ul>' . '  <li>Drupalproject:  [[drupalproject:freelinking]]</li>' . '  <li>Drupalorgnid:   [[drupalorgnid:1]]</li>' . '  <li>One inch frame: [[oif:about-one-inch-frame]]</li>' . '  <li>Nodetitle:      [[nodetitle:First page]]</li>' . '  <li>Search:         [[search:test]]</li>' . '  <li>Nid:            [[nid:2]]</li>' . '  <li>Google:         [[google:drupal]]</li>' . '  <li>Image:          [[image:logo.png]]</li>' . '  <li>File:           [[image:logo.png]]</li>' . '  <li>Wikisource:     [[wikisource:Main_Page]]</li>' . '  <li>Wiktionary:     [[wiktionary:Wiktionary:Main_Page]]</li>' . '  <li>Wikiquote:      [[wikiquote:Main_Page]]</li>' . '  <li>Wikibooks:      [[wikibooks:Main_Page]]</li>' . '  <li>Wikinews:       [[wikinews:Main_Page]]</li>' . '  <li>User:           [[u:' . $this->privileged_user->uid . ']]</li>' . '  <li>Path:           [[path:/node/1]]</li>' . '  <li>Wikipedia:      [[wikipedia:Main_Page]]</li>' . '</ul>';
    $this
      ->drupalPost('node/add/page', $edit, t('Save'));
    $this
      ->assertText(t('Page @title has been created.', array(
      '@title' => $edit['title'],
    )));

    // Verify each freelink plugin
    $this
      ->assertLinkByHref('http://drupal.org/project/freelinking', 0, t('Drupalproject freelink was generated successfully.'));
    $this
      ->assertLinkByHref('http://drupal.org/node/1', 0, t('Drupalorgnid freelink was generated successfully.'));
    $this
      ->assertLinkByHref('http://oif.eafarris.com/wiki/about-one-inch-frame', 0, t('One inch frame freelink was generated successfully.'));
    $this
      ->assertLink(t('First page'), 0, t('Nodetitle freelink was generated successfully.'));
    $this
      ->assertLinkByHref('/search/node/test', 0, t('Search freelink was generated successfully.'));
    $this
      ->assertLink(t('Second page'), 0, t('Nid freelink was generated successfully.'));
    $this
      ->assertLinkByHref('http://www.google.com/search?q=drupal&hl=en', 0, t('Google freelink was generated successfully.'));
    $this
      ->assertLink('logo.png', 0, t('Image freelink was generated successfully.'));
    $this
      ->assertLink('logo.png', 1, t('File freelink was generated successfully.'));
    $this
      ->assertLinkByHref('http://en.wikisource.org/wiki/Main_Page', 0, t('Wikisource freelink was generated successfully.'));
    $this
      ->assertLinkByHref('http://en.wiktionary.org/wiki/Wiktionary:Main_Page', 0, t('Wiktionary freelink was generated successfully.'));
    $this
      ->assertLinkByHref('http://en.wikiquote.org/wiki/Main_Page', 0, t('Wikiquote freelink was generated successfully.'));
    $this
      ->assertLinkByHref('http://en.wikibooks.org/wiki/Main_Page', 0, t('Wikibooks freelink was generated successfully.'));
    $this
      ->assertLinkByHref('http://en.wikinews.org/wiki/Main_Page', 0, t('Wikinews freelink was generated successfully.'));
    $this
      ->assertLink($this->privileged_user->name, 0, t('User freelink was generated successfully.'));
    $this
      ->assertLink(t('First page'), 1, t('Path freelink was generated successfully.'));
    $this
      ->assertLinkByHref('http://en.wikipedia.org/wiki/Main_Page', 0, t('Wikipedia freelink was generated successfully.'));
  }

}

Classes

Namesort descending Description
FreelinkingTest @file Unit tests for the freelinking Module.