Skip to content

Commit 1cafdf5

Browse files
author
Hayder Sharhan
committed
MAGETWO-46020: [Integration] 2 config files needed to create single integartion
- Refactored integration.xsd to account for integration data defined in different files. - Removed integrations node since config node was added. - Updated tests
1 parent bc1c90c commit 1cafdf5

File tree

12 files changed

+154
-172
lines changed

12 files changed

+154
-172
lines changed

app/code/Magento/Integration/Model/Config/Reader.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ class Reader extends \Magento\Framework\Config\Reader\Filesystem
1616
* @var array
1717
*/
1818
protected $_idAttributes = [
19-
'/integrations/integration' => 'name',
20-
'/integrations/integration/resources/resource' => 'name',
19+
'/config/integration' => 'name',
20+
'/config/integration/resources/resource' => 'name',
21+
'/config/integration/'
2122
];
2223

2324
/**

app/code/Magento/Integration/Model/Config/SchemaLocator.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ class SchemaLocator implements \Magento\Framework\Config\SchemaLocatorInterface
3131
*/
3232
public function __construct(\Magento\Framework\Module\Dir\Reader $moduleReader)
3333
{
34-
$this->_schema = $moduleReader->getModuleDir(Dir::MODULE_ETC_DIR, 'Magento_Integration')
35-
. '/integration/integration.xsd';
34+
$etcDir = $moduleReader->getModuleDir(Dir::MODULE_ETC_DIR, 'Magento_Integration');
35+
$this->_schema = $etcDir . '/integration/integration.xsd';
36+
$this->_perFileSchema = $etcDir . '/integration/integration_file.xsd';
3637
}
3738

