Exemplo n.º 1
0
 /**
  * Validate sample resource (file or URL)
  *
  * @param LinkContentInterface $linkContent
  * @throws InputException
  * @return void
  */
 protected function validateSampleResource(LinkContentInterface $linkContent)
 {
     if ($linkContent->getSampleType() == 'url' && !$this->urlValidator->isValid($linkContent->getSampleUrl())) {
         throw new InputException(__('Sample URL must have valid format.'));
     }
     if ($linkContent->getSampleType() == 'file' && (!$linkContent->getSampleFile() || !$this->fileContentValidator->isValid($linkContent->getSampleFile()))) {
         throw new InputException(__('Provided file content must be valid base64 encoded data.'));
     }
 }
 /**
  * @expectedException \Magento\Framework\Exception\InputException
  * @expectedExceptionMessage Provided file name contains forbidden characters.
  * @dataProvider getInvalidNames
  * @param string $fileName
  */
 public function testIsValidThrowsExceptionIfProvidedImageNameContainsForbiddenCharacters($fileName)
 {
     $this->fileContentMock->expects($this->any())->method('getFileData')->will($this->returnValue(base64_encode('test content')));
     $this->fileContentMock->expects($this->any())->method('getName')->will($this->returnValue($fileName));
     $this->assertTrue($this->validator->isValid($this->fileContentMock));
 }