public function testGetSubtotals()
 {
     $this->translator->expects($this->once())->method('trans')->with(sprintf('orob2b.order.subtotals.%s', Subtotal::TYPE_SUBTOTAL))->willReturn(ucfirst(Subtotal::TYPE_SUBTOTAL));
     $order = new Order();
     $perUnitLineItem = new OrderLineItem();
     $perUnitLineItem->setPriceType(OrderLineItem::PRICE_TYPE_UNIT);
     $perUnitLineItem->setPrice(Price::create(20, 'USD'));
     $perUnitLineItem->setQuantity(2);
     $bundledUnitLineItem = new OrderLineItem();
     $bundledUnitLineItem->setPriceType(OrderLineItem::PRICE_TYPE_BUNDLED);
     $bundledUnitLineItem->setPrice(Price::create(2, 'USD'));
     $bundledUnitLineItem->setQuantity(10);
     $otherCurrencyLineItem = new OrderLineItem();
     $otherCurrencyLineItem->setPriceType(OrderLineItem::PRICE_TYPE_UNIT);
     $otherCurrencyLineItem->setPrice(Price::create(10, 'EUR'));
     $otherCurrencyLineItem->setQuantity(10);
     $emptyLineItem = new OrderLineItem();
     $order->addLineItem($perUnitLineItem);
     $order->addLineItem($bundledUnitLineItem);
     $order->addLineItem($emptyLineItem);
     $order->addLineItem($otherCurrencyLineItem);
     $order->setCurrency('USD');
     $subtotals = $this->provider->getSubtotals($order);
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $subtotals);
     $subtotal = $subtotals->get(Subtotal::TYPE_SUBTOTAL);
     $this->assertInstanceOf('OroB2B\\Bundle\\OrderBundle\\Model\\Subtotal', $subtotal);
     $this->assertEquals(Subtotal::TYPE_SUBTOTAL, $subtotal->getType());
     $this->assertEquals(ucfirst(Subtotal::TYPE_SUBTOTAL), $subtotal->getLabel());
     $this->assertEquals($order->getCurrency(), $subtotal->getCurrency());
     $this->assertInternalType('float', $subtotal->getAmount());
     $this->assertEquals(142.0, $subtotal->getAmount());
 }
 /**
  * @param bool $withRelations
  *
  * @dataProvider testDataProvider
  */
 public function testBuildFormRegularGuesser($withRelations)
 {
     $entityName = 'Test\\Entity';
     $this->doctrineHelperMock->expects($this->once())->method('getEntityIdentifierFieldNames')->with($entityName)->willReturn(['id']);
     $fields = [['name' => 'oneField', 'type' => 'string', 'label' => 'One field'], ['name' => 'anotherField', 'type' => 'string', 'label' => 'Another field']];
     if ($withRelations) {
         $fields[] = ['name' => 'relField', 'relation_type' => 'ref-one', 'label' => 'Many to One field'];
     }
     $this->entityFieldMock->expects($this->once())->method('getFields')->willReturn($fields);
     $this->formConfigMock->expects($this->at(0))->method('getConfig')->with($entityName, 'oneField')->willReturn(new Config(new FieldConfigId('form', $entityName, 'someField'), ['is_enabled' => false]));
     $this->formConfigMock->expects($this->at(1))->method('getConfig')->with($entityName, 'anotherField')->willReturn(new Config(new FieldConfigId('form', $entityName, 'anotherField'), ['is_enabled' => true]));
     if ($withRelations) {
         $this->formConfigMock->expects($this->at(2))->method('getConfig')->with($entityName, 'relField')->willReturn(new Config(new FieldConfigId('form', $entityName, 'relField'), ['is_enabled' => true]));
         $this->translatorMock->expects($this->at(0))->method('trans')->with('oro.entity.form.entity_fields')->willReturn('Fields');
         $this->translatorMock->expects($this->at(1))->method('trans')->with('oro.entity.form.entity_related')->willReturn('Relations');
     }
     $form = $this->factory->create($this->type, null, ['entity' => $entityName, 'with_relations' => $withRelations]);
     $view = $form->createView();
     $this->assertEquals('update_field_choice', $view->vars['full_name'], 'Failed asserting that field name is correct');
     $this->assertNotEmpty($view->vars['configs']['component']);
     $this->assertEquals('entity-field-choice', $view->vars['configs']['component']);
     $this->assertEquals('update_field_choice', $form->getConfig()->getType()->getName(), 'Failed asserting that correct underlying type was used');
     if ($withRelations) {
         $this->assertCount(2, $view->vars['choices'], 'Failed asserting that choices are grouped');
     } else {
         $this->assertCount(1, $view->vars['choices'], 'Failed asserting that choices exists');
         /** @var ChoiceView $choice */
         $choice = reset($view->vars['choices']);
         $this->assertEquals('Another field', $choice->label);
     }
 }
 public function testGetFailedMessage()
 {
     $message = 'test message';
     $this->router->expects($this->never())->method($this->anything());
     $this->translator->expects($this->once())->method('trans')->willReturn($message);
     $this->assertEquals($message, $this->generator->getFailedMessage());
 }
 protected function setUp()
 {
     $this->translator = $this->getMock('Symfony\\Component\\Translation\\TranslatorInterface');
     $this->translator->expects($this->any())->method('trans')->willReturnCallback(function ($id) {
         return $id . '.trans';
     });
     $this->doctrineHelper = $this->getMockBuilder('Oro\\Bundle\\EntityBundle\\ORM\\DoctrineHelper')->disableOriginalConstructor()->getMock();
 }
 protected function setUp()
 {
     parent::setUp();
     /** @var TranslatorInterface $translator */
     $this->translator = $this->getMock('Symfony\\Component\\Translation\\TranslatorInterface');
     $this->translator->expects($this->any())->method('trans')->with('orob2b.fallback.type.parent_locale')->willReturn('Parent Locale');
     $this->formType = new FallbackPropertyType($this->translator);
 }
 protected function setUp()
 {
     $this->translator = $this->getMock('Symfony\\Component\\Translation\\TranslatorInterface');
     $this->translator->expects($this->any())->method('trans')->willReturnCallback(function ($message) {
         return $message . '.trans';
     });
     $this->formFactory = $this->getMock('Symfony\\Component\\Form\\FormFactoryInterface');
     $this->componentRegistry = $this->getMockBuilder('OroB2B\\Bundle\\ProductBundle\\Model\\ComponentProcessorRegistry')->disableOriginalConstructor()->getMock();
     $this->handler = new QuickAddHandler($this->translator, $this->formFactory, $this->componentRegistry);
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->translator = $this->getMock('Symfony\\Component\\Translation\\TranslatorInterface');
     $this->translator->expects(static::any())->method('trans')->will(static::returnCallback(function ($id, array $params) {
         return $id . ':' . $params['{title}'];
     }));
     $this->formType = new ProductRemovedSelectType();
     $this->formType->setTranslator($this->translator);
     parent::setUp();
 }
 public function testOnPostSubmitWithInvalidForm()
 {
     $event = $this->createFormEventMock();
     $event->expects($this->once())->method('getForm')->will($this->returnValue($form = $this->createFormMock()));
     $form->expects($this->once())->method('isValid')->will($this->returnValue(false));
     $this->session->expects($this->once())->method('getFlashBag')->will($this->returnValue($flashBag = $this->createFlashBagMock()));
     $this->translator->expects($this->once())->method('trans')->with($this->identicalTo('lug.resource.csrf.error'), $this->identicalTo([]), $this->identicalTo('flashes'))->will($this->returnValue($translation = 'translation'));
     $flashBag->expects($this->once())->method('add')->with($this->identicalTo('error'), $this->identicalTo($translation));
     $this->flashCsrfProtectionSubscriber->onPostSubmit($event);
 }
Example #9
0
 protected function setUp()
 {
     $this->configProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock();
     $this->activityManager = $this->getMockBuilder('Oro\\Bundle\\ActivityBundle\\Manager\\ActivityManager')->disableOriginalConstructor()->getMock();
     $this->translator = $this->getMock('Symfony\\Component\\Translation\\TranslatorInterface');
     $this->translator->expects($this->any())->method('trans')->willReturn('Items');
     $this->listener = new MergeListener($this->translator, $this->configProvider, $this->activityManager);
     $this->entityMetadata = $this->getMockBuilder('Oro\\Bundle\\EntityMergeBundle\\Metadata\\EntityMetadata')->setMethods(['getClassName', 'addFieldMetadata'])->disableOriginalConstructor()->getMock();
     $this->entityMetadata->expects($this->any())->method('getClassName')->will($this->returnValue(get_class($this->createEntity())));
 }
Example #10
0
 public function testGetWidgetDefinitions()
 {
     $placement = 'left';
     $title = 'Foo';
     $definitions = new ArrayCollection();
     $definitions->set('test', array('title' => $title, 'icon' => 'test.ico', 'module' => 'widget/foo', 'placement' => 'left'));
     $this->widgetDefinitionsRegistry->expects($this->once())->method('getWidgetDefinitionsByPlacement')->with($placement)->will($this->returnValue($definitions));
     $this->translator->expects($this->once())->method('trans')->with($title)->will($this->returnValue('trans' . $title));
     $expected = array('test' => array('title' => 'transFoo', 'icon' => 'test.ico', 'module' => 'widget/foo', 'placement' => 'left'));
     $this->assertEquals($expected, $this->extension->getWidgetDefinitions($placement));
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->translator = $this->getMock('Symfony\\Component\\Translation\\TranslatorInterface');
     $this->translator->expects(static::any())->method('trans')->willReturnCallback(function ($id, array $params) {
         return isset($params['{title}']) ? $id . ':' . $params['{title}'] : $id;
     });
     $productUnitLabelFormatter = new ProductUnitLabelFormatter($this->translator);
     $this->formType = new ProductUnitRemovedSelectionType($productUnitLabelFormatter, $this->translator);
     $this->formType->setEntityClass('OroB2B\\Bundle\\ProductBundle\\Entity\\ProductUnit');
     parent::setUp();
 }
 protected function setUp()
 {
     $this->translator = $this->getMock('Symfony\\Component\\Translation\\TranslatorInterface');
     $this->translator->expects($this->any())->method('trans')->with($this->isType('string'))->willReturnCallback(function ($id, array $params = []) {
         $id = str_replace(array_keys($params), array_values($params), $id);
         return $id . '.trans';
     });
     $this->doctrineHelper = $this->getMockBuilder('Oro\\Bundle\\EntityBundle\\ORM\\DoctrineHelper')->disableOriginalConstructor()->getMock();
     $this->priceListRequestHandler = $this->getMockBuilder('OroB2B\\Bundle\\PricingBundle\\Model\\PriceListRequestHandler')->disableOriginalConstructor()->getMock();
     $this->listener = new ProductPriceDatagridListener($this->translator, $this->doctrineHelper, $this->priceListRequestHandler);
 }
