Skip to content

Commit

Permalink
Merge pull request #595 from magento-firedrakes/MAGETWO-52170
Browse files Browse the repository at this point in the history
[Firedrakes] Bugfixes
  • Loading branch information
Momotenko,Natalia(nmomotenko) committed May 6, 2016
2 parents efc35bb + 04366d2 commit 0dfd558
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 22 deletions.
27 changes: 18 additions & 9 deletions app/code/Magento/Downloadable/Model/Link/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,11 @@ public function build(\Magento\Downloadable\Api\Data\LinkInterface $link)
'to_link',
$this->data
);
$downloadableLinkSampleData = $this->objectCopyService->getDataFromFieldset(
'downloadable_link_sample_data',
'to_link_sample',
$this->data['sample']
);
$this->dataObjectHelper->populateWithArray(
$link,
array_merge(
$this->data,
$downloadableData,
$downloadableLinkSampleData
$downloadableData
),
\Magento\Downloadable\Api\Data\LinkInterface::class
);
Expand All @@ -114,8 +108,10 @@ public function build(\Magento\Downloadable\Api\Data\LinkInterface $link)
$link->setLinkFile($linkFileName);
$link->setLinkUrl(null);
}

$link = $this->buildSample($link, $this->data['sample']);

if (isset($this->data['sample'])) {
$link = $this->buildSample($link, $this->data['sample']);
}

if (!$link->getSortOrder()) {
$link->setSortOrder(1);
Expand Down Expand Up @@ -161,6 +157,19 @@ private function getComponent()
private function buildSample(\Magento\Downloadable\Api\Data\LinkInterface $link, array $sample)
{
if (!empty($sample['url']) || !empty($sample['file'])) {
$downloadableLinkSampleData = $this->objectCopyService->getDataFromFieldset(
'downloadable_link_sample_data',
'to_link_sample',
$this->data['sample']
);
$this->dataObjectHelper->populateWithArray(
$link,
array_merge(
$this->data,
$downloadableLinkSampleData
),
\Magento\Downloadable\Api\Data\LinkInterface::class
);
if ($link->getSampleType() === \Magento\Downloadable\Helper\Download::LINK_TYPE_FILE) {
$linkSampleFileName = $this->downloadableFile->moveFileFromTmp(
$this->getComponent()->getBaseSampleTmpPath(),
Expand Down
32 changes: 19 additions & 13 deletions app/code/Magento/Downloadable/Test/Unit/Model/Link/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,24 @@ public function testBuild($data, $expectedPrice)
)->willReturn($downloadableData);
$this->service->setData($data);
$this->dataObjectHelperMock->method('populateWithArray')
->with(
$this->linkMock,
array_merge(
$data,
$downloadableData
),
LinkInterface::class
->withConsecutive(
[
$this->linkMock,
array_merge(
$data,
$downloadableData
),
LinkInterface::class
],
[
$this->linkMock,
array_merge(
$data,
$downloadableData,
$data['sample']
),
LinkInterface::class
]
)->willReturn($this->linkMock);
$this->linkMock->expects($this->once())->method('getLinkType')->willReturn(Download::LINK_TYPE_FILE);
$linkModel = $this->getMockBuilder(Link::class)
Expand Down Expand Up @@ -172,16 +183,11 @@ public function testBuildFileNotProvided()
]
];
$downloadableData = ['sort_order' => 1];
$this->objectCopyServiceMock->expects($this->exactly(2))->method('getDataFromFieldset')->withConsecutive(
$this->objectCopyServiceMock->expects($this->once())->method('getDataFromFieldset')->withConsecutive(
[
'downloadable_data',
'to_link',
$data
],
[
'downloadable_link_sample_data',
'to_link_sample',
$data['sample']
]
)->willReturn($downloadableData);
$this->service->setData($data);
Expand Down

0 comments on commit 0dfd558

Please sign in to comment.