Skip to content

Commit

Permalink
MAGETWO-59258: [Github] Override module-directory/etc/zip_codes.xml o…
Browse files Browse the repository at this point in the history
…nly the last code of a country gets included #6694
  • Loading branch information
Stanislav Idolov committed Oct 21, 2016
1 parent c7d18bd commit cec25e1
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ class Reader extends \Magento\Framework\Config\Reader\Filesystem
*
* @var array
*/
protected $_idAttributes = ['/config/zip' => 'countryCode'];
protected $_idAttributes = [
'/config/zip' => 'countryCode',
'/config/zip/codes/code' => 'id',
];

/**
* Construct the FileSystem Reader Class
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_TestModuleDirectoryZipCodes" setup_version="0.0.1" active="true">
<sequence>
<module name="Magento_Directory"/>
</sequence>
</module>
</config>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Directory:etc/zip_codes.xsd">
<zip countryCode="NL">
<codes>
<code id="pattern_1" active="true" example="test1">^[0-9]{4}[a-zA-Z]{2}$</code>
<code id="pattern_2" active="true" example="test2">^[0-5]{4}[a-z]{2}$</code>
</codes>
</zip>
<zip countryCode="NL_NEW">
<codes>
<code id="pattern_1" active="true" example="test1">^[0-2]{4}[A-Z]{2}$</code>
</codes>
</zip>
</config>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

use Magento\Framework\Component\ComponentRegistrar;

$registrar = new ComponentRegistrar();
if ($registrar->getPath(ComponentRegistrar::MODULE, 'Magento_TestModuleDirectoryZipCodes') === null) {
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_TestModuleDirectoryZipCodes', __DIR__);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Directory\Model\Country\Postcode\Config;

class ReaderTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Magento\Directory\Model\Country\Postcode\Config\Reader
*/
private $reader;

protected function setUp()
{
$this->reader = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Directory\Model\Country\Postcode\Config\Reader::class
);
}

public function testRead()
{
$result = $this->reader->read();

$this->assertArrayHasKey('NL', $result);
$this->assertArrayHasKey('pattern_1', $result['NL']);
$this->assertArrayHasKey('pattern_2', $result['NL']);

$this->assertEquals('test1', $result['NL']['pattern_1']['example']);
$this->assertEquals('^[0-9]{4}[a-zA-Z]{2}$', $result['NL']['pattern_1']['pattern']);

$this->assertEquals('test2', $result['NL']['pattern_2']['example']);
$this->assertEquals('^[0-5]{4}[a-z]{2}$', $result['NL']['pattern_2']['pattern']);

$this->assertArrayHasKey('NL_NEW', $result);
$this->assertArrayHasKey('pattern_1', $result['NL_NEW']);

$this->assertEquals('test1', $result['NL_NEW']['pattern_1']['example']);
$this->assertEquals('^[0-2]{4}[A-Z]{2}$', $result['NL_NEW']['pattern_1']['pattern']);
}
}

0 comments on commit cec25e1

Please sign in to comment.