示例#1
0
 /**
  * {@inheritdoc}
  */
 public function getLocales()
 {
     if (!isset($this->cache['locales'])) {
         $this->cache['locales'] = $this->localeRepository->findBy($this->createCriteria());
     }
     return $this->cache['locales'];
 }
示例#2
0
 public function testSubmit()
 {
     $this->repository->expects($this->once())->method('findAll')->will($this->returnValue([$locale = $this->createLocaleMock()]));
     $locale->expects($this->once())->method('getCode')->will($this->returnValue('fr'));
     $form = $this->factory->create(LocaleCodeType::class, $code = 'en')->submit($code);
     $this->assertSame($code, $form->getData());
     $this->assertCount(562, $form->createView()->vars['choices']);
 }
示例#3
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $locales = array_flip(array_map(function (LocaleInterface $locale) {
         return (string) $locale->getCode();
     }, $this->localeRepository->findAll()));
     foreach ($view->vars['choices'] as $index => $choiceView) {
         if ($view->vars['data'] !== $choiceView->data && isset($locales[$choiceView->data])) {
             unset($view->vars['choices'][$index]);
         }
     }
 }
示例#4
0
 public function testFindByPassException()
 {
     $this->resource->expects($this->exactly(2))->method('getName')->will($this->returnValue($name = 'name'));
     $this->repository->expects($this->once())->method($repositoryMethod = 'findForShow')->with($this->identicalTo($criteria = ['criteria']), $this->identicalTo($sorting = ['sorting']))->will($this->throwException(new \Exception()));
     $this->eventDispatcher->expects($this->at(0))->method('dispatch')->with($this->identicalTo('lug.' . $name . '.pre_find.' . ($action = 'action')), $this->callback(function (DomainEvent $event) use($action) {
         return $event->getResource() === $this->resource && $event->getObject() === null && $event->getAction() === 'find.' . $action;
     }));
     $this->eventDispatcher->expects($this->at(1))->method('dispatch')->with($this->identicalTo('lug.' . $name . '.error_find.' . $action), $this->callback(function (DomainEvent $event) use($action) {
         $result = $event->getResource() === $this->resource && $event->getObject() === null && $event->getAction() === 'find.' . $action;
         $event->setStopped(false);
         return $result;
     }));
     $this->assertNull($this->domainManager->find($action, $repositoryMethod, $criteria, $sorting));
 }
示例#5
0
 public function testSubmitDefaultLocale()
 {
     $this->localeProvider->expects($this->once())->method('getDefaultLocale')->will($this->returnValue($defaultLocale = $this->createLocaleMock()));
     $defaultLocale->expects($this->exactly(2))->method('getCode')->will($this->returnValue($defaultLocaleCode = 'fr'));
     $defaultLocale->expects($this->never())->method('setCode');
     $defaultLocale->expects($this->never())->method('setEnabled');
     $defaultLocale->expects($this->never())->method('setRequired');
     $this->resource->expects($this->once())->method('getModel')->will($this->returnValue(get_class($defaultLocale)));
     $this->repository->expects($this->once())->method('findAll')->will($this->returnValue([$defaultLocale]));
     $form = $this->formFactory->create(LocaleType::class, $defaultLocale)->submit(['code' => 'USD', 'enabled' => false, 'required' => false]);
     $view = $form->createView();
     $this->assertCount(4, $view->children);
     $this->assertArrayHasKey('code', $view->children);
     $this->assertArrayHasKey('enabled', $view->children);
     $this->assertArrayHasKey('required', $view->children);
     $this->assertArrayHasKey('submit', $view->children);
     $this->assertArrayHasKey('disabled', $view->children['code']->vars);
     $this->assertTrue($view->children['code']->vars['disabled']);
     $this->assertArrayHasKey('disabled', $view->children['enabled']->vars);
     $this->assertTrue($view->children['enabled']->vars['disabled']);
     $this->assertArrayHasKey('disabled', $view->children['required']->vars);
     $this->assertTrue($view->children['required']->vars['disabled']);
 }
示例#6
0
 /**
  * {@inheritdoc}
  */
 protected function findChoices(GridInterface $grid, RepositoryInterface $repository, array $choices)
 {
     $queryBuilder = $repository->createQueryBuilderForCollection();
     $result = $queryBuilder->andWhere($queryBuilder->expr()->in($repository->getProperty($grid->getResource()->getIdPropertyPath(), $queryBuilder), ':' . ($placeholder = 'lug_id_' . str_replace('.', '', uniqid(null, true)))))->setParameter($placeholder, $choices)->getQuery()->getResult();
     return count($result) === count($choices) ? $result : [];
 }
示例#7
0
 /**
  * @expectedException \Lug\Component\Locale\Exception\LocaleNotFoundException
  * @expectedExceptionMessage The default locale "en" could not be found.
  */
 public function testInvalidDefaultLocale()
 {
     $this->localeRepository->expects($this->once())->method('findOneBy')->with($this->identicalTo(['enabled' => true, 'code' => $this->defaultLocale]))->will($this->returnValue(null));
     $this->localeProvider->getDefaultLocale();
 }
示例#8
0
 /**
  * {@inheritdoc}
  */
 protected function findChoices(GridInterface $grid, RepositoryInterface $repository, array $choices)
 {
     $result = $repository->createQueryBuilderForCollection()->field($repository->getProperty($grid->getResource()->getIdPropertyPath()))->in($choices)->getQuery()->getIterator()->toArray();
     return count($result) === count($choices) ? $result : [];
 }