You are here

textimage_url.test in Textimage 7.2

Textimage - web test case script.

File

tests/textimage_url.test
View source
<?php

/**
 * @file
 * Textimage - web test case script.
 */

/**
 * Functional tests for Textimage.
 */
class TextimageUrlTest extends DrupalWebTestCase {
  protected $textimageAdmin = 'admin/config/media/textimage';

  /**
   * Get info.
   */
  public static function getInfo() {
    return array(
      'name' => 'Textimage URL',
      'description' => 'Generation of deriviative via URL request',
      'group' => 'Textimage',
    );
  }

  /**
   * Set up.
   */
  public function setUp() {

    // Enable required modules.
    $modules = array(
      'textimage',
    );
    parent::setUp($modules);
  }

  /**
   * Tear down.
   */
  public function tearDown() {
    parent::tearDown();
  }

  /**
   * Build and display a URL derivative.
   */
  public function testTextimage() {
    $stream_wrapper = file_stream_wrapper_get_instance_by_scheme(variable_get('file_default_scheme', 'public'));
    $directory_path = $stream_wrapper
      ->getDirectoryPath();

    // Create a user and log it in.
    $this->admin_user = $this
      ->drupalCreateUser(array(
      'administer site configuration',
      'create textimages',
    ));
    $this
      ->drupalLogin($this->admin_user);

    // Change the font directory.
    $edit = array(
      'textimage_fonts_path' => drupal_get_path('module', 'textimage') . '/tests/fonts',
    );
    $this
      ->drupalPost($this->textimageAdmin . '/settings', $edit, t('Save configuration'));

    // Create a test preset.
    $edit = array(
      'name' => 'textimage_test',
      'description' => 'textimage_test description',
      'settings[font][file]' => 'OldStandard-Regular.ttf',
      'settings[font][size]' => 20,
      'settings[text][maximum_width]' => 200,
      'settings[text][fixed_width]' => TRUE,
    );
    $this
      ->drupalPost($this->textimageAdmin . '/preset/new', $edit, t('Save preset'));

    // Build and display a URL derivative.
    $this
      ->drupalGet($directory_path . '/textimage/textimage_test/url preview text image');

    // Check file was generated.
    $files_count = 0;
    $dir = dir($directory_path . '/textimage/textimage_test');
    if ($dir) {
      while (($entry = $dir
        ->read()) !== FALSE) {
        if ($entry == '.' || $entry == '..') {
          continue;
        }
        $files_count++;
      }
      $dir
        ->close();
    }
    $this
      ->assertTrue($files_count == 1, t('Textimage generation via request URL.'));
  }

}

Classes

Namesort descending Description
TextimageUrlTest Functional tests for Textimage.