/** * @param QuoteProduct $inputData * @param array $expectedData * * @dataProvider preSetDataProvider */ public function testPreSetData(QuoteProduct $inputData = null, array $expectedData = []) { $this->translator->expects($this->any())->method('trans')->will($this->returnCallback(function ($id, array $params) { return $id . ':' . $params['{title}']; })); $form = $this->factory->create($this->formType); $this->formType->preSetData(new FormEvent($form, $inputData)); foreach ($expectedData as $field => $fieldOptions) { $options = $form->get($field)->getConfig()->getOptions(); foreach ($fieldOptions as $key => $value) { $this->assertEquals($value, $options[$key], $key); } } }
/** * {@inheritdoc} */ protected function getExtensions() { /* @var $translator \PHPUnit_Framework_MockObject_MockObject|TranslatorInterface */ $translator = $this->getMockBuilder('Symfony\\Component\\Translation\\TranslatorInterface')->disableOriginalConstructor()->getMock(); /* @var $productUnitLabelFormatter \PHPUnit_Framework_MockObject_MockObject|ProductUnitLabelFormatter */ $productUnitLabelFormatter = $this->getMockBuilder('OroB2B\\Bundle\\ProductBundle\\Formatter\\ProductUnitLabelFormatter')->disableOriginalConstructor()->getMock(); $userSelectType = new StubEntityType([1 => $this->getEntity('Oro\\Bundle\\UserBundle\\Entity\\User', 1), 2 => $this->getEntity('Oro\\Bundle\\UserBundle\\Entity\\User', 2)], 'oro_user_select'); $accountSelectType = new StubEntityType([1 => $this->getEntity('OroB2B\\Bundle\\AccountBundle\\Entity\\Account', 1), 2 => $this->getEntity('OroB2B\\Bundle\\AccountBundle\\Entity\\Account', 2)], AccountSelectType::NAME); $accountUserSelectType = new StubEntityType([1 => $this->getEntity('OroB2B\\Bundle\\AccountBundle\\Entity\\AccountUser', 1), 2 => $this->getEntity('OroB2B\\Bundle\\AccountBundle\\Entity\\AccountUser', 2)], AccountUserSelectType::NAME); $priceType = $this->preparePriceType(); $entityType = $this->prepareProductEntityType(); $productSelectType = new ProductSelectTypeStub(); $currencySelectionType = new CurrencySelectionTypeStub(); $productUnitSelectionType = $this->prepareProductUnitSelectionType(); $quoteProductOfferType = $this->prepareQuoteProductOfferType(); $quoteProductRequestType = $this->prepareQuoteProductRequestType(); $quoteProductType = new QuoteProductType($translator, $productUnitLabelFormatter, $this->quoteProductFormatter); $quoteProductType->setDataClass('OroB2B\\Bundle\\SaleBundle\\Entity\\QuoteProduct'); return [new PreloadedExtension([OroDateTimeType::NAME => new OroDateTimeType(), CollectionType::NAME => new CollectionType(), QuoteProductOfferType::NAME => new QuoteProductOfferType($this->quoteProductOfferFormatter), QuoteProductCollectionType::NAME => new QuoteProductCollectionType(), QuoteProductOfferCollectionType::NAME => new QuoteProductOfferCollectionType(), QuoteProductRequestCollectionType::NAME => new QuoteProductRequestCollectionType(), ProductRemovedSelectType::NAME => new StubProductRemovedSelectType(), ProductUnitRemovedSelectionType::NAME => new StubProductUnitRemovedSelectionType(), $priceType->getName() => $priceType, $entityType->getName() => $entityType, $userSelectType->getName() => $userSelectType, $quoteProductType->getName() => $quoteProductType, $productSelectType->getName() => $productSelectType, $currencySelectionType->getName() => $currencySelectionType, $quoteProductOfferType->getName() => $quoteProductOfferType, $quoteProductRequestType->getName() => $quoteProductRequestType, $productUnitSelectionType->getName() => $productUnitSelectionType, $accountSelectType->getName() => $accountSelectType, $accountUserSelectType->getName() => $accountUserSelectType], []), $this->getValidatorExtension(true)]; }