View source
<?php
namespace Drupal\Tests\responsivewrappers\Functional;
use Drupal\filter\Entity\FilterFormat;
use Drupal\Tests\BrowserTestBase;
class ResponsiveWrappersTest extends BrowserTestBase {
public static $modules = [
'field',
'node',
'responsivewrappers',
'text',
'user',
];
protected $defaultTheme = 'stable';
protected $user;
protected $node;
protected function setUp() {
parent::setUp();
$this->user = $this
->drupalCreateUser([
'access content',
'access administration pages',
'administer filters',
]);
FilterFormat::create([
'format' => 'full_html',
'name' => 'Full HTML',
'weight' => 1,
'filters' => [],
])
->save();
$this
->drupalCreateContentType([
'type' => 'page',
'name' => 'Basic Page',
]);
$this->node = $this
->drupalCreateNode([
'type' => 'page',
'title' => 'Responsive filter test',
'body' => [
'value' => '<img scr="#" /><table></table><iframe src="https://www.youtube.com/embed/"></iframe><iframe src="https://player.vimeo.com/video/"></iframe>',
'format' => 'full_html',
],
]);
$this
->drupalLogin($this->user);
}
public function testsFilterContentOutput() {
$this
->drupalGet('node/' . $this->node
->id());
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->responseContains('<img scr="#" />');
$this
->assertSession()
->responseContains('<table></table>');
$this
->assertSession()
->responseContains('<iframe src="https://www.youtube.com/embed/"></iframe>');
$this
->assertSession()
->responseContains('<iframe src="https://player.vimeo.com/video/"></iframe>');
$this
->drupalGet('admin/config/content/formats/manage/full_html');
$edit = [
'filters[filter_bootstrap_responsive_wrapper][status]' => TRUE,
'filters[filter_bootstrap_responsive_wrapper][settings][responsive_iframe]' => TRUE,
'filters[filter_bootstrap_responsive_wrapper][settings][responsive_table]' => TRUE,
'filters[filter_bootstrap_responsive_wrapper][settings][responsive_image]' => TRUE,
];
$this
->drupalPostForm(NULL, $edit, t('Save configuration'));
$this
->drupalGet('node/' . $this->node
->id());
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->responseContains('<img scr="#" class="img-fluid" />');
$this
->assertSession()
->responseContains('<div class="table-responsive"><table class="table"></table></div>');
$this
->assertSession()
->responseContains('<div class="embed-responsive embed-responsive-16by9"><iframe src="https://www.youtube.com/embed/" class="embed-responsive-item"></iframe></div>');
$this
->assertSession()
->responseContains('<div class="embed-responsive embed-responsive-16by9"><iframe src="https://player.vimeo.com/video/" class="embed-responsive-item"></iframe></div>');
$this
->drupalGet('admin/config/content/responsivewrappers');
$this
->drupalPostForm(NULL, [
'version' => 3,
], t('Save configuration'));
$this->node
->setTitle('Responsive filter test B3');
$this->node
->save();
$this
->drupalGet('node/' . $this->node
->id());
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->responseContains('<img scr="#" class="img-responsive" />');
$this
->drupalGet('admin/config/content/responsivewrappers');
$this
->drupalPostForm(NULL, [
'version' => 0,
'image_class' => 'holi',
], t('Save configuration'));
$this->node
->setTitle('Responsive filter test Custom');
$this->node
->save();
$this
->drupalGet('node/' . $this->node
->id());
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->responseContains('<img scr="#" class="holi" />');
}
}