-
-
Notifications
You must be signed in to change notification settings - Fork 142
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
8 changed files
with
203 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\BlockBundle\Tests\App; | ||
|
||
use Sonata\BlockBundle\SonataBlockBundle; | ||
use Symfony\Bundle\FrameworkBundle\FrameworkBundle; | ||
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; | ||
use Symfony\Bundle\TwigBundle\TwigBundle; | ||
use Symfony\Component\Config\Loader\LoaderInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\HttpKernel\Kernel; | ||
use Symfony\Component\Routing\RouteCollectionBuilder; | ||
|
||
final class AppKernel extends Kernel | ||
{ | ||
use MicroKernelTrait; | ||
|
||
public function __construct() | ||
{ | ||
parent::__construct('test', false); | ||
} | ||
|
||
public function registerBundles() | ||
{ | ||
return [ | ||
new FrameworkBundle(), | ||
new TwigBundle(), | ||
new SonataBlockBundle(), | ||
]; | ||
} | ||
|
||
public function getCacheDir(): string | ||
{ | ||
return $this->getBaseDir().'cache'; | ||
} | ||
|
||
public function getLogDir(): string | ||
{ | ||
return $this->getBaseDir().'log'; | ||
} | ||
|
||
public function getProjectDir(): string | ||
{ | ||
return __DIR__; | ||
} | ||
|
||
protected function configureRoutes(RouteCollectionBuilder $routes) | ||
{ | ||
$routes->import(__DIR__.'/Controller/', '/', 'annotation'); | ||
} | ||
|
||
protected function configureContainer(ContainerBuilder $containerBuilder, LoaderInterface $loader) | ||
{ | ||
$loader->load(__DIR__.'/config.yml'); | ||
} | ||
|
||
private function getBaseDir(): string | ||
{ | ||
return sys_get_temp_dir().'/sonata-block-bundle/var/'; | ||
} | ||
} |
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 Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\BlockBundle\Tests\App\Block; | ||
|
||
use Sonata\BlockBundle\Block\Service\AbstractBlockService; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
final class DemoBlockService extends AbstractBlockService | ||
{ | ||
public function configureSettings(OptionsResolver $resolver): void | ||
{ | ||
$resolver->setDefaults([ | ||
'template' => 'block.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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\BlockBundle\Tests\App\Controller; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
final class DemoController extends AbstractController | ||
{ | ||
/** | ||
* @Route("/", name="home") | ||
*/ | ||
public function index() | ||
{ | ||
return $this->render('index.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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
framework: | ||
secret: secret | ||
|
||
twig: | ||
paths: | ||
- '%kernel.project_dir%/templates' | ||
|
||
services: | ||
_defaults: | ||
autowire: true | ||
autoconfigure: true | ||
|
||
Sonata\BlockBundle\Tests\App\Block\DemoBlockService: | ||
tags: ['sonata.block'] | ||
|
||
Sonata\BlockBundle\Tests\App\Controller\DemoController: | ||
tags: | ||
- controller.service_arguments |
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 @@ | ||
Foo |
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,14 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Welcome!</title> | ||
</head> | ||
<body> | ||
{{ sonata_block_render({ 'type': 'Sonata\\BlockBundle\\Tests\\App\\Block\\DemoBlockService' }, { | ||
}) }} | ||
|
||
{{ sonata_block_render({ 'type': 'sonata.block.service.text' }, { | ||
}) }} | ||
</body> | ||
</html> |
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,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\BlockBundle\Tests\Functional; | ||
|
||
use Sonata\BlockBundle\Tests\App\AppKernel; | ||
use Symfony\Bundle\FrameworkBundle\KernelBrowser; | ||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | ||
|
||
final class FunctionalTest extends WebTestCase | ||
{ | ||
public function testRenderBlock(): void | ||
{ | ||
$kernel = new AppKernel(); | ||
$client = new KernelBrowser($kernel); | ||
$client->request('GET', '/'); | ||
|
||
$this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
} | ||
} |