123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Paypal\Test\Unit\Model\Config\Structure;
- use Magento\Paypal\Model\Config\Structure\PaymentSectionModifier;
- class PaymentSectionModifierTest extends \PHPUnit\Framework\TestCase
- {
- private static $specialGroups = [
- 'account',
- 'recommended_solutions',
- 'other_paypal_payment_solutions',
- 'other_payment_methods',
- ];
- /**
- * @param string $case
- * @param array $structure
- * @dataProvider caseProvider
- */
- public function testSpecialGroupsPresent($case, $structure)
- {
- $modifier = new PaymentSectionModifier();
- $modifiedStructure = $modifier->modify($structure);
- $presentSpecialGroups = array_intersect(
- self::$specialGroups,
- array_keys($modifiedStructure)
- );
- $this->assertEquals(
- self::$specialGroups,
- $presentSpecialGroups,
- sprintf('All special groups must be present in %s case', $case)
- );
- }
- /**
- * @param string $case
- * @param array $structure
- * @dataProvider caseProvider
- */
- public function testOnlySpecialGroupsPresent($case, $structure)
- {
- $modifier = new PaymentSectionModifier();
- $modifiedStructure = $modifier->modify($structure);
- $presentNotSpecialGroups = array_diff(
- array_keys($modifiedStructure),
- self::$specialGroups
- );
- $this->assertEquals(
- [],
- $presentNotSpecialGroups,
- sprintf('Only special groups should be present at top level in "%s" case', $case)
- );
- }
- /**
- * @param string $case
- * @param array $structure
- * @dataProvider caseProvider
- */
- public function testGroupsNotRemovedAfterModification($case, $structure)
- {
- $modifier = new PaymentSectionModifier();
- $modifiedStructure = $modifier->modify($structure);
- $removedGroups = array_diff(
- $this->fetchAllAvailableGroups($structure),
- $this->fetchAllAvailableGroups($modifiedStructure)
- );
- $this->assertEquals(
- [],
- $removedGroups,
- sprintf('Groups should not be removed after modification in "%s" case', $case)
- );
- }
- public function testMovedToTargetSpecialGroup()
- {
- $structure = [
- 'some_payment_method1' => [
- 'id' => 'some_payment_method1',
- 'displayIn' => 'recommended_solutions',
- ],
- 'some_group' => [
- 'id' => 'some_group',
- 'children' => [
- 'some_payment_method2' => [
- 'id' => 'some_payment_method2',
- 'displayIn' => 'recommended_solutions'
- ],
- 'some_payment_method3' => [
- 'id' => 'some_payment_method3',
- 'displayIn' => 'other_payment_methods'
- ],
- 'some_payment_method4' => [
- 'id' => 'some_payment_method4',
- 'displayIn' => 'recommended_solutions'
- ],
- 'some_payment_method5' => [
- 'id' => 'some_payment_method5',
- ],
- ]
- ],
- ];
- $modifier = new PaymentSectionModifier();
- $modifiedStructure = $modifier->modify($structure);
- $this->assertEquals(
- [
- 'account' => [],
- 'recommended_solutions' => [
- 'children' => [
- 'some_payment_method1' => [
- 'id' => 'some_payment_method1',
- ],
- 'some_payment_method2' => [
- 'id' => 'some_payment_method2',
- ],
- 'some_payment_method4' => [
- 'id' => 'some_payment_method4',
- ],
- ],
- ],
- 'other_paypal_payment_solutions' => [],
- 'other_payment_methods' => [
- 'children' => [
- 'some_payment_method3' => [
- 'id' => 'some_payment_method3',
- ],
- 'some_group' => [
- 'id' => 'some_group',
- 'children' => [
- 'some_payment_method5' => [
- 'id' => 'some_payment_method5',
- ],
- ],
- ],
- ],
- ],
- ],
- $modifiedStructure,
- 'Some group is not moved correctly'
- );
- }
- /**
- * This helper method walks recursively through configuration structure and
- * collect available configuration groups
- *
- * @param array $structure
- * @return array Sorted list of group identifiers
- */
- private function fetchAllAvailableGroups($structure)
- {
- $availableGroups = [];
- foreach ($structure as $group => $data) {
- $availableGroups[] = $group;
- if (isset($data['children'])) {
- $availableGroups = array_merge(
- $availableGroups,
- $this->fetchAllAvailableGroups($data['children'])
- );
- }
- }
- $availableGroups = array_values(array_unique($availableGroups));
- sort($availableGroups);
- return $availableGroups;
- }
- /**
- * @return mixed
- */
- public function caseProvider()
- {
- return include __DIR__ . '/_files/payment_section_structure_variations.php';
- }
- }
|