FieldXssTest.php 1.52 KB
Newer Older
merlinofchaos's avatar
merlinofchaos committed
1 2 3 4
<?php

/**
 * @file
5
 * Definition of Drupal\views\Tests\Handler\FieldXssTest.
merlinofchaos's avatar
merlinofchaos committed
6 7
 */

8 9
namespace Drupal\views\Tests\Handler;

10 11
use Drupal\views\Tests\ViewUnitTestBase;

merlinofchaos's avatar
merlinofchaos committed
12
/**
aspilicious's avatar
aspilicious committed
13
 * Tests the core Drupal\views\Plugin\views\field\Xss handler.
merlinofchaos's avatar
merlinofchaos committed
14 15 16
 *
 * @see CommonXssUnitTest
 */
17
class FieldXssTest extends ViewUnitTestBase {
18

19 20 21 22 23 24 25
  /**
   * Views used by this test.
   *
   * @var array
   */
  public static $testViews = array('test_view');

merlinofchaos's avatar
merlinofchaos committed
26 27
  public static function getInfo() {
    return array(
28
      'name' => 'Field: XSS',
aspilicious's avatar
aspilicious committed
29
      'description' => 'Test the core Drupal\views\Plugin\views\field\Xss handler.',
merlinofchaos's avatar
merlinofchaos committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
      'group' => 'Views Handlers',
    );
  }

  function dataHelper() {
    $map = array(
      'John' => 'John',
      "Foo\xC0barbaz" => '',
      'Fooÿñ' => 'Fooÿñ'
    );

    return $map;
  }


  function viewsData() {
    $data = parent::viewsData();
47
    $data['views_test_data']['name']['field']['id'] = 'xss';
merlinofchaos's avatar
merlinofchaos committed
48 49 50 51 52

    return $data;
  }

  public function testFieldXss() {
53 54
    $view = views_get_view('test_view');
    $view->setDisplay();
merlinofchaos's avatar
merlinofchaos committed
55

56
    $view->displayHandlers['default']->overrideOption('fields', array(
merlinofchaos's avatar
merlinofchaos committed
57 58
      'name' => array(
        'id' => 'name',
59
        'table' => 'views_test_data',
merlinofchaos's avatar
merlinofchaos committed
60 61 62 63 64 65 66 67
        'field' => 'name',
      ),
    ));

    $this->executeView($view);

    $counter = 0;
    foreach ($this->dataHelper() as $input => $expected_result) {
68
      $view->result[$counter]->views_test_data_name = $input;
merlinofchaos's avatar
merlinofchaos committed
69 70 71 72
      $this->assertEqual($view->field['name']->advanced_render($view->result[$counter]), $expected_result);
      $counter++;
    }
  }
73

merlinofchaos's avatar
merlinofchaos committed
74
}