Commit bd90f56f authored by catch's avatar catch

Issue #3103913 by Lendude, mondrake: ViewExecutableTest::testAddHandler and...

Issue #3103913 by Lendude, mondrake: ViewExecutableTest::testAddHandler and ::testAddHandlerWithEntityField are misusing the mock expectation

(cherry picked from commit 04722fbe)
(cherry picked from commit f60d6f7f)
parent e12cee71
......@@ -340,8 +340,15 @@ public function testGenerateHandlerId() {
/**
* @covers ::addHandler
*
* @dataProvider addHandlerProvider
*
* @param string $option
* The option to set on the View.
* @param $handler_type
* The handler type to set.
*/
public function testAddHandler() {
public function testAddHandler($option, $handler_type) {
/** @var \Drupal\views\ViewExecutable|\PHPUnit\Framework\MockObject\MockObject $view */
/** @var \Drupal\views\Plugin\views\display\DisplayPluginBase|\PHPUnit\Framework\MockObject\MockObject $display */
list($view, $display) = $this->setupBaseViewAndDisplay();
......@@ -359,31 +366,34 @@ public function testAddHandler() {
->with('test_entity')
->willReturn($views_data);
foreach (['field', 'filter', 'argument', 'sort'] as $handler_type) {
$display->expects($this->atLeastOnce())
->method('setOption')
->with($this->anything(), [
'test_field' => [
'id' => 'test_field',
'table' => 'test_entity',
'field' => 'test_field',
'plugin_id' => 'standard',
],
]);
}
$display->expects($this->atLeastOnce())
->method('setOption')
->with($option, [
'test_field' => [
'id' => 'test_field',
'table' => 'test_entity',
'field' => 'test_field',
'plugin_id' => 'standard',
],
]);
foreach (['field', 'filter', 'argument', 'sort'] as $handler_type) {
$view->addHandler('default', $handler_type, 'test_entity', 'test_field');
}
$view->addHandler('default', $handler_type, 'test_entity', 'test_field');
}
/**
* @covers ::addHandler
*
* @dataProvider addHandlerProvider
*
* @param string $option
* The option to set on the View.
* @param $handler_type
* The handler type to set.
*/
public function testAddHandlerWithEntityField() {
public function testAddHandlerWithEntityField($option, $handler_type) {
/** @var \Drupal\views\ViewExecutable|\PHPUnit\Framework\MockObject\MockObject $view */
/** @var \Drupal\views\Plugin\views\display\DisplayPluginBase|\PHPUnit\Framework\MockObject\MockObject $display */
list($view, $display) = $this->setupBaseViewAndDisplay();
[$view, $display] = $this->setupBaseViewAndDisplay();
$views_data = [];
$views_data['table']['entity type'] = 'test_entity_type';
......@@ -400,24 +410,35 @@ public function testAddHandlerWithEntityField() {
->with('test_entity')
->willReturn($views_data);
foreach (['field', 'filter', 'argument', 'sort'] as $handler_type) {
$display->expects($this->atLeastOnce())
->method('setOption')
->with($this->anything(), [
'test_field' => [
'id' => 'test_field',
'table' => 'test_entity',
'field' => 'test_field',
'entity_type' => 'test_entity_type',
'entity_field' => 'test_field',
'plugin_id' => 'standard',
],
]);
}
$display->expects($this->atLeastOnce())
->method('setOption')
->with($option, [
'test_field' => [
'id' => 'test_field',
'table' => 'test_entity',
'field' => 'test_field',
'entity_type' => 'test_entity_type',
'entity_field' => 'test_field',
'plugin_id' => 'standard',
],
]);
foreach (['field', 'filter', 'argument', 'sort'] as $handler_type) {
$view->addHandler('default', $handler_type, 'test_entity', 'test_field');
}
$view->addHandler('default', $handler_type, 'test_entity', 'test_field');
}
/**
* Data provider for testAddHandlerWithEntityField and testAddHandler.
*
* @return array[]
* Test data set.
*/
public function addHandlerProvider() {
return [
'field' => ['fields', 'field'],
'filter' => ['filters', 'filter'],
'argument' => ['arguments', 'argument'],
'sort' => ['sorts', 'sort'],
];
}
/**
......
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