|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2015 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +namespace Magento\Setup\Test\Unit\Fixtures; |
| 8 | + |
| 9 | +use \Magento\Setup\Fixtures\CartPriceRulesFixture; |
| 10 | + |
| 11 | +class CartPriceRulesFixtureTest extends \PHPUnit_Framework_TestCase |
| 12 | +{ |
| 13 | + /** |
| 14 | + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Fixtures\FixtureModel |
| 15 | + */ |
| 16 | + private $fixtureModelMock; |
| 17 | + |
| 18 | + /** |
| 19 | + * @var \Magento\Setup\Fixtures\CartPriceRulesFixture |
| 20 | + */ |
| 21 | + private $model; |
| 22 | + |
| 23 | + public function setUp() |
| 24 | + { |
| 25 | + $this->fixtureModelMock = $this->getMock('\Magento\Setup\Fixtures\FixtureModel', [], [], '', false); |
| 26 | + |
| 27 | + $this->model = new CartPriceRulesFixture($this->fixtureModelMock); |
| 28 | + } |
| 29 | + |
| 30 | + public function testExecute() |
| 31 | + { |
| 32 | + $storeMock = $this->getMock('\Magento\Store\Model\Store', [], [], '', false); |
| 33 | + $storeMock->expects($this->once()) |
| 34 | + ->method('getRootCategoryId') |
| 35 | + ->will($this->returnValue(2)); |
| 36 | + |
| 37 | + $websiteMock = $this->getMock('\Magento\Store\Model\Website', [], [], '', false); |
| 38 | + $websiteMock->expects($this->once()) |
| 39 | + ->method('getGroups') |
| 40 | + ->will($this->returnValue([$storeMock])); |
| 41 | + $websiteMock->expects($this->once()) |
| 42 | + ->method('getId') |
| 43 | + ->will($this->returnValue('website_id')); |
| 44 | + |
| 45 | + $contextMock = $this->getMock('\Magento\Framework\Model\Resource\Db\Context', [], [], '', false); |
| 46 | + $abstractDbMock = $this->getMockForAbstractClass( |
| 47 | + '\Magento\Framework\Model\Resource\Db\AbstractDb', |
| 48 | + [$contextMock], |
| 49 | + '', |
| 50 | + true, |
| 51 | + true, |
| 52 | + true, |
| 53 | + ['getAllChildren'] |
| 54 | + ); |
| 55 | + $abstractDbMock->expects($this->once()) |
| 56 | + ->method('getAllChildren') |
| 57 | + ->will($this->returnValue([1])); |
| 58 | + |
| 59 | + $storeManagerMock = $this->getMock('Magento\Store\Model\StoreManager', [], [], '', false); |
| 60 | + $storeManagerMock->expects($this->once()) |
| 61 | + ->method('getWebsites') |
| 62 | + ->will($this->returnValue([$websiteMock])); |
| 63 | + |
| 64 | + $categoryMock = $this->getMock('Magento\Catalog\Model\Category', [], [], '', false); |
| 65 | + $categoryMock->expects($this->once()) |
| 66 | + ->method('getResource') |
| 67 | + ->will($this->returnValue($abstractDbMock)); |
| 68 | + $categoryMock->expects($this->once()) |
| 69 | + ->method('getPath') |
| 70 | + ->will($this->returnValue('path/to/file')); |
| 71 | + $categoryMock->expects($this->once()) |
| 72 | + ->method('getId') |
| 73 | + ->will($this->returnValue('category_id')); |
| 74 | + |
| 75 | + $modelMock = $this->getMock('\Magento\SalesRule\Model\Rule', [], [], '', false); |
| 76 | + $modelMock->expects($this->once()) |
| 77 | + ->method('getIdFieldName') |
| 78 | + ->will($this->returnValue('Field Id Name')); |
| 79 | + |
| 80 | + $objectValueMap = [ |
| 81 | + ['Magento\SalesRule\Model\Rule', $modelMock], |
| 82 | + ['Magento\Catalog\Model\Category', $categoryMock] |
| 83 | + ]; |
| 84 | + |
| 85 | + $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); |
| 86 | + $objectManagerMock->expects($this->once()) |
| 87 | + ->method('create') |
| 88 | + ->will($this->returnValue($storeManagerMock)); |
| 89 | + $objectManagerMock->expects($this->exactly(2)) |
| 90 | + ->method('get') |
| 91 | + ->will($this->returnValueMap($objectValueMap)); |
| 92 | + |
| 93 | + $valueMap = [ |
| 94 | + ['cart_price_rules', 0, 1], |
| 95 | + ['cart_price_rules_floor', 3, 3] |
| 96 | + ]; |
| 97 | + |
| 98 | + $this->fixtureModelMock |
| 99 | + ->expects($this->exactly(2)) |
| 100 | + ->method('getValue') |
| 101 | + ->will($this->returnValueMap($valueMap)); |
| 102 | + $this->fixtureModelMock |
| 103 | + ->expects($this->exactly(3)) |
| 104 | + ->method('getObjectManager') |
| 105 | + ->will($this->returnValue($objectManagerMock)); |
| 106 | + |
| 107 | + $this->model->execute(); |
| 108 | + } |
| 109 | + |
| 110 | + public function testNoFixtureConfigValue() |
| 111 | + { |
| 112 | + $ruleMock = $this->getMock('\Magento\SalesRule\Model\Rule', [], [], '', false); |
| 113 | + $ruleMock->expects($this->never())->method('save'); |
| 114 | + |
| 115 | + $objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false); |
| 116 | + $objectManagerMock->expects($this->never()) |
| 117 | + ->method('get') |
| 118 | + ->with($this->equalTo('Magento\SalesRule\Model\Rule')) |
| 119 | + ->willReturn($ruleMock); |
| 120 | + |
| 121 | + $this->fixtureModelMock |
| 122 | + ->expects($this->never()) |
| 123 | + ->method('getObjectManager') |
| 124 | + ->willReturn($objectManagerMock); |
| 125 | + $this->fixtureModelMock |
| 126 | + ->expects($this->once()) |
| 127 | + ->method('getValue') |
| 128 | + ->willReturn(false); |
| 129 | + |
| 130 | + $this->model->execute(); |
| 131 | + } |
| 132 | + |
| 133 | + public function testGetActionTitle() |
| 134 | + { |
| 135 | + $this->assertSame('Generating Cart Price Rules', $this->model->getActionTitle()); |
| 136 | + } |
| 137 | + |
| 138 | + public function testIntroduceParamLabels() |
| 139 | + { |
| 140 | + $this->assertSame([ |
| 141 | + 'cart_price_rules' => 'Cart Price Rules' |
| 142 | + ], $this->model->introduceParamLabels()); |
| 143 | + } |
| 144 | +} |
0 commit comments