diff --git a/tests/src/FunctionalJavascript/SimpleGmapTest.php b/tests/src/FunctionalJavascript/SimpleGmapTest.php index 36b37ff..c3cd58d 100644 --- a/tests/src/FunctionalJavascript/SimpleGmapTest.php +++ b/tests/src/FunctionalJavascript/SimpleGmapTest.php @@ -140,37 +140,6 @@ class SimpleGmapTest extends WebDriverTestBase { $this->assertTrue($field_row_updated->has('css', 'div:contains("Original text displayed")')); } - /** - * Inspect the formatter output. - * - * Find one good example and two troublesome senarios. - * - * Troublesome senarious :- - * A complex character set. - * A XSS attack. - */ - public function testFormatterOutput() { - $address1 = 'Eiffel Tower'; - $address2 = "Place de l'Université-du-Québec, boulevard Charest Est, Québec, QC G1K"; - $address2entities = "Place de l'Université-du-Québec, boulevard Charest Est, Québec, QC G1K"; - $address3 = ' Empire State Building'; - - $assert_session = $this->assertSession(); - // Get the node edit form. - $this->drupalGet('node/' . $this->node->id()); - - $this->pass('Open the previous link. In the first field, verify: (1) Both the static and dynamic maps are displayed. (2) The link to the larger map is included, with text "View larger map". (3) If you click the map link, the larger map is shown and "Eiffel Tower" appears in the address box. (4) The text "Eiffel Tower" appears below the maps and link.'); - $this->pass("In the second field, verify: (1) Both the static and dynamic maps are displayed. (2) They should be zoomed way out to the regional level, rather than street level. (3) They should be satellite images rather than street maps. (4) The link to the larger map is included, but the link text is \"Place de l'Université-du-Québec, boulevard Charest Est, Québec, QC G1K\". (5) Verify that the map link has &hl=en in it (so it picked up the page language). (6) If you click the map link, the larger map is shown and \"Place de l'Université-du-Québec, boulevard Charest Est, Québec, QC G1K\" appears in the address box. (7) The text \"Place de l'Université-du-Québec, boulevard Charest Est, Québec, QC G1K\" appears below the maps and link."); - $this->pass("The third field is a XSS test. Verify that the script tags are shown rather than being processed by the browser. Maps will likely show the entire world as it is not a valid address. There should not be a JavaScript alert box shown."); - $session = $this->getSession(); - $article = $session->getPage(); - - $assert_session->linkExists('View larger map'); - - $this->assertTrue($article->has('css', "p:contains('$address1')")); - $this->assertTrue($article->has('css', "p:contains('$address2entities')")); - $this->assertEscaped("", ENT_QUOTES, 'UTF-8'); - } } diff --git a/tests/src/Kernel/SimpleGMapFormatterTest.php b/tests/src/Kernel/SimpleGMapFormatterTest.php new file mode 100644 index 0000000..63f9cce --- /dev/null +++ b/tests/src/Kernel/SimpleGMapFormatterTest.php @@ -0,0 +1,78 @@ +installConfig('node'); + $this->installEntitySchema('node'); + $this->installConfig('simple_gmap'); + $this->installConfig('simple_gmap_stress_test'); + + // Populate the node this the default values. + $this->node = Node::create([ + 'type' => 'simple_gmap_stress_test', + 'title' => 'Stress ball', + ]); + $this->node->save(); + + } + + /** + * Inspect the formatter output. + * + * Find one good example and two troublesome senarios. + * + * Troublesome senarious :- + * A complex character set. + * A XSS attack. + */ + 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); + } + } + +}