39 $this->fileValidatorMock = $this->createMock(\
Magento\Downloadable\Model\
File\ContentValidator::class);
40 $this->urlValidatorMock = $this->createMock(\
Magento\Framework\Url\Validator::class);
41 $this->linkFileMock = $this->createMock(\
Magento\Downloadable\Api\Data\
File\ContentInterface::class);
42 $this->sampleFileMock = $this->createMock(\
Magento\Downloadable\Api\Data\
File\ContentInterface::class);
43 $this->validator =
new ContentValidator($this->fileValidatorMock, $this->urlValidatorMock);
48 $linkFileContentMock = $this->createMock(\
Magento\Downloadable\Api\Data\
File\ContentInterface::class);
49 $sampleFileContentMock = $this->createMock(\
Magento\Downloadable\Api\Data\
File\ContentInterface::class);
55 'number_of_downloads' => 100,
56 'link_type' =>
'file',
57 'sample_type' =>
'file',
58 'link_file_content' => $linkFileContentMock,
59 'sample_file_content' => $sampleFileContentMock,
61 $this->fileValidatorMock->expects($this->any())->method(
'isValid')->will($this->returnValue(
true));
62 $this->urlValidatorMock->expects($this->any())->method(
'isValid')->will($this->returnValue(
true));
64 $this->assertTrue($this->validator->isValid($linkMock));
69 $sampleFileContentMock = $this->createMock(\
Magento\Downloadable\Api\Data\
File\ContentInterface::class);
75 'number_of_downloads' => 100,
77 'link_url' =>
'http://example.com',
78 'sample_type' =>
'file',
79 'sample_file_content' => $sampleFileContentMock,
81 $this->fileValidatorMock->expects($this->once())->method(
'isValid')->will($this->returnValue(
true));
82 $this->urlValidatorMock->expects($this->never())->method(
'isValid')->will($this->returnValue(
true));
84 $this->assertTrue($this->validator->isValid($linkMock,
false));
89 $sampleFileContentMock = $this->createMock(\
Magento\Downloadable\Api\Data\
File\ContentInterface::class);
95 'number_of_downloads' => 100,
97 'link_url' =>
'http://example.com',
98 'sample_type' =>
'file',
99 'sample_file_content' => $sampleFileContentMock,
101 $this->fileValidatorMock->expects($this->never())->method(
'isValid')->will($this->returnValue(
true));
102 $this->urlValidatorMock->expects($this->once())->method(
'isValid')->will($this->returnValue(
true));
104 $this->assertTrue($this->validator->isValid($linkMock,
true,
false));
117 'sort_order' => $sortOrder,
120 'number_of_downloads' => 100,
121 'link_type' =>
'file',
122 'sample_type' =>
'file',
124 $this->fileValidatorMock->expects($this->any())->method(
'isValid')->will($this->returnValue(
true));
125 $this->urlValidatorMock->expects($this->any())->method(
'isValid')->will($this->returnValue(
true));
126 $contentMock = $this->
getLinkMock($linkContentData);
127 $this->validator->isValid($contentMock);
155 'number_of_downloads' => 100,
156 'link_type' =>
'file',
157 'sample_type' =>
'file',
159 $this->fileValidatorMock->expects($this->any())->method(
'isValid')->will($this->returnValue(
true));
160 $this->urlValidatorMock->expects($this->any())->method(
'isValid')->will($this->returnValue(
true));
161 $contentMock = $this->
getLinkMock($linkContentData);
162 $this->validator->isValid($contentMock);
189 'number_of_downloads' => $numberOfDownloads,
190 'link_type' =>
'file',
191 'sample_type' =>
'file',
193 $this->urlValidatorMock->expects($this->any())->method(
'isValid')->will($this->returnValue(
true));
194 $this->fileValidatorMock->expects($this->any())->method(
'isValid')->will($this->returnValue(
true));
195 $contentMock = $this->
getLinkMock($linkContentData);
196 $this->validator->isValid($contentMock);
217 $linkMock = $this->getMockBuilder(\
Magento\Downloadable\Api\Data\LinkInterface::class)
224 'getNumberOfDownloads',
229 ->getMockForAbstractClass();
230 $linkMock->expects($this->any())->method(
'getTitle')->will($this->returnValue(
233 $linkMock->expects($this->any())->method(
'getPrice')->will($this->returnValue(
236 $linkMock->expects($this->any())->method(
'getSortOrder')->will($this->returnValue(
239 $linkMock->expects($this->any())->method(
'isShareable')->will($this->returnValue(
242 $linkMock->expects($this->any())->method(
'getNumberOfDownloads')->will($this->returnValue(
245 $linkMock->expects($this->any())->method(
'getLinkType')->will($this->returnValue(
248 $linkMock->expects($this->any())->method(
'getLinkFile')->will($this->returnValue(
252 $linkMock->expects($this->any())->method(
'getLinkUrl')->will($this->returnValue(
257 $linkMock->expects($this->any())->method(
'getSampleUrl')->will($this->returnValue(
262 $linkMock->expects($this->any())->method(
'getSampleType')->will($this->returnValue(
266 if (isset(
$linkData[
'link_file_content'])) {
267 $linkMock->expects($this->any())->method(
'getLinkFileContent')->willReturn(
$linkData[
'link_file_content']);
269 if (isset(
$linkData[
'sample_file_content'])) {
270 $linkMock->expects($this->any())->method(
'getSampleFileContent')
271 ->willReturn(
$linkData[
'sample_file_content']);
273 $linkMock->expects($this->any())->method(
'getSampleFile')->will($this->returnValue(
274 $this->sampleFileMock
testIsValidSkipSampleContent()
testIsValidThrowsExceptionIfSortOrderIsInvalid($sortOrder)
testIsValidThrowsExceptionIfPriceIsInvalid($price)
testIsValidSkipLinkContent()
testIsValidThrowsExceptionIfNumberOfDownloadsIsInvalid($numberOfDownloads)
getInvalidNumberOfDownloads()
getLinkMock(array $linkData)