Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the order of the palette combiner #5271

Merged
merged 7 commits into from Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion core-bundle/src/Resources/contao/drivers/DC_Table.php
Expand Up @@ -3243,7 +3243,12 @@ public function getPalette()
}
else
{
$sValues[] = $trigger;
// Use string comparison to allow "0"
if ((string) $trigger !== '')
{
$sValues[] = (string) $trigger;
}

$key = $name . '_' . $trigger;

// Look for a subpalette
Expand Down
56 changes: 56 additions & 0 deletions core-bundle/tests/Contao/DataContainerTest.php
@@ -0,0 +1,56 @@
<?php

declare(strict_types=1);

/*
* This file is part of Contao.
*
* (c) Leo Feyer
*
* @license LGPL-3.0-or-later
*/

namespace Contao\CoreBundle\Tests\Contao;

use Contao\CoreBundle\Tests\TestCase;
use Contao\DC_Table;

class DataContainerTest extends TestCase
{
/**
* @dataProvider getCombinerValues
*/
public function testCombiner(array $source, array $expected): void
{
$class = new \ReflectionClass(DC_Table::class);

$method = $class->getMethod('combiner');
$method->setAccessible(true);

$names = $method->invoke($class->newInstanceWithoutConstructor(), $source);

$this->assertSame($expected, array_values($names));
}

public function getCombinerValues(): array
{
return [
[
['foo'],
['foo'],
],
[
['foo', 'bar'],
['bar', 'foobar', 'foo'],
],
[
['foo', 'bar', 'baz'],
['baz', 'barbaz', 'bar', 'foobar', 'foobarbaz', 'foobaz', 'foo'],
leofeyer marked this conversation as resolved.
Show resolved Hide resolved
],
[
['foo', 0, 'bar'],
['bar', '0bar', 'foo0', 'foo0bar', 'foobar', 'foo'],
],
];
}
}
87 changes: 87 additions & 0 deletions core-bundle/tests/Contao/DcTableTest.php
@@ -0,0 +1,87 @@
<?php

declare(strict_types=1);

/*
* This file is part of Contao.
*
* (c) Leo Feyer
*
* @license LGPL-3.0-or-later
*/

namespace Contao\CoreBundle\Tests\Contao;

use Contao\CoreBundle\Tests\TestCase;
use Contao\Database;
use Contao\Database\Result;
use Contao\Database\Statement;
use Contao\DC_Table;

class DcTableTest extends TestCase
{
/**
* @dataProvider getPalette
*/
public function testGetPalette(array $dca, array $row, string $expected): void
{
$result = new Result([$row], '');

$statement = $this->createMock(Statement::class);
$statement
->method('limit')
->willReturn($statement)
;

$statement
->method('execute')
->willReturn($result)
;

$database = $this->createMock(Database::class);
$database
->method('prepare')
->willReturn($statement)
;

$reflection = new \ReflectionClass(DC_Table::class);
$dataContainer = $reflection->newInstanceWithoutConstructor();

$method = $reflection->getMethod('import');
$method->setAccessible(true);
$method->invoke($dataContainer, $database, 'Database');
leofeyer marked this conversation as resolved.
Show resolved Hide resolved

$table = $reflection->getProperty('strTable');
$table->setAccessible(true);
$table->setValue($dataContainer, 'tl_test');

$GLOBALS['TL_DCA']['tl_test'] = $dca;

$this->assertSame($expected, $dataContainer->getPalette());
}

public function getPalette(): array
{
return [[
[
'palettes' => [
'__selector__' => ['fieldA', 'fieldB', 'fieldC'],
'default' => 'paletteDefault',
'valueA' => 'paletteA',
'valueAvalueC' => 'paletteAC',
],
'fields' => [
'fieldA' => ['inputType' => 'text'],
'fieldB' => ['inputType' => 'text'],
'fieldC' => ['inputType' => 'text'],
],
],
[
'fieldA' => 'valueA',
'fieldB' => null,
'fieldC' => 'valueC',
],
'paletteAC',
]];
}
}