2015-10-01 20:25:23 +00:00
|
|
|
<?php
|
|
|
|
|
2016-09-30 19:01:36 +00:00
|
|
|
namespace Tests\Wallabag\UserBundle\EventListener;
|
2015-10-01 20:25:23 +00:00
|
|
|
|
2022-09-01 18:54:56 +00:00
|
|
|
use Doctrine\ORM\EntityManager;
|
2015-12-22 09:16:34 +00:00
|
|
|
use FOS\UserBundle\Event\FilterUserResponseEvent;
|
|
|
|
use FOS\UserBundle\FOSUserEvents;
|
2017-12-16 21:17:42 +00:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2015-10-01 20:25:23 +00:00
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher;
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
2018-10-13 07:24:39 +00:00
|
|
|
use Symfony\Component\HttpFoundation\Session\Session;
|
|
|
|
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
2015-10-01 20:25:23 +00:00
|
|
|
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;
|
2015-10-01 20:25:23 +00:00
|
|
|
|
2017-12-16 21:17:42 +00:00
|
|
|
class CreateConfigListenerTest extends TestCase
|
2015-10-01 20:25:23 +00:00
|
|
|
{
|
|
|
|
private $em;
|
|
|
|
private $listener;
|
|
|
|
private $dispatcher;
|
|
|
|
private $request;
|
|
|
|
private $response;
|
|
|
|
|
2020-06-15 06:25:59 +00:00
|
|
|
protected function setUp(): void
|
2015-10-01 20:25:23 +00:00
|
|
|
{
|
2018-10-13 07:24:39 +00:00
|
|
|
$session = new Session(new MockArraySessionStorage());
|
2022-09-01 18:54:56 +00:00
|
|
|
$this->em = $this->getMockBuilder(EntityManager::class)
|
2015-10-01 20:25:23 +00:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
2016-09-30 19:01:36 +00:00
|
|
|
$this->listener = new CreateConfigListener(
|
2015-10-01 20:25:23 +00:00
|
|
|
$this->em,
|
|
|
|
20,
|
|
|
|
50,
|
2016-09-30 19:01:36 +00:00
|
|
|
'fr',
|
2016-12-12 16:41:03 +00:00
|
|
|
1,
|
|
|
|
1,
|
2018-10-13 07:24:39 +00:00
|
|
|
1,
|
|
|
|
$session
|
2015-10-01 20:25:23 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$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->setItemsPerPage(20);
|
2017-06-13 16:48:10 +00:00
|
|
|
$config->setFeedLimit(50);
|
2015-10-01 20:25:23 +00:00
|
|
|
$config->setLanguage('fr');
|
2019-09-19 12:23:06 +00:00
|
|
|
$config->setReadingSpeed(200);
|
2015-10-01 20:25:23 +00:00
|
|
|
|
|
|
|
$this->em->expects($this->once())
|
|
|
|
->method('persist')
|
2019-05-10 13:49:39 +00:00
|
|
|
->willReturn($config);
|
2015-10-01 20:25:23 +00:00
|
|
|
$this->em->expects($this->once())
|
|
|
|
->method('flush');
|
|
|
|
|
|
|
|
$this->dispatcher->dispatch(
|
2016-09-30 19:01:36 +00:00
|
|
|
FOSUserEvents::REGISTRATION_COMPLETED,
|
2015-10-01 20:25:23 +00:00
|
|
|
$event
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|