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

/**
 * @file
5
 * Definition of Drupal\views\Tests\Handler\FieldCustomTest.
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\Custom handler.
merlinofchaos's avatar
merlinofchaos committed
14
 */
15
class FieldCustomTest extends ViewUnitTestBase {
16

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

merlinofchaos's avatar
merlinofchaos committed
24 25 26
  public static function getInfo() {
    return array(
      'name' => 'Field: Custom',
aspilicious's avatar
aspilicious committed
27
      'description' => 'Test the core Drupal\views\Plugin\views\field\Custom handler.',
merlinofchaos's avatar
merlinofchaos committed
28 29 30 31 32 33
      'group' => 'Views Handlers',
    );
  }

  function viewsData() {
    $data = parent::viewsData();
34
    $data['views_test_data']['name']['field']['id'] = 'custom';
merlinofchaos's avatar
merlinofchaos committed
35 36 37 38
    return $data;
  }

  public function testFieldCustom() {
39 40
    $view = views_get_view('test_view');
    $view->setDisplay();
merlinofchaos's avatar
merlinofchaos committed
41 42 43

    // Alter the text of the field to a random string.
    $random = $this->randomName();
44
    $view->displayHandlers['default']->overrideOption('fields', array(
merlinofchaos's avatar
merlinofchaos committed
45 46
      'name' => array(
        'id' => 'name',
47
        'table' => 'views_test_data',
merlinofchaos's avatar
merlinofchaos committed
48 49 50 51 52 53 54 55 56 57 58 59
        'field' => 'name',
        'relationship' => 'none',
        'alter' => array(
          'text' => $random,
        ),
      ),
    ));

    $this->executeView($view);

    $this->assertEqual($random, $view->style_plugin->get_field(0, 'name'));
  }
60

merlinofchaos's avatar
merlinofchaos committed
61
}