mirror of
https://github.com/wallabag/wallabag.git
synced 2025-09-15 18:57:05 +00:00
Add some fixtures
Improve test, so user can login Fix some leftJoin Cleanup EntryController
This commit is contained in:
parent
d91691573f
commit
3b815d2de5
11 changed files with 361 additions and 54 deletions
|
@ -19,9 +19,7 @@ class EntryController extends Controller
|
|||
*/
|
||||
public function addEntryAction(Request $request)
|
||||
{
|
||||
$repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:User');
|
||||
$user = $repository->find(1);
|
||||
$entry = new Entry($user);
|
||||
$entry = new Entry($this->getUser());
|
||||
|
||||
$form = $this->createFormBuilder($entry)
|
||||
->add('url', 'url')
|
||||
|
@ -61,10 +59,10 @@ class EntryController extends Controller
|
|||
*/
|
||||
public function showUnreadAction()
|
||||
{
|
||||
$repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entry');
|
||||
// TODO don't give the user ID like this
|
||||
// TODO change pagination
|
||||
$entries = $repository->findUnreadByUser(1, 0);
|
||||
$entries = $this->getDoctrine()
|
||||
->getRepository('WallabagCoreBundle:Entry')
|
||||
->findUnreadByUser($this->getUser()->getId(), 0);
|
||||
|
||||
return $this->render(
|
||||
'WallabagCoreBundle:Entry:entries.html.twig',
|
||||
|
@ -80,10 +78,10 @@ class EntryController extends Controller
|
|||
*/
|
||||
public function showArchiveAction()
|
||||
{
|
||||
$repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entry');
|
||||
// TODO don't give the user ID like this
|
||||
// TODO change pagination
|
||||
$entries = $repository->findArchiveByUser(1, 0);
|
||||
$entries = $this->getDoctrine()
|
||||
->getRepository('WallabagCoreBundle:Entry')
|
||||
->findArchiveByUser($this->getUser()->getId(), 0);
|
||||
|
||||
return $this->render(
|
||||
'WallabagCoreBundle:Entry:entries.html.twig',
|
||||
|
@ -99,10 +97,10 @@ class EntryController extends Controller
|
|||
*/
|
||||
public function showStarredAction()
|
||||
{
|
||||
$repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entry');
|
||||
// TODO don't give the user ID like this
|
||||
// TODO change pagination
|
||||
$entries = $repository->findStarredByUser(1, 0);
|
||||
$entries = $this->getDoctrine()
|
||||
->getRepository('WallabagCoreBundle:Entry')
|
||||
->findStarredByUser($this->getUser()->getId(), 0);
|
||||
|
||||
return $this->render(
|
||||
'WallabagCoreBundle:Entry:entries.html.twig',
|
||||
|
|
35
src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php
Normal file
35
src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php
Normal file
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\DataFixtures\ORM;
|
||||
|
||||
use Doctrine\Common\DataFixtures\AbstractFixture;
|
||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||
use Doctrine\Common\Persistence\ObjectManager;
|
||||
use Wallabag\CoreBundle\Entity\Entry;
|
||||
|
||||
class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
$entry1 = new Entry($this->getReference('admin-user'));
|
||||
$entry1->setUrl('http://0.0.0.0');
|
||||
$entry1->setTitle('test title');
|
||||
$entry1->setContent('This is my content /o/');
|
||||
|
||||
$manager->persist($entry1);
|
||||
$manager->flush();
|
||||
|
||||
$this->addReference('entry1', $entry1);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getOrder()
|
||||
{
|
||||
return 20;
|
||||
}
|
||||
}
|
34
src/Wallabag/CoreBundle/DataFixtures/ORM/LoadUserData.php
Normal file
34
src/Wallabag/CoreBundle/DataFixtures/ORM/LoadUserData.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\DataFixtures\ORM;
|
||||
|
||||
use Doctrine\Common\DataFixtures\AbstractFixture;
|
||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||
use Doctrine\Common\Persistence\ObjectManager;
|
||||
use Wallabag\CoreBundle\Entity\User;
|
||||
|
||||
class LoadUserData extends AbstractFixture implements OrderedFixtureInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
$userAdmin = new User();
|
||||
$userAdmin->setUsername('admin');
|
||||
$userAdmin->setPassword('test');
|
||||
|
||||
$manager->persist($userAdmin);
|
||||
$manager->flush();
|
||||
|
||||
$this->addReference('admin-user', $userAdmin);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getOrder()
|
||||
{
|
||||
return 10;
|
||||
}
|
||||
}
|
|
@ -11,19 +11,20 @@ class EntryRepository extends EntityRepository
|
|||
/**
|
||||
* Retrieves unread entries for a user
|
||||
*
|
||||
* @param $userId
|
||||
* @param $firstResult
|
||||
* @param int $maxResults
|
||||
* @param int $userId
|
||||
* @param int $firstResult
|
||||
* @param int $maxResults
|
||||
*
|
||||
* @return Paginator
|
||||
*/
|
||||
public function findUnreadByUser($userId, $firstResult, $maxResults = 12)
|
||||
{
|
||||
$qb = $this->createQueryBuilder('e')
|
||||
->select('e')
|
||||
->setFirstResult($firstResult)
|
||||
->setMaxResults($maxResults)
|
||||
->leftJoin('e.user', 'u')
|
||||
->where('e.isArchived = false')
|
||||
->andWhere('e.userId =:userId')->setParameter('userId', $userId)
|
||||
->andWhere('u.id =:userId')->setParameter('userId', $userId)
|
||||
->andWhere('e.isDeleted=false')
|
||||
->orderBy('e.createdAt', 'desc')
|
||||
->getQuery();
|
||||
|
@ -36,9 +37,10 @@ class EntryRepository extends EntityRepository
|
|||
/**
|
||||
* Retrieves read entries for a user
|
||||
*
|
||||
* @param $userId
|
||||
* @param $firstResult
|
||||
* @param int $maxResults
|
||||
* @param int $userId
|
||||
* @param int $firstResult
|
||||
* @param int $maxResults
|
||||
*
|
||||
* @return Paginator
|
||||
*/
|
||||
public function findArchiveByUser($userId, $firstResult, $maxResults = 12)
|
||||
|
@ -47,8 +49,9 @@ class EntryRepository extends EntityRepository
|
|||
->select('e')
|
||||
->setFirstResult($firstResult)
|
||||
->setMaxResults($maxResults)
|
||||
->leftJoin('e.user', 'u')
|
||||
->where('e.isArchived = true')
|
||||
->andWhere('e.userId =:userId')->setParameter('userId', $userId)
|
||||
->andWhere('u.id =:userId')->setParameter('userId', $userId)
|
||||
->andWhere('e.isDeleted=false')
|
||||
->orderBy('e.createdAt', 'desc')
|
||||
->getQuery();
|
||||
|
@ -61,9 +64,10 @@ class EntryRepository extends EntityRepository
|
|||
/**
|
||||
* Retrieves starred entries for a user
|
||||
*
|
||||
* @param $userId
|
||||
* @param $firstResult
|
||||
* @param int $maxResults
|
||||
* @param int $userId
|
||||
* @param int $firstResult
|
||||
* @param int $maxResults
|
||||
*
|
||||
* @return Paginator
|
||||
*/
|
||||
public function findStarredByUser($userId, $firstResult, $maxResults = 12)
|
||||
|
@ -72,9 +76,10 @@ class EntryRepository extends EntityRepository
|
|||
->select('e')
|
||||
->setFirstResult($firstResult)
|
||||
->setMaxResults($maxResults)
|
||||
->leftJoin('e.user', 'u')
|
||||
->where('e.isStarred = true')
|
||||
->andWhere('e.userId =:userId')->setParameter('userId', $userId)
|
||||
->andWhere('e.isDeleted=false')
|
||||
->andWhere('u.id =:userId')->setParameter('userId', $userId)
|
||||
->andWhere('e.isDeleted = false')
|
||||
->orderBy('e.createdAt', 'desc')
|
||||
->getQuery();
|
||||
|
||||
|
@ -83,22 +88,34 @@ class EntryRepository extends EntityRepository
|
|||
return $paginator;
|
||||
}
|
||||
|
||||
public function findEntries($userId, $isArchived, $isStarred, $isDeleted, $sort, $order)
|
||||
/**
|
||||
* Find Entries
|
||||
*
|
||||
* @param int $userId
|
||||
* @param bool $isArchived
|
||||
* @param bool $isStarred
|
||||
* @param bool $isDeleted
|
||||
* @param string $sort
|
||||
* @param string $order
|
||||
*
|
||||
* @return ArrayCollection
|
||||
*/
|
||||
public function findEntries($userId, $isArchived = null, $isStarred = null, $isDeleted = null, $sort = 'created', $order = 'ASC')
|
||||
{
|
||||
$qb = $this->createQueryBuilder('e')
|
||||
->select('e')
|
||||
->where('e.userId =:userId')->setParameter('userId', $userId);
|
||||
->leftJoin('e.user', 'u')
|
||||
->where('u.id =:userId')->setParameter('userId', $userId);
|
||||
|
||||
if (!is_null($isArchived)) {
|
||||
$qb->andWhere('e.isArchived =:isArchived')->setParameter('isArchived', $isArchived);
|
||||
if (null !== $isArchived) {
|
||||
$qb->andWhere('e.isArchived =:isArchived')->setParameter('isArchived', (bool) $isArchived);
|
||||
}
|
||||
|
||||
if (!is_null($isStarred)) {
|
||||
$qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', $isStarred);
|
||||
if (null !== $isStarred) {
|
||||
$qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', (bool) $isStarred);
|
||||
}
|
||||
|
||||
if (!is_null($isDeleted)) {
|
||||
$qb->andWhere('e.isDeleted =:isDeleted')->setParameter('isDeleted', $isDeleted);
|
||||
if (null !== $isDeleted) {
|
||||
$qb->andWhere('e.isDeleted =:isDeleted')->setParameter('isDeleted', (bool) $isDeleted);
|
||||
}
|
||||
|
||||
if ('created' === $sort) {
|
||||
|
|
|
@ -2,13 +2,24 @@
|
|||
|
||||
namespace Wallabag\CoreBundle\Tests\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Wallabag\CoreBundle\Tests\WallabagTestCase;
|
||||
|
||||
class EntryControllerTest extends WebTestCase
|
||||
class EntryControllerTest extends WallabagTestCase
|
||||
{
|
||||
public function testLogin()
|
||||
{
|
||||
$client = $this->getClient();
|
||||
|
||||
$crawler = $client->request('GET', '/new');
|
||||
|
||||
$this->assertEquals(302, $client->getResponse()->getStatusCode());
|
||||
$this->assertContains('login', $client->getResponse()->headers->get('location'));
|
||||
}
|
||||
|
||||
public function testGetNew()
|
||||
{
|
||||
$client = static::createClient();
|
||||
$this->logIn();
|
||||
$client = $this->getClient();
|
||||
|
||||
$crawler = $client->request('GET', '/new');
|
||||
|
||||
|
@ -20,7 +31,8 @@ class EntryControllerTest extends WebTestCase
|
|||
|
||||
public function testPostNewEmpty()
|
||||
{
|
||||
$client = static::createClient();
|
||||
$this->logIn();
|
||||
$client = $this->getClient();
|
||||
|
||||
$crawler = $client->request('GET', '/new');
|
||||
|
||||
|
@ -37,7 +49,8 @@ class EntryControllerTest extends WebTestCase
|
|||
|
||||
public function testPostNewOk()
|
||||
{
|
||||
$client = static::createClient();
|
||||
$this->logIn();
|
||||
$client = $this->getClient();
|
||||
|
||||
$crawler = $client->request('GET', '/new');
|
||||
|
||||
|
@ -55,13 +68,14 @@ class EntryControllerTest extends WebTestCase
|
|||
|
||||
$crawler = $client->followRedirect();
|
||||
|
||||
$this->assertCount(1, $alert = $crawler->filter('h2 a')->extract(array('_text')));
|
||||
$this->assertGreaterThan(1, $alert = $crawler->filter('h2 a')->extract(array('_text')));
|
||||
$this->assertContains('Mailjet', $alert[0]);
|
||||
}
|
||||
|
||||
public function testArchive()
|
||||
{
|
||||
$client = static::createClient();
|
||||
$this->logIn();
|
||||
$client = $this->getClient();
|
||||
|
||||
$crawler = $client->request('GET', '/archive');
|
||||
|
||||
|
@ -70,7 +84,8 @@ class EntryControllerTest extends WebTestCase
|
|||
|
||||
public function testStarred()
|
||||
{
|
||||
$client = static::createClient();
|
||||
$this->logIn();
|
||||
$client = $this->getClient();
|
||||
|
||||
$crawler = $client->request('GET', '/starred');
|
||||
|
||||
|
@ -79,13 +94,18 @@ class EntryControllerTest extends WebTestCase
|
|||
|
||||
public function testView()
|
||||
{
|
||||
$client = static::createClient();
|
||||
$this->logIn();
|
||||
$client = $this->getClient();
|
||||
|
||||
$content = $client->getContainer()
|
||||
->get('doctrine.orm.entity_manager')
|
||||
->getRepository('WallabagCoreBundle:Entry')
|
||||
->findOneByIsArchived(false);
|
||||
|
||||
if (!$content) {
|
||||
$this->markTestSkipped('No content found in db.');
|
||||
}
|
||||
|
||||
$crawler = $client->request('GET', '/view/'.$content->getId());
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode());
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Tests\Controller;
|
||||
|
||||
use Wallabag\CoreBundle\Tests\WallabagTestCase;
|
||||
|
||||
class SecurityControllerTest extends WallabagTestCase
|
||||
{
|
||||
public function testLogin()
|
||||
{
|
||||
$client = $this->getClient();
|
||||
|
||||
$crawler = $client->request('GET', '/new');
|
||||
|
||||
$this->assertEquals(302, $client->getResponse()->getStatusCode());
|
||||
$this->assertContains('login', $client->getResponse()->headers->get('location'));
|
||||
}
|
||||
|
||||
public function testLoginFail()
|
||||
{
|
||||
$client = $this->getClient();
|
||||
|
||||
$crawler = $client->request('GET', '/login');
|
||||
|
||||
$form = $crawler->filter('button[type=submit]')->form();
|
||||
$data = array(
|
||||
'_username' => 'admin',
|
||||
'_password' => 'admin',
|
||||
);
|
||||
|
||||
$client->submit($form, $data);
|
||||
|
||||
$this->assertEquals(302, $client->getResponse()->getStatusCode());
|
||||
$this->assertContains('login', $client->getResponse()->headers->get('location'));
|
||||
|
||||
$crawler = $client->followRedirect();
|
||||
|
||||
$this->assertContains('Bad credentials', $client->getResponse()->getContent());
|
||||
}
|
||||
}
|
34
src/Wallabag/CoreBundle/Tests/WallabagTestCase.php
Normal file
34
src/Wallabag/CoreBundle/Tests/WallabagTestCase.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Tests;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Symfony\Component\BrowserKit\Cookie;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
|
||||
|
||||
class WallabagTestCase extends WebTestCase
|
||||
{
|
||||
private $client = null;
|
||||
|
||||
public function getClient()
|
||||
{
|
||||
return $this->client;
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->client = static::createClient();
|
||||
}
|
||||
|
||||
public function logIn()
|
||||
{
|
||||
$crawler = $this->client->request('GET', '/login');
|
||||
$form = $crawler->filter('button[type=submit]')->form();
|
||||
$data = array(
|
||||
'_username' => 'admin',
|
||||
'_password' => 'test',
|
||||
);
|
||||
|
||||
$this->client->submit($form, $data);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue