Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Commit

Permalink
Merge 45c30c1 into 2708de5
Browse files Browse the repository at this point in the history
  • Loading branch information
wbloszyk committed Jan 9, 2020
2 parents 2708de5 + 45c30c1 commit 3b64175
Show file tree
Hide file tree
Showing 8 changed files with 255 additions and 7 deletions.
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
"require-dev": {
"friendsofsymfony/rest-bundle": "^2.2",
"jms/serializer-bundle": "^1.0 || ^2.0",
"matthiasnoback/symfony-config-test": "^4.0",
"matthiasnoback/symfony-dependency-injection-test": "^3.0",
"nelmio/api-doc-bundle": "^2.13",
"symfony/phpunit-bridge": "^5.0"
},
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/bundles/customer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The bundle allows you to configure the entity classes; you'll also need to regis
sonata_customer:
profile:
template: 'SonataCustomerBundle:Profile:action.html.twig' # or 'SonataCustomerBundle:Profile:action_with_user_menu.html.twig'
template: '@SonataCustomer/Profile/action.html.twig' # or '@SonataCustomer/Profile/action_with_user_menu.html.twig'
menu_builder: 'sonata.customer.profile.menu_builder.default'
menu:
Expand Down
2 changes: 1 addition & 1 deletion src/CustomerBundle/Block/ProfileMenuBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function configureSettings(OptionsResolver $resolver): void

$resolver->setDefaults([
'cache_policy' => 'private',
'menu_template' => 'SonataBlockBundle:Block:block_side_menu_template.html.twig',
'menu_template' => '@SonataBlockBundle/Block/block_side_menu_template.html.twig',
]);
}

Expand Down
4 changes: 2 additions & 2 deletions src/CustomerBundle/Block/RecentCustomersBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct($name, EngineInterface $templating, CustomerManagerI
parent::__construct($name, $templating);
}

public function execute(BlockContextInterface $blockContext, Response $response = null)
public function execute(BlockContextInterface $blockContext, Response $response = null): Response
{
$criteria = [
// 'mode' => $blockContext->getSetting('mode')
Expand Down Expand Up @@ -82,7 +82,7 @@ public function buildEditForm(FormMapper $formMapper, BlockInterface $block): vo
]);
}

public function getName()
public function getName(): string
{
return 'Recent Customers';
}
Expand Down
2 changes: 1 addition & 1 deletion src/CustomerBundle/Controller/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class DashboardController extends Controller
{
public function dashboardAction(): Response
{
return $this->render('SonataCustomerBundle:Profile:dashboard.html.twig', [
return $this->render('@SonataCustomer/Profile/dashboard.html.twig', [
'blocks' => $this->container->getParameter('sonata.customer.profile.blocks'),
]);
}
Expand Down
3 changes: 1 addition & 2 deletions src/CustomerBundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private function addProfileSection(ArrayNodeDefinition $node): void
->scalarNode('template')
->info('This is the profile template. You should extend your profile actions template by using {% extends sonata_customer.profileTemplate %}.')
->cannotBeEmpty()
->defaultValue('SonataCustomerBundle:Profile:action.html.twig')
->defaultValue('@SonataCustomer/Profile/action.html.twig')
->end()
->scalarNode('menu_builder')
->info('MenuBuilder::createProfileMenu(array $itemOptions = []):ItemInterface is used to build profile menu.')
Expand All @@ -107,7 +107,6 @@ private function addProfileSection(ArrayNodeDefinition $node): void
->info('Define your customer profile menu records here.')
->prototype('array')
->addDefaultsIfNotSet()
->cannotBeEmpty()
->children()
->scalarNode('route')->cannotBeEmpty()->end()
->arrayNode('route_parameters')
Expand Down
91 changes: 91 additions & 0 deletions tests/CustomerBundle/DependencyInjection/ConfigurationTest.php
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' => [],
],
],
],
]);
}
}
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);
}
}
}

0 comments on commit 3b64175

Please sign in to comment.