Example #13
0
 /**
  * setup mocks
  */
 protected function setUp()
 {
     $this->loader = $this->getMock('\\Twig_Loader_String');
     $this->securityPolicy = $this->getMockBuilder('\\Twig_Sandbox_SecurityPolicy')->disableOriginalConstructor()->getMock();
     $this->sandbox = $this->getMockBuilder('\\Twig_Extension_Sandbox')->disableOriginalConstructor()->getMock();
     $this->sandbox->expects($this->once())->method('getName')->will($this->returnValue('sandbox'));
     $this->sandbox->expects($this->once())->method('getSecurityPolicy')->will($this->returnValue($this->securityPolicy));
     $this->variablesProvider = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Provider\\VariablesProvider')->disableOriginalConstructor()->getMock();
     $this->cache = $this->getMockBuilder('Doctrine\\Common\\Cache\\Cache')->disableOriginalConstructor()->getMock();
     $this->translation = $this->getMockBuilder('Symfony\\Component\\Translation\\TranslatorInterface')->getMock();
     $this->translation->expects($this->any())->method('trans')->will($this->returnArgument(0));
 }
 /**
  * @param QuoteProductOffer $inputData
  * @param array $expectedData
  *
  * @dataProvider preSetDataProvider
  */
 public function testPreSetData(QuoteProductOffer $inputData = null, array $expectedData = [])
 {
     $this->translator->expects($expectedData['empty_value'] ? $this->once() : $this->never())->method('trans')->with($expectedData['empty_value'], ['{title}' => $inputData ? $inputData->getProductUnitCode() : ''])->will($this->returnValue($expectedData['empty_value']));
     $form = $this->factory->create($this->formType);
     $this->formType->preSetData(new FormEvent($form, $inputData));
     $this->assertTrue($form->has('productUnit'));
     $config = $form->get('productUnit')->getConfig();
     $this->assertEquals(ProductUnitSelectionType::NAME, $config->getType()->getName());
     $options = $form->get('productUnit')->getConfig()->getOptions();
     foreach ($expectedData as $key => $value) {
         $this->assertEquals($value, $options[$key], $key);
     }
 }
 public function testBuild()
 {
     $this->translator->expects($this->once())->method('trans')->with('orob2b.customer.menu.account_user_logout.label')->willReturn('Logout');
     $child = $this->getMock('Knp\\Menu\\ItemInterface');
     $child->expects($this->once())->method('setLabel')->with('')->willReturnSelf();
     $child->expects($this->once())->method('setAttribute')->with('class', 'divider')->willReturnSelf();
     /** @var \PHPUnit_Framework_MockObject_MockObject|\Knp\Menu\ItemInterface $menu */
     $menu = $this->getMock('Knp\\Menu\\ItemInterface');
     $menu->expects($this->at(0))->method('setExtra')->with('type', 'dropdown');
     $menu->expects($this->at(1))->method('addChild')->willReturn($child);
     $menu->expects($this->at(2))->method('addChild')->with('Logout', ['route' => 'orob2b_customer_account_user_security_logout', 'linkAttributes' => ['class' => 'no-hash']]);
     $this->builder->build($menu);
 }
 protected function setUp()
 {
     $this->translator = $this->getMock('Symfony\\Component\\Translation\\TranslatorInterface');
     $this->translator->expects($this->any())->method('trans')->willReturnCallback(function ($message) {
         return $message . '_trans';
     });
     $this->doctrineHelper = $this->getMockBuilder('Oro\\Bundle\\EntityBundle\\ORM\\DoctrineHelper')->disableOriginalConstructor()->getMock();
     $accountGroupId = 1;
     $this->repository = $this->getMockBuilder('OroB2B\\Bundle\\PaymentBundle\\Entity\\Repository\\PaymentTermRepository')->disableOriginalConstructor()->getMock();
     $this->doctrineHelper->expects($this->any())->method('getEntityReference')->with('OroB2BAccountBundle:AccountGroup', $accountGroupId)->willReturn(new AccountGroup());
     $this->doctrineHelper->expects($this->any())->method('getEntityRepository')->with(static::PAYMENT_TERM_CLASS)->willReturn($this->repository);
     $this->extension = new AccountGroupFormExtension($this->doctrineHelper, $this->translator, static::PAYMENT_TERM_CLASS);
 }
 /**
  * @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);
         }
     }
 }
 /**
  * @param RequestProduct $inputData
  * @param array $expectedData
  *
  * @dataProvider preSetDataProvider
  */
 public function testPreSetData(RequestProduct $inputData = null, array $expectedData = [])
 {
     $productSku = $inputData ? $inputData->getProductSku() : '';
     $placeholder = $expectedData['configs']['placeholder'];
     $this->translator->expects($placeholder ? $this->once() : $this->never())->method('trans')->with($placeholder, ['{title}' => $productSku])->will($this->returnValue($placeholder));
     $form = $this->factory->create($this->formType);
     $this->formType->preSetData(new FormEvent($form, $inputData));
     $this->assertTrue($form->has('product'));
     $config = $form->get('product')->getConfig();
     $this->assertEquals(ProductSelectType::NAME, $config->getType()->getName());
     $options = $form->get('product')->getConfig()->getOptions();
     foreach ($expectedData as $key => $value) {
         $this->assertEquals($value, $options[$key], $key);
     }
 }
 public function testSaveAndDuplicate()
 {
     $entity = $this->getProductMock();
     $queryParameters = ['qwe' => 'rty'];
     $this->request->query = new ParameterBag($queryParameters);
     $this->request->expects($this->once())->method('getMethod')->will($this->returnValue('POST'));
     $this->request->expects($this->at(1))->method('get')->with($this->anything())->will($this->returnValue(false));
     $this->request->expects($this->at(2))->method('get')->with(Router::ACTION_PARAMETER)->will($this->returnValue(ProductUpdateHandler::ACTION_SAVE_AND_DUPLICATE));
     $this->doctrineHelper->expects($this->once())->method('getEntityManager')->with($entity)->will($this->returnValue($this->entityManager));
     $message = 'Saved';
     $savedAndDuplicatedMessage = 'Saved and duplicated';
     /** @var \PHPUnit_Framework_MockObject_MockObject|Form $form */
     $form = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock();
     $form->expects($this->once())->method('isValid')->will($this->returnValue(true));
     $flashBag = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\Session\\Flash\\FlashBagInterface')->getMock();
     $flashBag->expects($this->once())->method('add')->with('success', $message);
     $flashBag->expects($this->once())->method('set')->with('success', $savedAndDuplicatedMessage);
     $this->session->expects($this->any())->method('getFlashBag')->will($this->returnValue($flashBag));
     $saveAndStayRoute = ['route' => 'test_update'];
     $saveAndCloseRoute = ['route' => 'test_view'];
     $this->router->expects($this->once())->method('redirectAfterSave')->with(array_merge($saveAndStayRoute, ['parameters' => $queryParameters]), array_merge($saveAndCloseRoute, ['parameters' => $queryParameters]), $entity)->will($this->returnValue(new RedirectResponse('test_url')));
     $this->translator->expects($this->once())->method('trans')->with('orob2b.product.controller.product.saved_and_duplicated.message')->will($this->returnValue($savedAndDuplicatedMessage));
     $this->urlGenerator->expects($this->once())->method('generate')->with('orob2b_product_duplicate', ['id' => self::PRODUCT_ID])->will($this->returnValue('generated_redirect_url'));
     $result = $this->handler->handleUpdate($entity, $form, $saveAndStayRoute, $saveAndCloseRoute, $message);
     $this->assertEquals('generated_redirect_url', $result->headers->get('location'));
     $this->assertEquals(302, $result->getStatusCode());
 }
 public function testUntouchedException()
 {
     $exception = new \RuntimeException('foo');
     $event = $this->generateExceptionEvent($exception);
     $this->translator->expects($this->never())->method('trans');
     $this->listener->onKernelException($event);
     self::assertSame($exception, $event->getException());
 }
 public function testValidateDefaultLocale()
 {
     $this->localeProvider->expects($this->once())->method('getDefaultLocale')->will($this->returnValue($locale = $this->createLocaleMock()));
     $domainEvent = $this->createDomainEventMock();
     $domainEvent->expects($this->once())->method('getData')->will($this->returnValue($locale));
     $domainEvent->expects($this->once())->method('getResource')->will($this->returnValue($resource = $this->createResourceMock()));
     $resource->expects($this->exactly(2))->method('getName')->will($this->returnValue($resourceName = 'resource'));
     $resource->expects($this->once())->method('getLabelPropertyPath')->will($this->returnValue($labelPropertyPath = 'code'));
     $this->propertyAccessor->expects($this->once())->method('getValue')->with($this->identicalTo($locale), $this->identicalTo($labelPropertyPath))->will($this->returnValue($localeCode = 'code'));
     $domainEvent->expects($this->once())->method('setStopped')->with($this->identicalTo(true));
     $domainEvent->expects($this->once())->method('setStatusCode')->with($this->identicalTo(409));
     $domainEvent->expects($this->once())->method('setMessageType')->with($this->identicalTo('error'));
     $domainEvent->expects($this->once())->method('getAction')->will($this->returnValue('action'));
     $this->translator->expects($this->once())->method('trans')->with($this->identicalTo('lug.resource.action.default'), $this->identicalTo(['%resource%' => $localeCode]), $this->identicalTo('flashes'))->will($this->returnValue($translation = 'translation'));
     $domainEvent->expects($this->once())->method('setMessage')->with($this->identicalTo($translation));
     $this->localeDomainSubscriber->validateDefaultLocale($domainEvent);
 }
 /**
  * @dataProvider configValuesProvider
  *
  * @param string $entityName
  * @param bool   $hasConfig
  * @param array  $configValuesMap
  * @param array  $expectedResult
  */
 public function testGetMetadata($entityName, $hasConfig, array $configValuesMap, array $expectedResult)
 {
     $classMetadata = new ClassMetadataInfo($entityName);
     $object = $this->getMock('Oro\\Bundle\\SoapBundle\\Controller\\Api\\EntityManagerAwareInterface');
     $apiManager = $this->getMockBuilder('Oro\\Bundle\\SoapBundle\\Entity\\Manager\\ApiEntityManager')->disableOriginalConstructor()->getMock();
     $apiManager->expects($this->once())->method('getMetadata')->willReturn($classMetadata);
     $object->expects($this->once())->method('getManager')->willReturn($apiManager);
     $this->cm->expects($this->once())->method('hasConfig')->willReturn($hasConfig);
     if ($hasConfig) {
         $config = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigInterface');
         $this->cm->expects($this->once())->method('getConfig')->with(new EntityConfigId('entity', $entityName))->willReturn($config);
         $config->expects($this->any())->method('get')->willReturnMap($configValuesMap);
         $this->translator->expects($this->any())->method('trans')->willReturnArgument(0);
     }
     $result = $this->provider->getMetadataFor($object);
     $this->assertInternalType('array', $result);
     $this->assertEquals($expectedResult, $result);
 }
Example #23
0
 /**
  * @dataProvider getLocales
  *
  * @param string $locale
  */
 public function testSetLocale($locale)
 {
     $expected = substr($locale, 0, 2);
     /* @var $request \PHPUnit_Framework_MockObject_MockObject|HttpRequest */
     $request = $this->getMockBuilder('\\Symfony\\Component\\HttpFoundation\\Request')->disableOriginalConstructor()->getMock();
     $request->expects($this->once())->method('setLocale')->with($expected);
     $this->translator->expects($this->once())->method('setLocale')->with($expected);
     $this->translatable->expects($this->once())->method('setTranslatableLocale')->with($expected);
     $this->listener->setLocale($request, $locale);
 }
 /**
  * @param array $inputData
  * @param array $expectedData
  *
  * @dataProvider formatOfferProvider
  */
 public function testFormatOffer(array $inputData, array $expectedData)
 {
     /* @var $item QuoteProductOffer */
     $item = $inputData['item'];
     $item->setQuantity($inputData['quantity'])->setProductUnit($inputData['unit'])->setProductUnitCode($inputData['unitCode'])->setPrice($inputData['price']);
     $this->productUnitValueFormatter->expects($inputData['unit'] ? $this->once() : $this->never())->method('format')->with($inputData['quantity'], $inputData['unitCode'])->will($this->returnValue($expectedData['formattedUnits']));
     $price = $inputData['price'] ?: new Price();
     $this->numberFormatter->expects($price ? $this->once() : $this->never())->method('formatCurrency')->with($price->getValue(), $price->getCurrency())->will($this->returnValue($expectedData['formattedPrice']));
     $this->productUnitLabelFormatter->expects($this->once())->method('format')->with($inputData['unitCode'])->will($this->returnValue($expectedData['formattedUnit']));
     $this->translator->expects($this->once())->method('transChoice')->with($expectedData['transConstant'], $expectedData['transIndex'], ['{units}' => $expectedData['formattedUnits'], '{price}' => $expectedData['formattedPrice'], '{unit}' => $expectedData['formattedUnit']]);
     $this->formatter->formatOffer($inputData['item']);
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->fieldTypeProvider = $this->getMockBuilder('Oro\\Bundle\\EntityExtendBundle\\Provider\\FieldTypeProvider')->disableOriginalConstructor()->getMock();
     $this->fieldTypeProvider->expects(static::any())->method('getSupportedFieldTypes')->willReturn(['type1', 'type2']);
     $this->fieldTypeProvider->expects(static::any())->method('getFieldProperties')->willReturn([]);
     $this->translator = $this->getMock('Symfony\\Component\\Translation\\TranslatorInterface');
     $this->translator->expects(static::any())->method('trans')->willReturnCallback(function ($value) {
         return $value;
     });
     /** @var FieldHelper $fieldHelper */
     $this->fieldHelper = $this->getMockBuilder('Oro\\Bundle\\ImportExportBundle\\Field\\FieldHelper')->disableOriginalConstructor()->getMock();
     /** @var ImportStrategyHelper $strategyHelper */
     $this->strategyHelper = $this->getMockBuilder('Oro\\Bundle\\ImportExportBundle\\Strategy\\Import\\ImportStrategyHelper')->disableOriginalConstructor()->getMock();
     $this->databaseHelper = $this->getMockBuilder('Oro\\Bundle\\ImportExportBundle\\Field\\DatabaseHelper')->disableOriginalConstructor()->getMock();
     $this->strategy = $this->createStrategy();
     /** @var ContextInterface $context */
     $context = $this->getMock('Oro\\Bundle\\ImportExportBundle\\Context\\ContextInterface');
     $this->strategy->setImportExportContext($context);
     $this->strategy->setEntityName('Oro\\Bundle\\EntityConfigBundle\\Entity\\FieldConfigModel');
     $this->strategy->setFieldTypeProvider($this->fieldTypeProvider);
     $this->strategy->setTranslator($this->translator);
 }
