EmbedPreviewTest.php in Embed 8
File
tests/src/Functional/EmbedPreviewTest.php
View source
<?php
namespace Drupal\Tests\embed\Functional;
use Drupal\Component\Serialization\Json;
use Drupal\filter\Entity\FilterFormat;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\BrowserTestBase;
class EmbedPreviewTest extends BrowserTestBase {
public static $modules = [
'embed_test',
'filter',
];
protected $defaultTheme = 'stark';
public function testPreview() {
NodeType::create([
'type' => 'baz',
'label' => 'Bazzz',
])
->save();
$filter_format = FilterFormat::create([
'format' => 'foo',
'name' => 'Foo',
]);
$filter_format
->filters()
->addInstanceId('embed_test_node', [
'id' => 'embed_test_node',
'provider' => 'embed_test',
'status' => TRUE,
'settings' => [],
]);
$filter_format
->save();
$node = Node::create([
'title' => 'Foobaz',
'type' => 'baz',
]);
$node
->save();
$account = $this
->drupalCreateUser([
'use text format foo',
]);
$this
->drupalLogin($account);
$response = $this
->drupalGet('/embed/preview/foo', [
'query' => [
'value' => 'node:' . $node
->id(),
'_wrapper_format' => 'drupal_ajax',
],
]);
$this
->assertSession()
->statusCodeEquals(200);
$commands = Json::decode($response);
$this
->assertGreaterThan(1, count($commands));
$this
->assertMatch($commands, function (array $command) {
return $command['command'] == 'insert' && $command['method'] == 'append' && $command['selector'] == 'body' && strpos($command['data'], 'jquery.min.js') > 0;
});
}
protected function assertMatch(array $items, callable $predicate) {
$items = array_filter($items, $predicate);
$this
->assertNotEmpty($items);
}
}