public function test()
 {
     $peRepository = $this->getMockBuilder(PageEleveurBranchRepository::class)->disableOriginalConstructor()->getMock();
     /** @var EntityManager|PHPUnit_Framework_MockObject_MockObject $doctrine */
     $doctrine = $this->getMockBuilder(EntityManager::class)->disableOriginalConstructor()->getMock();
     $doctrine->method('getRepository')->with('AppBundle:PageEleveurBranch')->willReturn($peRepository);
     $this->client->getContainer()->set('doctrine.orm.entity_manager', $doctrine);
     // simule les PE en bdd
     $pageEleveurBranch1 = new PageEleveurBranch();
     $pageEleveurBranch1->setSlug('test-sitemap1');
     $pageEleveurBranch2 = new PageEleveurBranch();
     $pageEleveurBranch2->setSlug('test-sitemap2');
     $peRepository->method('findAll')->willReturn([$pageEleveurBranch1, $pageEleveurBranch2]);
     $crawler = $this->client->request('GET', '/sitemap.xml');
     $this->assertTrue($this->client->getResponse()->isOk());
     $this->assertEquals('text/xml; charset=UTF-8', $this->client->getResponse()->headers->get('Content-Type'));
     /** @var Router $router */
     $router = $this->client->getContainer()->get('router');
     $this->assertContains($router->generate('getPageEleveur_route', ['pageEleveurSlug' => 'test-sitemap1'], Router::ABSOLUTE_URL), $crawler->text());
     $this->assertContains($router->generate('getPageEleveur_route', ['pageEleveurSlug' => 'test-sitemap2'], Router::ABSOLUTE_URL), $crawler->text());
 }
Example #2
0
 /**
  * @param string $nom
  * @param User $owner
  * @return PageEleveur
  * @throws HistoryException
  */
 public function create($nom, User $owner)
 {
     if ($this->pageEleveurBranchRepository->findByOwner($owner)) {
         $this->logger->notice('', debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS));
         throw new HistoryException(HistoryException::DEJA_OWNER);
     }
     $commit = new PageEleveurCommit(null, $nom, null, null, null, null, null, null);
     $pageEleveurBranch = new PageEleveurBranch();
     $pageEleveurBranch->setCommit($commit);
     try {
         $pageEleveurBranch->setSlug(static::slug($nom));
     } catch (InvalidArgumentException $e) {
         throw new HistoryException(HistoryException::NOM_INVALIDE);
     }
     $pageEleveurBranch->setOwner($owner);
     if ($this->pageEleveurBranchRepository->findBySlug($pageEleveurBranch->getSlug())) {
         throw new HistoryException(HistoryException::SLUG_DEJA_EXISTANT);
     }
     $this->doctrine->persist($pageEleveurBranch->getCommit());
     $this->doctrine->persist($pageEleveurBranch);
     $this->doctrine->flush([$pageEleveurBranch->getCommit(), $pageEleveurBranch]);
     return $this->fromBranch($pageEleveurBranch);
 }
 public function testOrdre_Actualite()
 {
     // Mock d'une page eleveur en base de données
     $user = new User();
     $user->setId(1);
     $pageEleveurBranch = new PageEleveurBranch();
     $pageEleveurBranch->setId(1);
     $pageEleveurBranch->setOwner($user);
     $this->pageEleveurBranchRepository->method('find')->withAnyParameters()->willReturn($pageEleveurBranch);
     $commit1 = $this->newCommit(1);
     $pageEleveurBranch->setCommit($commit1);
     $this->pageEleveurCommitRepository->method('find')->withAnyParameters()->willReturn($commit1);
     //Simulation d'une requete de commit
     $pageEleveur = new PageEleveur();
     $pageEleveur->setId($pageEleveurBranch->getId());
     $pageEleveur->setHead($commit1->getId());
     // Les actu sont commités dans le mauvais ordre
     $pageEleveur->setActualites([new Actualite('actu 1', new \DateTime()), new Actualite('actu 2', (new \DateTime())->add(new \DateInterval('P2D')))]);
     $pageEleveur = $this->pageEleveurService->commit($user, $pageEleveur);
     // commit() doit retourner les actu dans le bon ordre
     $this->assertEquals('actu 2', $pageEleveur->getActualites()[0]->getContenu());
     $this->assertEquals('actu 1', $pageEleveur->getActualites()[1]->getContenu());
 }