getContainer() ->get('doctrine.orm.entity_manager'); $center = static::$em->getRepository('ChillMainBundle:Center') ->findOneBy(['name' => 'Center A']); $person = (new Person(new DateTime('2015-05-01'))) ->setGender(Person::FEMALE_GENDER) ->setFirstName('Nelson') ->setLastName('Mandela') ->setCenter($center); static::$em->persist($person); $this->person = $person; $scopesSocial = array_filter( static::$em ->getRepository('ChillMainBundle:Scope') ->findAll(), function (Scope $scope) { return $scope->getName()['en'] === 'social'; } ); $report = (new Report()) ->setUser(static::$em->getRepository('ChillMainBundle:User') ->findOneByUsername('center a_social')) ->setDate(new DateTime('2015-05-02')) ->setPerson($this->person) ->setCFGroup($this->getHousingCustomFieldsGroup()) ->setCFData(['has_logement' => 'own_house', 'house-desc' => 'blah blah', ]) ->setScope(end($scopesSocial)); static::$em->persist($report); $this->report = $report; static::$em->flush(); } public function tearDown() { //static::$em->refresh($this->person); //static::$em->refresh($this->report); // static::$em->remove($this->person); //static::$em->remove($this->report); } public function testReportIsNotVisibleToUngrantedUsers() { $client = static::createClient( [], MainTestHelper::getAuthenticatedClientOptions('center a_administrative') ); $crawler = $client->request('GET', '/fr/person/' . $this->person->getId() . '/timeline'); $this->assertEquals( 0, $crawler->filter('.report_entry .summary') ->count(), 'the page does not contains a .report .summary element' ); } /** * Test that a report is shown in timeline. */ public function testTimelineReport() { $client = static::createClient( [], 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"' ); } public function testTimelineReportWithSummaryField() { //load the page $client = static::createClient( [], MainTestHelper::getAuthenticatedClientOptions() ); $crawler = $client->request('GET', '/fr/person/' . $this->person->getId() . '/timeline'); //performs tests $this->assertTrue( $client->getResponse()->isSuccessful(), 'The page timeline is loaded successfully' ); $this->assertGreaterThan( 0, $crawler->filter('.report_entry .summary') ->count(), 'the page contains a .report .summary element' ); $this->assertContains( 'blah blah', $crawler->filter('.report_entry .summary') ->text(), 'the page contains the text "blah blah"' ); $this->assertContains( 'Propriétaire', $crawler->filter('.report_entry .summary') ->text(), 'the page contains the mention "Propriétaire"' ); } /** * get a random custom fields group. * * @return \Chill\CustomFieldsBundle\Entity\CustomFieldsGroup */ private function getHousingCustomFieldsGroup() { $groups = static::$em ->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup') ->findAll(); foreach ($groups as $group) { if ($group->getName()['fr'] === 'Situation de logement') { return $group; } } return $groups[rand(0, count($groups) - 1)]; } }