Skip to content

Commit

Permalink
increase test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
koertho committed Apr 11, 2024
1 parent 79e0b51 commit 2c4d855
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions tests/EventListener/DcaField/DateAddedFieldListenerTest.php
Expand Up @@ -42,6 +42,67 @@ public function testOnLoadDataContainer()
$this->assertArrayHasKey('dateAdded', $GLOBALS['TL_DCA'][$table]['fields']);
}

public function dateAddedConfig():array
{
return [
[null, false, false, false, false],
[1, true, false, false, false],
[2, false, true, false, false],
[null, false, false, true, false],
[null, false, false, false, true],
];
}

/**
* @dataProvider dateAddedConfig
* @runInSeparateProcess
*/
public function testConfig(?int $flag, bool $sorting, bool $exclude, bool $filter, bool $search)
{
$container = $this->createMock(ContainerInterface::class);

$listener = new DateAddedFieldListener($container);
$table = 'test_table';

// Mock the global array
$GLOBALS['TL_DCA'][$table] = [
'config' => [],
'fields' => [],
];

$config = DateAddedField::register($table);
$config->setFlag($flag);
$config->setSorting($sorting);
$config->setExclude($exclude);
$config->setFilter($filter);
$config->setSearch($search);

$listener->onLoadDataContainer($table);

$this->assertArrayHasKey('dateAdded', $GLOBALS['TL_DCA'][$table]['fields']);
$field = $GLOBALS['TL_DCA'][$table]['fields']['dateAdded'];
if ($flag) {
$this->assertArrayHasKey('flag', $field);
$this->assertEquals($flag, $field['flag']);
}
if ($sorting) {
$this->assertArrayHasKey('sorting', $field);
$this->assertTrue($field['sorting']);
}
if ($exclude) {
$this->assertArrayHasKey('exclude', $field);
$this->assertTrue($field['exclude']);
}
if ($filter) {
$this->assertArrayHasKey('filter', $field);
$this->assertTrue($field['filter']);
}
if ($search) {
$this->assertArrayHasKey('search', $field);
$this->assertTrue($field['search']);
}
}

public function testOnLoadCallback()
{
// Without DataContainer
Expand Down

0 comments on commit 2c4d855

Please sign in to comment.