wallabag/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php
Jeremy Benoist 755ff9e835
Create config even if user is disabled
When a user register itself AND the wallabag instance is configured to send a confirmation email, the user is disabled when the listener (which create the config) receive the event.
There were a check (don't know why) if the user is enabled we create the config. But the user is disabled when confirmation email is actived.
2016-10-04 10:42:46 +02:00

74 lines
1.9 KiB
PHP

<?php
namespace Tests\Wallabag\UserBundle\EventListener;
use FOS\UserBundle\Event\FilterUserResponseEvent;
use FOS\UserBundle\FOSUserEvents;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Wallabag\CoreBundle\Entity\Config;
use Wallabag\UserBundle\EventListener\CreateConfigListener;
use Wallabag\UserBundle\Entity\User;
class CreateConfigListenerTest extends \PHPUnit_Framework_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
);
$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
);
}
}