Skip to content

Commit

Permalink
BAP-18759: Upgrade to Symfony 3.4.27 (master) (#23502)
Browse files Browse the repository at this point in the history
* BAP-18759: Upgrade to Symfony 3.4.27
Co-authored-by: Vitaliy Berdylo
Co-authored-by: Vova Soroka
Co-authored-by: Eugene Chetverikov
Co-authored-by: Vladimir Seniuk
Co-authored-by: Ruslan Panasiuk
  • Loading branch information
anyt authored and vitaliyberdylo committed May 17, 2019
1 parent 94db83d commit a75d9a2
Show file tree
Hide file tree
Showing 25 changed files with 409 additions and 140 deletions.
261 changes: 165 additions & 96 deletions dev.lock

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion src/Oro/Bundle/CMSBundle/Form/Type/PageType.php
Expand Up @@ -14,6 +14,9 @@
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Validator\Constraints\NotBlank;

/**
* CMS Page form type
*/
class PageType extends AbstractType
{
const NAME = 'oro_cms_page';
Expand Down Expand Up @@ -100,7 +103,8 @@ public function preSetDataListener(FormEvent $event)
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Page::class
'data_class' => Page::class,
'csrf_token_id' => 'cms_page',
]);
}

Expand Down
Expand Up @@ -147,7 +147,8 @@ public function testConfigureOptions()
->method('setDefaults')
->with(
[
'data_class' => Page::class
'data_class' => Page::class,
'csrf_token_id' => 'cms_page',
]
);

