1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sonata Project package. |
5
|
|
|
* |
6
|
|
|
* (c) Thomas Rabaix <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sonata\Tests\Action; |
13
|
|
|
|
14
|
|
|
use PHPUnit\Framework\TestCase; |
15
|
|
|
use Prophecy\Argument; |
16
|
|
|
use Sonata\DatagridBundle\Pager\PagerInterface; |
17
|
|
|
use Sonata\IntlBundle\Templating\Helper\DateTimeHelper; |
18
|
|
|
use Sonata\NewsBundle\Action\DailyPostArchiveAction; |
19
|
|
|
use Sonata\NewsBundle\Entity\PostManager; |
20
|
|
|
use Sonata\NewsBundle\Model\BlogInterface; |
21
|
|
|
use Symfony\Component\DependencyInjection\Container; |
22
|
|
|
use Symfony\Component\HttpFoundation\Request; |
23
|
|
|
use Symfony\Component\HttpFoundation\Response; |
24
|
|
|
use Symfony\Component\Translation\TranslatorInterface; |
25
|
|
|
use Twig\Environment; |
26
|
|
|
|
27
|
|
|
class DailyPostArchiveActionTest extends TestCase |
28
|
|
|
{ |
29
|
|
|
public function testInvoke() |
30
|
|
|
{ |
31
|
|
|
$blog = $this->prophesize(BlogInterface::class); |
32
|
|
|
$translator = $this->prophesize(TranslatorInterface::class); |
33
|
|
|
$dateTimeHelper = $this->prophesize(DateTimeHelper::class); |
34
|
|
|
|
35
|
|
|
$dataParams = [ |
36
|
|
|
'query' => 'foo.publicationDateStart >= :startDate AND bar.publicationDateStart < :endDate', |
37
|
|
|
'params' => [ |
38
|
|
|
'startDate' => new \DateTime(), |
39
|
|
|
'endDate' => new \DateTime('tomorrow'), |
40
|
|
|
], |
41
|
|
|
]; |
42
|
|
|
|
43
|
|
|
$postManager = $this->prophesize(PostManager::class); |
44
|
|
|
$postManager->getPublicationDateQueryParts('2018-7-8', 'day') |
45
|
|
|
->willReturn($dataParams); |
46
|
|
|
$postManager->getPager([ |
47
|
|
|
'date' => $dataParams, |
48
|
|
|
], 1) |
49
|
|
|
->willReturn($this->prophesize(PagerInterface::class)); |
50
|
|
|
|
51
|
|
|
$twig = $this->prophesize(Environment::class); |
52
|
|
|
$twig->render('@SonataNews/Post/archive.html.twig', Argument::any()) |
53
|
|
|
->willReturn('HTML CONTENT'); |
54
|
|
|
|
55
|
|
|
$container = new Container(); |
56
|
|
|
$container->set('twig', $twig->reveal()); |
57
|
|
|
|
58
|
|
|
$action = new DailyPostArchiveAction( |
59
|
|
|
$blog->reveal(), |
60
|
|
|
$postManager->reveal(), |
61
|
|
|
$translator->reveal(), |
62
|
|
|
$dateTimeHelper->reveal() |
63
|
|
|
); |
64
|
|
|
$action->setContainer($container); |
65
|
|
|
|
66
|
|
|
$request = new Request(); |
67
|
|
|
$request->query->set('page', 1); |
68
|
|
|
|
69
|
|
|
$response = $action($request, 2018, 7, 8); |
70
|
|
|
|
71
|
|
|
$this->assertInstanceOf(Response::class, $response); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|