Example #1
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']);
 }
Example #2
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));
 }
Example #3
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']);
 }
Example #4
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();
 }