Fix Postgres tests

This commit is contained in:
Jeremy Benoist 2015-09-28 19:35:55 +02:00
parent da3d4998c0
commit 159986c4fb
3 changed files with 52 additions and 22 deletions

View file

@ -161,4 +161,40 @@ class EntryRepository extends EntityRepository
return $languages; return $languages;
} }
/**
* Used only in test case to get the right entry associated to the right user
*
* @param string $username
*
* @return Entry
*/
public function findOneByUsernameAndNotStarred($username)
{
return $this->createQueryBuilder('e')
->leftJoin('e.user', 'u')
->where('u.username = :username')->setParameter('username', $username)
->andWhere('e.isStarred = false')
->setMaxResults(1)
->getQuery()
->getSingleResult();
}
/**
* Used only in test case to get the right entry associated to the right user
*
* @param string $username
*
* @return Entry
*/
public function findOneByUsernameAndNotArchived($username)
{
return $this->createQueryBuilder('e')
->leftJoin('e.user', 'u')
->where('u.username = :username')->setParameter('username', $username)
->andWhere('e.isArchived = false')
->setMaxResults(1)
->getQuery()
->getSingleResult();
}
} }

View file

@ -101,7 +101,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$content = $client->getContainer() $content = $client->getContainer()
->get('doctrine.orm.entity_manager') ->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry') ->getRepository('WallabagCoreBundle:Entry')
->findOneByIsArchived(false); ->findOneByUsernameAndNotArchived('admin');
$client->request('GET', '/view/'.$content->getId()); $client->request('GET', '/view/'.$content->getId());
@ -117,7 +117,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$content = $client->getContainer() $content = $client->getContainer()
->get('doctrine.orm.entity_manager') ->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry') ->getRepository('WallabagCoreBundle:Entry')
->findOneByIsArchived(false); ->findOneByUsernameAndNotArchived('admin');
$crawler = $client->request('GET', '/edit/'.$content->getId()); $crawler = $client->request('GET', '/edit/'.$content->getId());
@ -135,7 +135,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$content = $client->getContainer() $content = $client->getContainer()
->get('doctrine.orm.entity_manager') ->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry') ->getRepository('WallabagCoreBundle:Entry')
->findOneByIsArchived(false); ->findOneByUsernameAndNotArchived('admin');
$crawler = $client->request('GET', '/edit/'.$content->getId()); $crawler = $client->request('GET', '/edit/'.$content->getId());
@ -165,7 +165,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$content = $client->getContainer() $content = $client->getContainer()
->get('doctrine.orm.entity_manager') ->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry') ->getRepository('WallabagCoreBundle:Entry')
->findOneByIsArchived(false); ->findOneByUsernameAndNotArchived('admin');
$client->request('GET', '/archive/'.$content->getId()); $client->request('GET', '/archive/'.$content->getId());
@ -174,7 +174,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$res = $client->getContainer() $res = $client->getContainer()
->get('doctrine.orm.entity_manager') ->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry') ->getRepository('WallabagCoreBundle:Entry')
->findOneById($content->getId()); ->find($content->getId());
$this->assertEquals($res->isArchived(), true); $this->assertEquals($res->isArchived(), true);
} }
@ -187,7 +187,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$content = $client->getContainer() $content = $client->getContainer()
->get('doctrine.orm.entity_manager') ->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry') ->getRepository('WallabagCoreBundle:Entry')
->findOneByIsStarred(false); ->findOneByUsernameAndNotStarred('admin');
$client->request('GET', '/star/'.$content->getId()); $client->request('GET', '/star/'.$content->getId());
@ -209,7 +209,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$content = $client->getContainer() $content = $client->getContainer()
->get('doctrine.orm.entity_manager') ->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry') ->getRepository('WallabagCoreBundle:Entry')
->findOneByIsStarred(false); ->findOneByUsernameAndNotStarred('admin');
$client->request('GET', '/delete/'.$content->getId()); $client->request('GET', '/delete/'.$content->getId());
@ -222,21 +222,15 @@ class EntryControllerTest extends WallabagCoreTestCase
public function testViewOtherUserEntry() public function testViewOtherUserEntry()
{ {
$this->logInAs('bob'); $this->logInAs('admin');
$client = $this->getClient(); $client = $this->getClient();
$content = $client->getContainer() $content = $client->getContainer()
->get('doctrine.orm.entity_manager') ->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry') ->getRepository('WallabagCoreBundle:Entry')
->createQueryBuilder('e') ->findOneByUsernameAndNotArchived('bob');
->select('e.id')
->leftJoin('e.user', 'u')
->where('u.username != :username')->setParameter('username', 'bob')
->setMaxResults(1)
->getQuery()
->getSingleResult(AbstractQuery::HYDRATE_ARRAY);
$client->request('GET', '/view/'.$content['id']); $client->request('GET', '/view/'.$content->getId());
$this->assertEquals(403, $client->getResponse()->getStatusCode()); $this->assertEquals(403, $client->getResponse()->getStatusCode());
} }
@ -360,7 +354,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$form['entry_filter[isStarred]']->untick(); $form['entry_filter[isStarred]']->untick();
$crawler = $client->submit($form); $crawler = $client->submit($form);
$this->assertCount(2, $crawler->filter('div[class=entry]')); $this->assertCount(1, $crawler->filter('div[class=entry]'));
$form = $crawler->filter('button[id=submit-filter]')->form(); $form = $crawler->filter('button[id=submit-filter]')->form();
$form['entry_filter[isArchived]']->untick(); $form['entry_filter[isArchived]']->untick();
@ -391,11 +385,11 @@ class EntryControllerTest extends WallabagCoreTestCase
$crawler = $client->request('GET', '/unread/list'); $crawler = $client->request('GET', '/unread/list');
$form = $crawler->filter('button[id=submit-filter]')->form(); $form = $crawler->filter('button[id=submit-filter]')->form();
$data = array( $data = array(
'entry_filter[language]' => 'de', 'entry_filter[language]' => 'fr',
); );
$crawler = $client->submit($form, $data); $crawler = $client->submit($form, $data);
$this->assertCount(1, $crawler->filter('div[class=entry]')); $this->assertCount(3, $crawler->filter('div[class=entry]'));
$form = $crawler->filter('button[id=submit-filter]')->form(); $form = $crawler->filter('button[id=submit-filter]')->form();
$data = array( $data = array(

View file

@ -24,7 +24,7 @@ class TagControllerTest extends WallabagCoreTestCase
$entry = $client->getContainer() $entry = $client->getContainer()
->get('doctrine.orm.entity_manager') ->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry') ->getRepository('WallabagCoreBundle:Entry')
->findOneBy(array()); ->findOneByUsernameAndNotArchived('admin');
$crawler = $client->request('GET', '/view/'.$entry->getId()); $crawler = $client->request('GET', '/view/'.$entry->getId());
@ -46,7 +46,7 @@ class TagControllerTest extends WallabagCoreTestCase
$newEntry = $client->getContainer() $newEntry = $client->getContainer()
->get('doctrine.orm.entity_manager') ->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry') ->getRepository('WallabagCoreBundle:Entry')
->findOneById($entry->getId()); ->find($entry->getId());
$this->assertEquals(1, count($newEntry->getTags())); $this->assertEquals(1, count($newEntry->getTags()));
@ -61,7 +61,7 @@ class TagControllerTest extends WallabagCoreTestCase
$newEntry = $client->getContainer() $newEntry = $client->getContainer()
->get('doctrine.orm.entity_manager') ->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry') ->getRepository('WallabagCoreBundle:Entry')
->findOneById($entry->getId()); ->find($entry->getId());
$this->assertEquals(2, count($newEntry->getTags())); $this->assertEquals(2, count($newEntry->getTags()));
} }