<?php
namespace Drupal\system\Tests\Theme;
use Drupal\simpletest\WebTestBase;
class EntityFilteringThemeTest extends WebTestBase {
protected $profile = 'standard';
protected $themes;
protected $user;
protected $node;
protected $term;
protected $comment;
protected $xss_label = "string with <em>HTML</em> and <script>alert('JS');</script>";
public static function getInfo() {
return array(
'name' => 'Entity filtering theme test',
'description' => 'Tests themed output for each entity type in all available themes to ensure entity labels are filtered for XSS.',
'group' => 'Theme',
);
}
function setUp() {
parent::setUp();
$this->themes = array_keys(list_themes());
theme_enable($this->themes);
$this->user = $this
->drupalCreateUser(array(
'access content',
'access user profiles',
));
$this->user->name = $this->xss_label;
$this->user
->save();
$this
->drupalLogin($this->user);
$this->term = entity_create('taxonomy_term', array(
'name' => $this->xss_label,
'vid' => 1,
));
taxonomy_term_save($this->term);
$this->node = $this
->drupalCreateNode(array(
'title' => $this->xss_label,
'type' => 'article',
'promote' => NODE_PROMOTED,
'field_tags' => array(
LANGUAGE_NOT_SPECIFIED => array(
array(
'tid' => $this->term->tid,
),
),
),
));
$this->comment = entity_create('comment', array(
'nid' => $this->node->nid,
'node_type' => $this->node->type,
'status' => COMMENT_PUBLISHED,
'subject' => $this->xss_label,
'comment_body' => array(
LANGUAGE_NOT_SPECIFIED => array(
$this
->randomName(),
),
),
));
comment_save($this->comment);
}
function testThemedEntity() {
$paths = array(
'user',
'node',
'node/' . $this->node->nid,
'taxonomy/term/' . $this->term->tid,
);
foreach ($this->themes as $theme) {
variable_set('theme_default', $theme);
foreach ($paths as $path) {
$this
->drupalGet($path);
$this
->assertResponse(200);
$this
->assertNoRaw($this->xss_label);
}
}
}
}