3839
/**

app/code/Magento/Integration/Test/Unit/Model/Config/SchemaLocatorTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public function testGetSchema()
3535

3636
public function testGetPerFileSchema()
3737
{
38-
$this->assertNull($this->schemaLocator->getPerFileSchema());
38+
$this->assertEquals($this->moduleDir . '/integration/integration_file.xsd',
39+
$this->schemaLocator->getPerFileSchema());
3940
}
4041
}

app/code/Magento/Integration/Test/Unit/Model/Config/XsdTest.php

Lines changed: 7 additions & 58 deletions
Large diffs are not rendered by default.

app/code/Magento/Integration/Test/Unit/Model/Config/_files/integration.xml

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,19 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Integration:etc/integration/integration.xsd">
9-
<integrations>
10-
<integration name="TestIntegration1">
11-
<email>test-integration1@magento.com</email>
12-
<endpoint_url>http://endpoint.com</endpoint_url>
13-
<identity_link_url>http://www.example.com/identity</identity_link_url>
14-
<resources>
15-
<resource name="Magento_Customer::manage" />
16-
<resource name="Magento_SalesRule::quote" />
17-
</resources>
18-
</integration>
19-
<integration name="TestIntegration2">
20-
<email>test-integration2@magento.com</email>
21-
<resources>
22-
<resource name="Magento_Sales::sales" />
23-
</resources>
24-
</integration>
25-
</integrations>
9+
<integration name="TestIntegration1">
10+
<email>test-integration1@magento.com</email>
11+
<endpoint_url>http://endpoint.com</endpoint_url>
12+
<identity_link_url>http://www.example.com/identity</identity_link_url>
13+
<resources>
14+
<resource name="Magento_Customer::manage" />
15+
<resource name="Magento_SalesRule::quote" />
16+
</resources>
17+
</integration>
18+
<integration name="TestIntegration2">
19+
<email>test-integration2@magento.com</email>
20+
<resources>
21+
<resource name="Magento_Sales::sales" />
22+
</resources>
23+
</integration>
2624
</config>

app/code/Magento/Integration/etc/integration/integration.xsd

Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,57 +8,21 @@
88
*/
99
-->
1010
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
11+
<xs:include schemaLocation="urn:magento:module:Magento_Integration:etc/integration/integration_base.xsd" />
1112
<xs:element name="config">
1213
<xs:complexType>
1314
<xs:sequence>
14-
<xs:element name="integrations" type="integrationsType" minOccurs="1" maxOccurs="1"/>
15+
<xs:element name="integration" type="integrationType" maxOccurs="unbounded" minOccurs="1"/>
1516
</xs:sequence>
1617
</xs:complexType>
1718
</xs:element>
18-
<xs:complexType name="integrationsType">
19-
<xs:sequence>
20-
<xs:element name="integration" type="integrationType" maxOccurs="unbounded" minOccurs="1"/>
21-
</xs:sequence>
22-
</xs:complexType>
2319
<xs:complexType name="integrationType">
24-
<xs:sequence>
25-
<xs:element name="email" type="emailType"/>
26-
<xs:element name="endpoint_url" type="urlType" minOccurs="0"/>
27-
<xs:element name="identity_link_url" type="urlType" minOccurs="0"/>
28-
<xs:element name="resources" type="resourcesType"/>
29-
</xs:sequence>
20+
<xs:all>
21+
<xs:element name="email" type="emailType" minOccurs="1" maxOccurs="1"/>
22+
<xs:element name="endpoint_url" type="urlType" minOccurs="0" maxOccurs="1"/>
23+
<xs:element name="identity_link_url" type="urlType" minOccurs="0" maxOccurs="1"/>
24+
<xs:element name="resources" type="resourcesType" minOccurs="0" maxOccurs="1"/>
25+
</xs:all>
3026
<xs:attribute name="name" type="integrationNameType" use="required"/>
3127
</xs:complexType>
32-
<xs:simpleType name="urlType">
33-
<xs:restriction base="xs:anyURI">
34-
<xs:minLength value="4"/>
35-
</xs:restriction>
36-
</xs:simpleType>
37-
<xs:simpleType name="integrationNameType">
38-
<xs:restriction base="xs:string">
39-
<xs:minLength value="2"/>
40-
</xs:restriction>
41-
</xs:simpleType>
42-
<xs:simpleType name="emailType">
43-
<xs:restriction base="xs:string">
44-
<xs:pattern value="[^@]+@[^\.]+\..+"/>
45-
</xs:restriction>
46-
</xs:simpleType>
47-
<xs:complexType name="resourcesType">
48-
<xs:sequence>
49-
<xs:element name="resource" type="resourceType" maxOccurs="unbounded" minOccurs="1"/>
50-
</xs:sequence>
51-
</xs:complexType>
52-
<xs:complexType name="resourceType">
53-
<xs:simpleContent>
54-
<xs:extension base="xs:string">
55-
<xs:attribute name="name" type="resourceNameType" use="required"/>
56-
</xs:extension>
57-
</xs:simpleContent>
58-
</xs:complexType>
59-
<xs:simpleType name="resourceNameType">
60-
<xs:restriction base="xs:string">
61-
<xs:pattern value=".+_.+::.+"/>
62-
</xs:restriction>
63-
</xs:simpleType>
6428
</xs:schema>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Schema for integration configuration.
5+
*
6+
* Copyright © 2015 Magento. All rights reserved.
7+
* See COPYING.txt for license details.
8+
*/
9+
-->
10+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
11+
<xs:simpleType name="urlType">
12+
<xs:restriction base="xs:anyURI">
13+
<xs:minLength value="4"/>
14+
</xs:restriction>
15+
</xs:simpleType>
16+
<xs:simpleType name="integrationNameType">
17+
<xs:restriction base="xs:string">
18+
<xs:minLength value="2"/>
19+
</xs:restriction>
20+
</xs:simpleType>
21+
<xs:simpleType name="emailType">
22+
<xs:restriction base="xs:string">
23+
<xs:pattern value="[^@]+@[^\.]+\..+"/>
24+
</xs:restriction>
25+
</xs:simpleType>
26+
<xs:complexType name="resourcesType">
27+
<xs:sequence>
28+
<xs:element name="resource" type="resourceType" maxOccurs="unbounded" minOccurs="1"/>
29+
</xs:sequence>
30+
</xs:complexType>
31+
<xs:complexType name="resourceType">
32+
<xs:simpleContent>
33+
<xs:extension base="xs:string">
34+
<xs:attribute name="name" type="resourceNameType" use="required"/>
35+
</xs:extension>
36+
</xs:simpleContent>
37+
</xs:complexType>
38+
<xs:simpleType name="resourceNameType">
39+
<xs:restriction base="xs:string">
40+
<xs:pattern value=".+_.+::.+"/>
41+
</xs:restriction>
42+
</xs:simpleType>
43+
</xs:schema>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Schema for integration configuration.
5+
*
6+
* Copyright © 2015 Magento. All rights reserved.
7+
* See COPYING.txt for license details.
8+
*/
9+
-->
10+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
11+
<xs:include schemaLocation="urn:magento:module:Magento_Integration:etc/integration/integration_base.xsd" />
12+
<xs:element name="config">
13+
<xs:complexType>
14+
<xs:sequence>
15+
<xs:element name="integration" type="integrationType" maxOccurs="unbounded" minOccurs="1"/>
16+
</xs:sequence>
17+
</xs:complexType>
18+
</xs:element>
19+
<xs:complexType name="integrationType">
20+
<xs:all>
21+
<xs:element name="email" type="emailType" minOccurs="0" maxOccurs="1"/>
22+
<xs:element name="endpoint_url" type="urlType" minOccurs="0" maxOccurs="1"/>
23+
<xs:element name="identity_link_url" type="urlType" minOccurs="0" maxOccurs="1"/>
24+
<xs:element name="resources" type="resourcesType" minOccurs="0" maxOccurs="1"/>
25+
</xs:all>
26+
<xs:attribute name="name" type="integrationNameType" use="required"/>
27+
</xs:complexType>
28+
</xs:schema>

