123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Framework\Config\Test\Unit\Dom;
- use \Magento\Framework\Config\Dom\ArrayNodeConfig;
- class ArrayNodeConfigTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var ArrayNodeConfig
- */
- protected $object;
- /**
- * @var NodePathMatcher|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $nodePathMatcher;
- protected function setUp()
- {
- $this->nodePathMatcher = $this->createMock(\Magento\Framework\Config\Dom\NodePathMatcher::class);
- $this->object = new ArrayNodeConfig(
- $this->nodePathMatcher,
- ['/root/assoc/one' => 'name', '/root/assoc/two' => 'id', '/root/assoc/three' => 'key'],
- ['/root/numeric/one', '/root/numeric/two', '/root/numeric/three']
- );
- }
- public function testIsNumericArrayMatched()
- {
- $xpath = '/root/numeric[@attr="value"]/two';
- $this->nodePathMatcher->expects(
- $this->at(0)
- )->method(
- 'match'
- )->with(
- '/root/numeric/one',
- $xpath
- )->will(
- $this->returnValue(false)
- );
- $this->nodePathMatcher->expects(
- $this->at(1)
- )->method(
- 'match'
- )->with(
- '/root/numeric/two',
- $xpath
- )->will(
- $this->returnValue(true)
- );
- $this->assertTrue($this->object->isNumericArray($xpath));
- }
- public function testIsNumericArrayNotMatched()
- {
- $xpath = '/root/numeric[@attr="value"]/four';
- $this->nodePathMatcher->expects(
- $this->at(0)
- )->method(
- 'match'
- )->with(
- '/root/numeric/one',
- $xpath
- )->will(
- $this->returnValue(false)
- );
- $this->nodePathMatcher->expects(
- $this->at(1)
- )->method(
- 'match'
- )->with(
- '/root/numeric/two',
- $xpath
- )->will(
- $this->returnValue(false)
- );
- $this->nodePathMatcher->expects(
- $this->at(2)
- )->method(
- 'match'
- )->with(
- '/root/numeric/three',
- $xpath
- )->will(
- $this->returnValue(false)
- );
- $this->assertFalse($this->object->isNumericArray($xpath));
- }
- public function testGetAssocArrayKeyAttributeMatched()
- {
- $xpath = '/root/assoc[@attr="value"]/two';
- $this->nodePathMatcher->expects(
- $this->at(0)
- )->method(
- 'match'
- )->with(
- '/root/assoc/one',
- $xpath
- )->will(
- $this->returnValue(false)
- );
- $this->nodePathMatcher->expects(
- $this->at(1)
- )->method(
- 'match'
- )->with(
- '/root/assoc/two',
- $xpath
- )->will(
- $this->returnValue(true)
- );
- $this->assertEquals('id', $this->object->getAssocArrayKeyAttribute($xpath));
- }
- public function testGetAssocArrayKeyAttributeNotMatched()
- {
- $xpath = '/root/assoc[@attr="value"]/four';
- $this->nodePathMatcher->expects(
- $this->at(0)
- )->method(
- 'match'
- )->with(
- '/root/assoc/one',
- $xpath
- )->will(
- $this->returnValue(false)
- );
- $this->nodePathMatcher->expects(
- $this->at(1)
- )->method(
- 'match'
- )->with(
- '/root/assoc/two',
- $xpath
- )->will(
- $this->returnValue(false)
- );
- $this->nodePathMatcher->expects(
- $this->at(2)
- )->method(
- 'match'
- )->with(
- '/root/assoc/three',
- $xpath
- )->will(
- $this->returnValue(false)
- );
- $this->assertNull($this->object->getAssocArrayKeyAttribute($xpath));
- }
- }
|