Skip to content

Commit 94437f2

Browse files
author
Korshenko, Olexii(okorshenko)
committed
Merge pull request #724 from magento-south/MAGETWO-37276
[SOUTH] Bugfixes and Tasks
2 parents dd344de + d25e715 commit 94437f2

15 files changed

+1140
-0
lines changed
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Customer\Test\Unit\Ui\Component;
7+
8+
use Magento\Customer\Api\Data\AttributeMetadataInterface;
9+
use Magento\Customer\Ui\Component\DataProvider;
10+
use Magento\Customer\Ui\Component\Listing\AttributeRepository;
11+
use Magento\Framework\Api\FilterBuilder;
12+
use Magento\Framework\Api\Search\SearchCriteriaInterface;
13+
use Magento\Framework\View\Element\UiComponent\DataProvider\Reporting;
14+
15+
class DataProviderTest extends \PHPUnit_Framework_TestCase
16+
{
17+
const TEST_REQUEST_NAME = 'test_request_name';
18+
19+
/**
20+
* @var DataProvider
21+
*/
22+
protected $model;
23+
24+
/**
25+
* @var Reporting | \PHPUnit_Framework_MockObject_MockObject
26+
*/
27+
protected $reporting;
28+
29+
/**
30+
* @var SearchCriteriaInterface | \PHPUnit_Framework_MockObject_MockObject
31+
*/
32+
protected $searchCriteria;
33+
34+
/**
35+
* @var \Magento\Framework\App\RequestInterface | \PHPUnit_Framework_MockObject_MockObject
36+
*/
37+
protected $request;
38+
39+
/**
40+
* @var FilterBuilder | \PHPUnit_Framework_MockObject_MockObject
41+
*/
42+
protected $filterBuilder;
43+
44+
/**
45+
* @var AttributeRepository | \PHPUnit_Framework_MockObject_MockObject
46+
*/
47+
protected $attributeRepository;
48+
49+
public function setUp()
50+
{
51+
$this->reporting = $this->getMockBuilder('Magento\Framework\View\Element\UiComponent\DataProvider\Reporting')
52+
->disableOriginalConstructor()
53+
->getMock();
54+
55+
$searchCriteriaBuilder = $this->mockSearchCriteria();
56+
57+
$this->request = $this->getMockBuilder('Magento\Framework\App\RequestInterface')
58+
->getMockForAbstractClass();
59+
60+
$this->filterBuilder = $this->getMockBuilder('Magento\Framework\Api\FilterBuilder')
61+
->disableOriginalConstructor()
62+
->getMock();
63+
64+
$this->attributeRepository = $this->getMockBuilder('Magento\Customer\Ui\Component\Listing\AttributeRepository')
65+
->disableOriginalConstructor()
66+
->getMock();
67+
68+
$this->model = new DataProvider(
69+
self::TEST_REQUEST_NAME,
70+
'',
71+
'',
72+
$this->reporting,
73+
$searchCriteriaBuilder,
74+
$this->request,
75+
$this->filterBuilder,
76+
$this->attributeRepository
77+
);
78+
}
79+
80+
public function testGetData()
81+
{
82+
$attributeCode = 'attribute_code';
83+
$attributeValue = [
84+
AttributeMetadataInterface::OPTIONS => [
85+
[
86+
'label' => 'opt1_label',
87+
'value' => 'opt1_value',
88+
],
89+
],
90+
];
91+
92+
$expected = [
93+
[
94+
'attribute_code' => ['opt1_value'],
95+
],
96+
];
97+
98+
$attributeMock = $this->getMockBuilder('Magento\Framework\Api\AttributeInterface')
99+
->getMockForAbstractClass();
100+
$attributeMock->expects($this->once())
101+
->method('getAttributeCode')
102+
->willReturn($attributeCode);
103+
$attributeMock->expects($this->once())
104+
->method('getValue')
105+
->willReturn('opt1_value');
106+
107+
$searchDocumentMock = $this->getMockBuilder('Magento\Framework\Api\Search\DocumentInterface')
108+
->getMockForAbstractClass();
109+
$searchDocumentMock->expects($this->once())
110+
->method('getCustomAttributes')
111+
->willReturn([$attributeMock]);
112+
113+
$searchResultMock = $this->getMockBuilder('Magento\Framework\Api\Search\SearchResultInterface')
114+
->getMockForAbstractClass();
115+
$searchResultMock->expects($this->once())
116+
->method('getTotalCount')
117+
->willReturn(1);
118+
$searchResultMock->expects($this->once())
119+
->method('getItems')
120+
->willReturn([$searchDocumentMock]);
121+
122+
$this->searchCriteria->expects($this->once())
123+
->method('setRequestName')
124+
->with(self::TEST_REQUEST_NAME)
125+
->willReturnSelf();
126+
127+
$this->reporting->expects($this->once())
128+
->method('search')
129+
->with($this->searchCriteria)
130+
->willReturn($searchResultMock);
131+
132+
$this->attributeRepository->expects($this->once())
133+
->method('getList')
134+
->willReturn([$attributeCode => $attributeValue]);
135+
136+
$result = $this->model->getData();
137+
138+
$this->assertTrue(is_array($result));
139+
$this->assertArrayHasKey('totalRecords', $result);
140+
$this->assertEquals(1, $result['totalRecords']);
141+
$this->assertArrayHasKey('items', $result);
142+
$this->assertTrue(is_array($result['items']));
143+
$this->assertEquals($result['items'], $expected);
144+
}
145+
146+
/**
147+
* @return \PHPUnit_Framework_MockObject_MockObject
148+
*/
149+
protected function mockSearchCriteria()
150+
{
151+
$this->searchCriteria = $this->getMockBuilder('Magento\Framework\Api\Search\SearchCriteriaInterface')
152+
->getMockForAbstractClass();
153+
154+
$searchCriteriaBuilder = $this->getMockBuilder('Magento\Framework\Api\Search\SearchCriteriaBuilder')
155+
->disableOriginalConstructor()
156+
->getMock();
157+
158+
$searchCriteriaBuilder->expects($this->any())
159+
->method('create')
160+
->willReturn($this->searchCriteria);
161+
162+
return $searchCriteriaBuilder;
163+
}
164+
}
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Bundle\Api;
7+
8+
use Magento\TestFramework\TestCase\WebapiAbstract;
9+
10+
class OrderItemRepositoryTest extends WebapiAbstract
11+
{
12+
const RESOURCE_PATH = '/V1/orders/items';
13+
14+
const SERVICE_VERSION = 'V1';
15+
const SERVICE_NAME = 'salesOrderItemRepositoryV1';
16+
17+
const ORDER_INCREMENT_ID = '100000001';
18+
19+
/**
20+
* @var \Magento\TestFramework\ObjectManager
21+
*/
22+
protected $objectManager;
23+
24+
protected function setUp()
25+
{
26+
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
27+
}
28+
29+
/**
30+
* @magentoApiDataFixture Magento/Bundle/_files/order_item_with_bundle_and_options.php
31+
*/
32+
public function testGet()
33+
{
34+
/** @var \Magento\Sales\Model\Order $order */
35+
$order = $this->objectManager->create('Magento\Sales\Model\Order');
36+
$order->loadByIncrementId(self::ORDER_INCREMENT_ID);
37+
$orderItem = current($order->getItems());
38+
39+
$serviceInfo = [
40+
'rest' => [
41+
'resourcePath' => self::RESOURCE_PATH . '/' . $orderItem->getId(),
42+
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET,
43+
],
44+
'soap' => [
45+
'service' => self::SERVICE_NAME,
46+
'serviceVersion' => self::SERVICE_VERSION,
47+
'operation' => self::SERVICE_NAME . 'get',
48+
],
49+
];
50+
51+
$response = $this->_webApiCall($serviceInfo, ['id' => $orderItem->getId()]);
52+
53+
$this->assertTrue(is_array($response));
54+
$this->assertOrderItem($orderItem, $response);
55+
}
56+
57+
/**
58+
* @magentoApiDataFixture Magento/Bundle/_files/order_item_with_bundle_and_options.php
59+
*/
60+
public function testGetList()
61+
{
62+
/** @var \Magento\Sales\Model\Order $order */
63+
$order = $this->objectManager->create('Magento\Sales\Model\Order');
64+
$order->loadByIncrementId(self::ORDER_INCREMENT_ID);
65+
66+
/** @var $searchCriteriaBuilder \Magento\Framework\Api\SearchCriteriaBuilder */
67+
$searchCriteriaBuilder = $this->objectManager->create('Magento\Framework\Api\SearchCriteriaBuilder');
68+
/** @var $filterBuilder \Magento\Framework\Api\FilterBuilder */
69+
$filterBuilder = $this->objectManager->create('Magento\Framework\Api\FilterBuilder');
70+
71+
$searchCriteriaBuilder->addFilters(
72+
[
73+
$filterBuilder->setField('order_id')
74+
->setValue($order->getId())
75+
->create(),
76+
]
77+
);
78+
79+
$requestData = ['criteria' => $searchCriteriaBuilder->create()->__toArray()];
80+
81+
$serviceInfo = [
82+
'rest' => [
83+
'resourcePath' => self::RESOURCE_PATH . '?' . http_build_query($requestData),
84+
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET,
85+
],
86+
'soap' => [
87+
'service' => self::SERVICE_NAME,
88+
'serviceVersion' => self::SERVICE_VERSION,
89+
'operation' => self::SERVICE_NAME . 'getList',
90+
],
91+
];
92+
93+
$response = $this->_webApiCall($serviceInfo, $requestData);
94+
95+
$this->assertTrue(is_array($response));
96+
$this->assertArrayHasKey('items', $response);
97+
$this->assertCount(1, $response['items']);
98+
$this->assertTrue(is_array($response['items'][0]));
99+
$this->assertOrderItem(current($order->getItems()), $response['items'][0]);
100+
}
101+
102+
/**
103+
* @param \Magento\Sales\Model\Order\Item $orderItem
104+
* @param array $response
105+
* @return void
106+
*/
107+
protected function assertOrderItem(\Magento\Sales\Model\Order\Item $orderItem, array $response)
108+
{
109+
$bundleOption = $orderItem->getBuyRequest()->getBundleOption();
110+
$bundleOptionQty = $orderItem->getBuyRequest()->getBundleOptionQty();
111+
112+
$this->assertArrayHasKey('product_option', $response);
113+
$this->assertArrayHasKey('extension_attributes', $response['product_option']);
114+
$this->assertArrayHasKey('bundle_options', $response['product_option']['extension_attributes']);
115+
116+
$actualOptions = $response['product_option']['extension_attributes']['bundle_options'];
117+
118+
$this->assertEquals(array_keys($bundleOption), array_column($actualOptions, 'option_id'));
119+
$this->assertEquals($bundleOptionQty, array_column($actualOptions, 'option_qty', 'option_id'));
120+
121+
foreach ($actualOptions as $option) {
122+
$expectedSelections = is_array($bundleOption[$option['option_id']])
123+
? $bundleOption[$option['option_id']]
124+
: [$bundleOption[$option['option_id']]];
125+
$this->assertEquals($expectedSelections, $option['option_selections']);
126+
}
127+
}
128+
}

0 commit comments

Comments
 (0)