SimpleGMapFormatterTest.php in Simple Google Maps 8
File
tests/src/Kernel/SimpleGMapFormatterTest.php
View source
<?php
namespace Drupal\Tests\simple_gmap\Kernel;
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
use Drupal\node\Entity\Node;
use Drupal\Core\Render\Markup;
class SimpleGMapFormatterTest extends EntityKernelTestBase {
public static $modules = [
'node',
'simple_gmap',
'simple_gmap_stress_test',
];
protected $node;
protected function setUp() {
parent::setUp();
$this
->installConfig('node');
$this
->installEntitySchema('node');
$this
->installConfig('simple_gmap');
$this
->installConfig('simple_gmap_stress_test');
$this->node = Node::create([
'type' => 'simple_gmap_stress_test',
'title' => 'Stress ball',
]);
$this->node
->save();
}
public function testFormatterOutput() {
$viewBuilder = \Drupal::entityTypeManager()
->getViewBuilder('node');
$renderer = \Drupal::service('renderer');
$values = [
'field_map2' => 'Place de l&#039;Université-du-Québec, boulevard Charest Est, Québec, QC G1K',
'field_xss' => '<script>alert("hello");</script> Empire State Building',
];
foreach ($values as $field => $raw_text) {
$view = $this->node
->get($field)
->view();
$renderer
->renderRoot($view[0]);
$expected_markup = Markup::create($raw_text);
$this
->assertEquals($view[0]['#children'], $expected_markup);
}
}
}