Projet

Général

Profil

Paste
Télécharger (6,36 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / media / modules / media_wysiwyg / tests / media_wysiwyg.macro.test @ ba3b3627

1
<?php
2

    
3
/**
4
 * @file
5
 * Tests for ensuring media macros render properly.
6
 */
7

    
8
/**
9
 * Base class for testing rendered wysiwyg macros.
10
 */
11
abstract class MediaWYSIWYGMacroTestHelper extends MediaWYSIWYGTestHelper {
12

    
13
  /**
14
   * Common setup routines for rendered media macros.
15
   */
16
  public function setUp() {
17
    parent::setUp(array('field_ui', 'token'));
18

    
19
    // Create and log in a user.
20
    $this->admin_user = $this->drupalCreateUser(array(
21
      'administer file types',
22
      'administer fields',
23
      'administer filters',
24
      'create article content',
25
      'use text format filtered_html',
26
    ));
27
    $this->drupalLogin($this->admin_user);
28

    
29
    // Enable the media filter for full html.
30
    $edit = array(
31
      'filters[media_filter][status]' => TRUE,
32
      'filters[filter_html][status]' => FALSE,
33
    );
34
    $this->drupalPost('admin/config/content/formats/filtered_html', $edit, t('Save configuration'));
35
  }
36

    
37
}
38

    
39
/**
40
 * Defines rendered media macros test cases.
41
 */
42
class MediaWYSIWYGRenderMacrosTest extends MediaWYSIWYGMacroTestHelper {
43

    
44
  /**
45
   * Test information.
46
   */
47
  public static function getInfo() {
48
    return array(
49
      'name' => t('Media WYSIWYG Rendered Macros test'),
50
      'description' => t('Test that rendered macros are displayed correctly.'),
51
      'group' => t('Media WYSIWYG'),
52
      'dependencies' => array('token'),
53
    );
54
  }
55

    
56
  /**
57
   * Test that displayed fields on file entity are rendered correctly.
58
   */
59
  public function testEmptyField() {
60
    // Add a field as part of the rendered macro.
61
    $edit = array(
62
      'fields[field_file_image_title_text][type]' => 'text_default',
63
    );
64
    $this->drupalPost('admin/structure/file-types/manage/image/display/preview', $edit, t('Save'));
65

    
66
    // Assert that fields that are enabled in display settings for macro are NOT
67
    // rendered if empty.
68
    $files = $this->drupalGetTestFiles('image');
69
    $attributes = array(
70
      'alt' => $this->randomName(),
71
      'title' => '',
72
    );
73
    $fields = array(
74
      'field_file_image_alt_text[und][0][value]' => $attributes['alt'],
75
      'field_file_image_title_text[und][0][value]' => $attributes['title'],
76
    );
77
    $files[0]->field_file_image_alt_text[LANGUAGE_NONE][0]['value'] = $attributes['alt'];
78
    $files[0]->field_file_image_title_text[LANGUAGE_NONE][0]['value'] = $attributes['title'];
79
    $file = file_save($files[0]);
80
    $nid = $this->createNode($file->fid, $attributes, $fields);
81
    $this->drupalGet('node/' . $nid);
82
    // Assert that the empty field isn't rendered.
83
    $this->assertNoPattern('|<div class="[^">]*field-name-field-file-image-title-text|', t('Displayed text field with empty value not rendered.'));
84
  }
85

    
86
}
87

    
88
/**
89
 * Defines media macro override test cases.
90
 */
91
class MediaWYSIWYGWYSIWYGOverridesTest extends MediaWYSIWYGMacroTestHelper {
92

    
93
  /**
94
   * Provide test information.
95
   */
96
  public static function getInfo() {
97
    return array(
98
      'name' => t('Media WYSIWYG WYSIWYG overrides'),
99
      'description' => t('Tests that overridden attributes display correct.'),
100
      'group' => t('Media WYSIWYG'),
101
      'dependencies' => array('token'),
102
    );
103
  }
104

    
105
  /**
106
   * Test image media overrides.
107
   */
108
  public function testAttributeOverrides() {
109
    $files = $this->drupalGetTestFiles('image');
110
    $file = file_save($files[0]);
111

    
112
    // Create a node to test with.
113
    $nid = $this->createNode($file->fid);
114

    
115
    $this->drupalGet('node/' . $nid);
116
    $this->assertRaw('width="100"', t('Image displays with default width attribute.'));
117
    $this->assertRaw('height="100"', t('Image displays with default height attribute.'));
118

    
119
    // Create a node with a style attribute.
120
    $attributes = array(
121
      'style' => 'float: left; width: 50px;',
122
    );
123
    $nid = $this->createNode($file->fid, $attributes);
124
    $this->drupalGet('node/' . $nid);
125
    $this->assertRaw(drupal_attributes($attributes), t('Image displays with overriden attributes.'));
126

    
127
    // Create a node with overriden alt/title attributes.
128
    $attributes = array(
129
      'alt' => $this->randomName(),
130
      'title' => $this->randomName(),
131
    );
132
    $nid = $this->createNode($file->fid, $attributes);
133
    $this->drupalGet('node/' . $nid);
134
    $this->assertRaw(drupal_attributes($attributes), t('Image displays with alt/title set as attributes.'));
135

    
136
    // Create a node with overriden alt/title fields.
137
    $fields = $attributes = array();
138
    $attributes['alt'] = $fields['field_file_image_alt_text[und][0][value]'] = $this->randomName();
139
    $attributes['title'] = $fields['field_file_image_title_text[und][0][value]'] = $this->randomName();
140

    
141
    $nid = $this->createNode($file->fid, array(), $fields);
142
    $this->drupalGet('node/' . $nid);
143
    // Ensure that the alt/title from attributes display.
144
    $this->assertRaw(drupal_attributes($attributes), t('Image displays with alt/title set as fields.'));
145

    
146
    // Create a node with overriden alt/title fields as well as attributes.
147
    $attributes = array(
148
      'alt' => $this->randomName(),
149
      'title' => $this->randomName(),
150
    );
151
    $fields = array(
152
      'field_file_image_alt_text[und][0][value]' => $this->randomName(),
153
      'field_file_image_title_text[und][0][value]' => $this->randomName(),
154
    );
155
    $nid = $this->createNode($file->fid, $attributes, $fields);
156
    $this->drupalGet('node/' . $nid);
157
    // Ensure that the alt/title from attributes display rather the field ones.
158
    $this->assertRaw(drupal_attributes($attributes), t('Image displays with alt/title set as attributes overriding field values.'));
159
  }
160

    
161
  /**
162
   * Test image media overrides on images with fields attached.
163
   */
164
  public function testAttributeOverridesWithFields() {
165
    // First make images display the title field on the preview mode we use.
166
    $instance = field_read_instance('file', 'field_file_image_title_text', 'image');
167
    $instance['display']['preview']['type'] = 'text_default';
168
    $instance['display']['preview']['module'] = 'text';
169
    field_update_instance($instance);
170

    
171
    $files = $this->drupalGetTestFiles('image');
172
    $file = file_save($files[0]);
173

    
174
    $attributes = array(
175
      'style' => 'float: left;',
176
    );
177
    $fields = array(
178
      'field_file_image_title_text[und][0][value]' => $this->randomName(),
179
    );
180
    $nid = $this->createNode($file->fid, $attributes, $fields);
181
    $this->drupalGet('node/' . $nid);
182
    $this->assertRaw('float: left;', 'Image displays with overriden attributes when displays with fields.');
183
    $this->assertRaw('media-float-left', 'Media float class added.');
184
  }
185
}