public function testGetTitleTemplatesFromDatabase() { $routeName = 'test_route'; $title = new Title(); $title->setTitle('db_title'); $title->setShortTitle('db_short_title'); $repo = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock(); $this->doctrineHelper->expects($this->once())->method('getEntityRepository')->with('Oro\\Bundle\\NavigationBundle\\Entity\\Title')->will($this->returnValue($repo)); $repo->expects($this->once())->method('findOneBy')->with(['route' => $routeName])->will($this->returnValue($title)); $result = $this->titleProvider->getTitleTemplates($routeName); $this->assertEquals(['title' => $title->getTitle(), 'short_title' => $title->getShortTitle()], $result); // test that loaded titles are cached $this->titleProvider->getTitleTemplates($routeName); }
/** * Updates title index * * @param array $routes */ public function update($routes) { $data = $routes; foreach ($this->readers as $reader) { /** @var $reader \Oro\Bundle\NavigationBundle\Title\TitleReader\ReaderInterface */ $data = array_merge($data, $reader->getData($routes)); } $dbData = $this->getStoredTitlesRepository()->findAll(); /** @var $entity Title */ foreach ($dbData as $entity) { if (!array_key_exists($entity->getRoute(), $data)) { // remove not existing entries $this->em->remove($entity); continue; } $route = $entity->getRoute(); $title = ''; if (!$data[$route] instanceof Route) { $title = $data[$route]; } // update existing system titles if ($entity->getIsSystem()) { $entity->setShortTitle($this->getShortTitle($title, $route)); $title = $this->createTitle($route, $title); if (!$title) { $title = ''; } $entity->setTitle($title); $this->em->persist($entity); } unset($data[$route]); } // create title items for new routes foreach ($data as $route => $title) { if ($fullTitle = $this->createTitle($route, $title)) { $entity = new Title(); $entity->setShortTitle($this->getShortTitle($title, $route)); $entity->setTitle($fullTitle); $entity->setRoute($route); $entity->setIsSystem(true); $this->em->persist($entity); } } $this->em->flush(); }
/** * {@inheritDoc} */ public function setShortTitle($shortTitle) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'setShortTitle', array($shortTitle)); return parent::setShortTitle($shortTitle); }