Commit 827d3116 authored by Julien Fastré's avatar Julien Fastré
Browse files

add test for timeline page

parent d93aa527
<?php
/*
* Chill is a software for social workers
* Copyright (C) 2015 Champs Libres <info@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Chill\ReportBundle\Tests\Timeline;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Chill\PersonBundle\Entity\Person;
use Chill\ReportBundle\Entity\Report;
use Chill\MainBundle\Tests\TestHelper as MainTestHelper;
/**
* Test a report is shown into timeline
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
* @author Champs Libres <info@champs-libres.coop>
*/
class TimelineProviderTest extends WebTestCase
{
/**
*
* @var \Doctrine\ORM\EntityManager
*/
private static $em;
/**
*
* @var Person
*/
private $person;
/**
*
* @var Report
*/
private $report;
/**
* Create a person with a report associated with the person
*/
public function setUp()
{
static::bootKernel();
static::$em = static::$kernel->getContainer()
->get('doctrine.orm.entity_manager');
$this->person = (new Person(new \DateTime('2015-05-01')))
->setGenre(Person::GENRE_WOMAN)
->setFirstName('Nelson')
->setLastName('Mandela');
static::$em->persist($this->person);
$this->report = (new Report)
->setUser(static::$em->getRepository('ChillMainBundle:User')
->findOneByUsername('chill b_social'))
->setDate(new \DateTime('2015-05-02'))
->setPerson($this->person)
->setCFGroup($this->getRandomCustomFieldsGroup())
->setCFData(array());
static::$em->persist($this->report);
static::$em->flush();
}
public function testTimelineReport()
{
$client = static::createClient(array(),
MainTestHelper::getAuthenticatedClientOptions()
);
$crawler = $client->request('GET', '/fr/person/'.$this->person->getId()
.'/timeline');
$this->assertTrue($client->getResponse()->isSuccessful(),
'The page timeline is loaded successfully');
$this->assertContains('a ajouté un rapport', $crawler->text(),
'the page contains the text "a publié un rapport"');
}
/**
* get a random custom fields group
*
* @return \Chill\CustomFieldsBundle\Entity\CustomFieldsGroup
*/
private function getRandomCustomFieldsGroup()
{
$groups = static::$em
->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup')
->findBy(array('entity' => 'Chill\ReportBundle\Entity\Report'));
return $groups[rand(0, count($groups) -1)];
}
public function tearDown()
{
static::$em->remove($this->person);
static::$em->remove($this->report);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment