-
Notifications
You must be signed in to change notification settings - Fork 6
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
1 parent
80935f7
commit 609f00e
Showing
25 changed files
with
406 additions
and
116 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
4 changes: 2 additions & 2 deletions
4
packages/basic-page-bundle/src/Resources/views/show.html.twig
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
<h1>{{ page.content.basicPage.title }}</h1> | ||
<div>{{ page.content.basicPage.content|raw }}</div> | ||
<h1>{{ model.basicPage.title }}</h1> | ||
<div>{{ model.basicPage.content|raw }}</div> |
27 changes: 27 additions & 0 deletions
27
packages/basic-page-bundle/src/Twig/BasicPageExtension.php
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,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Runroom package. | ||
* | ||
* (c) Runroom <runroom@runroom.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Runroom\BasicPageBundle\Twig; | ||
|
||
use Twig\Extension\AbstractExtension; | ||
use Twig\TwigFunction; | ||
|
||
class BasicPageExtension extends AbstractExtension | ||
{ | ||
public function getFunctions(): array | ||
{ | ||
return [ | ||
new TwigFunction('get_basic_pages', [BasicPageRuntime::class, 'getBasicPages']), | ||
]; | ||
} | ||
} |
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,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Runroom package. | ||
* | ||
* (c) Runroom <runroom@runroom.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Runroom\BasicPageBundle\Twig; | ||
|
||
use Runroom\BasicPageBundle\Entity\BasicPage; | ||
use Runroom\BasicPageBundle\Repository\BasicPageRepository; | ||
use Twig\Extension\RuntimeExtensionInterface; | ||
|
||
class BasicPageRuntime implements RuntimeExtensionInterface | ||
{ | ||
private BasicPageRepository $repository; | ||
|
||
public function __construct(BasicPageRepository $repository) | ||
{ | ||
$this->repository = $repository; | ||
} | ||
|
||
/** @return BasicPage[] */ | ||
public function getBasicPages(?string $location = null): array | ||
{ | ||
$criteria = ['publish' => true]; | ||
|
||
if (null !== $location) { | ||
$criteria['location'] = $location; | ||
} | ||
|
||
return $this->repository->findBy($criteria) ?? []; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
packages/basic-page-bundle/tests/Fixtures/Twig/get_basic_pages.test
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,13 @@ | ||
--TEST-- | ||
"get_basic_pages" function | ||
--TEMPLATE-- | ||
{% set basicPages = get_basic_pages('footer') %} | ||
|
||
{% for basicPage in basicPages %} | ||
{{ basicPage.getLocation }} | ||
{% endfor %} | ||
--DATA-- | ||
return [] | ||
--EXPECT-- | ||
footer | ||
footer |
37 changes: 37 additions & 0 deletions
37
packages/basic-page-bundle/tests/Functional/BasicPageControllerTest.php
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,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Runroom package. | ||
* | ||
* (c) Runroom <runroom@runroom.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Runroom\BasicPageBundle\Tests\Functional; | ||
|
||
use Runroom\BasicPageBundle\Factory\BasicPageFactory; | ||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | ||
use Zenstruck\Foundry\Test\Factories; | ||
use Zenstruck\Foundry\Test\ResetDatabase; | ||
|
||
class BasicPageControllerTest extends WebTestCase | ||
{ | ||
use Factories; | ||
use ResetDatabase; | ||
|
||
/** @test */ | ||
public function itRendersStatic(): void | ||
{ | ||
$client = static::createClient(); | ||
|
||
$basicPage = BasicPageFactory::new(['publish' => true])->withTranslations(['en'])->create()->object(); | ||
|
||
$client->request('GET', '/' . $basicPage->getSlug()); | ||
|
||
self::assertResponseIsSuccessful(); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
packages/basic-page-bundle/tests/Integration/BasicPageExtensionTest.php
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,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Runroom package. | ||
* | ||
* (c) Runroom <runroom@runroom.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Runroom\BasicPageBundle\Tests\Integration; | ||
|
||
use Runroom\BasicPageBundle\Entity\BasicPage; | ||
use Runroom\BasicPageBundle\Factory\BasicPageFactory; | ||
use Runroom\BasicPageBundle\Repository\BasicPageRepository; | ||
use Runroom\BasicPageBundle\Twig\BasicPageExtension; | ||
use Runroom\BasicPageBundle\Twig\BasicPageRuntime; | ||
use Twig\RuntimeLoader\RuntimeLoaderInterface; | ||
use Twig\Test\IntegrationTestCase; | ||
use Zenstruck\Foundry\Test\Factories; | ||
|
||
class BasicPageExtensionTest extends IntegrationTestCase | ||
{ | ||
use Factories; | ||
|
||
public function getFixturesDir() | ||
{ | ||
return __DIR__ . '/../Fixtures/Twig/'; | ||
} | ||
|
||
protected function getExtensions() | ||
{ | ||
return [ | ||
new BasicPageExtension(), | ||
]; | ||
} | ||
|
||
protected function getRuntimeLoaders() | ||
{ | ||
$basicPages = BasicPageFactory::createMany(2, [ | ||
'publish' => true, | ||
'location' => BasicPage::LOCATION_FOOTER, | ||
]); | ||
|
||
$basicPageRepository = $this->createStub(BasicPageRepository::class); | ||
$basicPageRepository->method('findBy')->willReturn($basicPages); | ||
|
||
$basicPageRuntime = new BasicPageRuntime($basicPageRepository); | ||
|
||
$runtimeLoader = $this->createMock(RuntimeLoaderInterface::class); | ||
$runtimeLoader->method('load')->with(BasicPageRuntime::class)->willReturn($basicPageRuntime); | ||
|
||
return [$runtimeLoader]; | ||
} | ||
} |
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
Oops, something went wrong.