filefield_paths.test 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * @file
  4. * Tests for the File (Field) Paths module.
  5. */
  6. /**
  7. * Class FileFieldPathsTestCase
  8. */
  9. class FileFieldPathsTestCase extends FileFieldTestCase {
  10. var $content_type = NULL;
  11. var $public_files_directory = NULL;
  12. /**
  13. * @inheritdoc
  14. */
  15. function setUp() {
  16. // Setup required modules.
  17. $modules = func_get_args();
  18. if (isset($modules[0]) && is_array($modules[0])) {
  19. $modules = $modules[0];
  20. }
  21. $modules[] = 'filefield_paths_test';
  22. $modules[] = 'image';
  23. $modules[] = 'token';
  24. parent::setUp($modules);
  25. // Include all optional dependency files.
  26. $dirname = dirname(__FILE__) . "/../modules";
  27. $includes = file_scan_directory($dirname, '/.inc$/');
  28. foreach (array_keys($includes) as $file) {
  29. require_once $file;
  30. }
  31. // Create a content type.
  32. $content_type = $this->drupalCreateContentType();
  33. $this->content_type = $content_type->name;
  34. }
  35. /**
  36. * @inheritdoc
  37. */
  38. function createFileField($name, $type_name, $field_settings = array(), $instance_settings = array(), $widget_settings = array()) {
  39. parent::createFileField($name, $type_name, $field_settings, $instance_settings, $widget_settings);
  40. $this->drupalPost("admin/structure/types/manage/{$this->content_type}/fields/{$name}", array(), t('Save settings'));
  41. }
  42. /**
  43. * Creates a new image field.
  44. *
  45. * @param $name
  46. * The name of the new field (all lowercase), exclude the "field_" prefix.
  47. * @param $type_name
  48. * The node type that this field will be added to.
  49. * @param $field_settings
  50. * A list of field settings that will be added to the defaults.
  51. * @param $instance_settings
  52. * A list of instance settings that will be added to the instance defaults.
  53. * @param $widget_settings
  54. * A list of widget settings that will be added to the widget defaults.
  55. */
  56. function createImageField($name, $type_name, $field_settings = array(), $instance_settings = array(), $widget_settings = array()) {
  57. $field = array(
  58. 'field_name' => $name,
  59. 'type' => 'image',
  60. 'settings' => array(),
  61. 'cardinality' => !empty($field_settings['cardinality']) ? $field_settings['cardinality'] : 1,
  62. );
  63. $field['settings'] = array_merge($field['settings'], $field_settings);
  64. field_create_field($field);
  65. $instance = array(
  66. 'field_name' => $name,
  67. 'label' => $name,
  68. 'entity_type' => 'node',
  69. 'bundle' => $type_name,
  70. 'required' => !empty($instance_settings['required']),
  71. 'settings' => array(),
  72. 'widget' => array(
  73. 'type' => 'image_image',
  74. 'settings' => array(),
  75. ),
  76. );
  77. $instance['settings'] = array_merge($instance['settings'], $instance_settings);
  78. $instance['widget']['settings'] = array_merge($instance['widget']['settings'], $widget_settings);
  79. field_create_instance($instance);
  80. $this->drupalPost("admin/structure/types/manage/{$this->content_type}/fields/{$name}", array(), t('Save settings'));
  81. }
  82. }