You are here

public function TextimageTest::testTextimage in Textimage 7.3

Same name and namespace in other branches
  1. 7.2 tests/textimage.test \TextimageTest::testTextimage()

Test functionality of the module.

File

tests/textimage.test, line 177
Textimage - web test case script.

Class

TextimageTest
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();

  // Generate a few derivative images via theme.
  theme('textimage_style_image', array(
    'style_name' => 'textimage_test',
    'text' => array(
      'preview text image',
    ),
  ));
  theme('textimage_style_image', array(
    'style_name' => 'textimage_test',
    'text' => array(
      'Предварительный просмотр текста',
    ),
  ));
  theme('textimage_style_image', array(
    'style_name' => 'textimage_test',
    'text' => array(
      'προεπισκόπηση της εικόνας κείμενο',
    ),
  ));
  theme('textimage_formatter', array(
    'style_name' => 'textimage_test',
    'text' => array(
      'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
    ),
  ));

  // Check files were generated.
  $files_count = count(file_scan_directory($directory_path . '/textimage/textimage_test', '/.*/'));
  $this
    ->assertTrue($files_count == 4, t('Textimage generation via theme.'));
  $this
    ->assertTextimage($directory_path . '/textimage/textimage_test/preview text image.png', 177, 28);
  $this
    ->assertTextimage($directory_path . '/textimage/textimage_test/Предварительный просмотр текста.png', 331, 28);
  $this
    ->assertTextimage($directory_path . '/textimage/textimage_test/προεπισκόπηση της εικόνας κείμενο.png', 328, 28);

  // Build and display a URL derivative.
  variable_set('clean_url', 1);
  $this
    ->drupalGet($directory_path . '/textimage/textimage_test/url_preview_text_image');
  $this
    ->assertResponse(200);

  // Check file was generated.
  $files_count = count(file_scan_directory($directory_path . '/textimage/textimage_test', '/.*/'));
  $this
    ->assertTrue($files_count == 5, t('Textimage generation via request URL.'));
  $this
    ->assertTextimage($directory_path . '/textimage/textimage_test/url_preview_text_image.png', 225, 28);

  // Build a textimage at target URI via API.
  $uri = TextimageImager::getImageUri('textimage_test', NULL, array(
    'test',
  ), 'png', FALSE, NULL, NULL, 'public://textimage-testing/bingo-bongo.png');

  // Check file was generated.
  $files_count = count(file_scan_directory('public://textimage-testing', '/.*/'));
  $this
    ->assertTrue($files_count == 1, t('Textimage generation at target URI via API.'));
  $this
    ->assertTextimage('public://textimage-testing/bingo-bongo.png', 35, 28);

  // Build another textimage at same target URI.
  $uri = TextimageImager::getImageUri('textimage_test', NULL, array(
    'another test',
  ), 'png', FALSE, NULL, NULL, 'public://textimage-testing/bingo-bongo.png');

  // Check file was replaced.
  $files_count = count(file_scan_directory('public://textimage-testing', '/.*/'));
  $this
    ->assertTrue($files_count == 1, t('Textimage replaced at target URI via API.'));
  $this
    ->assertTextimage('public://textimage-testing/bingo-bongo.png', 113, 28);

  // Build a textimage at target URI via theme.
  $textimage = theme('textimage_formatter', array(
    'style_name' => 'textimage_test',
    'text' => array(
      'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.',
    ),
    'target_uri' => 'public://textimage-testing/ut-enim.png',
  ));

  // Check file was generated.
  $files_count = count(file_scan_directory('public://textimage-testing', '/.*/'));
  $this
    ->assertTrue($files_count == 2, t('Textimage generation at target URI via theme.'));

  // Test token resolution.
  //
  // Create a text field for Textimage test.
  $field_name = strtolower($this
    ->randomName());
  $this
    ->createTextimageField($field_name, 'article');

  // Create a new node.
  $field_value = $this
    ->randomName(20);
  $nid = $this
    ->createTextimageNode($field_name, $field_value, 'article');

  // Set the textimage formatter - no link.
  $instance = field_info_instance('node', $field_name, 'article');
  $instance['display']['default']['type'] = 'textimage';
  $instance['display']['default']['settings']['image_style'] = 'textimage_test';
  field_update_instance($instance);
  $this
    ->drupalGet('node/' . $nid);

  // Check token.
  $node = node_load($nid, NULL, TRUE);
  $uri = token_replace('[textimage:uri:' . $field_name . ']', array(
    'node' => $node,
  ));
  $this
    ->assertEqual('public://textimage/textimage_test/' . $field_value . '.png', $uri);
}