Commit f3c1c193 authored by dawehner's avatar dawehner Committed by tim.plunkett
Browse files

Add tests for language handlers.

parent 418a6dc9
<?php
/**
* @file
* Definition of Drupal\views\Tests\Language\ArgumentLanguage.php
*/
namespace Drupal\views\Tests\Language;
use Drupal\Core\Language\Language;
/**
* Tests the argument language handler.
*
* @see Views\language\Plugin\views\argument\Language.php
*/
class ArgumentLanguage extends LanguageTestBase {
public static function getInfo() {
return array(
'name' => 'Argument: Language',
'description' => 'Tests the argument language handler.',
'group' => 'Views Handlers'
);
}
public function testFilter() {
foreach (array('en' => 'John', 'xx-lolspeak' => 'George') as $langcode => $name) {
$view = $this->getBasicView();
$view->display['default']->handler->override_option('arguments', array(
'langcode' => array(
'id' => 'langcode',
'table' => 'views_test',
'field' => 'langcode',
),
));
$this->executeView($view, array($langcode));
$expected = array(array(
'name' => $name,
));
$this->assertIdenticalResultset($view, $expected, array('views_test_name' => 'name'));
$view->destroy();
}
}
}
<?php
/**
* @file
* Definition of Drupal\views\Tests\Language\FieldLanguage.php
*/
namespace Drupal\views\Tests\Language;
use Drupal\Core\Language\Language;
/**
* Tests the field language handler.
*
* @see Views\language\Plugin\views\field\Language
*/
class FieldLanguage extends LanguageTestBase {
public static function getInfo() {
return array(
'name' => 'Field: Language',
'description' => 'Tests the field language handler.',
'group' => 'Views Handlers'
);
}
public function testField() {
$view = $this->getBasicView();
$view->display['default']->handler->override_option('fields', array(
'langcode' => array(
'id' => 'langcode',
'table' => 'views_test',
'field' => 'langcode',
),
));
$this->executeView($view);
$this->assertEqual($view->field['langcode']->advanced_render($view->result[0]), 'English');
$this->assertEqual($view->field['langcode']->advanced_render($view->result[1]), 'Lolspeak');
}
}
<?php
/**
* @file
* Definition of Drupal\views\Tests\Language\FilterLanguage.php
*/
namespace Drupal\views\Tests\Language;
use Drupal\Core\Language\Language;
/**
* Tests the filter language handler.
*
* @see Views\language\Plugin\views\filter\Language
*/
class FilterLanguage extends LanguageTestBase {
public static function getInfo() {
return array(
'name' => 'Filter: Language',
'description' => 'Tests the filter language handler.',
'group' => 'Views Handlers'
);
}
public function testFilter() {
foreach (array('en' => 'John', 'xx-lolspeak' => 'George') as $langcode => $name) {
$view = $this->getBasicView();
$view->display['default']->handler->override_option('filters', array(
'langcode' => array(
'id' => 'langcode',
'table' => 'views_test',
'field' => 'langcode',
'value' => array($langcode),
),
));
$this->executeView($view);
$expected = array(array(
'name' => $name,
));
$this->assertIdenticalResultset($view, $expected, array('views_test_name' => 'name'));
$view->destroy();
}
}
}
<?php
/**
* @file
* Definition of Drupal\views\Tests\Language\LanguageTestBase.php
*/
namespace Drupal\views\Tests\Language;
use Drupal\views\Tests\ViewsSqlTest;
use Drupal\Core\Language\Language;
/**
* Base class for all Language handler tests.
*/
abstract class LanguageTestBase extends ViewsSqlTest {
public static $modules = array('views', 'language');
protected function setUp() {
parent::setUp();
// Create another language beside english.
$language = new Language(array('langcode' => 'xx-lolspeak', 'name' => 'Lolspeak'));
language_save($language);
}
protected function schemaDefinition() {
$schema = parent::schemaDefinition();
$schema['views_test']['fields']['langcode'] = array(
'description' => 'The {language}.langcode of this beatle.',
'type' => 'varchar',
'length' => 12,
'default' => '',
);
return $schema;
}
protected function viewsData() {
$data = parent::viewsData();
$data['views_test']['langcode'] = array(
'title' => t('Langcode'),
'help' => t('Langcode'),
'field' => array(
'id' => 'language',
),
'argument' => array(
'id' => 'language',
),
'filter' => array(
'id' => 'language',
),
);
return $data;
}
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;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment