wallabag/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php

81 lines
2.1 KiB
PHP
Raw Normal View History

<?php
namespace Tests\Wallabag\UserBundle\EventListener;
use FOS\UserBundle\Event\FilterUserResponseEvent;
use FOS\UserBundle\FOSUserEvents;
2017-12-16 21:17:42 +00:00
use PHPUnit\Framework\TestCase;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
use Wallabag\CoreBundle\Entity\Config;
2015-10-03 04:29:55 +00:00
use Wallabag\UserBundle\Entity\User;
2017-07-01 07:52:38 +00:00
use Wallabag\UserBundle\EventListener\CreateConfigListener;
2017-12-16 21:17:42 +00:00
class CreateConfigListenerTest extends TestCase
{
private $em;
private $listener;
private $dispatcher;
private $request;
private $response;
protected function setUp()
{
$session = new Session(new MockArraySessionStorage());
$this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
->disableOriginalConstructor()
->getMock();
$this->listener = new CreateConfigListener(
$this->em,
'baggy',
20,
50,
'fr',
2016-12-12 16:41:03 +00:00
1,
1,
1,
$session
);
$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->setFeedLimit(50);
$config->setLanguage('fr');
$config->setReadingSpeed(1);
$this->em->expects($this->once())
->method('persist')
2019-05-10 13:49:39 +00:00
->willReturn($config);
$this->em->expects($this->once())
->method('flush');
$this->dispatcher->dispatch(
FOSUserEvents::REGISTRATION_COMPLETED,
$event
);
}
}