Projet

Général

Profil

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

root / drupal7 / sites / all / modules / media / modules / media_wysiwyg / tests / media_wysiwyg.paragraph_fix_filter.test @ 05237dd8

1
<?php
2

    
3
/**
4
 * @file
5
 * Tests for ensuring filters are working properly.
6
 */
7

    
8
/**
9
 * Defines media macro test cases.
10
 */
11
class MediaWYSIWYGParagraphFixFilterTest extends MediaWYSIWYGTestHelper {
12

    
13
  /**
14
   * Defines the regex to test for a media tag replacement.
15
   *
16
   * @var string
17
   */
18
  protected $regexpMediaTag = '/<div [^>]*media\-element\-container[^>]*>/i';
19

    
20
  /**
21
   * Defines the regex to test for in the raw body field source.
22
   *
23
   * @var string
24
   */
25
  protected $regexpPWrapped = '/<p[^>]*><div [^>]*media\-element\-container[^>]*>/i';
26

    
27
  /**
28
   * Defines the regex to test for the P replacement filter.
29
   *
30
   * @var string
31
   */
32
  protected $regexpReplaced = '/<div class\="media\-p"><div/i';
33

    
34
  /**
35
   * Provide test information.
36
   */
37
  public static function getInfo() {
38
    return array(
39
      'name' => t('Media WYSIWYG Paragraph Filter Test'),
40
      'description' => t('Tests that this media filter is working.'),
41
      'group' => t('Media WYSIWYG'),
42
      'dependencies' => array('token'),
43
    );
44
  }
45

    
46
  /**
47
   * Set-up the system for testing without the filter enabled.
48
   */
49
  public function setUp() {
50
    parent::setUp('token');
51

    
52
    // Create and log in a user.
53
    $account = $this->drupalCreateUser(array(
54
      'create article content',
55
      'administer filters',
56
      'use text format filtered_html',
57
    ));
58
    $this->drupalLogin($account);
59

    
60
    // Enable the media filter for full html.
61
    $edit = array(
62
      'filters[media_filter][status]' => TRUE,
63
      'filters[filter_autop][status]' => FALSE,
64
      'filters[filter_html][status]' => FALSE,
65
      'filters[filter_htmlcorrector][status]' => FALSE,
66
    );
67
    $this->drupalPost('admin/config/content/formats/filtered_html', $edit, t('Save configuration'));
68
  }
69

    
70
  /**
71
   * Test image media overrides.
72
   */
73
  public function testMediaFilterParagraphFixMultipleImages() {
74
    $files = $this->drupalGetTestFiles('image');
75
    $file = file_save($files[0]);
76

    
77
    // Create a node to test with 3 images.
78
    $nid = $this->createNode($file->fid);
79
    $node = node_load($nid);
80
    $node->body[LANGUAGE_NONE][0]['value'] = $this->generateJsonTokenMarkup($file->fid, 3);
81
    node_save($node);
82

    
83
    // Check without the filter enabled.
84
    $html = $this->drupalGet('node/' . $nid);
85
    $count = preg_match_all($this->regexpMediaTag, $html);
86
    $this->assertEqual($count, 3, t('Three media tags found, found @count.', array('@count' => $count)));
87

    
88
    $count = preg_match_all($this->regexpPWrapped, $html);
89
    $this->assertEqual($count, 3, t('Three media tags with original wrapping HTML present, found @count.', array('@count' => $count)));
90

    
91
    $count = preg_match_all($this->regexpReplaced, $html);
92
    $this->assertEqual($count, 0, t('No media tags with P replaced present, found @count.', array('@count' => $count)));
93

    
94
    // Enable the default P fix filter.
95
    $edit = array(
96
      'filters[media_filter_paragraph_fix][status]' => TRUE,
97
    );
98
    $this->drupalPost('admin/config/content/formats/filtered_html', $edit, t('Save configuration'));
99
    $html = $this->drupalGet('node/' . $nid);
100

    
101
    $count = preg_match_all($this->regexpMediaTag, $html);
102
    $this->assertEqual($count, 3, t('Three media tags found, found @count.', array('@count' => $count)));
103

    
104
    $count = preg_match_all($this->regexpPWrapped, $html);
105
    $this->assertEqual($count, 0, t('No media tags with original wrapping HTML present, found @count.', array('@count' => $count)));
106

    
107
    $count = preg_match_all($this->regexpReplaced, $html);
108
    $this->assertEqual($count, 0, t('No media tags with P replaced present, found @count.', array('@count' => $count)));
109

    
110
    // Enable the replace P fix filter option.
111
    $edit = array(
112
      'filters[media_filter_paragraph_fix][settings][replace]' => TRUE,
113
    );
114
    $this->drupalPost('admin/config/content/formats/filtered_html', $edit, t('Save configuration'));
115
    $html = $this->drupalGet('node/' . $nid);
116

    
117
    $count = preg_match_all($this->regexpMediaTag, $html);
118
    $this->assertEqual($count, 3, t('Three media tags found, found @count.', array('@count' => $count)));
119

    
120
    $count = preg_match_all($this->regexpPWrapped, $html);
121
    $this->assertEqual($count, 0, t('No media tags with original wrapping HTML present, found @count.', array('@count' => $count)));
122

    
123
    $count = preg_match_all($this->regexpReplaced, $html);
124
    $this->assertEqual($count, 3, t('Three media tags with P replaced present, found @count.', array('@count' => $count)));
125
  }
126

    
127
  /**
128
   * Test image media overrides.
129
   */
130
  public function testMediaFilterParagraphFixDefault() {
131
    $files = $this->drupalGetTestFiles('image');
132
    $file = file_save($files[0]);
133

    
134
    // Create a node to test with.
135
    $nid = $this->createNode($file->fid);
136

    
137
    // Check without the filter enabled.
138
    $this->drupalGet('node/' . $nid);
139
    $this->assertPattern($this->regexpPWrapped, t('Nested media DIV tags within paragraphs without filter.'));
140
    $this->assertNoPattern($this->regexpReplaced, t('No replacement DIV tag found without filter.'));
141

    
142
    // Enable the default P fix filter.
143
    $edit = array(
144
      'filters[media_filter_paragraph_fix][status]' => TRUE,
145
    );
146
    $this->drupalPost('admin/config/content/formats/filtered_html', $edit, t('Save configuration'));
147

    
148
    // Retest the content to check nested paragraphs are removed.
149
    $this->drupalGet('node/' . $nid);
150
    $this->assertNoPattern($this->regexpPWrapped, t('Nested media DIV tags within paragraphs with filter defaults.'));
151
    $this->assertNoPattern($this->regexpReplaced, t('No replacement DIV tag found with filter defaults.'));
152

    
153
    // Enable replacement option.
154
    $edit = array(
155
      'filters[media_filter_paragraph_fix][settings][replace]' => TRUE,
156
    );
157
    $this->drupalPost('admin/config/content/formats/filtered_html', $edit, t('Save configuration'));
158

    
159
    // Test that the replace text was found.
160
    $this->drupalGet('node/' . $nid);
161
    $this->assertNoPattern($this->regexpPWrapped, t('No nested media DIV tags within paragraphs with filter P replacement.'));
162
    $this->assertPattern($this->regexpReplaced, t('No replacement DIV tag found with filter P replacement.'));
163
  }
164

    
165
}