Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MinsaleqtyTest.php
Go to the documentation of this file.
1 <?php
8 
11 
12 class MinsaleqtyTest extends \PHPUnit\Framework\TestCase
13 {
15  private $minSaleQtyConfig;
16 
17  protected function setUp()
18  {
20  $this->minSaleQtyConfig = $objectManager->create(Minsaleqty::class);
21  $this->minSaleQtyConfig->setPath('cataloginventory/item_options/min_sale_qty');
22  }
23 
35  public function testSaveAndLoad($value, $encodedExpectedValue, array $decodedExpectedValue)
36  {
37  $this->minSaleQtyConfig->setValue($value);
38  $this->minSaleQtyConfig->save();
39  $this->assertEquals($encodedExpectedValue, $this->minSaleQtyConfig->getValue());
40 
41  $this->minSaleQtyConfig->load($this->minSaleQtyConfig->getId());
42  $hashedConfig = $this->minSaleQtyConfig->getValue();
43 
44  if (!is_array($hashedConfig)) {
45  $this->fail('Loaded value is not an array, skipping further validation');
46  }
47 
48  $indexedConfig = array_values($hashedConfig);
49  $this->assertEquals($decodedExpectedValue, $indexedConfig);
50  }
51 
55  public function saveAndLoadDataProvider()
56  {
58  $groupManagement = $objectManager->create(GroupManagementInterface::class);
59  $allCustomersGroupID = $groupManagement->getAllCustomersGroup()->getId();
60  $notLoggedInGroupID = $groupManagement->getNotLoggedInGroup()->getId();
61 
62  return [
63  'bool' => [false, '', []],
64  'empty string' => ['', '', []],
65  'empty array' => [[], '[]', []],
66  'valid numeric - all customer group' => [
67  '22',
68  '22',
69  [
70  [
71  'customer_group_id' => $allCustomersGroupID,
72  'min_sale_qty' => 22
73  ]
74  ]
75  ],
76  'invalid named group array' => [
77  ['customer_group_id' => 1, 'min_sale_qty' => 2.5],
78  '{"customer_group_id":1,"min_sale_qty":2.5}',
79  [
80  0 => [
81  'customer_group_id' => 'customer_group_id',
82  'min_sale_qty' => 1
83  ],
84  1 => [
85  'customer_group_id' => 'min_sale_qty',
86  'min_sale_qty' => 2.5
87  ]
88  ]
89  ],
90  'valid array - all customer group' => [
91  [['customer_group_id' => $allCustomersGroupID, 'min_sale_qty' => 2.5]],
92  '2.5',
93  [
94  0 => [
95  'customer_group_id' => $allCustomersGroupID,
96  'min_sale_qty' => 2.5
97  ]
98  ]
99  ],
100  'valid named group' => [
101  [['customer_group_id' => 2, 'min_sale_qty' => 2.5]],
102  '{"2":2.5}',
103  [
104  0 => [
105  'customer_group_id' => 2,
106  'min_sale_qty' => 2.5
107  ]
108  ]
109  ],
110  'invalid - cannot override not logged in group' => [
111  [$notLoggedInGroupID => ['min_sale_qty' => 2.5]],
112  '[1]',
113  [
114  0 => [
115  'customer_group_id' => $notLoggedInGroupID,
116  'min_sale_qty' => 1
117  ]
118  ]
119  ]
120  ];
121  }
122 }
$objectManager
Definition: bootstrap.php:17
$value
Definition: gender.phtml:16
testSaveAndLoad($value, $encodedExpectedValue, array $decodedExpectedValue)