-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
129 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/8.5/phpunit.xsd" | ||
colors="true" | ||
bootstrap="config/bootstrap.php"> | ||
<testsuites> | ||
<testsuite name="Test Suite"> | ||
<directory>vendor/sylius/bootstrap-theme/tests/PHPUnit</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<php> | ||
<ini name="error_reporting" value="-1" /> | ||
|
||
<server name="KERNEL_CLASS_PATH" value="src/Kernel.php" /> | ||
<server name="IS_DOCTRINE_ORM_SUPPORTED" value="true" /> | ||
|
||
<env name="APP_ENV" value="test"/> | ||
<env name="SHELL_VERBOSITY" value="-1" /> | ||
</php> | ||
</phpunit> |
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,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\BootstrapTheme; | ||
|
||
use Doctrine\ORM\EntityManager; | ||
use Sylius\Component\Core\Model\Channel; | ||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
abstract class AbstractTest extends WebTestCase | ||
{ | ||
protected function useNoneTheme(): void | ||
{ | ||
/** @var EntityManager $manager */ | ||
$manager = $this->getContainer()->get('doctrine')->getManager(); | ||
|
||
$channel = $manager->getRepository(Channel::class)->findOneBy([]); | ||
$channel->setThemeName(null); | ||
$manager->flush(); | ||
} | ||
} |
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,71 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\BootstrapTheme; | ||
|
||
use App\Entity\User\AdminUser; | ||
use Doctrine\ORM\EntityManager; | ||
use Symfony\Bundle\FrameworkBundle\KernelBrowser; | ||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class ChangeThemeInAdminAreaTest extends AbstractTest | ||
{ | ||
private KernelBrowser $client; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->client = self::createClient(); | ||
$this->client->followRedirects(); | ||
$this->useNoneTheme(); | ||
} | ||
|
||
public function testAccessToAdminArea(): void | ||
{ | ||
$this->client->request('GET', '/admin/login'); | ||
|
||
self::assertResponseIsSuccessful(); | ||
self::assertPageTitleContains('Sylius | Administration panel login'); | ||
|
||
$this->adminLogin(); | ||
$this->client->request('GET', '/admin/'); | ||
|
||
self::assertResponseIsSuccessful(); | ||
self::assertPageTitleContains('Dashboard | Sylius'); | ||
} | ||
|
||
public function testChangeThemeAffectFront(): void | ||
{ | ||
/** @var UrlGeneratorInterface $urlGenerator */ | ||
$urlGenerator = $this->getContainer()->get(UrlGeneratorInterface::class); | ||
|
||
$crawler = $this->client->request('GET', '/'); | ||
$semanticBodyClass = $crawler->filter('body')->attr('class'); | ||
|
||
$this->adminLogin(); | ||
$url = $urlGenerator->generate('sylius_admin_channel_update', ['id' => 1]); | ||
$this->client->request('GET', $url); | ||
self::assertSelectorTextContains('h1', 'Edit channel'); | ||
|
||
$crawler = $this->client->submitForm('Save changes', ['sylius_channel[themeName]' => 'sylius/bootstrap-theme',]); | ||
|
||
$crawler = $this->client->request('GET', '/'); | ||
$bootstrapBodyClass = $crawler->filter('body')->attr('class'); | ||
|
||
self::assertNotSame($semanticBodyClass, $bootstrapBodyClass); | ||
self::assertStringContainsString('pushable', $semanticBodyClass); | ||
self::assertStringContainsString('d-flex', $bootstrapBodyClass); | ||
} | ||
|
||
private function adminLogin(): void | ||
{ | ||
/** @var EntityManager $manager */ | ||
$manager = $this->getContainer()->get('doctrine')->getManager(); | ||
|
||
$user = $manager->getRepository(AdminUser::class)->findOneBy(['username' => 'sylius']); | ||
$this->client->loginUser($user, 'admin'); | ||
} | ||
} |