Skip to content

Commit 3719481

Browse files
author
Alexander Makeev
committed
MAGETWO-48192: More than 100 rows cannot be exported in Braintree Settlement Report
- Fixed tests
1 parent d31fee9 commit 3719481

File tree

2 files changed

+59
-23
lines changed

2 files changed

+59
-23
lines changed

app/code/Magento/BraintreeTwo/Test/Unit/Model/Report/TransactionsCollectionTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,39 @@ public function testGetItemsWithLimit()
145145
$this->braintreeAdapterMock,
146146
$this->filterMapperMock
147147
);
148+
$collection->setPageSize(TransactionsCollection::TRANSACTION_MAXIMUM_COUNT);
149+
150+
$collection->addFieldToFilter('orderId', ['like' => '0']);
151+
$items = $collection->getItems();
152+
$this->assertEquals(TransactionsCollection::TRANSACTION_MAXIMUM_COUNT, count($items));
153+
$this->assertInstanceOf(DocumentInterface::class, $items[1]);
154+
}
155+
156+
/**
157+
* Get items with limit
158+
*/
159+
public function testGetItemsWithNullLimit()
160+
{
161+
$transations = range(1, TransactionsCollection::TRANSACTION_MAXIMUM_COUNT + 10);
162+
163+
$this->filterMapperMock->expects($this->once())
164+
->method('getFilter')
165+
->willReturn(new BraintreeSearchNodeStub());
166+
167+
$this->braintreeAdapterMock->expects($this->once())
168+
->method('search')
169+
->willReturn($transations);
170+
171+
$this->entityFactoryMock->expects($this->exactly(TransactionsCollection::TRANSACTION_MAXIMUM_COUNT))
172+
->method('create')
173+
->willReturn($this->transactionMapMock);
174+
175+
$collection = new TransactionsCollection(
176+
$this->entityFactoryMock,
177+
$this->braintreeAdapterMock,
178+
$this->filterMapperMock
179+
);
180+
$collection->setPageSize(NULL);
148181

149182
$collection->addFieldToFilter('orderId', ['like' => '0']);
150183
$items = $collection->getItems();

app/code/Magento/Ui/Test/Unit/Model/Export/ConvertToXmlTest.php

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Ui\Test\Unit\Model\Export;
77

8+
use Magento\Framework\Api\Search\DocumentInterface;
89
use Magento\Framework\App\Filesystem\DirectoryList;
910
use Magento\Framework\Convert\ExcelFactory;
1011
use Magento\Framework\Filesystem;
@@ -15,6 +16,10 @@
1516
use Magento\Ui\Model\Export\ConvertToXml;
1617
use Magento\Ui\Model\Export\MetadataProvider;
1718
use Magento\Ui\Model\Export\SearchResultIteratorFactory;
19+
use Magento\Framework\View\Element\UiComponent\ContextInterface;
20+
use Magento\Ui\Model\Export\SearchResultIterator;
21+
use Magento\Framework\Api\Search\SearchResultInterface;
22+
use Magento\Framework\View\Element\UiComponent\DataProvider\DataProviderInterface;
1823

1924
class ConvertToXmlTest extends \PHPUnit_Framework_TestCase
2025
{
@@ -65,26 +70,26 @@ class ConvertToXmlTest extends \PHPUnit_Framework_TestCase
6570

6671
public function setUp()
6772
{
68-
$this->directory = $this->getMockBuilder('Magento\Framework\Filesystem\Directory\WriteInterface')
73+
$this->directory = $this->getMockBuilder(DirectoryWriteInterface::class)
6974
->getMockForAbstractClass();
7075

71-
$this->filesystem = $this->getMockBuilder('Magento\Framework\Filesystem')
76+
$this->filesystem = $this->getMockBuilder(Filesystem::class)
7277
->disableOriginalConstructor()
7378
->getMock();
7479
$this->filesystem->expects($this->any())
7580
->method('getDirectoryWrite')
7681
->with(DirectoryList::VAR_DIR)
7782
->willReturn($this->directory);
7883

79-
$this->filter = $this->getMockBuilder('Magento\Ui\Component\MassAction\Filter')
84+
$this->filter = $this->getMockBuilder(Filter::class)
8085
->disableOriginalConstructor()
8186
->getMock();
8287

83-
$this->metadataProvider = $this->getMockBuilder('Magento\Ui\Model\Export\MetadataProvider')
88+
$this->metadataProvider = $this->getMockBuilder(MetadataProvider::class)
8489
->disableOriginalConstructor()
8590
->getMock();
8691

87-
$this->excelFactory = $this->getMockBuilder('Magento\Framework\Convert\ExcelFactory')
92+
$this->excelFactory = $this->getMockBuilder(ExcelFactory::class)
8893
->disableOriginalConstructor()
8994
->setMethods(['create'])
9095
->getMock();
@@ -94,10 +99,10 @@ public function setUp()
9499
->setMethods(['create'])
95100
->getMock();
96101

97-
$this->component = $this->getMockBuilder('Magento\Framework\View\Element\UiComponentInterface')
102+
$this->component = $this->getMockBuilder(UiComponentInterface::class)
98103
->getMockForAbstractClass();
99104

100-
$this->stream = $this->getMockBuilder('Magento\Framework\Filesystem\File\WriteInterface')
105+
$this->stream = $this->getMockBuilder(FileWriteInterface::class)
101106
->setMethods([
102107
'lock',
103108
'unlock',
@@ -118,7 +123,8 @@ public function testGetRowData()
118123
{
119124
$data = ['data_value'];
120125

121-
$document = $this->getMockBuilder('Magento\Framework\Api\Search\DocumentInterface')
126+
/** @var DocumentInterface $document */
127+
$document = $this->getMockBuilder(DocumentInterface::class)
122128
->getMockForAbstractClass();
123129

124130
$this->metadataProvider->expects($this->once())
@@ -145,14 +151,15 @@ public function testGetXmlFile()
145151
{
146152
$componentName = 'component_name';
147153

148-
$document = $this->getMockBuilder('Magento\Framework\Api\Search\DocumentInterface')
154+
/** @var DocumentInterface $document */
155+
$document = $this->getMockBuilder(DocumentInterface::class)
149156
->getMockForAbstractClass();
150157

151158
$this->mockComponent($componentName, $document);
152159
$this->mockStream();
153160
$this->mockFilter();
154161
$this->mockDirectory();
155-
$this->mockExcel($componentName);
162+
$this->mockExcel($componentName, $document);
156163

157164
$this->metadataProvider->expects($this->once())
158165
->method('getHeaders')
@@ -186,10 +193,11 @@ protected function mockStream()
186193

187194
/**
188195
* @param string $componentName
196+
* @param DocumentInterface $document
189197
*/
190-
protected function mockExcel($componentName)
198+
protected function mockExcel($componentName, DocumentInterface $document)
191199
{
192-
$searchResultIterator = $this->getMockBuilder('Magento\Ui\Model\Export\SearchResultIterator')
200+
$searchResultIterator = $this->getMockBuilder(SearchResultIterator::class)
193201
->disableOriginalConstructor()
194202
->getMock();
195203

@@ -199,7 +207,7 @@ protected function mockExcel($componentName)
199207

200208
$this->iteratorFactory->expects($this->once())
201209
->method('create')
202-
->with(['items' => []])
210+
->with(['items' => [$document]])
203211
->willReturn($searchResultIterator);
204212

205213
$this->excelFactory->expects($this->once())
@@ -222,21 +230,19 @@ protected function mockExcel($componentName)
222230

223231
/**
224232
* @param string $componentName
225-
* @param null|object $document
233+
* @param DocumentInterface|null $document
226234
*/
227-
protected function mockComponent($componentName, $document = null)
235+
protected function mockComponent($componentName, DocumentInterface $document = null)
228236
{
229-
$context = $this->getMockBuilder('Magento\Framework\View\Element\UiComponent\ContextInterface')
237+
$context = $this->getMockBuilder(ContextInterface::class)
230238
->setMethods(['getDataProvider'])
231239
->getMockForAbstractClass();
232240

233-
$dataProvider = $this->getMockBuilder(
234-
'Magento\Framework\View\Element\UiComponent\DataProvider\DataProviderInterface'
235-
)
241+
$dataProvider = $this->getMockBuilder(DataProviderInterface::class)
236242
->setMethods(['getSearchResult', 'setLimit'])
237243
->getMockForAbstractClass();
238244

239-
$searchResult = $this->getMockBuilder('Magento\Framework\Api\Search\SearchResultInterface')
245+
$searchResult = $this->getMockBuilder(SearchResultInterface::class)
240246
->setMethods(['getItems'])
241247
->getMockForAbstractClass();
242248

@@ -263,9 +269,6 @@ protected function mockComponent($componentName, $document = null)
263269
$searchResult->expects($this->at(0))
264270
->method('getItems')
265271
->willReturn([$document]);
266-
$searchResult->expects($this->at(1))
267-
->method('getItems')
268-
->willReturn([]);
269272
} else {
270273
$searchResult->expects($this->at(0))
271274
->method('getItems')

0 commit comments

Comments
 (0)