-
-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Autocomplete] Add a test to make sure extra attributes are properly …
…merged with value and text
- Loading branch information
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
src/Autocomplete/tests/Fixtures/Autocompleter/CustomAttributesProductAutocompleter.php
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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Symfony\UX\Autocomplete\Tests\Fixtures\Autocompleter; | ||
|
||
class CustomAttributesProductAutocompleter extends CustomProductAutocompleter | ||
{ | ||
public function getAttributes(object $entity): array | ||
{ | ||
return ['disabled' => true]; | ||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
src/Autocomplete/tests/Integration/AutocompleteResultsExecutorTest.php
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,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Symfony\UX\Autocomplete\Tests\Integration; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
use Symfony\UX\Autocomplete\AutocompleteResultsExecutor; | ||
use Symfony\UX\Autocomplete\Tests\Fixtures\Autocompleter\CustomAttributesProductAutocompleter; | ||
use Symfony\UX\Autocomplete\Tests\Fixtures\Factory\ProductFactory; | ||
use Symfony\UX\Autocomplete\Tests\Fixtures\Kernel; | ||
use Zenstruck\Foundry\Test\Factories; | ||
use Zenstruck\Foundry\Test\ResetDatabase; | ||
|
||
class AutocompleteResultsExecutorTest extends KernelTestCase | ||
{ | ||
use Factories; | ||
use ResetDatabase; | ||
|
||
public function testItReturnsExtraAttributes(): void | ||
{ | ||
$kernel = new Kernel('test', true); | ||
$kernel->disableForms(); | ||
$kernel->boot(); | ||
|
||
$product = ProductFactory::createOne(['name' => 'Foo']); | ||
|
||
/** @var AutocompleteResultsExecutor $executor */ | ||
$executor = $kernel->getContainer()->get('public.results_executor'); | ||
$autocompleter = $kernel->getContainer()->get(CustomAttributesProductAutocompleter::class); | ||
$data = $executor->fetchResults($autocompleter, '', 1); | ||
$this->assertCount(1, $data->results); | ||
$this->assertSame(['disabled' => true, 'value' => $product->getId(), 'text' => 'Foo'], $data->results[0]); | ||
} | ||
} |