-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecate FormColumnType, add tests for built-in column types
- Loading branch information
Showing
15 changed files
with
822 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kreyu\Bundle\DataTableBundle\Tests\Fixtures\Enum; | ||
|
||
use Symfony\Contracts\Translation\TranslatableInterface; | ||
use Symfony\Contracts\Translation\TranslatorInterface; | ||
|
||
enum TranslatableEnum implements TranslatableInterface | ||
{ | ||
case Foo; | ||
case Bar; | ||
|
||
public function trans(TranslatorInterface $translator, ?string $locale = null): string | ||
{ | ||
return match ($this) { | ||
self::Foo => 'Translated foo', | ||
self::Bar => 'Translated bar', | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kreyu\Bundle\DataTableBundle\Tests\Fixtures\Enum; | ||
|
||
enum UnitEnum | ||
{ | ||
case Foo; | ||
case Bar; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kreyu\Bundle\DataTableBundle\Tests\Unit\Column\Type; | ||
|
||
use Kreyu\Bundle\DataTableBundle\Column\Type\BooleanColumnType; | ||
use Kreyu\Bundle\DataTableBundle\Column\Type\ColumnTypeInterface; | ||
use Kreyu\Bundle\DataTableBundle\Test\Column\Type\ColumnTypeTestCase; | ||
|
||
class BooleanColumnTypeTest extends ColumnTypeTestCase | ||
{ | ||
protected function getTestedColumnType(): ColumnTypeInterface | ||
{ | ||
return new BooleanColumnType(); | ||
} | ||
|
||
public function testLabelTrueOption(): void | ||
{ | ||
$column = $this->createColumn([ | ||
'label_true' => 'True', | ||
]); | ||
|
||
$valueView = $this->createColumnValueView($column); | ||
|
||
$this->assertEquals('True', $valueView->vars['label_true']); | ||
} | ||
|
||
public function testLabelFalseOption(): void | ||
{ | ||
$column = $this->createColumn([ | ||
'label_false' => 'False', | ||
]); | ||
|
||
$valueView = $this->createColumnValueView($column); | ||
|
||
$this->assertEquals('False', $valueView->vars['label_false']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kreyu\Bundle\DataTableBundle\Tests\Unit\Column\Type; | ||
|
||
use Kreyu\Bundle\DataTableBundle\Column\Type\CheckboxColumnType; | ||
use Kreyu\Bundle\DataTableBundle\Column\Type\ColumnTypeInterface; | ||
use Kreyu\Bundle\DataTableBundle\Test\Column\Type\ColumnTypeTestCase; | ||
|
||
class CheckboxColumnTypeTest extends ColumnTypeTestCase | ||
{ | ||
protected function getTestedColumnType(): ColumnTypeInterface | ||
{ | ||
return new CheckboxColumnType(); | ||
} | ||
|
||
public function testPassingIdentifierNameOption(): void | ||
{ | ||
$column = $this->createColumn([ | ||
'identifier_name' => 'uuid', | ||
]); | ||
|
||
$columnHeaderView = $this->createColumnHeaderView($column); | ||
$columnValueView = $this->createColumnValueView($column); | ||
|
||
$this->assertEquals('uuid', $columnHeaderView->vars['identifier_name']); | ||
$this->assertEquals('uuid', $columnValueView->vars['identifier_name']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kreyu\Bundle\DataTableBundle\Tests\Unit\Column\Type; | ||
|
||
use Kreyu\Bundle\DataTableBundle\Column\ColumnValueView; | ||
use Kreyu\Bundle\DataTableBundle\Column\Type\CollectionColumnType; | ||
use Kreyu\Bundle\DataTableBundle\Column\Type\ColumnType; | ||
use Kreyu\Bundle\DataTableBundle\Column\Type\ColumnTypeInterface; | ||
use Kreyu\Bundle\DataTableBundle\Column\Type\NumberColumnType; | ||
use Kreyu\Bundle\DataTableBundle\Column\Type\TextColumnType; | ||
use Kreyu\Bundle\DataTableBundle\Test\Column\Type\ColumnTypeTestCase; | ||
|
||
class CollectionColumnTypeTest extends ColumnTypeTestCase | ||
{ | ||
protected function getTestedColumnType(): ColumnTypeInterface | ||
{ | ||
return new CollectionColumnType(); | ||
} | ||
|
||
protected function getAdditionalColumnTypes(): array | ||
{ | ||
return [ | ||
new NumberColumnType(), | ||
new TextColumnType(), | ||
new ColumnType(), | ||
]; | ||
} | ||
|
||
public function testPassingSeparatorOptionAsString(): void | ||
{ | ||
$column = $this->createColumn([ | ||
'separator' => '|', | ||
]); | ||
|
||
$valueView = $this->createColumnValueView($column); | ||
|
||
$this->assertEquals('|', $valueView->vars['separator']); | ||
} | ||
|
||
public function testPassingSeparatorOptionAsNull(): void | ||
{ | ||
$column = $this->createColumn([ | ||
'separator' => null, | ||
]); | ||
|
||
$valueView = $this->createColumnValueView($column); | ||
|
||
$this->assertNull($valueView->vars['separator']); | ||
} | ||
|
||
public function testCreatesChildren(): void | ||
{ | ||
$column = $this->createColumn([ | ||
'entry_type' => NumberColumnType::class, | ||
'entry_options' => [ | ||
'use_intl_formatter' => false, | ||
], | ||
]); | ||
|
||
$data = new class { | ||
public array $collection = [1, 2, 3]; | ||
}; | ||
|
||
$valueRowView = $this->createValueRowView(data: $data); | ||
$columnValueView = $this->createColumnValueView($column, $valueRowView); | ||
|
||
$this->assertCount(3, $columnValueView->vars['children']); | ||
$this->assertContainsOnlyInstancesOf(ColumnValueView::class, $columnValueView->vars['children']); | ||
|
||
for ($i = 0; $i <= 2; ++$i) { | ||
/** @var ColumnValueView $child */ | ||
$child = $columnValueView->vars['children'][$i]; | ||
|
||
$expectedValueRowView = clone $valueRowView; | ||
$expectedValueRowView->origin = $valueRowView; | ||
$expectedValueRowView->index = $i; | ||
$expectedValueRowView->data = $data->collection[$i]; | ||
|
||
$this->assertEquals((string) $i, $child->vars['name']); | ||
$this->assertEquals($expectedValueRowView, $child->vars['row']); | ||
$this->assertFalse($child->vars['use_intl_formatter']); | ||
$this->assertEquals($child->getDataTable(), $columnValueView->getDataTable()); | ||
} | ||
} | ||
} |
Oops, something went wrong.