transliteration.test 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * @file
  4. * Transliteration module tests for the File (Field) Paths module.
  5. */
  6. /**
  7. * Class FileFieldPathsTransliterationCase
  8. */
  9. class FileFieldPathsTransliterationCase extends FileFieldPathsTestCase {
  10. /**
  11. * @inheritdoc
  12. */
  13. function setUp() {
  14. // Setup required modules.
  15. parent::setUp(array('transliteration'));
  16. }
  17. /**
  18. * @inheritdoc
  19. */
  20. public static function getInfo() {
  21. return array(
  22. 'name' => 'Transliteration integration',
  23. 'description' => 'Tests the Transliteration module integration.',
  24. 'group' => 'File (Field) Paths',
  25. );
  26. }
  27. /**
  28. * Test File (Field) Paths Transliteration UI.
  29. */
  30. public function testUI() {
  31. // Create a File field.
  32. $field_name = drupal_strtolower($this->randomName());
  33. $this->createFileField($field_name, $this->content_type);
  34. // Ensure File (Field) Paths Transliteration settings are present and available.
  35. $this->drupalGet("admin/structure/types/manage/{$this->content_type}/fields/{$field_name}");
  36. foreach (array('path', 'name') as $field) {
  37. $this->assertField("instance[settings][filefield_paths][file_{$field}][options][transliterate]", t('Transliteration checkbox is present in File @field settings.', array('@field' => drupal_ucfirst($field))));
  38. $element = $this->xpath('//input[@name=:name]/@disabled', array(':name' => "instance[settings][filefield_paths][file_{$field}][options][transliterate]"));
  39. $this->assert(empty($element), t('Transliteration checkbox is not disabled in File @field settings.', array('@field' => drupal_ucfirst($field))));
  40. }
  41. }
  42. /**
  43. * Test Transliteration cleanup in File (Field) Paths.
  44. */
  45. public function testTransliteration() {
  46. $langcode = LANGUAGE_NONE;
  47. // Create a File field.
  48. $field_name = drupal_strtolower($this->randomName());
  49. $instance_settings['filefield_paths']['file_path']['value'] = 'node/[node:title]';
  50. $instance_settings['filefield_paths']['file_path']['options']['transliterate'] = TRUE;
  51. $instance_settings['filefield_paths']['file_name']['value'] = '[node:title].[file:ffp-extension-original]';
  52. $instance_settings['filefield_paths']['file_name']['options']['transliterate'] = TRUE;
  53. $this->createFileField($field_name, $this->content_type, array(), $instance_settings);
  54. // Create a node with a test file.
  55. $test_file = $this->getTestFile('text');
  56. $edit['title'] = 'тест';
  57. $edit['files[' . $field_name . '_' . $langcode . '_0]'] = drupal_realpath($test_file->uri);
  58. $this->drupalPost("node/add/{$this->content_type}", $edit, t('Save'));
  59. // Get created Node ID.
  60. $matches = array();
  61. preg_match('/node\/([0-9]+)/', $this->getUrl(), $matches);
  62. $nid = $matches[1];
  63. // Ensure that file path/name have been processed correctly by
  64. // Transliteration.
  65. $node = node_load($nid);
  66. $this->assertEqual($node->{$field_name}[$langcode][0]['uri'], "public://node/test/test.txt", t('File path/name has been processed correctly by Transliteration'));
  67. }
  68. }