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

[TwigExtra] Add functional tests #51

Merged
merged 1 commit into from
Sep 23, 2024
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
18 changes: 18 additions & 0 deletions src/TwigExtra/tests/Functional/.application/config/routes.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
#index:
# path: /
# controller: App\Controller\DefaultController::index

test_html_attribute:
path: /test_html_attribute
controller: Symfony\Bundle\FrameworkBundle\Controller\TemplateController
defaults:
template: 'test_html_attribute.html.twig'

route_exists:
path: /route_exists
controller: Symfony\Bundle\FrameworkBundle\Controller\TemplateController
defaults:
template: 'route_exists.html.twig'

sort_by:
path: /sort_by
controller: Symfony\Bundle\FrameworkBundle\Controller\TemplateController
defaults:
template: 'sort_by.html.twig'
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div data-test-route-exists>
{{ sylius_route_exists('route_exists') ? 'yes' : 'no' }}
</div>

<div data-test-route-not-exists>
{{ sylius_route_exists('nowhere') ? 'yes' : 'no' }}
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% set data = [
{'number': 42},
{'number': 5},
{'number': 77},
] %}

<div data-test-sort-by-asc>
{% for row in data|sort_by('[number]') %}
diimpp marked this conversation as resolved.
Show resolved Hide resolved
{{ row.number }}
{% endfor %}
</div>

<div data-test-sort-by-desc>
{% for row in data|sort_by('[number]', 'DESC') %}
{{ row.number }}
{% endfor %}
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h2 {{ sylius_test_html_attribute('foo') }}>Test html attribute</h2>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Tests\Sylius\TwigExtra\Functional\Twig\Extension;

use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

final class RouteExistsExtensionTest extends WebTestCase
{
private KernelBrowser $client;

protected function setUp(): void
{
$this->client = self::createClient();
}

public function testTwigFunctionInTemplate(): void
{
$this->client->request('GET', '/route_exists');

self::assertResponseIsSuccessful();
self::assertSelectorTextContains('[data-test-route-exists]', 'yes');
self::assertSelectorTextContains('[data-test-route-not-exists]', 'no');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Tests\Sylius\TwigExtra\Functional\Twig\Extension;

use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

final class SortByExtensionTest extends WebTestCase
{
private KernelBrowser $client;

protected function setUp(): void
{
$this->client = self::createClient();
}

public function testTwigFunctionInTemplate(): void
{
$this->client->request('GET', '/sort_by');

self::assertResponseIsSuccessful();
self::assertSelectorTextContains('[data-test-sort-by-asc]', '5 42 77');
self::assertSelectorTextContains('[data-test-sort-by-desc]', '77 42 5');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Tests\Sylius\TwigExtra\Functional\Twig\Extension;

use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

final class TestHtmlAttributeExtensionTest extends WebTestCase
{
private KernelBrowser $client;

protected function setUp(): void
{
$this->client = self::createClient();
}

public function testTwigFunctionInTemplate(): void
{
$this->client->request('GET', '/test_html_attribute');

self::assertResponseIsSuccessful();
self::assertSelectorExists('[data-test-foo]');
}
}
Loading