Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PaymentSectionModifierTest.php
Go to the documentation of this file.
1 <?php
8 
10 
11 class PaymentSectionModifierTest extends \PHPUnit\Framework\TestCase
12 {
13  private static $specialGroups = [
14  'account',
15  'recommended_solutions',
16  'other_paypal_payment_solutions',
17  'other_payment_methods',
18  ];
19 
25  public function testSpecialGroupsPresent($case, $structure)
26  {
27  $modifier = new PaymentSectionModifier();
28  $modifiedStructure = $modifier->modify($structure);
29  $presentSpecialGroups = array_intersect(
30  self::$specialGroups,
31  array_keys($modifiedStructure)
32  );
33 
34  $this->assertEquals(
35  self::$specialGroups,
36  $presentSpecialGroups,
37  sprintf('All special groups must be present in %s case', $case)
38  );
39  }
40 
46  public function testOnlySpecialGroupsPresent($case, $structure)
47  {
48  $modifier = new PaymentSectionModifier();
49  $modifiedStructure = $modifier->modify($structure);
50  $presentNotSpecialGroups = array_diff(
51  array_keys($modifiedStructure),
52  self::$specialGroups
53  );
54 
55  $this->assertEquals(
56  [],
57  $presentNotSpecialGroups,
58  sprintf('Only special groups should be present at top level in "%s" case', $case)
59  );
60  }
61 
67  public function testGroupsNotRemovedAfterModification($case, $structure)
68  {
69  $modifier = new PaymentSectionModifier();
70  $modifiedStructure = $modifier->modify($structure);
71 
72  $removedGroups = array_diff(
73  $this->fetchAllAvailableGroups($structure),
74  $this->fetchAllAvailableGroups($modifiedStructure)
75  );
76 
77  $this->assertEquals(
78  [],
79  $removedGroups,
80  sprintf('Groups should not be removed after modification in "%s" case', $case)
81  );
82  }
83 
85  {
86  $structure = [
87  'some_payment_method1' => [
88  'id' => 'some_payment_method1',
89  'displayIn' => 'recommended_solutions',
90  ],
91  'some_group' => [
92  'id' => 'some_group',
93  'children' => [
94  'some_payment_method2' => [
95  'id' => 'some_payment_method2',
96  'displayIn' => 'recommended_solutions'
97  ],
98  'some_payment_method3' => [
99  'id' => 'some_payment_method3',
100  'displayIn' => 'other_payment_methods'
101  ],
102  'some_payment_method4' => [
103  'id' => 'some_payment_method4',
104  'displayIn' => 'recommended_solutions'
105  ],
106  'some_payment_method5' => [
107  'id' => 'some_payment_method5',
108  ],
109  ]
110  ],
111  ];
112 
113  $modifier = new PaymentSectionModifier();
114  $modifiedStructure = $modifier->modify($structure);
115 
116  $this->assertEquals(
117  [
118  'account' => [],
119  'recommended_solutions' => [
120  'children' => [
121  'some_payment_method1' => [
122  'id' => 'some_payment_method1',
123  ],
124  'some_payment_method2' => [
125  'id' => 'some_payment_method2',
126  ],
127  'some_payment_method4' => [
128  'id' => 'some_payment_method4',
129  ],
130  ],
131  ],
132  'other_paypal_payment_solutions' => [],
133  'other_payment_methods' => [
134  'children' => [
135  'some_payment_method3' => [
136  'id' => 'some_payment_method3',
137  ],
138  'some_group' => [
139  'id' => 'some_group',
140  'children' => [
141  'some_payment_method5' => [
142  'id' => 'some_payment_method5',
143  ],
144  ],
145  ],
146  ],
147  ],
148  ],
149  $modifiedStructure,
150  'Some group is not moved correctly'
151  );
152  }
153 
161  private function fetchAllAvailableGroups($structure)
162  {
163  $availableGroups = [];
164  foreach ($structure as $group => $data) {
165  $availableGroups[] = $group;
166  if (isset($data['children'])) {
167  $availableGroups = array_merge(
168  $availableGroups,
169  $this->fetchAllAvailableGroups($data['children'])
170  );
171  }
172  }
173  $availableGroups = array_values(array_unique($availableGroups));
174  sort($availableGroups);
175  return $availableGroups;
176  }
177 
181  public function caseProvider()
182  {
183  return include __DIR__ . '/_files/payment_section_structure_variations.php';
184  }
185 }
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
$case
$group
Definition: sections.phtml:16