Skip to content

Commit

Permalink
Fixed installation without template engine and translator (#144)
Browse files Browse the repository at this point in the history
* Fix plain php template, tests

* Improve template

* Fix StyleCI config
  • Loading branch information
msmakouz committed Jan 31, 2024
1 parent c6e775f commit b716755
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 13 deletions.
1 change: 0 additions & 1 deletion .styleci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ enabled:
- linebreak_after_opening_tag
- single_quote
- no_blank_lines_after_phpdoc
- unary_operator_spaces
- no_useless_else
- no_useless_return
- trailing_comma_in_multiline_array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Tests\Feature\Controller;

use Spiral\Bootloader\I18nBootloader;
use Tests\TestCase;
use Spiral\Testing\Http\FakeHttp;

Expand All @@ -20,19 +21,26 @@ protected function setUp(): void

public function testDefaultActionWorks(): void
{
$this->http
->get('/')
->assertOk()
->assertBodyContains('The PHP Framework for future Innovators');
$response = $this->http->get('/')->assertOk();

$this->assertStringContainsString(
'The PHP Framework for future Innovators',
\strip_tags((string) $response->getOriginalResponse()->getBody())
);
}

public function testDefaultActionWithRuLocale(): void
{
$this->http
->withHeader('accept-language', 'ru')
->get('/')
->assertOk()
->assertBodyContains('PHP Framework для будущих инноваторов');
if (!\in_array(I18nBootloader::class, $this->getRegisteredBootloaders())) {
$this->markTestSkipped('Component `spiral/translator` is not installed.');
}

$response = $this->http->withHeader('accept-language', 'ru')->get('/')->assertOk();

$this->assertStringContainsString(
'PHP Framework для будущих инноваторов',
\strip_tags((string) $response->getOriginalResponse()->getBody())
);
}

public function testInteractWithConsole(): void
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?php $translator = $this->container->get(\Spiral\Translator\TranslatorInterface::class); ?>
<?php $translator = $this->container->has(\Spiral\Translator\TranslatorInterface::class)
? $this->container->get(\Spiral\Translator\TranslatorInterface::class)
: null;
?>
<!DOCTYPE html>
<html lang="<?=$translator->getLocale()?>>">
<html lang="<?=$translator?->getLocale() ?? 'en'?>>">
<head>
<title><?=$translator->trans('The PHP Framework for future Innovators')?></title>
<title><?=$translator?->trans('The PHP Framework for future Innovators') ?? 'The PHP Framework for future Innovators'?></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
Expand Down
73 changes: 73 additions & 0 deletions installer/Tests/Feature/Application/WebTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public function testStemplerTemplateEngine(): void
{
$result = $this
->install(Application::class)
->withSkeleton()
->addAnswer(Module\TemplateEngines\Question::class, 1)
->addModule(new TestModule\Console())
->addModule(new TestModule\RoadRunnerBridge())
Expand All @@ -128,6 +129,7 @@ public function testTwigTemplateEngine(): void
{
$result = $this
->install(Application::class)
->withSkeleton()
->addAnswer(Module\TemplateEngines\Question::class, 2)
->addModule(new TestModule\Console())
->addModule(new TestModule\RoadRunnerBridge())
Expand All @@ -149,7 +151,78 @@ public function testPlainPHPTemplateEngine(): void
{
$result = $this
->install(Application::class)
->withSkeleton()
->addAnswer(Module\TemplateEngines\Question::class, 3)
->addModule(new TestModule\Console())
->addModule(new TestModule\RoadRunnerBridge())
->addModule(new TestModule\RoadRunnerCli())
->addModule(new TestModule\YiiErrorHandler())
->addModule(new TestModule\NyholmPsr7())
->addModule(new TestModule\Dumper())
->addModule(new TestModule\ExtSockets())
->addModule(new TestModule\ExtMbString())
->addModule(new TestModule\Exception())
->addModule(new TestModule\TemplateEngines\PlainPHP())
->addModule(new TestModule\Http())
->run();

$result->storeLog();
}

public function testWithoutTranslatorStempler(): void
{
$result = $this
->install(Application::class)
->withSkeleton()
->addAnswer(Module\TemplateEngines\Question::class, 1)
->addAnswer(Module\Translator\Question::class, false)
->addModule(new TestModule\Console())
->addModule(new TestModule\RoadRunnerBridge())
->addModule(new TestModule\RoadRunnerCli())
->addModule(new TestModule\YiiErrorHandler())
->addModule(new TestModule\NyholmPsr7())
->addModule(new TestModule\Dumper())
->addModule(new TestModule\ExtSockets())
->addModule(new TestModule\ExtMbString())
->addModule(new TestModule\Exception())
->addModule(new TestModule\TemplateEngines\Stempler())
->addModule(new TestModule\Http())
->run();

$result->storeLog();
}

public function testWithoutTranslatorTwig(): void
{
$result = $this
->install(Application::class)
->withSkeleton()
->addAnswer(Module\TemplateEngines\Question::class, 2)
->addAnswer(Module\Translator\Question::class, false)
->addAnswer(Module\Translator\Question::class, false)
->addModule(new TestModule\Console())
->addModule(new TestModule\RoadRunnerBridge())
->addModule(new TestModule\RoadRunnerCli())
->addModule(new TestModule\YiiErrorHandler())
->addModule(new TestModule\NyholmPsr7())
->addModule(new TestModule\Dumper())
->addModule(new TestModule\ExtSockets())
->addModule(new TestModule\ExtMbString())
->addModule(new TestModule\Exception())
->addModule(new TestModule\TemplateEngines\Twig())
->addModule(new TestModule\Http())
->run();

$result->storeLog();
}

public function testWithoutTranslatorPlainPhp(): void
{
$result = $this
->install(Application::class)
->withSkeleton()
->addAnswer(Module\TemplateEngines\Question::class, 3)
->addAnswer(Module\Translator\Question::class, false)
->addModule(new TestModule\Console())
->addModule(new TestModule\RoadRunnerBridge())
->addModule(new TestModule\RoadRunnerCli())
Expand Down

0 comments on commit b716755

Please sign in to comment.