Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

Permalink
Added support for latest formatter-bundle (#475)
Browse files Browse the repository at this point in the history
Closes #474
  • Loading branch information
greg0ire authored and OskarStark committed Oct 1, 2018
1 parent 4cbad1a commit 8cc0eae
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"sonata-project/core-bundle": "^3.9",
"sonata-project/datagrid-bundle": "^2.3",
"sonata-project/easy-extends-bundle": "^2.5",
"sonata-project/formatter-bundle": "^3.4",
"sonata-project/formatter-bundle": "^3.4 || ^4.0",
"sonata-project/intl-bundle": "^2.4",
"sonata-project/media-bundle": "^3.10",
"sonata-project/user-bundle": "^3.6 || ^4.0",
Expand Down
36 changes: 26 additions & 10 deletions tests/Controller/Api/PostControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
namespace Sonata\NewsBundle\Tests\Controller\Api;

use PHPUnit\Framework\TestCase;
use Sonata\FormatterBundle\Formatter\FormatterInterface;
use Sonata\FormatterBundle\Formatter\Pool;
use Sonata\NewsBundle\Controller\Api\PostController;
use Sonata\NewsBundle\Model\CommentInterface;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -98,14 +100,18 @@ public function testPostPostAction()
{
$post = $this->createMock('Sonata\NewsBundle\Model\PostInterface');
$post->expects($this->once())->method('setContent');
$post->expects($this->once())->method('getContentFormatter')->willReturn('text');
$post->expects($this->once())->method('getRawContent')->willReturn('');

$postManager = $this->createMock('Sonata\NewsBundle\Model\PostManagerInterface');
$postManager->expects($this->once())->method('save')->will($this->returnValue($post));

$formatterPool = $this->createMock('Sonata\FormatterBundle\Formatter\Pool');
$formatterPool->expects($this->once())->method('transform')->will($this->returnValue($post->getContent()));
$formatter = $this->createMock(FormatterInterface::class);
$formatter->expects($this->once())->method('transform')->will($this->returnValue(''));
$formatterPool = new Pool('text');
$formatterPool->add('text', $formatter);

$form = $this->getMockBuilder('Symfony\Component\Form\Form')->disableOriginalConstructor()->getMock();
$form = $this->createMock('Symfony\Component\Form\Form');
$form->expects($this->once())->method('handleRequest');
$form->expects($this->once())->method('isValid')->will($this->returnValue(true));
$form->expects($this->once())->method('getData')->will($this->returnValue($post));
Expand All @@ -126,8 +132,10 @@ public function testPostPostInvalidAction()
$postManager = $this->createMock('Sonata\NewsBundle\Model\PostManagerInterface');
$postManager->expects($this->never())->method('save')->will($this->returnValue($post));

$formatterPool = $this->createMock('Sonata\FormatterBundle\Formatter\Pool');
$formatterPool->expects($this->never())->method('transform')->will($this->returnValue($post->getContent()));
$formatter = $this->createMock(FormatterInterface::class);
$formatter->expects($this->never())->method('transform');
$formatterPool = new Pool('text');
$formatterPool->add('text', $formatter);

$form = $this->getMockBuilder('Symfony\Component\Form\Form')->disableOriginalConstructor()->getMock();
$form->expects($this->once())->method('handleRequest');
Expand All @@ -145,13 +153,18 @@ public function testPutPostAction()
{
$post = $this->createMock('Sonata\NewsBundle\Model\PostInterface');
$post->expects($this->once())->method('setContent');
$post->expects($this->once())->method('getContentFormatter')->willReturn('text');
$post->expects($this->once())->method('getRawContent')->willReturn('');
$post->expects($this->once())->method('getContent')->willReturn('');

$postManager = $this->createMock('Sonata\NewsBundle\Model\PostManagerInterface');
$postManager->expects($this->once())->method('find')->will($this->returnValue($post));
$postManager->expects($this->once())->method('save')->will($this->returnValue($post));

$formatterPool = $this->createMock('Sonata\FormatterBundle\Formatter\Pool');
$formatterPool->expects($this->once())->method('transform')->will($this->returnValue($post->getContent()));
$formatter = $this->createMock(FormatterInterface::class);
$formatter->expects($this->once())->method('transform')->will($this->returnValue($post->getContent()));
$formatterPool = new Pool('text');
$formatterPool->add('text', $formatter);

$form = $this->getMockBuilder('Symfony\Component\Form\Form')->disableOriginalConstructor()->getMock();
$form->expects($this->once())->method('handleRequest');
Expand All @@ -175,8 +188,10 @@ public function testPutPostInvalidAction()
$postManager->expects($this->once())->method('find')->will($this->returnValue($post));
$postManager->expects($this->never())->method('save')->will($this->returnValue($post));

$formatterPool = $this->createMock('Sonata\FormatterBundle\Formatter\Pool');
$formatterPool->expects($this->never())->method('transform')->will($this->returnValue($post->getContent()));
$formatter = $this->createMock(FormatterInterface::class);
$formatter->expects($this->never())->method('transform');
$formatterPool = new Pool('text');
$formatterPool->add('text', $formatter);

$form = $this->getMockBuilder('Symfony\Component\Form\Form')->disableOriginalConstructor()->getMock();
$form->expects($this->once())->method('handleRequest');
Expand Down Expand Up @@ -360,7 +375,8 @@ protected function createPostController($postManager = null, $commentManager = n
$formFactory = $this->createMock('Symfony\Component\Form\FormFactoryInterface');
}
if (null === $formatterPool) {
$formatterPool = $this->createMock('Sonata\FormatterBundle\Formatter\Pool');
$formatterPool = new Pool('text');
$formatterPool->add('text', $this->createMock(FormatterInterface::class));
}

return new PostController($postManager, $commentManager, $mailer, $formFactory, $formatterPool);
Expand Down

0 comments on commit 8cc0eae

Please sign in to comment.