You are here

quote.test in Quote 7

Test the Quote filter.

File

tests/quote.test
View source
<?php

/**
 * @file
 * Test the Quote filter.
 */
class QuoteTest extends DrupalWebTestCase {
  protected $quoteUser;
  protected $quoteType;
  protected $quoteFormat;
  protected $sampleText1 = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
  protected $sampleText2 = 'Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?';
  public static function getInfo() {
    return array(
      'name' => 'Quote',
      'description' => 'Tests the Quote filter.',
      'group' => 'Filter',
      'dependencies' => array(),
    );
  }
  function setUp() {
    parent::setUp(array(
      'quote',
      'comment',
    ));
    $this->quoteType = $this
      ->drupalCreateContentType(array(
      'name' => 'Quote Node',
      'type' => 'quote',
    ));
    $this
      ->addFormat();
    $this->quoteUser = $this
      ->drupalCreateUser(array(
      'create quote content',
      'edit any quote content',
      'administer filters',
      'use text format ' . $this->quoteFormat->format,
    ));
    $this
      ->drupalLogin($this->quoteUser);
    $this
      ->quoteConfigure();
  }

  /**
   * Modify the quote module's configuration form.
   * @param Boolean $enabled
   *   Indicates if the quote node type is to be associated with the module.
   * @param Boolean $nodeQuoteLink
   *   Indicates if the quote link is to be displayed for nodes.
   */
  function quoteConfigure($enabled = TRUE, $nodeQuoteLink = TRUE) {
    $edit = array(
      'quote[node_types][quote]' => $enabled,
      'quote[node_link_display]' => $nodeQuoteLink,
    );
    $this
      ->drupalPost('admin/config/content/quote', $edit, t('Save configuration'));
  }

  /**
   * Add a (default) text format to contain the quote filter.
   */
  function addFormat() {
    $format = new stdClass();
    $format->format = 'quote_format';
    $format->name = 'Quote format';
    $format->weight = -100;
    filter_format_save($format);

    // Add standard filters.
    $format->filters['autop']['status'] = 1;
    $format->filters['html']['status'] = 1;
    $format->filters['url']['status'] = 1;

    // Add quote filter and save.
    $format->filters['quote']['status'] = 1;
    filter_format_save($format);

    // Clear cache.
    $this
      ->checkPermissions(array(), TRUE);
    $this->quoteFormat = $format;
  }

  /**
   * Create a node.
   * @param String $type
   *   The machine name of the node.
   * @param String $body
   *   The contents of the body field.
   * @param String $format
   *   The machine name of the body field's text format.
   */
  function addNode($type = 'quote', $body = NULL, $format = 'quote_format') {
    $edit = array(
      'title' => $this
        ->randomName(),
      'body[und][0][value]' => is_null($body) ? $this->sampleText1 : $body,
      'body[und][0][format]' => $format,
    );
    $this
      ->drupalPost("node/add/{$type}", $edit, t('Save'));
    $this
      ->assertText('Node ' . $edit['title'] . ' has been created', 'Found node creation message', 'Quote');
  }

  /**
   * Test the quote filter within nodes (as opposed to within comments).
   */
  function testNodeQuote() {
    $this
      ->addNode('quote', $this->sampleText1 . "\n\n" . '[quote=foo]' . $this->sampleText2 . '[/quote]');
    $this
      ->assertText($this->sampleText1, 'Node content detected successfully.', 'Quote');
    $this
      ->assertText('foo wrote: ' . $this->sampleText2, 'Quote detected successfully.', 'Quote');
  }

  /**
   * Test the quote link feature.
   */
  function testNodeLink() {

    // Test link when quote is enabled for the Quote node type.
    $this
      ->addNode('quote', $this->sampleText1);
    $this
      ->drupalGet('node/1');
    $this
      ->assertLink(t('Quote'), 0, 'Quote link found', 'Quote');
    $this
      ->assertLinkByHref('comment/reply/1?quote=1#comment-form', 0, 'Quote HREF confirmed', 'Quote');

    // Click link.
    $this
      ->clickLink(t('Quote'));

    // Check if the quote is being included in the comment field.
    $this
      ->assertText('[quote=' . $this->quoteUser->name . ']' . $this->sampleText1 . '[/quote]', 'Comment textarea detected with correct value.', 'Quote');

    // Test link when quote is not enabled for the Quote node type.
    $this
      ->quoteConfigure(FALSE);
    $this
      ->drupalGet('node/1');
    $this
      ->assertNoLink(t('Quote'), 0, 'Quote link not found with node link support disabled', 'Quote');
  }

}

Classes

Namesort descending Description
QuoteTest @file Test the Quote filter.