Projet

Général

Profil

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

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

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
    $forphp53compat = array();
86
    $count = preg_match_all($this->regexpMediaTag, $html, $forphp53compat);
87
    $this->assertEqual($count, 3, t('Three media tags found, found @count.', array('@count' => $count)));
88

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
166
}