Skip to content

Commit

Permalink
[TASK] Added tests for EventController::isOverwriteDemand()
Browse files Browse the repository at this point in the history
Refs #1175
  • Loading branch information
derhansen committed Dec 3, 2023
1 parent 17e9e61 commit fdba923
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 6 deletions.
3 changes: 0 additions & 3 deletions Classes/Controller/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -942,9 +942,6 @@ public function searchAction(SearchDemand $searchDemand = null, array $overwrite

/**
* Returns if a demand object can be overwritten with the given overwriteDemand array
*
* @param array $overwriteDemand
* @return bool
*/
protected function isOverwriteDemand(array $overwriteDemand): bool
{
Expand Down
64 changes: 61 additions & 3 deletions Tests/Unit/Controller/EventControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ public function listActionDoesNotOverrideDemandIfDisabled()

$overrideDemand = ['category' => 10];

$settings = ['disableOverrideDemand' => 1, 'pagination' => []];
$settings = ['disableOverrideDemand' => '1', 'pagination' => []];
$this->subject->_set('settings', $settings);

// Ensure overwriteDemand is not called
Expand Down Expand Up @@ -1965,7 +1965,7 @@ public function searchActionOverwritesDemandFieldsIfOverwriteDemandObjectGiven()
$overrideDemand = ['category' => 10];
$this->subject->expects(self::once())->method('overwriteEventDemandObject')->willReturn(new EventDemand());

$settings = ['disableOverrideDemand' => 0];
$settings = ['disableOverrideDemand' => '0'];
$this->subject->_set('settings', $settings);

$allEvents = $this->createMock(QueryResult::class);
Expand Down Expand Up @@ -2033,7 +2033,7 @@ public function searchActionDoesNotOverridesDemandIfOverwriteDemandDisabled()
$overrideDemand = ['category' => 10];
$this->subject->expects(self::never())->method('overwriteEventDemandObject');

$settings = ['disableOverrideDemand' => 1];
$settings = ['disableOverrideDemand' => '1'];
$this->subject->_set('settings', $settings);

$allEvents = $this->createMock(QueryResult::class);
Expand Down Expand Up @@ -2315,4 +2315,62 @@ public function evaluateIsShortcutSettingIsWorking()
$mockedController->_set('settings', ['detail' => ['isShortcut' => 1]]);
self::assertEquals($mockEvent, $mockedController->_call('evaluateIsShortcutSetting', null));
}

public static function isOverwriteDemandDataProvider(): array
{
return [
'setting is "1" - no overwriteDemand' => [
['disableOverrideDemand' => '1'],
[],
false,
],
'setting is "1" - with overwriteDemand' => [
['disableOverrideDemand' => '1'],
['foo' => 'bar'],
false,
],
'setting is "0" - no overwriteDemand' => [
['disableOverrideDemand' => '0'],
[],
false,
],
'setting is "0" - with overwriteDemand' => [
['disableOverrideDemand' => '0'],
['foo' => 'bar'],
true,
],
'setting is 1 - no overwriteDemand' => [
['disableOverrideDemand' => 1],
[],
false,
],
'setting is 1 - with overwriteDemand' => [
['disableOverrideDemand' => 1],
['foo' => 'bar'],
false,
],
'setting is 0 - no overwriteDemand' => [
['disableOverrideDemand' => 0],
[],
false,
],
'setting is 0 - with overwriteDemand' => [
['disableOverrideDemand' => 0],
['foo' => 'bar'],
true,
],
];
}

/**
* @test
* @dataProvider isOverwriteDemandDataProvider
*/
public function isOverwriteDemandIsWorking(array $settings, array $overwriteDemand, bool $expected): void
{
$mockedController = $this->getAccessibleMock(EventController::class, null);

$mockedController->_set('settings', $settings);
self::assertEquals($expected, $mockedController->_call('isOverwriteDemand', $overwriteDemand));
}
}

0 comments on commit fdba923

Please sign in to comment.