Expand Down
Expand Up @@ -546,7 +546,7 @@ protected function assertEdit(
if ($title === self::DEFAULT_SUBCATEGORY_TITLE) {
$appendProduct = $testProductFour;
};
$crfToken = $this->getContainer()->get('security.csrf.token_manager')->getToken('category');
$crfToken = $this->getContainer()->get('security.csrf.token_manager')->getToken('category')->getValue();
$parameters = [
'input_action' => 'save_and_stay',
'oro_catalog_category' => [
Expand Down
Expand Up @@ -22,6 +22,8 @@ public function testAddQuantityToOrder()
$categoryId = $this->getReference(LoadCategoryData::FIRST_LEVEL)->getId();
$crawler = $this->updateCategory($categoryId, '123', '321', null, null);
$form = $crawler->selectButton('Save')->form();

$this->assertNotContains('The CSRF token is invalid. Please try to resubmit the form.', $crawler->html());
$this->assertEquals(
'123',
$form['oro_catalog_category[minimumQuantityToOrder][scalarValue]']->getValue()
Expand All @@ -38,6 +40,7 @@ public function testFallbackQuantity()
$crawler = $this->updateCategory($categoryId, null, null, 'systemConfig', 'systemConfig');
$form = $crawler->selectButton('Save')->form();

$this->assertNotContains('The CSRF token is invalid. Please try to resubmit the form.', $crawler->html());
$this->assertEquals(
'systemConfig',
$form['oro_catalog_category[minimumQuantityToOrder][fallback]']->getValue()
Expand Down Expand Up @@ -66,7 +69,8 @@ protected function updateCategory($categoryId, $minScalar, $maxScalar, $minFallb
$values = $form->getPhpValues();
$values['oro_catalog_category']['_token'] = $this->getContainer()
->get('security.csrf.token_manager')
->getToken('category');
->getToken('category')
->getValue();

$this->client->followRedirects();

Expand Down
Expand Up @@ -182,7 +182,7 @@ protected function setCategoryInventoryField($ownValue, $useFallbackValue, $fall
$formValues['oro_catalog_category']['inventoryThreshold']['useFallback'] = '1';
$formValues['oro_catalog_category'][$lowInventoryThresholdOption]['useFallback'] = '1';
$formValues['oro_catalog_category']['_token'] =
$this->getContainer()->get('security.csrf.token_manager')->getToken('category');
$this->getContainer()->get('security.csrf.token_manager')->getToken('category')->getValue();

$this->client->followRedirects(true);

Expand Down
Expand Up @@ -2,6 +2,7 @@

namespace Oro\Bundle\PaymentBundle\Form\Type;

use Oro\Bundle\FormBundle\Form\Type\OroUnstructuredHiddenType;
use Oro\Bundle\PaymentBundle\Entity\PaymentMethodConfig;
use Oro\Bundle\PaymentBundle\Method\Provider\PaymentMethodProviderInterface;
use Oro\Bundle\PaymentBundle\Method\View\PaymentMethodViewProviderInterface;
Expand All @@ -12,6 +13,9 @@
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* Form type for PaymentMethodConfig entity
*/
class PaymentMethodConfigType extends AbstractType
{
const NAME = 'oro_payment_method_config';
Expand Down Expand Up @@ -52,7 +56,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'attr' => ['placeholder' => 'oro.payment.paymentmethodconfig.type.label']
]
);
$builder->add('options', HiddenType::class);
$builder->add('options', OroUnstructuredHiddenType::class);
}

/**
Expand Down
Expand Up @@ -61,8 +61,7 @@ public function testSubmit($data)

$paymentMethodConfig = (new PaymentMethodConfig())
->setType('MO')
->setOptions(['client_id' => 3])
;
->setOptions(['client_id' => 3]);

$this->assertTrue($form->isValid());
$this->assertEquals($paymentMethodConfig, $form->getData());
Expand All @@ -76,7 +75,7 @@ public function submitDataProvider()
return [
[new PaymentMethodConfig()],
[
(new PaymentMethodConfig())->setType('PP')->setOptions(['client_id' => 5])
(new PaymentMethodConfig())->setType('PP')->setOptions(['client_id' => 3])
],
];
}
Expand Down
Expand Up @@ -86,7 +86,7 @@ public function testSubmit($data)
$this->assertEquals($data, $form->getData());

$form->submit([
'methodConfigs' => [['type' => self::PAYMENT_TYPE, 'options' => []]],
'methodConfigs' => [['type' => self::PAYMENT_TYPE, 'options' => ['option' => 1]]],
'destinations' => [['country' => 'US']],
'currency' => 'USD',
'rule' => [
Expand All @@ -101,7 +101,11 @@ public function testSubmit($data)
->setCurrency('USD')
->setRule((new Rule())->setSortOrder(1)->setName('rule2')->setEnabled(false))
->addDestination((new PaymentMethodsConfigsRuleDestination())->setCountry(new Country('US')))
->addMethodConfig((new PaymentMethodConfig())->setType(self::PAYMENT_TYPE)),
->addMethodConfig(
(new PaymentMethodConfig())
->setType(self::PAYMENT_TYPE)
->setOptions(['option' => 1])
),
$form->getData()
);
}
Expand Down
@@ -0,0 +1,36 @@
<?php


namespace Oro\Bundle\ProductBundle\Form\DataTransformer;

use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Form\DataTransformerInterface;

/**
* Transforms an NULL to empty array and ArrayCollection to array.
*/
class ProductImageTypesTransformer implements DataTransformerInterface
{
/**
* @param mixed $value
* @return array
*/
public function transform($value): array
{
if ($value instanceof ArrayCollection) {
return $value->toArray();
}

return [];
}

/**
* @param mixed $value
* @return array
*/
public function reverseTransform($value): array
{
// Data should not be transformed
return $value;
}
}
10 changes: 4 additions & 6 deletions src/Oro/Bundle/ProductBundle/Form/Type/ProductImageType.php
Expand Up @@ -5,12 +5,14 @@
use Oro\Bundle\AttachmentBundle\Form\Type\ImageType;
use Oro\Bundle\ProductBundle\Form\EventSubscriber\ProductImageTypesSubscriber;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* Responsible for image and image types for the product.
*/
class ProductImageType extends AbstractType
{
const NAME = 'oro_product_image';
Expand All @@ -28,11 +30,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
]
);

$builder->add(
'types',
HiddenType::class
);

$builder->add('types', ProductImageTypesType::class, ['image_types' => $options['image_types']]);
$builder->addEventSubscriber(new ProductImageTypesSubscriber($options['image_types']));
}

Expand Down
55 changes: 55 additions & 0 deletions src/Oro/Bundle/ProductBundle/Form/Type/ProductImageTypesType.php
@@ -0,0 +1,55 @@
<?php

namespace Oro\Bundle\ProductBundle\Form\Type;

use Oro\Bundle\LayoutBundle\Model\ThemeImageType;
use Oro\Bundle\ProductBundle\Form\DataTransformer\ProductImageTypesTransformer;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* Responsible for product image types.
*/
class ProductImageTypesType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->addModelTransformer(new ProductImageTypesTransformer());
}

/**
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver): void
{
$resolver
->setRequired('image_types')
->setAllowedTypes('image_types', 'array')
->setDefaults([
'multiple' => true,
'choices' => function (Options $options) {
$typesKeys = array_map(function (ThemeImageType $imageType) {
return $imageType->getName();
}, $options['image_types']);

return array_combine($typesKeys, $typesKeys);
}
]);
}


/**
* @return string
*/
public function getParent(): string
{
return ChoiceType::class;
}
}
Expand Up @@ -45,7 +45,7 @@ public function testSubmit($defaultData, $submittedData, $expectedTypes, array $
$form->submit($submittedData);
$this->assertTrue($form->isValid());
/** @var ProductImage $productImage */
$productImage = $form->getData();
$productImage = $form->getData();
$this->assertEquals($expectedTypes, array_keys($productImage->getTypes()->toArray()));
}

Expand All @@ -54,27 +54,28 @@ public function submitDataProvider()
$imageTypes = [
new ThemeImageType('main', 'Main', []),
new ThemeImageType('listing', 'Listing', []),
new ThemeImageType('additional', 'Additional', []),
];

$defaultProductImage = new StubProductImage();
$defaultProductImage->addType('test');

return [
'without default data' => [
'defaultData' => null,
'submittedData' => [
'main' => 1
'main' => true
],
'expectedTypes' => ['main'],
'options' => ['image_types' => $imageTypes]
],
'with default data' => [
'defaultData' => $defaultProductImage,
'submittedData' => [
'main' => 1,
'listing' => 1
'main' => true,
'listing' => true,
'additional' => true
],
'expectedTypes' => ['main', 'listing'],
'expectedTypes' => ['main', 'listing', 'additional'],
'options' => ['image_types' => $imageTypes]
]
];
Expand Down
@@ -0,0 +1,60 @@
<?php

namespace Oro\Bundle\ProductBundle\Tests\Unit\Form\Type;

use Doctrine\Common\Collections\ArrayCollection;
use Oro\Bundle\LayoutBundle\Model\ThemeImageType;
use Oro\Bundle\ProductBundle\Form\Type\ProductImageTypesType;
use Symfony\Component\Form\Test\FormIntegrationTestCase;

class ProductImageTypesTypeTest extends FormIntegrationTestCase
{
/**
* @param array|null $defaultData
* @param array|null $submittedData
* @param array $expectedTypes
* @param array $options
* @dataProvider submitDataProvider
*/
public function testSubmit($defaultData, $submittedData, $expectedTypes, array $options): void
{
$form = $this->factory->create(ProductImageTypesType::class, $defaultData, $options);
$this->assertEquals($defaultData, $form->getData());

$form->submit($submittedData);
$this->assertTrue($form->isValid());
$this->assertEquals($expectedTypes, $form->getData());
}

/**
* @return array
*/
public function submitDataProvider(): array
{
$imageTypes = [
new ThemeImageType('main', 'Main', []),
new ThemeImageType('listing', 'Listing', []),
new ThemeImageType('additional', 'Additional', []),
];

return [
'without default data' => [
'defaultData' => null,
'submittedData' => [
'main',
'listing'
],
'expectedTypes' => ['main', 'listing'],
'options' => ['image_types' => $imageTypes]
],
'with default data' => [
'defaultData' => new ArrayCollection(['main', 'listing', 'additional']),
'submittedData' => [
'main',
],
'expectedTypes' => ['main'],
'options' => ['image_types' => $imageTypes]
]
];
}
}
Expand Up @@ -145,7 +145,7 @@

{% block __oro_promotion_coupon_form__applied_coupons_list_row_promotion_name_widget %}
{% if promotion is not null %}
<span>{{ promotion.labels|localized_value ? promotion.labels|localized_value : promotion.rule.name }}</span>
<span>{{ promotion.labels|localized_value ? promotion.labels|localized_value|oro_html_sanitize : promotion.rule.name }}</span>
{% endif %}
{% endblock %}

Expand Down

0 comments on commit a75d9a2

Please sign in to comment.