Example #26
0
 public function testMessageWithoutLabelPropertyPath()
 {
     $event = $this->createDomainEventMock();
     $event->expects($this->once())->method('getMessageType')->will($this->returnValue($messageType = 'message_type'));
     $event->expects($this->once())->method('setMessageType')->with($this->identicalTo($messageType));
     $event->expects($this->once())->method('getMessage')->will($this->returnValue(null));
     $event->expects($this->once())->method('getAction')->will($this->returnValue($action = 'action'));
     $event->expects($this->once())->method('getObject')->will($this->returnValue($object = $this->createObjectMock()));
     $object->expects($this->once())->method('__toString')->will($this->returnValue($property = 'property'));
     $event->expects($this->once())->method('getResource')->will($this->returnValue($resource = $this->createResourceMock()));
     $resource->expects($this->once())->method('getName')->will($this->returnValue($name = 'name'));
     $this->translator->expects($this->once())->method('trans')->with($this->identicalTo('lug.' . $name . '.' . $action . '.' . $messageType), $this->identicalTo(['%' . $name . '%' => $property]))->will($this->returnValue($translation = 'translation'));
     $event->expects($this->once())->method('setMessage')->with($this->identicalTo($translation));
     $this->messageListener->addMessage($event);
 }
Example #27
0
 public function testProcessInvalidSegment()
 {
     $this->request->setMethod('POST');
     $this->form->expects($this->once())->method('submit')->with($this->request);
     $this->assertProcessSegment();
     $this->form->expects($this->once())->method('isValid')->will($this->returnValue(false));
     $violation = $this->getMockForAbstractClass('Symfony\\Component\\Validator\\ConstraintViolationInterface');
     $violation->expects($this->once())->method('getMessage')->will($this->returnValue('message'));
     $violation->expects($this->once())->method('getMessageTemplate')->will($this->returnValue('message template'));
     $violation->expects($this->once())->method('getMessageParameters')->will($this->returnValue(['test']));
     $violation->expects($this->once())->method('getMessagePluralization')->will($this->returnValue('message pluralization'));
     $errors = new ConstraintViolationList([$violation]);
     $this->validator->expects($this->once())->method('validate')->with($this->isInstanceOf('Oro\\Bundle\\SegmentBundle\\Entity\\Segment'), ['Default', 'marketing_list'])->will($this->returnValue($errors));
     $this->translator->expects($this->once())->method('trans')->with($this->isType('string'), $this->isType('array'))->will($this->returnValue('Marketing List test segment'));
     $this->form->expects($this->once())->method('addError')->with(new FormError('message', 'message template', ['test'], 'message pluralization'));
     $this->manager->expects($this->never())->method('persist');
     $this->manager->expects($this->never())->method('flush');
     $this->assertFalse($this->handler->process($this->testEntity));
     $this->assertSegmentData();
 }
 public function testHandleUpdateNotAllowed()
 {
     $massActionMock = $this->getMock(MassActionInterface::class);
     $datagridMock = $this->getMock('Oro\\Bundle\\DataGridBundle\\Datagrid\\DatagridInterface');
     $iteratorMock = $this->getMock('Oro\\Bundle\\DataGridBundle\\Datasource\\Orm\\IterableResultInterface');
     $entityName = 'Test\\EntityName';
     $hasConfig = true;
     $isEnabled = true;
     $isGranted = false;
     $data = [];
     $this->actionRepoMock->expects($this->once())->method('getEntityName')->with($datagridMock)->will($this->returnValue($entityName));
     $this->configMock->expects($this->once())->method('hasConfig')->with($entityName)->will($this->returnValue($hasConfig));
     $this->configMock->expects($this->once())->method('getConfig')->with($entityName)->will($this->returnValue(new Config(new EntityConfigId('extend', $entityName), ['update_mass_action_enabled' => $isEnabled])));
     $this->securityMock->expects($this->once())->method('isGranted')->with('EDIT', 'entity:' . $entityName)->will($this->returnValue($isGranted));
     $this->actionRepoMock->expects($this->never())->method('batchUpdate');
     $this->transMock->expects($this->once())->method('trans')->will($this->returnValue(uniqid()));
     $options = ActionConfiguration::create(['success_message' => '', 'error_message' => '']);
     $massActionMock->expects($this->any())->method('getOptions')->will($this->returnValue($options));
     $this->transMock->expects($this->once())->method('trans')->with('', ['%error%' => 'Action not configured or not allowed']);
     $this->loggerMock->expects($this->once())->method('debug');
     $actionResponse = $this->handler->handle(new MassActionHandlerArgs($massActionMock, $datagridMock, $iteratorMock, $data));
     $this->assertFalse($actionResponse->isSuccessful());
 }
 protected function assertTranslationServicesCalled()
 {
     $this->translator->expects($this->once())->method('getLocale')->willReturn(self::LOCALE);
     $this->translationCache->expects($this->once())->method('updateTimestamp')->with(self::LOCALE);
 }
 /**
  * @param array $inputData
  * @param array $expectedData
  *
  * @dataProvider formatPriceTypeLabelsProvider
  */
 public function testFormatPriceTypeLabels(array $inputData, array $expectedData)
 {
     $this->translator->expects($this->any())->method('trans')->will($this->returnCallback(function ($type) {
         return $type;
     }));
     $this->assertSame($expectedData, $this->formatter->formatPriceTypeLabels($inputData));
 }