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

Add tests with grids #478

Merged
merged 2 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ jobs:
name: Run lint container without twig/twig package
run: |
composer remove symfony/twig-bundle --no-scripts
composer remove sylius/grid-bundle --no-scripts --dev
(cd src/Bundle/test && bin/console cache:clear --env=test_without_twig)
(cd src/Bundle/test && bin/console lint:container --env=test_without_twig)
composer require symfony/twig-bundle --no-scripts
composer require "sylius/grid-bundle: ^1.7 || v1.12.0-ALPHA.1" --no-scripts --dev
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"phpstan/phpstan-webmozart-assert": "^1.2",
"phpunit/phpunit": "^9.5",
"sylius-labs/coding-standard": "^4.0",
"sylius/grid-bundle": "^1.7 || dev-symfony-6",
"sylius/grid-bundle": "^1.7 || v1.12.0-ALPHA.1",
"symfony/dependency-injection": "^5.4 || ^6.0",
"symfony/dotenv": "^5.4 || ^6.0",
"symfony/workflow": "^5.4 || ^6.0",
Expand Down
2 changes: 2 additions & 0 deletions src/Bundle/test/config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use FOS\RestBundle\FOSRestBundle;
use JMS\SerializerBundle\JMSSerializerBundle;
use Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle;
use Sylius\Bundle\GridBundle\SyliusGridBundle;
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\TwigBundle\TwigBundle;
Expand All @@ -35,4 +36,5 @@
FidryAliceDataFixturesBundle::class => ['all' => true],
NelmioAliceBundle::class => ['all' => true],
winzouStateMachineBundle::class => ['all' => true, 'test_without_state_machine' => false],
SyliusGridBundle::class => ['all' => true, 'test_without_twig' => false],
];
23 changes: 23 additions & 0 deletions src/Bundle/test/config/packages/test/grids.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
sylius_grid:
grids:
science_book_grid:
driver:
options:
class: '%app.model.science_book.class%'
sorting:
title: asc
fields:
title:
type: string
sortable: ~
authorFirstName:
type: string
sortable: author.firstName
authorLastName:
type: string
sortable: author.firstName
filters:
search:
type: string
options:
fields: [title, author.firstName, author.lastName]
1 change: 1 addition & 0 deletions src/Bundle/test/config/routes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,5 @@ app_science_book:
resource: |
alias: app.science_book
templates: 'ScienceBook'
grid: science_book_grid
type: sylius.resource
21 changes: 21 additions & 0 deletions src/Bundle/test/src/Tests/Controller/ScienceBookUiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,27 @@ public function it_allows_updating_a_book(): void
$this->assertSame($newBookAuthorLastName, $book->getAuthorLastName());
}

/** @test */
public function it_allows_filtering_books(): void
{
$scienceBooks = $this->loadFixturesFromFile('science_books.yml');

$this->client->request('GET', '/science-books/?criteria[search][value]=history of time');
$response = $this->client->getResponse();

$this->assertResponseCode($response, Response::HTTP_OK);
$content = $response->getContent();
$this->assertStringContainsString('<h1>Books</h1>', $content);
$this->assertStringContainsString(
sprintf('<tr><td>%d</td><td>A Brief History of Time</td><td>Stephen Hawking</td></tr>', $scienceBooks['science-book1']->getId()),
$content,
);
$this->assertStringNotContainsString(
sprintf('<tr><td>%d</td><td>The Future of Humanity</td><td>Michio Kaku</td></tr>', $scienceBooks['science-book2']->getId()),
$content,
);
}

protected function buildMatcher(): Matcher
{
return $this->matcherFactory->createMatcher(new VoidBacktrace());
Expand Down
2 changes: 1 addition & 1 deletion src/Bundle/test/templates/ScienceBook/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</tr>
</thead>
<tbody>
{% for book in resources %}
{% for book in resources.data %}
<tr><td>{{ book.id }}</td><td>{{ book.title }}</td><td>{{ book.authorFirstName }} {{ book.authorLastName }}</td></tr>
{% endfor %}
</tbody>
Expand Down