filefield_paths.update.test 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * @file
  4. * Tests for the File (Field) Paths module.
  5. */
  6. /**
  7. * Class FileFieldPathsUpdatesCase
  8. */
  9. class FileFieldPathsUpdatesCase extends FileFieldPathsTestCase {
  10. /**
  11. * @inheritdoc
  12. */
  13. public static function getInfo() {
  14. return array(
  15. 'name' => 'Update functionality',
  16. 'description' => 'Tests retroactive and active updates functionality.',
  17. 'group' => 'File (Field) Paths',
  18. );
  19. }
  20. /**
  21. * Test behaviour of Retroactive updates when no updates are needed.
  22. */
  23. public function testRetroEmpty() {
  24. // Create a File field.
  25. $field_name = drupal_strtolower($this->randomName());
  26. $this->createFileField($field_name, $this->content_type);
  27. // Trigger retroactive updates.
  28. $edit = array(
  29. 'instance[settings][filefield_paths][retroactive_update]' => TRUE
  30. );
  31. $this->drupalPost("admin/structure/types/manage/{$this->content_type}/fields/{$field_name}", $edit, t('Save settings'));
  32. // Ensure no errors are thrown.
  33. $this->assertNoText('Error', t('No errors were found.'));
  34. }
  35. /**
  36. * Test basic Retroactive updates functionality.
  37. */
  38. public function testRetroBasic() {
  39. // Create an Image field.
  40. $field_name = drupal_strtolower($this->randomName());
  41. $this->createImageField($field_name, $this->content_type, array());
  42. // Modify instance settings.
  43. $instance = field_info_instance('node', $field_name, $this->content_type);
  44. $instance['display']['default']['settings']['image_style'] = 'thumbnail';
  45. $instance['display']['default']['settings']['image_link'] = 'content';
  46. field_update_instance($instance);
  47. $this->drupalGet("admin/structure/types/manage/{$this->content_type}/display");
  48. $original_instance = field_info_instance('node', $field_name, $this->content_type);
  49. // Create a node with a test file.
  50. $test_file = $this->getTestFile('image');
  51. $nid = $this->uploadNodeFile($test_file, $field_name, $this->content_type);
  52. // Ensure that the file is in the default path.
  53. $this->drupalGet("node/{$nid}");
  54. $this->assertRaw("{$this->public_files_directory}/styles/thumbnail/public/{$test_file->name}", t('The File is in the default path.'));
  55. // Trigger retroactive updates.
  56. $edit['instance[settings][filefield_paths][retroactive_update]'] = TRUE;
  57. $edit['instance[settings][filefield_paths][file_path][value]'] = 'node/[node:nid]';
  58. $this->drupalPost("admin/structure/types/manage/{$this->content_type}/fields/{$field_name}", $edit, t('Save settings'));
  59. // Ensure instance display settings haven't changed.
  60. // @see https://www.drupal.org/node/2276435
  61. drupal_static_reset('_field_info_field_cache');
  62. $instance = field_info_instance('node', $field_name, $this->content_type);
  63. $this->assert($original_instance['display'] === $instance['display'], t('Instance settings have not changed.'));
  64. // Ensure that the file path has been retroactively updated.
  65. $this->drupalGet("node/{$nid}");
  66. $this->assertRaw("{$this->public_files_directory}/styles/thumbnail/public/node/{$nid}/{$test_file->name}", t('The File path has been retroactively updated.'));
  67. }
  68. }