Skip to content

Commit

Permalink
Merge pull request #3212 from Soullivaneuh/block-settings
Browse files Browse the repository at this point in the history
Fix deprecated BlockService::setDefaultSettings usage
  • Loading branch information
soullivaneuh committed Sep 1, 2015
2 parents acc197c + 4a7ef8c commit fbd7300
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 11 deletions.
12 changes: 6 additions & 6 deletions Block/AdminListBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@
use Sonata\BlockBundle\Block\BlockContextInterface;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* Class AdminListBlockService.
*
* @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
* @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
*/
class AdminListBlockService extends BaseBlockService
{
protected $pool;

/**
* @param string $name
* @param \Symfony\Bundle\FrameworkBundle\Templating\EngineInterface $templating
* @param \Sonata\AdminBundle\Admin\Pool $pool
* @param string $name
* @param EngineInterface $templating
* @param Pool $pool
*/
public function __construct($name, EngineInterface $templating, Pool $pool)
{
Expand Down Expand Up @@ -74,7 +74,7 @@ public function getName()
/**
* {@inheritdoc}
*/
public function setDefaultSettings(OptionsResolverInterface $resolver)
public function configureSettings(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'groups' => false,
Expand Down
4 changes: 2 additions & 2 deletions Block/AdminSearchBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;

/**
Expand Down Expand Up @@ -91,7 +91,7 @@ public function getName()
/**
* {@inheritdoc}
*/
public function setDefaultSettings(OptionsResolverInterface $resolver)
public function configureSettings(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'admin_code' => false,
Expand Down
4 changes: 2 additions & 2 deletions Block/AdminStatsBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Sonata\BlockBundle\Block\BlockContextInterface;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* Class AdminStatsBlockService.
Expand Down Expand Up @@ -81,7 +81,7 @@ public function getName()
/**
* {@inheritdoc}
*/
public function setDefaultSettings(OptionsResolverInterface $resolver)
public function configureSettings(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'icon' => 'fa-line-chart',
Expand Down
55 changes: 55 additions & 0 deletions Tests/Block/AdminListBlockServiceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

/*
* 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\AdminBundle\Tests\Block;

use Sonata\AdminBundle\Admin\Pool;
use Sonata\AdminBundle\Block\AdminListBlockService;
use Sonata\BlockBundle\Tests\Block\AbstractBlockServiceTest;

/**
* @author Sullivan Senechal <soullivaneuh@gmail.com>
*/
class AdminListBlockServiceTest extends AbstractBlockServiceTest
{
/**
* @var Pool
*/
private $pool;

protected function setUp()
{
parent::setUp();

$this->pool = $this->getMockBuilder('Sonata\AdminBundle\Admin\Pool')->disableOriginalConstructor()->getMock();
}

public function testDefaultSettings()
{
$blockService = new AdminListBlockService('foo', $this->templating, $this->pool);
$blockContext = $this->getBlockContext($blockService);

$this->assertSettings(array(
'groups' => false,
), $blockContext);
}

public function testOverriddenDefaultSettings()
{
$blockService = new FakeBlockService('foo', $this->templating, $this->pool);
$blockContext = $this->getBlockContext($blockService);

$this->assertSettings(array(
'foo' => 'bar',
'groups' => true,
), $blockContext);
}
}
54 changes: 54 additions & 0 deletions Tests/Block/AdminSearchBlockServiceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

/*
* 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\AdminBundle\Tests\Block;

use Sonata\AdminBundle\Admin\Pool;
use Sonata\AdminBundle\Block\AdminSearchBlockService;
use Sonata\AdminBundle\Search\SearchHandler;
use Sonata\BlockBundle\Tests\Block\AbstractBlockServiceTest;

/**
* @author Sullivan Senechal <soullivaneuh@gmail.com>
*/
class AdminSearchBlockServiceTest extends AbstractBlockServiceTest
{
/**
* @var Pool
*/
private $pool;

/**
* @var SearchHandler
*/
private $searchHandler;

protected function setUp()
{
parent::setUp();

$this->pool = $this->getMockBuilder('Sonata\AdminBundle\Admin\Pool')->disableOriginalConstructor()->getMock();
$this->searchHandler = $this->getMockBuilder('Sonata\AdminBundle\Search\SearchHandler')->disableOriginalConstructor()->getMock();
}

public function testDefaultSettings()
{
$blockService = new AdminSearchBlockService('foo', $this->templating, $this->pool, $this->searchHandler);
$blockContext = $this->getBlockContext($blockService);

$this->assertSettings(array(
'admin_code' => false,
'query' => '',
'page' => 0,
'per_page' => 10,
), $blockContext);
}
}
50 changes: 50 additions & 0 deletions Tests/Block/AdminStatsBlockServiceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/*
* 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\AdminBundle\Tests\Block;

use Sonata\AdminBundle\Admin\Pool;
use Sonata\AdminBundle\Block\AdminStatsBlockService;
use Sonata\BlockBundle\Tests\Block\AbstractBlockServiceTest;

/**
* @author Sullivan Senechal <soullivaneuh@gmail.com>
*/
class AdminStatsBlockServiceTest extends AbstractBlockServiceTest
{
/**
* @var Pool
*/
private $pool;

protected function setUp()
{
parent::setUp();

$this->pool = $this->getMockBuilder('Sonata\AdminBundle\Admin\Pool')->disableOriginalConstructor()->getMock();
}

public function testDefaultSettings()
{
$blockService = new AdminStatsBlockService('foo', $this->templating, $this->pool);
$blockContext = $this->getBlockContext($blockService);

$this->assertSettings(array(
'icon' => 'fa-line-chart',
'text' => 'Statistics',
'color' => 'bg-aqua',
'code' => false,
'filters' => array(),
'limit' => 1000,
'template' => 'SonataAdminBundle:Block:block_stats.html.twig',
), $blockContext);
}
}
33 changes: 33 additions & 0 deletions Tests/Block/FakeBlockService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/*
* 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\AdminBundle\Tests\Block;

use Sonata\AdminBundle\Block\AdminListBlockService;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

/**
* @author Sullivan Senechal <soullivaneuh@gmail.com>
*/
class FakeBlockService extends AdminListBlockService
{
public function setDefaultSettings(OptionsResolverInterface $resolver)
{
parent::setDefaultSettings($resolver);

$resolver
->setDefaults(array(
'foo' => 'bar',
'groups' => true,
))
;
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"twig/twig": "~1.15",
"twig/extensions": "~1.0",
"sonata-project/exporter": "~1.0",
"sonata-project/block-bundle": "~2.3",
"sonata-project/block-bundle": "^2.3.8",
"sonata-project/core-bundle": "^2.3.6",
"doctrine/common": "~2.2",
"doctrine/inflector": "~1.0",
Expand Down

0 comments on commit fbd7300

Please sign in to comment.