You are here

textimage.test in Textimage 7.2

Same filename and directory in other branches
  1. 7.3 tests/textimage.test

Textimage - web test case script.

File

tests/textimage.test
View source
<?php

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

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

  /**
   * Get info.
   */
  public static function getInfo() {
    return array(
      'name' => 'Textimage functionality',
      'description' => 'Basic functionality of the Textimage module',
      'group' => 'Textimage',
    );
  }

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

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

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

  /**
   * Test functionality of the module.
   */
  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'));

    // Generate a few derivative images via theme.
    $textimage = theme('textimage_image', array(
      'preset' => 1,
      'text' => 'preview text image',
    ));
    $textimage = theme('textimage_image', array(
      'preset' => 1,
      'text' => 'Предварительный просмотр текста',
    ));
    $textimage = theme('textimage_image', array(
      'preset' => 1,
      'text' => 'προεπισκόπηση της εικόνας κείμενο',
    ));

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

}

Classes

Namesort descending Description
TextimageTest Functional tests for Textimage.