You are here

public function TextimageUrlTest::testTextimage in Textimage 7.2

Build and display a URL derivative.

File

tests/textimage_url.test, line 46
Textimage - web test case script.

Class

TextimageUrlTest
Functional tests for Textimage.

Code

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.'));
}