Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
[MINOR] Use new block signatures (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] committed Aug 7, 2019
2 parents c6d4189 + cd74350 commit 25e7de4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
17 changes: 15 additions & 2 deletions src/Block/Service/AbstractFacebookBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\NullLogger;
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\Model\BlockInterface;
use Sonata\Form\Validator\ErrorElement;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;

abstract class AbstractFacebookBlockService extends AbstractAdminBlockService implements LoggerAwareInterface
abstract class AbstractFacebookBlockService extends AbstractBlockService implements EditableBlockService, LoggerAwareInterface
{
use LoggerAwareTrait;

Expand All @@ -36,6 +40,15 @@ public function __construct(string $name, EngineInterface $templating, Facebook
$this->logger = new NullLogger();
}

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

public function validate(ErrorElement $errorElement, BlockInterface $block): void
{
}

protected function getFacebook(): Facebook
{
return $this->facebook;
Expand Down
9 changes: 5 additions & 4 deletions src/Block/Service/PageFeedBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
namespace Core23\FacebookBundle\Block\Service;

use Facebook\Exceptions\FacebookSDKException;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\BlockBundle\Block\BlockContextInterface;
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 Symfony\Component\Form\Extension\Core\Type\NumberType;
Expand All @@ -36,7 +37,7 @@ public function execute(BlockContextInterface $blockContext, Response $response
return $this->renderResponse($blockContext->getTemplate(), $parameters, $response);
}

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

public function getBlockMetadata($code = null)
public function getMetadata(): MetadataInterface
{
return new Metadata($this->getName(), $code ?? $this->getName(), null, 'Core23FacebookBundle', [
return new Metadata($this->getName(), null, null, 'Core23FacebookBundle', [
'class' => 'fa fa-facebook-official',
]);
}
Expand Down
19 changes: 9 additions & 10 deletions tests/Block/Service/PageFeedBlockServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
use Facebook\FacebookApp;
use Facebook\FacebookResponse;
use Facebook\GraphNodes\GraphEdge;
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;

final class PageFeedBlockServiceTest extends AbstractBlockServiceTestCase
final class PageFeedBlockServiceTest extends BlockServiceTestCase
{
private $facebook;

Expand Down Expand Up @@ -83,7 +83,7 @@ public function testExecute(): void
static::assertSame('@Core23Facebook/Block/block_page_feed.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']);

static::assertSame($feedResponse, $this->templating->parameters['feed']);
Expand Down Expand Up @@ -123,7 +123,7 @@ public function testExecuteThrowsFacebookException(): void
static::assertSame('@Core23Facebook/Block/block_page_feed.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']);

static::assertSame([], $this->templating->parameters['feed']);
Expand All @@ -146,14 +146,13 @@ public function testDefaultSettings(): void
], $blockContext);
}

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

$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('Core23FacebookBundle', $metadata->getDomain());
Expand All @@ -162,7 +161,7 @@ public function testGetBlockMetadata(): void
], $metadata->getOptions());
}

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

Expand All @@ -171,6 +170,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 25e7de4

Please sign in to comment.