1 | <?php |
||
23 | class MessageControllerTest extends \PHPUnit_Framework_TestCase |
||
24 | { |
||
25 | public function testGetMessagesAction() |
||
26 | { |
||
27 | $messageManager = $this->getMock('Sonata\NotificationBundle\Model\MessageManagerInterface'); |
||
28 | $messageManager->expects($this->once())->method('getPager')->will($this->returnValue(array())); |
||
29 | |||
30 | $paramFetcher = $this->getMock('FOS\RestBundle\Request\ParamFetcherInterface'); |
||
31 | $paramFetcher->expects($this->exactly(3))->method('get'); |
||
32 | $paramFetcher->expects($this->once())->method('all')->will($this->returnValue(array())); |
||
33 | |||
34 | $this->assertEquals(array(), $this->createMessageController(null, $messageManager)->getMessagesAction($paramFetcher)); |
||
35 | } |
||
36 | |||
37 | public function testPostMessageAction() |
||
38 | { |
||
39 | $message = $this->getMock('Sonata\NotificationBundle\Model\MessageInterface'); |
||
40 | |||
41 | $messageManager = $this->getMock('Sonata\NotificationBundle\Model\MessageManagerInterface'); |
||
42 | $messageManager->expects($this->once())->method('save')->will($this->returnValue($message)); |
||
43 | |||
44 | $form = $this->getMockBuilder('Symfony\Component\Form\Form')->disableOriginalConstructor()->getMock(); |
||
45 | $form->expects($this->once())->method('handleRequest'); |
||
46 | $form->expects($this->once())->method('isValid')->will($this->returnValue(true)); |
||
47 | $form->expects($this->once())->method('getData')->will($this->returnValue($message)); |
||
48 | |||
49 | $formFactory = $this->getMock('Symfony\Component\Form\FormFactoryInterface'); |
||
50 | $formFactory->expects($this->once())->method('createNamed')->will($this->returnValue($form)); |
||
51 | |||
52 | $view = $this->createMessageController(null, $messageManager, $formFactory)->postMessageAction(new Request()); |
||
53 | |||
54 | $this->assertInstanceOf('FOS\RestBundle\View\View', $view); |
||
55 | } |
||
56 | |||
57 | public function testPostMessageInvalidAction() |
||
58 | { |
||
59 | $message = $this->getMock('Sonata\NotificationBundle\Model\MessageInterface'); |
||
60 | |||
61 | $messageManager = $this->getMock('Sonata\NotificationBundle\Model\MessageManagerInterface'); |
||
62 | $messageManager->expects($this->never())->method('save')->will($this->returnValue($message)); |
||
63 | |||
64 | $form = $this->getMockBuilder('Symfony\Component\Form\Form')->disableOriginalConstructor()->getMock(); |
||
65 | $form->expects($this->once())->method('handleRequest'); |
||
66 | $form->expects($this->once())->method('isValid')->will($this->returnValue(false)); |
||
67 | |||
68 | $formFactory = $this->getMock('Symfony\Component\Form\FormFactoryInterface'); |
||
69 | $formFactory->expects($this->once())->method('createNamed')->will($this->returnValue($form)); |
||
70 | |||
71 | $view = $this->createMessageController(null, $messageManager, $formFactory)->postMessageAction(new Request()); |
||
72 | |||
73 | $this->assertInstanceOf('Symfony\Component\Form\FormInterface', $view); |
||
74 | } |
||
75 | |||
76 | /** |
||
77 | * @param $message |
||
78 | * @param $messageManager |
||
79 | * @param $formFactory |
||
80 | * |
||
81 | * @return MessageController |
||
82 | */ |
||
83 | public function createMessageController($message = null, $messageManager = null, $formFactory = null) |
||
97 | } |
||
98 |