LanguageTestBase.php 2.02 KB
Newer Older
1 2 3 4
<?php

/**
 * @file
5
 * Contains \Drupal\language\Tests\Views\LanguageTestBase.
6 7
 */

8
namespace Drupal\language\Tests\Views;
9

10
use Drupal\views\Tests\ViewUnitTestBase;
11 12 13 14 15
use Drupal\Core\Language\Language;

/**
 * Defines the base class for all Language handler tests.
 */
16
abstract class LanguageTestBase extends ViewUnitTestBase {
17

18 19 20 21 22 23 24
  /**
   * Modules to enable.
   *
   * @var array
   */
  public static $modules = array('system', 'language');

25 26
  protected function setUp() {
    parent::setUp();
27 28
    $this->installSchema('language', 'language');
    $this->installSchema('system', 'variable');
29 30


31 32 33
    // Create English and another language beside English.
    $language = new Language(array('langcode' => 'en'));
    language_save($language);
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
    $language = new Language(array('langcode' => 'xx-lolspeak', 'name' => 'Lolspeak'));
    language_save($language);
  }

  /**
   * Overrides \Drupal\views\Tests\ViewTestBase::schemaDefinition().
   */
  protected function schemaDefinition() {
    $schema = parent::schemaDefinition();
    $schema['views_test_data']['fields']['langcode'] = array(
      'description' => 'The {language}.langcode of this beatle.',
      'type' => 'varchar',
      'length' => 12,
      'default' => '',
    );

    return $schema;
  }

  /**
   * Overrides \Drupal\views\Tests\ViewTestBase::schemaDefinition().
   */
  protected function viewsData() {
    $data = parent::viewsData();
    $data['views_test_data']['langcode'] = array(
      'title' => t('Langcode'),
      'help' => t('Langcode'),
      'field' => array(
        'id' => 'language',
      ),
      'argument' => array(
        'id' => 'language',
      ),
      'filter' => array(
        'id' => 'language',
      ),
    );

    return $data;
  }

  /**
   * Overrides \Drupal\views\Tests\ViewTestBase::dataSet().
   */
  protected function dataSet() {
    $data = parent::dataSet();
    $data[0]['langcode'] = 'en';
    $data[1]['langcode'] = 'xx-lolspeak';
    $data[2]['langcode'] = '';
    $data[3]['langcode'] = '';
    $data[4]['langcode'] = '';

    return $data;
  }

}