class ViewsDataHelperTest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/views/tests/src/Unit/ViewsDataHelperTest.php \Drupal\Tests\views\Unit\ViewsDataHelperTest
@coversDefaultClass \Drupal\views\ViewsDataHelper @group views
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\views\Unit\ViewsDataHelperTest
Expanded class hierarchy of ViewsDataHelperTest
File
- core/
modules/ views/ tests/ src/ Unit/ ViewsDataHelperTest.php, line 18 - Contains \Drupal\Tests\views\Unit\ViewsDataHelperTest.
Namespace
Drupal\Tests\views\UnitView source
class ViewsDataHelperTest extends UnitTestCase {
/**
* Returns the views data definition.
*
* @return array
*/
protected function viewsData() {
$data = ViewTestData::viewsData();
// Tweak the views data to have a base for testing
// \Drupal\views\ViewsDataHelper::fetchFields().
unset($data['views_test_data']['id']['field']);
unset($data['views_test_data']['name']['argument']);
unset($data['views_test_data']['age']['filter']);
unset($data['views_test_data']['job']['sort']);
$data['views_test_data']['created']['area']['id'] = 'text';
$data['views_test_data']['age']['area']['id'] = 'text';
$data['views_test_data']['age']['area']['sub_type'] = 'header';
$data['views_test_data']['job']['area']['id'] = 'text';
$data['views_test_data']['job']['area']['sub_type'] = array(
'header',
'footer',
);
return $data;
}
/**
* Tests fetchFields.
*/
public function testFetchFields() {
$views_data = $this
->getMockBuilder('Drupal\\views\\ViewsData')
->disableOriginalConstructor()
->getMock();
$views_data
->expects($this
->once())
->method('get')
->will($this
->returnValue($this
->viewsData()));
$data_helper = new ViewsDataHelper($views_data);
$expected = array(
'field' => array(
'age',
'created',
'job',
'name',
'status',
),
'argument' => array(
'age',
'created',
'id',
'job',
),
'filter' => array(
'created',
'id',
'job',
'name',
'status',
),
'sort' => array(
'age',
'created',
'id',
'name',
'status',
),
'area' => array(
'age',
'created',
'job',
),
'header' => array(
'age',
'created',
'job',
),
'footer' => array(
'age',
'created',
'job',
),
);
$handler_types = array(
'field',
'argument',
'filter',
'sort',
'area',
);
foreach ($handler_types as $handler_type) {
$fields = $data_helper
->fetchFields('views_test_data', $handler_type);
$expected_keys = $expected[$handler_type];
array_walk($expected_keys, function (&$item) {
$item = "views_test_data.{$item}";
});
$this
->assertEquals($expected_keys, array_keys($fields), "Handlers of type {$handler_type} are not listed as expected");
}
// Check for subtype filtering, so header and footer.
foreach (array(
'header',
'footer',
) as $sub_type) {
$fields = $data_helper
->fetchFields('views_test_data', 'area', FALSE, $sub_type);
$expected_keys = $expected[$sub_type];
array_walk($expected_keys, function (&$item) {
$item = "views_test_data.{$item}";
});
$this
->assertEquals($expected_keys, array_keys($fields), "Sub_type {$sub_type} is not filtered as expected.");
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed in array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 259 | |
ViewsDataHelperTest:: |
public | function | Tests fetchFields. | |
ViewsDataHelperTest:: |
protected | function | Returns the views data definition. |