|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * |
| 4 | + * @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com) |
| 5 | + */ |
| 6 | +namespace Magento\Framework\Interception; |
| 7 | + |
| 8 | +use Magento\Framework\ObjectManager\Config\Config as ObjectManagerConfig; |
| 9 | + |
| 10 | +/** |
| 11 | + * Class GeneralTest |
| 12 | + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
| 13 | + */ |
| 14 | +class TwoPluginTest extends \PHPUnit_Framework_TestCase |
| 15 | +{ |
| 16 | + /** |
| 17 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 18 | + */ |
| 19 | + protected $_configReader; |
| 20 | + |
| 21 | + /** |
| 22 | + * @var \Magento\Framework\ObjectManagerInterface |
| 23 | + */ |
| 24 | + protected $_objectManager; |
| 25 | + |
| 26 | + public function setUp() |
| 27 | + { |
| 28 | + $config = new \Magento\Framework\Interception\ObjectManager\Config\Developer(); |
| 29 | + $factory = new \Magento\Framework\ObjectManager\Factory\Dynamic\Developer($config, null); |
| 30 | + |
| 31 | + $this->_configReader = $this->getMock('Magento\Framework\Config\ReaderInterface'); |
| 32 | + $this->_configReader->expects( |
| 33 | + $this->any() |
| 34 | + )->method( |
| 35 | + 'read' |
| 36 | + )->will( |
| 37 | + $this->returnValue( |
| 38 | + [ |
| 39 | + 'Magento\Framework\Interception\Fixture\Intercepted' => [ |
| 40 | + 'plugins' => [ |
| 41 | + 'first' => [ |
| 42 | + 'instance' => 'Magento\Framework\Interception\Fixture\Intercepted\FirstPlugin', |
| 43 | + 'sortOrder' => 10, |
| 44 | + ], 'second' => [ |
| 45 | + 'instance' => 'Magento\Framework\Interception\Fixture\Intercepted\Plugin', |
| 46 | + 'sortOrder' => 20, |
| 47 | + ] |
| 48 | + ], |
| 49 | + ] |
| 50 | + ] |
| 51 | + ) |
| 52 | + ); |
| 53 | + |
| 54 | + $areaList = $this->getMock('Magento\Framework\App\AreaList', [], [], '', false); |
| 55 | + $areaList->expects($this->any())->method('getCodes')->will($this->returnValue([])); |
| 56 | + $configScope = new \Magento\Framework\Config\Scope($areaList, 'global'); |
| 57 | + $cache = $this->getMock('Magento\Framework\Config\CacheInterface'); |
| 58 | + $cache->expects($this->any())->method('load')->will($this->returnValue(false)); |
| 59 | + $definitions = new \Magento\Framework\ObjectManager\Definition\Runtime(); |
| 60 | + $relations = new \Magento\Framework\ObjectManager\Relations\Runtime(); |
| 61 | + $interceptionConfig = new Config\Config( |
| 62 | + $this->_configReader, |
| 63 | + $configScope, |
| 64 | + $cache, |
| 65 | + $relations, |
| 66 | + $config, |
| 67 | + $definitions |
| 68 | + ); |
| 69 | + $interceptionDefinitions = new Definition\Runtime(); |
| 70 | + $this->_objectManager = new \Magento\Framework\ObjectManager\ObjectManager( |
| 71 | + $factory, |
| 72 | + $config, |
| 73 | + [ |
| 74 | + 'Magento\Framework\Config\CacheInterface' => $cache, |
| 75 | + 'Magento\Framework\Config\ScopeInterface' => $configScope, |
| 76 | + 'Magento\Framework\Config\ReaderInterface' => $this->_configReader, |
| 77 | + 'Magento\Framework\ObjectManager\RelationsInterface' => $relations, |
| 78 | + 'Magento\Framework\ObjectManager\ConfigInterface' => $config, |
| 79 | + 'Magento\Framework\Interception\ObjectManager\ConfigInterface' => $config, |
| 80 | + 'Magento\Framework\ObjectManager\DefinitionInterface' => $definitions, |
| 81 | + 'Magento\Framework\Interception\DefinitionInterface' => $interceptionDefinitions |
| 82 | + ] |
| 83 | + ); |
| 84 | + $factory->setObjectManager($this->_objectManager); |
| 85 | + $config->setInterceptionConfig($interceptionConfig); |
| 86 | + $config->extend( |
| 87 | + [ |
| 88 | + 'preferences' => [ |
| 89 | + 'Magento\Framework\Interception\PluginListInterface' => |
| 90 | + 'Magento\Framework\Interception\PluginList\PluginList', |
| 91 | + 'Magento\Framework\Interception\ChainInterface' => 'Magento\Framework\Interception\Chain\Chain', |
| 92 | + ], |
| 93 | + ] |
| 94 | + ); |
| 95 | + } |
| 96 | + |
| 97 | + public function testPluginBeforeWins() |
| 98 | + { |
| 99 | + $subject = $this->_objectManager->create('Magento\Framework\Interception\Fixture\Intercepted'); |
| 100 | + $this->assertEquals('<X><P:bX/></X>', $subject->X('test')); |
| 101 | + } |
| 102 | + |
| 103 | + public function testPluginAroundWins() |
| 104 | + { |
| 105 | + $subject = $this->_objectManager->create('Magento\Framework\Interception\Fixture\Intercepted'); |
| 106 | + $this->assertEquals('<F:Y>test<F:Y/>', $subject->Y('test')); |
| 107 | + } |
| 108 | + |
| 109 | + public function testPluginAfterWins() |
| 110 | + { |
| 111 | + $subject = $this->_objectManager->create('Magento\Framework\Interception\Fixture\Intercepted'); |
| 112 | + $this->assertEquals('<P:aZ/>', $subject->Z('test')); |
| 113 | + } |
| 114 | + |
| 115 | + public function testPluginBeforeAroundWins() |
| 116 | + { |
| 117 | + $subject = $this->_objectManager->create('Magento\Framework\Interception\Fixture\Intercepted'); |
| 118 | + $this->assertEquals('<F:V><F:bV/><F:V/>', $subject->V('test')); |
| 119 | + } |
| 120 | + public function testPluginBeforeAroundAfterWins() |
| 121 | + { |
| 122 | + $subject = $this->_objectManager->create('Magento\Framework\Interception\Fixture\Intercepted'); |
| 123 | + $this->assertEquals('<F:aW/>', $subject->W('test')); |
| 124 | + } |
| 125 | +} |
0 commit comments