-
-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add tests for export * Fix tests * Document the hack for Symfony < 6.2 * Actualizar ProxyQuery.php * Update src/Datagrid/ProxyQuery.php Co-authored-by: Vincent Langlet <VincentLanglet@users.noreply.github.com> * Add tests for setOrderBy with empty values * Recover removed test --------- Co-authored-by: Vincent Langlet <VincentLanglet@users.noreply.github.com>
- Loading branch information
1 parent
18d5bd5
commit 5f11ecb
Showing
11 changed files
with
239 additions
and
7 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
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
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,120 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\DoctrineORMAdminBundle\Tests\Functional; | ||
|
||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
final class ExportActionsTest extends BaseFunctionalTestCase | ||
{ | ||
/** | ||
* @dataProvider provideExportActionCases | ||
* | ||
* @param array<mixed> $parameters | ||
* @param array<mixed> $expected | ||
*/ | ||
public function testExportAction(string $url, array $parameters, array $expected): void | ||
{ | ||
// TODO: Remove the $content variable when drop support for Symfony < 6.2 | ||
ob_start(); | ||
$this->client->request(Request::METHOD_GET, $url, $parameters); | ||
$content = ob_get_contents(); | ||
ob_end_clean(); | ||
|
||
self::assertResponseIsSuccessful(); | ||
static::assertSame( | ||
$expected, | ||
json_decode( | ||
'' !== $content && false !== $content ? $content : $this->client->getInternalResponse()->getContent(), | ||
true, | ||
512, | ||
\JSON_THROW_ON_ERROR | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* @return iterable<array<string>> | ||
* | ||
* @phpstan-return iterable<array{0: string, 1: array<mixed>, 2: array<mixed>}> | ||
*/ | ||
public static function provideExportActionCases(): iterable | ||
{ | ||
yield 'Normal export' => ['/admin/tests/app/book/export', [ | ||
'format' => 'json', | ||
], [ | ||
['Id' => 'book_1', 'Name' => 'Book 1'], | ||
['Id' => 'book_2', 'Name' => 'Book 2'], | ||
['Id' => 'book_id', 'Name' => 'Don Quixote'], | ||
]]; | ||
|
||
yield 'Normal export with normal sort' => ['/admin/tests/app/book/export', [ | ||
'format' => 'json', | ||
'filter' => [ | ||
'_sort_by' => 'name', | ||
'_sort_order' => 'DESC', | ||
], | ||
], [ | ||
['Id' => 'book_id', 'Name' => 'Don Quixote'], | ||
['Id' => 'book_2', 'Name' => 'Book 2'], | ||
['Id' => 'book_1', 'Name' => 'Book 1'], | ||
]]; | ||
|
||
yield 'Joined export' => ['/admin/tests/app/author/export', [ | ||
'format' => 'json', | ||
], [ | ||
['Id' => 'anonymous', 'Name' => 'Anonymous', 'Address Street' => ''], | ||
['Id' => 'author_with_two_books', 'Name' => 'Author with 2 books', 'Address Street' => ''], | ||
['Id' => 'autocompletion_author', 'Name' => 'autocompletion author', 'Address Street' => ''], | ||
['Id' => 'miguel_de_cervantes', 'Name' => 'Miguel de Cervantes', 'Address Street' => 'Somewhere in La Mancha, in a place whose name I do not care to remember'], | ||
]]; | ||
|
||
yield 'Joined export with normal sort' => ['/admin/tests/app/author/export', [ | ||
'format' => 'json', | ||
'filter' => [ | ||
'_sort_by' => 'id', | ||
'_sort_order' => 'DESC', | ||
], | ||
], [ | ||
['Id' => 'miguel_de_cervantes', 'Name' => 'Miguel de Cervantes', 'Address Street' => 'Somewhere in La Mancha, in a place whose name I do not care to remember'], | ||
['Id' => 'autocompletion_author', 'Name' => 'autocompletion author', 'Address Street' => ''], | ||
['Id' => 'author_with_two_books', 'Name' => 'Author with 2 books', 'Address Street' => ''], | ||
['Id' => 'anonymous', 'Name' => 'Anonymous', 'Address Street' => ''], | ||
]]; | ||
|
||
yield 'Joined export with oneToMany sort' => ['/admin/tests/app/author/export', [ | ||
'format' => 'json', | ||
'filter' => [ | ||
'_sort_by' => 'firstBook', | ||
'_sort_order' => 'DESC', | ||
], | ||
], [ | ||
['Id' => 'miguel_de_cervantes', 'Name' => 'Miguel de Cervantes', 'Address Street' => 'Somewhere in La Mancha, in a place whose name I do not care to remember'], | ||
['Id' => 'autocompletion_author', 'Name' => 'autocompletion author', 'Address Street' => ''], | ||
['Id' => 'author_with_two_books', 'Name' => 'Author with 2 books', 'Address Street' => ''], | ||
['Id' => 'anonymous', 'Name' => 'Anonymous', 'Address Street' => ''], | ||
]]; | ||
|
||
yield 'Joined export with ManyToOne sort' => ['/admin/tests/app/item/export', [ | ||
'format' => 'json', | ||
'filter' => [ | ||
'_sort_by' => 'product.name', | ||
'_sort_order' => 'DESC', | ||
], | ||
], [ | ||
['Offered Price' => '3'], | ||
['Offered Price' => '2'], | ||
['Offered Price' => '2'], | ||
]]; | ||
} | ||
} |
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