public function testSubmit() { $this->translatableResource->expects($this->once())->method('getModel')->will($this->returnValue(TranslatableTest::class)); $this->translatableResource->expects($this->once())->method('getRelation')->with($this->identicalTo('translation'))->will($this->returnValue($translationResource = $this->createResourceMock())); $translationResource->expects($this->once())->method('getForm')->will($this->returnValue(TranslationTestType::class)); $this->translatableFactory->expects($this->once())->method('create')->will($this->returnValue(new TranslatableTest())); $form = $this->formFactory->create(TranslatableTestType::class)->submit(['translations' => ['en' => ['value' => 'value-en'], 'fr' => ['value' => 'value-fr']]]); $translatable = $form->getData(); $view = $form->createView(); $this->assertInstanceOf(TranslatableTest::class, $translatable); $this->assertCount(1, $view->children); $this->assertArrayHasKey('translations', $view->children); $this->assertCount(2, $translatable->getTranslations()); $this->assertTrue($translatable->getTranslations()->containsKey('en')); $this->assertTrue($translatable->getTranslations()->containsKey('fr')); $this->assertCount(2, $view->children['translations']); $this->assertArrayHasKey('en', $view->children['translations']); $this->assertArrayHasKey('fr', $view->children['translations']); $this->assertInstanceOf(TranslationTest::class, $translatable->getTranslations()['en']); $this->assertSame('value-en', $translatable->getTranslations()['en']->getValue()); $this->assertCount(1, $view->children['translations']['en']); $this->assertArrayHasKey('value', $view->children['translations']['en']); $this->assertInstanceOf(TranslationTest::class, $translatable->getTranslations()['fr']); $this->assertSame('value-fr', $translatable->getTranslations()['fr']->getValue()); $this->assertCount(1, $view->children['translations']['fr']); $this->assertArrayHasKey('value', $view->children['translations']['fr']); }
public function testSubmit() { $this->localeProvider->expects($this->once())->method('getDefaultLocale')->will($this->returnValue($this->createLocaleMock())); $this->resource->expects($this->once())->method('getModel')->will($this->returnValue(get_class($locale = $this->createLocaleMock()))); $this->repository->expects($this->once())->method('findAll')->will($this->returnValue([])); $this->resourceFactory->expects($this->once())->method('create')->will($this->returnValue($locale)); $locale->expects($this->once())->method('setCode')->with($this->identicalTo($code = 'fr')); $locale->expects($this->once())->method('setEnabled')->with($this->identicalTo(true)); $locale->expects($this->once())->method('setRequired')->with($this->identicalTo(true)); $form = $this->formFactory->create(LocaleType::class)->submit(['code' => $code, 'enabled' => true, 'required' => true]); $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->assertFalse($view->children['code']->vars['disabled']); $this->assertArrayHasKey('disabled', $view->children['enabled']->vars); $this->assertFalse($view->children['enabled']->vars['disabled']); $this->assertArrayHasKey('disabled', $view->children['required']->vars); $this->assertFalse($view->children['required']->vars['disabled']); }