aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php
blob: 2b540fdfeb334c20bb64953a340ec1e2c3db6f24 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php

namespace Tests\Wallabag\UserBundle\EventListener;

use FOS\UserBundle\Event\FilterUserResponseEvent;
use FOS\UserBundle\FOSUserEvents;
use PHPUnit\Framework\TestCase;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Wallabag\CoreBundle\Entity\Config;
use Wallabag\UserBundle\Entity\User;
use Wallabag\UserBundle\EventListener\CreateConfigListener;

class CreateConfigListenerTest extends TestCase
{
    private $em;
    private $listener;
    private $dispatcher;
    private $request;
    private $response;

    protected function setUp()
    {
        $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
            ->disableOriginalConstructor()
            ->getMock();

        $this->listener = new CreateConfigListener(
            $this->em,
            'baggy',
            20,
            50,
            'fr',
            1,
            1,
            1
        );

        $this->dispatcher = new EventDispatcher();
        $this->dispatcher->addSubscriber($this->listener);

        $this->request = Request::create('/');
        $this->response = Response::create();
    }

    public function testWithValidUser()
    {
        $user = new User();
        $user->setEnabled(true);

        $event = new FilterUserResponseEvent(
            $user,
            $this->request,
            $this->response
        );

        $config = new Config($user);
        $config->setTheme('baggy');
        $config->setItemsPerPage(20);
        $config->setRssLimit(50);
        $config->setLanguage('fr');
        $config->setReadingSpeed(1);

        $this->em->expects($this->once())
            ->method('persist')
            ->will($this->returnValue($config));
        $this->em->expects($this->once())
            ->method('flush');

        $this->dispatcher->dispatch(
            FOSUserEvents::REGISTRATION_COMPLETED,
            $event
        );
    }
}