You are here

public function StyleSerializerTest::testFieldapiField in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/rest/src/Tests/Views/StyleSerializerTest.php \Drupal\rest\Tests\Views\StyleSerializerTest::testFieldapiField()

Tests the field row style using fieldapi fields.

File

core/modules/rest/src/Tests/Views/StyleSerializerTest.php, line 530
Contains \Drupal\rest\Tests\Views\StyleSerializerTest.

Class

StyleSerializerTest
Tests the serializer style plugin.

Namespace

Drupal\rest\Tests\Views

Code

public function testFieldapiField() {
  $this
    ->drupalCreateContentType(array(
    'type' => 'page',
  ));
  $node = $this
    ->drupalCreateNode();
  $result = $this
    ->drupalGetJSON('test/serialize/node-field');
  $this
    ->assertEqual($result[0]['nid'], $node
    ->id());
  $this
    ->assertEqual($result[0]['body'], $node->body->processed);

  // Make sure that serialized fields are not exposed to XSS.
  $node = $this
    ->drupalCreateNode();
  $node->body = [
    'value' => '<script type="text/javascript">alert("node-body");</script>' . $this
      ->randomMachineName(32),
    'format' => filter_default_format(),
  ];
  $node
    ->save();
  $result = $this
    ->drupalGetJSON('test/serialize/node-field');
  $this
    ->assertEqual($result[1]['nid'], $node
    ->id());
  $this
    ->assertTrue(strpos($this
    ->getRawContent(), "<script") === FALSE, "No script tag is present in the raw page contents.");
}