pathauto.test 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * @file
  4. * Pathauto module tests for the File (Field) Paths module.
  5. */
  6. /**
  7. * Class FileFieldPathsPathautoCase
  8. */
  9. class FileFieldPathsPathautoCase extends FileFieldPathsTestCase {
  10. /**
  11. * @inheritdoc
  12. */
  13. function setUp() {
  14. // Setup required modules.
  15. parent::setUp(array('pathauto'));
  16. }
  17. /**
  18. * @inheritdoc
  19. */
  20. public static function getInfo() {
  21. return array(
  22. 'name' => 'Pathauto integration',
  23. 'description' => 'Tests the Pathauto module integration.',
  24. 'group' => 'File (Field) Paths',
  25. );
  26. }
  27. /**
  28. * Test File (Field) Paths Pathauto 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 Pathauto 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][pathauto]", t('Pathauto 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][pathauto]"));
  39. $this->assert(empty($element), t('Pathauto checkbox is not disabled in File @field settings.', array('@field' => drupal_ucfirst($field))));
  40. }
  41. }
  42. /**
  43. * Test Pathauto cleanup in File (Field) Paths.
  44. */
  45. public function testPathauto() {
  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']['pathauto'] = TRUE;
  51. $instance_settings['filefield_paths']['file_name']['value'] = '[node:title].[file:ffp-extension-original]';
  52. $instance_settings['filefield_paths']['file_name']['options']['pathauto'] = 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'] = $this->randomString() . ' ' . $this->randomString();
  57. $edit['files[' . $field_name . '_' . $langcode . '_0]'] = drupal_realpath($test_file->uri);
  58. $this->drupalPost("node/add/{$this->content_type}", $edit, t('Save'));
  59. // Ensure that file path/name have been processed correctly by Pathauto.
  60. $node = node_load(1);
  61. module_load_include('inc', 'pathauto');
  62. $parts = explode('/', $node->title);
  63. foreach ($parts as &$part) {
  64. $part = pathauto_cleanstring($part);
  65. }
  66. $title = implode('/', $parts);
  67. $this->assertEqual($node->{$field_name}[$langcode][0]['uri'], "public://node/{$title}/{$title}.txt", t('File path/name has been processed correctly by Pathauto'));
  68. }
  69. }