Skip to content

Commit

Permalink
#bug-33486 - fixing integration tests for multiselect attributes stor…
Browse files Browse the repository at this point in the history
…es in _text entity table
  • Loading branch information
Jakub Winkler committed Jul 18, 2021
1 parent 16ef8b1 commit 2be10b7
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 23 deletions.
Expand Up @@ -215,16 +215,36 @@ public function testGetAttributeTextArray()
$product = $this->productRepository->get('simple_ms_2');
$product->getAttributeText('multiselect_attribute');
$expected = [
'Option 2',
'Option 3',
'Option 4 "!@#$%^&*'
'Multiselect option 2',
'Multiselect option 3',
'Multiselect option 4'
];
self::assertEquals(
$expected,
$product->getAttributeText('multiselect_attribute')
);
}

/**
* @magentoDataFixture Magento/Catalog/_files/products_with_multiselect_attribute.php
*/
public function testMultipleMultiselectValues()
{
$expectedArray = [];

for ($i = 1; $i < 200; $i++) {
$expectedArray[] = sprintf('Multiselect option %d', $i);
}

$product = $this->productRepository->get('simple_ms_3');

self::assertEquals(
$expectedArray,
$product->getAttributeText('multiselect_attribute')
);
}


public function testGetCustomDesignDate()
{
$this->assertEquals(['from' => null, 'to' => null], $this->_model->getCustomDesignDate());
Expand Down
Expand Up @@ -12,6 +12,15 @@
$attribute = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class
);

$valueOptionArray = [];
$orderArray = [];

for ($i = 1; $i < 200; $i++) {
$valueOptionArray[sprintf('option_%d', $i)] = [sprintf('Multiselect option %d', $i)];
$orderArray[sprintf('option_%d', $i)] = $i;
}

$entityType = $installer->getEntityTypeId('catalog_product');
if (!$attribute->loadByCode($entityType, 'multiselect_attribute')->getAttributeId()) {
$attribute->setData(
Expand All @@ -34,21 +43,11 @@
'used_in_product_listing' => 0,
'used_for_sort_by' => 0,
'frontend_label' => ['Multiselect Attribute'],
'backend_type' => 'varchar',
'backend_type' => 'text',
'backend_model' => \Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend::class,
'option' => [
'value' => [
'option_1' => ['Option 1'],
'option_2' => ['Option 2'],
'option_3' => ['Option 3'],
'option_4' => ['Option 4 "!@#$%^&*']
],
'order' => [
'option_1' => 1,
'option_2' => 2,
'option_3' => 3,
'option_4' => 4,
],
'value' => $valueOptionArray,
'order' => $orderArray
],
]
);
Expand Down
Expand Up @@ -41,7 +41,7 @@
'used_in_product_listing' => 0,
'used_for_sort_by' => 0,
'frontend_label' => ['Multiselect Attribute'],
'backend_type' => 'varchar',
'backend_type' => 'text',
'backend_model' => ArrayBackend::class,
'option' => [
'value' => [
Expand Down
Expand Up @@ -33,7 +33,7 @@
'used_in_product_listing' => 0,
'used_for_sort_by' => 0,
'frontend_label' => ['Multiselect Attribute'],
'backend_type' => 'varchar',
'backend_type' => 'text',
'backend_model' => \Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend::class,
'option' => [
'value' => [
Expand Down
Expand Up @@ -34,7 +34,7 @@
'used_in_product_listing' => 0,
'used_for_sort_by' => 0,
'frontend_label' => ['Multiselect Attribute with Source Model'],
'backend_type' => 'varchar',
'backend_type' => 'text',
'backend_model' => \Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend::class,
'source_model' => \Magento\Catalog\_files\MultiselectSourceMock::class
]
Expand Down
Expand Up @@ -54,3 +54,17 @@
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
->save();

$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE)
->setId($optionIds[2] * 10)
->setAttributeSetId($installer->getAttributeSetId('catalog_product', 'Default'))
->setWebsiteIds([1])
->setName('With Multiselect 3')
->setSku('simple_ms_3')
->setPrice(10)
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
->setMultiselectAttribute(array_values($optionIds))
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
->save();
Expand Up @@ -140,7 +140,7 @@ public function createNewAttribute(): void
'used_in_product_listing' => 0,
'used_for_sort_by' => 0,
'frontend_label' => ['Multiselect Attribute'],
'backend_type' => 'varchar',
'backend_type' => 'text',
'backend_model' => ArrayBackend::class,
'option' => [
'value' => [
Expand Down
Expand Up @@ -34,7 +34,7 @@
'used_in_product_listing' => 0,
'used_for_sort_by' => 0,
'frontend_label' => ['Multiselect Attribute'],
'backend_type' => 'varchar',
'backend_type' => 'text',
'backend_model' => \Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend::class,
'option' => [
'value' => [
Expand Down
Expand Up @@ -54,7 +54,7 @@
'value' => ['option_0' => ['Option 1'], 'option_1' => ['Option 2']],
'order' => ['option_0' => 1, 'option_1' => 2],
],
'backend_type' => 'varchar',
'backend_type' => 'text',
]
);
$multiselectAttribute->save();
Expand Down
Expand Up @@ -40,7 +40,7 @@
'frontend_input' => 'multiselect',
'frontend_label' => ['Multiselect Attribute'],
'sort_order' => '0',
'backend_type' => 'varchar',
'backend_type' => 'text',
'is_user_defined' => 1,
'is_system' => 0,
'is_required' => '0',
Expand Down

0 comments on commit 2be10b7

Please sign in to comment.