dev/tests/api-functional/_files/Magento/TestModuleIntegrationFromConfig/etc/integration.xml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Integration:etc/integration/integration.xsd">
9-
<integrations>
10-
<integration name="Test Integration1">
11-
<email>test-integration@magento.com</email>
12-
<endpoint_url>http://example.com/endpoint1</endpoint_url>
13-
<resources>
14-
<resource name="Magento_Customer::customer" />
15-
<resource name="Magento_Customer::manage" />
16-
</resources>
17-
</integration>
18-
</integrations>
9+
<integration name="Test Integration1">
10+
<email>test-integration@magento.com</email>
11+
<endpoint_url>http://example.com/endpoint1</endpoint_url>
12+
<resources>
13+
<resource name="Magento_Customer::customer" />
14+
<resource name="Magento_Customer::manage" />
15+
</resources>
16+
</integration>
1917
</config>

dev/tests/integration/testsuite/Magento/Integration/Model/Config/ReaderTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
2222
protected function setUp()
2323
{
2424
parent::setUp();
25-
$this->_fileResolverMock = $this->getMock('Magento\Framework\Config\FileResolverInterface');
25+
$this->_fileResolverMock = $this->getMockBuilder('Magento\Framework\Config\FileResolverInterface')
26+
->disableOriginalConstructor()
27+
->setMethods([])
28+
->getMock();
2629
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
2730
$this->_configReader = $objectManager->create(
2831
'Magento\Integration\Model\Config\Reader',
@@ -34,7 +37,7 @@ public function testRead()
3437
{
3538
$configFiles = [
3639
file_get_contents(realpath(__DIR__ . '/_files/integrationA.xml')),
37-
file_get_contents(realpath(__DIR__ . '/_files/integrationB.xml')),
40+
file_get_contents(realpath(__DIR__ . '/_files/integrationB.xml'))
3841
];
3942
$this->_fileResolverMock->expects($this->any())->method('get')->will($this->returnValue($configFiles));
4043

0 commit comments

Comments
 (0)