Skip to content

Commit

Permalink
[MINOR] Use new block signatures (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] committed Aug 7, 2019
2 parents 328cbf4 + 783b4aa commit 1e99892
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
24 changes: 18 additions & 6 deletions src/Block/Service/GDPRInformationBlockService.php
Expand Up @@ -11,12 +11,15 @@

namespace Core23\GDPRBundle\Block\Service;

use Sonata\AdminBundle\Form\FormMapper;
use Sonata\BlockBundle\Block\BlockContextInterface;
use Sonata\BlockBundle\Block\Service\AbstractAdminBlockService;
use Sonata\BlockBundle\Block\Service\AbstractBlockService;
use Sonata\BlockBundle\Block\Service\EditableBlockService;
use Sonata\BlockBundle\Form\Mapper\FormMapper;
use Sonata\BlockBundle\Meta\Metadata;
use Sonata\BlockBundle\Meta\MetadataInterface;
use Sonata\BlockBundle\Model\BlockInterface;
use Sonata\Form\Type\ImmutableArrayType;
use Sonata\Form\Validator\ErrorElement;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
Expand All @@ -25,7 +28,7 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class GDPRInformationBlockService extends AbstractAdminBlockService
final class GDPRInformationBlockService extends AbstractBlockService implements EditableBlockService
{
public const COOKIE_NAME = 'GDPR_COOKIE_LAW_CONSENT';

Expand Down Expand Up @@ -56,7 +59,12 @@ public function execute(BlockContextInterface $blockContext, Response $response
return $this->renderPrivateResponse($blockContext->getTemplate(), $parameters, $response);
}

public function buildEditForm(FormMapper $formMapper, BlockInterface $block): void
public function configureCreateForm(FormMapper $form, BlockInterface $block): void
{
$this->configureEditForm($form, $block);
}

public function configureEditForm(FormMapper $formMapper, BlockInterface $block): void
{
$formMapper->add('settings', ImmutableArrayType::class, [
'keys' => [
Expand Down Expand Up @@ -92,9 +100,13 @@ public function configureSettings(OptionsResolver $resolver): void
]);
}

public function getBlockMetadata($code = null)
public function validate(ErrorElement $errorElement, BlockInterface $block): void
{
}

public function getMetadata(): MetadataInterface
{
return new Metadata($this->getName(), $code ?? $this->getName(), null, 'Core23GDPRBundle', [
return new Metadata($this->getName(), null, null, 'Core23GDPRBundle', [
'class' => 'fa fa-balance-scale',
]);
}
Expand Down
17 changes: 8 additions & 9 deletions tests/Block/Service/GDPRInformationBlockServiceTest.php
Expand Up @@ -11,15 +11,15 @@

use Core23\GDPRBundle\Block\Service\GDPRInformationBlockService;
use PHPUnit\Framework\MockObject\MockObject;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\BlockBundle\Block\BlockContext;
use Sonata\BlockBundle\Form\Mapper\FormMapper;
use Sonata\BlockBundle\Model\Block;
use Sonata\BlockBundle\Model\BlockInterface;
use Sonata\BlockBundle\Test\AbstractBlockServiceTestCase;
use Sonata\BlockBundle\Test\BlockServiceTestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;

final class GDPRInformationBlockServiceTest extends AbstractBlockServiceTestCase
final class GDPRInformationBlockServiceTest extends BlockServiceTestCase
{
/**
* @var MockObject|RequestStack
Expand Down Expand Up @@ -73,7 +73,7 @@ public function testExecute(): void
static::assertSame('@Core23GDPR/Block/block_gdpr.html.twig', $this->templating->view);

static::assertSame($blockContext, $this->templating->parameters['context']);
static::assertInternalType('array', $this->templating->parameters['settings']);
static::assertIsArray($this->templating->parameters['settings']);
static::assertInstanceOf(BlockInterface::class, $this->templating->parameters['block']);
}

Expand All @@ -96,14 +96,13 @@ public function testExecuteWithExistingCookie(): void
static::assertTrue($response->isEmpty());
}

public function testGetBlockMetadata(): void
public function testGetMetadata(): void
{
$blockService = new GDPRInformationBlockService('block.service', $this->templating, $this->requestStack);

$metadata = $blockService->getBlockMetadata('description');
$metadata = $blockService->getMetadata();

static::assertSame('block.service', $metadata->getTitle());
static::assertSame('description', $metadata->getDescription());
static::assertNotNull($metadata->getImage());
static::assertStringStartsWith('data:image/png;base64,', $metadata->getImage() ?? '');
static::assertSame('Core23GDPRBundle', $metadata->getDomain());
Expand All @@ -112,7 +111,7 @@ public function testGetBlockMetadata(): void
], $metadata->getOptions());
}

public function testBuildEditForm(): void
public function testConfigureEditForm(): void
{
$blockService = new GDPRInformationBlockService('block.service', $this->templating, $this->requestStack);

Expand All @@ -121,6 +120,6 @@ public function testBuildEditForm(): void
$formMapper = $this->createMock(FormMapper::class);
$formMapper->expects(static::once())->method('add');

$blockService->buildEditForm($formMapper, $block);
$blockService->configureEditForm($formMapper, $block);
}
}

0 comments on commit 1e99892

Please sign in to comment.