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

Commit

Permalink
Merge 219eefd into 2708de5
Browse files Browse the repository at this point in the history
  • Loading branch information
wbloszyk committed Jan 10, 2020
2 parents 2708de5 + 219eefd commit bd6bfab
Show file tree
Hide file tree
Showing 11 changed files with 204 additions and 15 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
16 changes: 12 additions & 4 deletions src/CustomerBundle/Block/ProfileMenuBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,30 @@ public function __construct(string $name, EngineInterface $templating, MenuProvi
$this->menuBuilder = $menuBuilder;
}

public function getName(): string
/**
* @return string
*/
public function getName()
{
return 'Ecommerce Profile Menu';
}

public function configureSettings(OptionsResolver $resolver): void
public function configureSettings(OptionsResolver $resolver)
{
parent::configureSettings($resolver);

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

protected function getMenu(BlockContextInterface $blockContext): ItemInterface
/**
* Gets the menu to render.
*
* @return ItemInterface|string
*/
protected function getMenu(BlockContextInterface $blockContext)
{
$settings = $blockContext->getSettings();

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

/**
* @return Response
*/
public function execute(BlockContextInterface $blockContext, Response $response = null)
{
$criteria = [
Expand All @@ -61,12 +64,12 @@ public function execute(BlockContextInterface $blockContext, Response $response
], $response);
}

public function validateBlock(ErrorElement $errorElement, BlockInterface $block): void
public function validateBlock(ErrorElement $errorElement, BlockInterface $block)
{
// TODO: Implement validateBlock() method.
}

public function buildEditForm(FormMapper $formMapper, BlockInterface $block): void
public function buildEditForm(FormMapper $formMapper, BlockInterface $block)
{
$formMapper->add('settings', ImmutableArrayType::class, [
'keys' => [
Expand All @@ -82,12 +85,15 @@ public function buildEditForm(FormMapper $formMapper, BlockInterface $block): vo
]);
}

/**
* @return string
*/
public function getName()
{
return 'Recent Customers';
}

public function configureSettings(OptionsResolver $resolver): void
public function configureSettings(OptionsResolver $resolver)
{
$resolver->setDefaults([
'number' => 5,
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ file that was distributed with this source code.
</div>

<div class="span10 col-lg-10">
{% include 'SonataCoreBundle:FlashMessage:render.html.twig' %}
{% include '@SonataCore/FlashMessage/render.html.twig' %}

{% block sonata_profile_content '' %}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ file that was distributed with this source code.
</div>

<div class="span10 col-lg-10">
{% include 'SonataCoreBundle:FlashMessage:render.html.twig' %}
{% include '@SonataCore/FlashMessage/render.html.twig' %}

{% block sonata_profile_content '' %}
</div>
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;

final 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,83 @@
<?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\Component\Config\Definition\Processor;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;

final class SonataCustomerExtensionTest extends AbstractExtensionTestCase
{
protected function setUp(): void
{
parent::setUp();

$this->setParameter('kernel.bundles', ['SonataCustomerBundle' => true]);
}

public function testAliases(): void
{
$this->load();

$this->assertContainerBuilderHasAlias(
'sonata.customer.profile.menu_builder',
'sonata.customer.profile.menu_builder.default'
);
}

public function testEmptyProfileMenu(): void
{
$this->load([
'profile' => [
'menu' => null,
],
]);
}

public function testEmptyProfileBlocks(): void
{
$this->load([
'profile' => [
'blocks' => null,
],
]);
}

protected function getMinimalConfiguration(): array
{
return (new Processor())->process((new Configuration())->getConfigTreeBuilder()->buildTree(), []);
}

protected function getContainerExtensions(): array
{
return [
new SonataCustomerExtension(),
];
}

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);
}
}
}
4 changes: 2 additions & 2 deletions tests/CustomerBundle/Twig/GlobalVariablesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ class GlobalVariablesTest extends TestCase

protected function setUp()
{
$this->globalVariables = new GlobalVariables('SonataCustomerBundle:Profile:action.html.twig');
$this->globalVariables = new GlobalVariables('@SonataCustomer/Profile/action.html.twig');
}

public function testGetProfileTemplate(): void
{
$this->assertSame('SonataCustomerBundle:Profile:action.html.twig', $this->globalVariables->getProfileTemplate());
$this->assertSame('@SonataCustomer/Profile/action.html.twig', $this->globalVariables->getProfileTemplate());
}
}

0 comments on commit bd6bfab

Please sign in to comment.