media_wysiwyg.paragraph_fix_filter.test in D7 Media 7.3
Same filename and directory in other branches
Tests for ensuring filters are working properly.
File
modules/media_wysiwyg/tests/media_wysiwyg.paragraph_fix_filter.testView source
<?php
/**
* @file
* Tests for ensuring filters are working properly.
*/
/**
* Defines media macro test cases.
*/
class MediaWYSIWYGParagraphFixFilterTest extends MediaWYSIWYGTestHelper {
/**
* Defines the regex to test for a media tag replacement.
*
* @var string
*/
protected $regexpMediaTag = '/<div [^>]*media\\-element\\-container[^>]*>/i';
/**
* Defines the regex to test for in the raw body field source.
*
* @var string
*/
protected $regexpPWrapped = '/<p[^>]*><div [^>]*media\\-element\\-container[^>]*>/i';
/**
* Defines the regex to test for the P replacement filter.
*
* @var string
*/
protected $regexpReplaced = '/<div class\\="media\\-p"><div/i';
/**
* Provide test information.
*/
public static function getInfo() {
return array(
'name' => t('Media WYSIWYG Paragraph Filter Test'),
'description' => t('Tests that this media filter is working.'),
'group' => t('Media WYSIWYG'),
'dependencies' => array(
'token',
),
);
}
/**
* Set-up the system for testing without the filter enabled.
*/
public function setUp() {
parent::setUp('token');
// Create and log in a user.
$account = $this
->drupalCreateUser(array(
'create article content',
'administer filters',
'use text format filtered_html',
));
$this
->drupalLogin($account);
// Enable the media filter for full html.
$edit = array(
'filters[media_filter][status]' => TRUE,
'filters[filter_autop][status]' => FALSE,
'filters[filter_html][status]' => FALSE,
'filters[filter_htmlcorrector][status]' => FALSE,
);
$this
->drupalPost('admin/config/content/formats/filtered_html', $edit, t('Save configuration'));
}
/**
* Test image media overrides.
*/
public function testMediaFilterParagraphFixMultipleImages() {
$files = $this
->drupalGetTestFiles('image');
$file = file_save($files[0]);
// Create a node to test with 3 images.
$nid = $this
->createNode($file->fid);
$node = node_load($nid);
$node->body[LANGUAGE_NONE][0]['value'] = $this
->generateJsonTokenMarkup($file->fid, 3);
node_save($node);
// Check without the filter enabled.
$html = $this
->drupalGet('node/' . $nid);
$forphp53compat = array();
$count = preg_match_all($this->regexpMediaTag, $html, $forphp53compat);
$this
->assertEqual($count, 3, t('Three media tags found, found @count.', array(
'@count' => $count,
)));
$count = preg_match_all($this->regexpPWrapped, $html, $forphp53compat);
$this
->assertEqual($count, 3, t('Three media tags with original wrapping HTML present, found @count.', array(
'@count' => $count,
)));
$count = preg_match_all($this->regexpReplaced, $html, $forphp53compat);
$this
->assertEqual($count, 0, t('No media tags with P replaced present, found @count.', array(
'@count' => $count,
)));
// Enable the default P fix filter.
$edit = array(
'filters[media_filter_paragraph_fix][status]' => TRUE,
);
$this
->drupalPost('admin/config/content/formats/filtered_html', $edit, t('Save configuration'));
$html = $this
->drupalGet('node/' . $nid);
$count = preg_match_all($this->regexpMediaTag, $html, $forphp53compat);
$this
->assertEqual($count, 3, t('Three media tags found, found @count.', array(
'@count' => $count,
)));
$count = preg_match_all($this->regexpPWrapped, $html, $forphp53compat);
$this
->assertEqual($count, 0, t('No media tags with original wrapping HTML present, found @count.', array(
'@count' => $count,
)));
$count = preg_match_all($this->regexpReplaced, $html, $forphp53compat);
$this
->assertEqual($count, 0, t('No media tags with P replaced present, found @count.', array(
'@count' => $count,
)));
// Enable the replace P fix filter option.
$edit = array(
'filters[media_filter_paragraph_fix][settings][replace]' => TRUE,
);
$this
->drupalPost('admin/config/content/formats/filtered_html', $edit, t('Save configuration'));
$html = $this
->drupalGet('node/' . $nid);
$count = preg_match_all($this->regexpMediaTag, $html, $forphp53compat);
$this
->assertEqual($count, 3, t('Three media tags found, found @count.', array(
'@count' => $count,
)));
$count = preg_match_all($this->regexpPWrapped, $html, $forphp53compat);
$this
->assertEqual($count, 0, t('No media tags with original wrapping HTML present, found @count.', array(
'@count' => $count,
)));
$count = preg_match_all($this->regexpReplaced, $html, $forphp53compat);
$this
->assertEqual($count, 3, t('Three media tags with P replaced present, found @count.', array(
'@count' => $count,
)));
}
/**
* Test image media overrides.
*/
public function testMediaFilterParagraphFixDefault() {
$files = $this
->drupalGetTestFiles('image');
$file = file_save($files[0]);
// Create a node to test with.
$nid = $this
->createNode($file->fid);
// Check without the filter enabled.
$this
->drupalGet('node/' . $nid);
$this
->assertPattern($this->regexpPWrapped, t('Nested media DIV tags within paragraphs without filter.'));
$this
->assertNoPattern($this->regexpReplaced, t('No replacement DIV tag found without filter.'));
// Enable the default P fix filter.
$edit = array(
'filters[media_filter_paragraph_fix][status]' => TRUE,
);
$this
->drupalPost('admin/config/content/formats/filtered_html', $edit, t('Save configuration'));
// Retest the content to check nested paragraphs are removed.
$this
->drupalGet('node/' . $nid);
$this
->assertNoPattern($this->regexpPWrapped, t('Nested media DIV tags within paragraphs with filter defaults.'));
$this
->assertNoPattern($this->regexpReplaced, t('No replacement DIV tag found with filter defaults.'));
// Enable replacement option.
$edit = array(
'filters[media_filter_paragraph_fix][settings][replace]' => TRUE,
);
$this
->drupalPost('admin/config/content/formats/filtered_html', $edit, t('Save configuration'));
// Test that the replace text was found.
$this
->drupalGet('node/' . $nid);
$this
->assertNoPattern($this->regexpPWrapped, t('No nested media DIV tags within paragraphs with filter P replacement.'));
$this
->assertPattern($this->regexpReplaced, t('No replacement DIV tag found with filter P replacement.'));
}
}
Classes
Name | Description |
---|---|
MediaWYSIWYGParagraphFixFilterTest | Defines media macro test cases. |