How to use configurable class

Best Atoum code snippet using configurable

ProductRepositoryTest.php

Source:ProductRepositoryTest.php Github

copy

Full Screen

...20{21 const SERVICE_NAME = 'catalogProductRepositoryV1';22 const SERVICE_VERSION = 'V1';23 const RESOURCE_PATH = '/V1/products';24 const CONFIGURABLE_PRODUCT_SKU = 'configurable-product-sku';25 /**26 * @var Config27 */28 protected $eavConfig;29 /**30 * @var ObjectManagerInterface31 */32 protected $objectManager;33 /**34 * @var Attribute35 */36 protected $configurableAttribute;37 /**38 * @inheritdoc39 */40 protected function setUp(): void41 {42 $this->objectManager = Bootstrap::getObjectManager();43 $this->eavConfig = $this->objectManager->get(Config::class);44 }45 /**46 * @inheritdoc47 */48 protected function tearDown(): void49 {50 $this->deleteProductBySku(self::CONFIGURABLE_PRODUCT_SKU);51 parent::tearDown();52 }53 /**54 * Retrieve configurable attribute options55 *56 * @return array57 */58 protected function getConfigurableAttributeOptions()59 {60 /** @var Collection $optionCollection */61 $optionCollection = $this->objectManager->create(62 Collection::class63 );64 $options = $optionCollection->setAttributeFilter($this->configurableAttribute->getId())->getData();65 return $options;66 }67 /**68 * Create configurable product by web api69 *70 * @return array71 */72 protected function createConfigurableProduct()73 {74 $productId1 = 10;75 $productId2 = 20;76 $label = "color";77 $this->configurableAttribute = $this->eavConfig->getAttribute('catalog_product', 'test_configurable');78 $this->assertNotNull($this->configurableAttribute);79 $options = $this->getConfigurableAttributeOptions();80 $this->assertCount(2, $options);81 $configurableProductOptions = [82 [83 "attribute_id" => $this->configurableAttribute->getId(),84 "label" => $label,85 "position" => 0,86 "values" => [87 [88 "value_index" => $options[0]['option_id'],89 ],90 [91 "value_index" => $options[1]['option_id'],92 ]93 ],94 ]95 ];96 $product = [97 "sku" => self::CONFIGURABLE_PRODUCT_SKU,98 "name" => self::CONFIGURABLE_PRODUCT_SKU,99 "type_id" => "configurable",100 "price" => 50,101 'attribute_set_id' => 4,102 "custom_attributes" => [103 [104 "attribute_code" => $this->configurableAttribute->getAttributeCode(),105 "value" => $options[0]['option_id'],106 ],107 ],108 "extension_attributes" => [109 "configurable_product_options" => $configurableProductOptions,110 "configurable_product_links" => [$productId1, $productId2],111 ],112 ];113 $response = $this->createProduct($product);114 return $response;115 }116 /**117 * @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable.php118 */119 public function testCreateConfigurableProduct()120 {121 $productId1 = 10;122 $productId2 = 20;123 $label = "color";124 $response = $this->createConfigurableProduct();125 $this->assertEquals(self::CONFIGURABLE_PRODUCT_SKU, $response[ProductInterface::SKU]);126 $this->assertTrue(127 isset($response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]["configurable_product_options"])128 );129 $resultConfigurableProductOptions130 = $response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]["configurable_product_options"];131 $this->assertCount(1, $resultConfigurableProductOptions);132 $this->assertTrue(isset($resultConfigurableProductOptions[0]['label']));133 $this->assertTrue(isset($resultConfigurableProductOptions[0]['id']));134 $this->assertEquals($label, $resultConfigurableProductOptions[0]['label']);135 $this->assertTrue(136 isset($resultConfigurableProductOptions[0]['values'])137 );138 $this->assertCount(2, $resultConfigurableProductOptions[0]['values']);139 $this->assertTrue(140 isset($response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]["configurable_product_links"])141 );142 $resultConfigurableProductLinks143 = $response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]["configurable_product_links"];144 $this->assertCount(2, $resultConfigurableProductLinks);145 $this->assertEquals([$productId1, $productId2], $resultConfigurableProductLinks);146 }147 /**148 * @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable.php149 */150 public function testDeleteConfigurableProductOption()151 {152 $response = $this->createConfigurableProduct();153 //delete existing option154 $response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]['configurable_product_options'] = [];155 //leave the product links unchanged156 unset($response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]['configurable_product_links']);157 $response = $this->saveProduct($response);158 $this->assertTrue(159 isset($response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]["configurable_product_options"])160 );161 $resultConfigurableProductOptions162 = $response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]["configurable_product_options"];163 $this->assertCount(0, $resultConfigurableProductOptions);164 $this->assertTrue(165 isset($response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]["configurable_product_links"])166 );167 $resultConfigurableProductLinks168 = $response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]["configurable_product_links"];169 $this->assertCount(0, $resultConfigurableProductLinks);170 $this->assertEquals([], $resultConfigurableProductLinks);171 }172 /**173 * @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable.php174 */175 public function testUpdateConfigurableProductOption()176 {177 $productId1 = 10;178 $newLabel = 'size';179 $response = $this->createConfigurableProduct();180 $option = $response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]["configurable_product_options"][0];181 $optionId = $option['id'];182 $productId = $option['product_id'];183 $updatedOption = [184 'id' => $optionId,185 'attribute_id' => $option['attribute_id'],186 'label' => $newLabel,187 'position' => 1,188 'values' => [189 [190 'value_index' => $option['values'][0]['value_index'],191 ],192 ],193 'product_id' => $productId,194 ];195 $response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]['configurable_product_options'][0] =196 $updatedOption;197 $response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]['configurable_product_links'] = [$productId1];198 $response = $this->saveProduct($response);199 $this->assertTrue(200 isset($response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]["configurable_product_options"])201 );202 $resultConfigurableProductOptions203 = $response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]["configurable_product_options"];204 $this->assertCount(1, $resultConfigurableProductOptions);205 unset($updatedOption['id']);206 unset($resultConfigurableProductOptions[0]['id']);207 $this->assertEquals($updatedOption, $resultConfigurableProductOptions[0]);208 }209 /**210 * @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable.php211 */212 public function testUpdateConfigurableProductLinks()213 {214 $productId1 = 10;215 $productId2 = 20;216 $response = $this->createConfigurableProduct();217 $options = $response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]['configurable_product_options'];218 //leave existing option untouched219 unset($response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]['configurable_product_options']);220 $response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]['configurable_product_links'] = [$productId1];221 $response = $this->saveProduct($response);222 $this->assertTrue(223 isset($response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]["configurable_product_options"])224 );225 $resultConfigurableProductOptions226 = $response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]["configurable_product_options"];227 $this->assertCount(1, $resultConfigurableProductOptions);228 //Since one product is removed, the available values for the option is reduced229 $this->assertCount(1, $resultConfigurableProductOptions[0]['values']);230 $this->assertTrue(231 isset($response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]["configurable_product_links"])232 );233 $resultConfigurableProductLinks234 = $response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]["configurable_product_links"];235 $this->assertCount(1, $resultConfigurableProductLinks);236 $this->assertEquals([$productId1], $resultConfigurableProductLinks);237 //adding back the product links, the option value should be restored238 $response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]['configurable_product_links']239 = [$productId1, $productId2];240 //set the value for required attribute241 $response["custom_attributes"][] =242 [243 "attribute_code" => $this->configurableAttribute->getAttributeCode(),244 "value" => $resultConfigurableProductOptions[0]['values'][0]['value_index'],245 ];246 $response = $this->saveProduct($response);247 $currentOptions = $response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]['configurable_product_options'];248 $this->assertEquals($options, $currentOptions);249 }250 /**251 * @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable.php252 */253 public function testUpdateConfigurableProductLinksWithNonExistingProduct()254 {255 $productId1 = 10;256 $nonExistingId = 999;257 $response = $this->createConfigurableProduct();258 //leave existing option untouched259 unset($response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]['configurable_product_options']);260 $response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]['configurable_product_links'] = [261 $productId1, $nonExistingId262 ];263 $expectedMessage = 'The product that was requested doesn\'t exist. Verify the product and try again.';264 try {265 $this->saveProduct($response);266 $this->fail("Expected exception");267 } catch (\SoapFault $e) {268 $this->assertStringContainsString(269 $expectedMessage,270 $e->getMessage(),271 "SoapFault does not contain expected message."272 );273 } catch (\Exception $e) {274 $errorObj = $this->processRestExceptionResult($e);275 $this->assertEquals($expectedMessage, $errorObj['message']);276 }277 }278 /**279 * @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable.php280 */281 public function testUpdateConfigurableProductLinksWithDuplicateAttributes()282 {283 $productId1 = 10;284 $productId2 = 20;285 $response = $this->createConfigurableProduct();286 $options = $response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]['configurable_product_options'];287 //make product2 and product1 have the same value for the configurable attribute288 $optionValue1 = $options[0]['values'][0]['value_index'];289 $product2 = $this->getProduct('simple_' . $productId2);290 $product2['custom_attributes'] = [291 [292 'attribute_code' => 'test_configurable',293 'value' => $optionValue1,294 ]295 ];296 $this->saveProduct($product2);297 //leave existing option untouched298 unset($response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]['configurable_product_options']);299 $response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]['configurable_product_links'] = [300 $productId1, $productId2301 ];302 $expectedMessage = 'Products "%1" and "%2" have the same set of attribute values.';303 try {304 $this->saveProduct($response);305 $this->fail("Expected exception");306 } catch (\SoapFault $e) {307 $this->assertStringContainsString(308 $expectedMessage,309 $e->getMessage(),310 "SoapFault does not contain expected message."311 );312 } catch (\Exception $e) {313 $errorObj = $this->processRestExceptionResult($e);314 $this->assertEquals($expectedMessage, $errorObj['message']);315 $this->assertEquals(['0' => 20, '1' => 10], $errorObj['parameters']);316 }317 }318 /**319 * @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable.php320 */321 public function testUpdateConfigurableProductLinksWithWithoutVariationAttributes()322 {323 $productId1 = 99;324 $productId2 = 88;325 $response = $this->createConfigurableProduct();326 /** delete all variation attribute */327 $response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]['configurable_product_options'] = [];328 $response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]['configurable_product_links'] = [329 $productId1, $productId2330 ];331 $expectedMessage = 'The product that was requested doesn\'t exist. Verify the product and try again.';332 try {333 $this->saveProduct($response);334 $this->fail("Expected exception");335 } catch (\SoapFault $e) {336 $this->assertStringContainsString(337 $expectedMessage,338 $e->getMessage(),339 "SoapFault does not contain expected message."340 );341 } catch (\Exception $e) {342 $errorObj = $this->processRestExceptionResult($e);...

Full Screen

Full Screen

ConfigurableTest.php

Source:ConfigurableTest.php Github

copy

Full Screen

...12 */13 public function exportImportDataProvider(): array14 {15 return [16 'configurable-product' => [17 [18 'Magento/ConfigurableProduct/_files/product_configurable.php'19 ],20 [21 'configurable',22 ],23 ['_cache_instance_products', '_cache_instance_configurable_attributes'],24 ],25 'configurable-product-12345' => [26 [27 'Magento/ConfigurableProduct/_files/product_configurable_12345.php'28 ],29 [30 '12345',31 ],32 ['_cache_instance_products', '_cache_instance_configurable_attributes'],33 ],34 ];35 }36 /**37 * @inheritdoc38 */39 protected function assertEqualsSpecificAttributes(40 \Magento\Catalog\Model\Product $expectedProduct,41 \Magento\Catalog\Model\Product $actualProduct42 ): void {43 /** @var \Magento\ConfigurableProduct\Model\Product\Type\Configurable $productType */44 $productType = $expectedProduct->getTypeInstance();45 $expectedAssociatedProducts = $productType->getUsedProductCollection($expectedProduct);46 $actualAssociatedProducts = iterator_to_array($productType->getUsedProductCollection($actualProduct));...

Full Screen

Full Screen

ConfigurableMethodsTest.php

Source:ConfigurableMethodsTest.php Github

copy

Full Screen

...16final class ConfigurableMethodsTest extends TestCase17{18 public function testTwoClassesUsingConfigurableMethodsDontInterfere(): void19 {20 $configurableMethodsA = [new ConfigurableMethod('foo', SimpleType::fromValue('boolean', false))];21 $configurableMethodsB = [];22 ClassUsingConfigurableMethods::__phpunit_initConfigurableMethods(...$configurableMethodsA);23 AnotherClassUsingConfigurableMethods::__phpunit_initConfigurableMethods(...$configurableMethodsB);24 $this->assertSame($configurableMethodsA, ClassUsingConfigurableMethods::getConfigurableMethods());25 $this->assertSame($configurableMethodsB, AnotherClassUsingConfigurableMethods::getConfigurableMethods());26 }27 public function testConfigurableMethodsAreImmutable(): void28 {29 ReinitializeConfigurableMethods::__phpunit_initConfigurableMethods();30 $this->expectException(ConfigurableMethodsAlreadyInitializedException::class);31 ReinitializeConfigurableMethods::__phpunit_initConfigurableMethods();32 }33}...

Full Screen

Full Screen

configurable

Using AI Code Generation

copy

Full Screen

1use mageekguy\atoum\configurable;2use mageekguy\atoum;3{4 use configurable;5 public function test()6 {7 $this->assert->string('test')->isEqualTo('test');8 }9}10use mageekguy\atoum\configurable;11use mageekguy\atoum;12{13 use configurable;14 public function test()15 {16 $this->assert->string('test')->isEqualTo('test

Full Screen

Full Screen

configurable

Using AI Code Generation

copy

Full Screen

1{2 public function testSomething()3 {4 ->given($this->newTestedInstance())5 ->object($this->testedInstance->doSomething())6 ->isInstanceOf('something')7 ;8 }9}10{11 public function testSomething()12 {13 ->given($this->newTestedInstance())14 ->object($this->testedInstance->doSomething())15 ->isInstanceOf('something')16 ;17 }18}19{20 public function testSomething()21 {22 ->given($this->newTestedInstance())23 ->object($this->testedInstance->doSomething())24 ->isInstanceOf('something')25 ;26 }27}28{29 public function testSomething()30 {31 ->given($this->newTestedInstance())32 ->object($this->testedInstance->doSomething())33 ->isInstanceOf('something')34 ;35 }36}37{38 public function testSomething()39 {40 ->given($this->newTestedInstance())41 ->object($this->testedInstance->doSomething())42 ->isInstanceOf('something')43 ;44 }45}46{47 public function testSomething()48 {49 ->given($this->newTestedInstance())50 ->object($this->

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Atoum automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful