This repository has been archived by the owner on Jul 22, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 139
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
255 additions
and
7 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
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
91 changes: 91 additions & 0 deletions
91
tests/CustomerBundle/DependencyInjection/ConfigurationTest.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,91 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\CustomerBundle\Tests\DependencyInjection; | ||
|
||
use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait; | ||
use PHPUnit\Framework\TestCase; | ||
use Sonata\CustomerBundle\DependencyInjection\Configuration; | ||
|
||
class ConfigurationTest extends TestCase | ||
{ | ||
use ConfigurationTestCaseTrait; | ||
|
||
public function getConfiguration(): Configuration | ||
{ | ||
return new Configuration(); | ||
} | ||
|
||
public function testDefault(): void | ||
{ | ||
$this->assertProcessedConfigurationEquals([ | ||
[], | ||
], [ | ||
'class' => [ | ||
'customer' => 'App\\Sonata\\CustomerBundle\\Entity\\Customer', | ||
'customer_selector' => 'Sonata\\Component\\Customer\\CustomerSelector', | ||
'address' => 'App\\Sonata\\CustomerBundle\\Entity\\Address', | ||
'order' => 'App\\Sonata\\OrderBundle\\Entity\\Order', | ||
'user' => 'App\\Sonata\\UserBundle\\Entity\\User', | ||
'user_identifier' => 'id', | ||
], | ||
'field' => [ | ||
'customer' => [ | ||
'user' => 'id', | ||
], | ||
|
||
], | ||
'profile' => [ | ||
'template' => '@SonataCustomer/Profile/action.html.twig', | ||
'menu_builder' => 'sonata.customer.profile.menu_builder.default', | ||
'blocks' => [ | ||
[ | ||
'position' => 'left', | ||
'type' => 'sonata.order.block.recent_orders', | ||
'settings' => ['title' => 'Recent Orders', 'number' => 5, 'mode' => 'public'], | ||
], | ||
[ | ||
'position' => 'right', | ||
'type' => 'sonata.news.block.recent_posts', | ||
'settings' => ['title' => 'Recent Posts', 'number' => 5, 'mode' => 'public'], | ||
], | ||
[ | ||
'position' => 'right', | ||
'type' => 'sonata.news.block.recent_comments', | ||
'settings' => ['title' => 'Recent Comments', 'number' => 5, 'mode' => 'public'], | ||
], | ||
], | ||
'menu' => [ | ||
[ | ||
'route' => 'sonata_customer_dashboard', | ||
'label' => 'link_list_dashboard', | ||
'domain' => 'SonataCustomerBundle', | ||
'route_parameters' => [], | ||
], | ||
[ | ||
'route' => 'sonata_customer_addresses', | ||
'label' => 'link_list_addresses', | ||
'domain' => 'SonataCustomerBundle', | ||
'route_parameters' => [], | ||
], | ||
[ | ||
'route' => 'sonata_order_index', | ||
'label' => 'order_list', | ||
'domain' => 'SonataOrderBundle', | ||
'route_parameters' => [], | ||
], | ||
], | ||
], | ||
]); | ||
} | ||
} |
156 changes: 156 additions & 0 deletions
156
tests/CustomerBundle/DependencyInjection/SonataCustomerExtensionTest.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,156 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\CustomerBundle\Tests\DependencyInjection; | ||
|
||
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; | ||
use Sonata\CustomerBundle\DependencyInjection\Configuration; | ||
use Sonata\CustomerBundle\DependencyInjection\SonataCustomerExtension; | ||
use Symfony\Bundle\TwigBundle\DependencyInjection\TwigExtension; | ||
use Symfony\Component\Config\Definition\Processor; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; | ||
|
||
final class SonataCustomerExtensionTest extends AbstractExtensionTestCase | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->setParameter('kernel.bundles', ['SonataCustomerBundle' => true]); | ||
} | ||
|
||
/** | ||
* @group legacy | ||
*/ | ||
public function testLoadDefault(): void | ||
{ | ||
$this->load(); | ||
|
||
$this->assertContainerBuilderHasAlias( | ||
'sonata.customer.profile.menu_builder', | ||
'sonata.customer.profile.menu_builder.default' | ||
); | ||
} | ||
|
||
public function testTwigConfigParameterIsSetting(): void | ||
{ | ||
$fakeContainer = $this->getMockBuilder(ContainerBuilder::class) | ||
->setMethods(['hasExtension', 'prependExtensionConfig']) | ||
->getMock(); | ||
|
||
$fakeContainer->expects($this->once()) | ||
->method('hasExtension') | ||
->with($this->equalTo('twig')) | ||
->willReturn(true); | ||
|
||
$fakeContainer->expects($this->once()) | ||
->method('prependExtensionConfig') | ||
->with('twig', ['form_themes' => ['@SonataCore/Form/datepicker.html.twig']]); | ||
|
||
foreach ($this->getContainerExtensions() as $extension) { | ||
if ($extension instanceof PrependExtensionInterface) { | ||
$extension->prepend($fakeContainer); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @group legacy | ||
*/ | ||
public function testTwigConfigParameterIsSet(): void | ||
{ | ||
$fakeTwigExtension = $this->getMockBuilder(TwigExtension::class) | ||
->setMethods(['load', 'getAlias']) | ||
->getMock(); | ||
|
||
$fakeTwigExtension | ||
->method('getAlias') | ||
->willReturn('twig'); | ||
|
||
$this->container->registerExtension($fakeTwigExtension); | ||
|
||
$this->load(); | ||
|
||
$twigConfigurations = $this->container->getExtensionConfig('twig'); | ||
|
||
$this->assertArrayHasKey(0, $twigConfigurations); | ||
$this->assertArrayHasKey('form_themes', $twigConfigurations[0]); | ||
$this->assertSame( | ||
['@SonataCore/Form/datepicker.html.twig'], | ||
$twigConfigurations[0]['form_themes'] | ||
); | ||
} | ||
|
||
/** | ||
* @group legacy | ||
*/ | ||
public function testTwigConfigParameterIsNotSet(): void | ||
{ | ||
$this->load(); | ||
|
||
$twigConfigurations = $this->container->getExtensionConfig('twig'); | ||
|
||
$this->assertArrayNotHasKey(0, $twigConfigurations); | ||
} | ||
|
||
/** | ||
* @group legacy | ||
*/ | ||
public function testEmptyProfile(): void | ||
{ | ||
$this->load([ | ||
'profile' => [ | ||
'menu' => null, | ||
'blocks' => null, | ||
], | ||
]); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getMinimalConfiguration() | ||
{ | ||
return (new Processor())->process((new Configuration())->getConfigTreeBuilder()->buildTree(), []); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getContainerExtensions(): array | ||
{ | ||
return [ | ||
new SonataCustomerExtension(), | ||
]; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function load(array $configurationValues = []): void | ||
{ | ||
$configs = [$this->getMinimalConfiguration(), $configurationValues]; | ||
|
||
foreach ($this->container->getExtensions() as $extension) { | ||
if ($extension instanceof PrependExtensionInterface) { | ||
$extension->prepend($this->container); | ||
} | ||
|
||
$extension->load($configs, $this->container); | ||
} | ||
} | ||
} |