Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ContentValidatorTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class ContentValidatorTest extends \PHPUnit\Framework\TestCase
11 {
15  protected $validator;
16 
20  protected $fileContentMock;
21 
22  protected function setUp()
23  {
24  $this->validator = new \Magento\Downloadable\Model\File\ContentValidator();
25 
26  $this->fileContentMock = $this->createMock(\Magento\Downloadable\Api\Data\File\ContentInterface::class);
27  }
28 
29  public function testIsValid()
30  {
31  $this->fileContentMock->expects($this->any())->method('getFileData')
32  ->will($this->returnValue(base64_encode('test content')));
33  $this->fileContentMock->expects($this->any())->method('getName')
34  ->will($this->returnValue('valid_name'));
35 
36  $this->assertTrue($this->validator->isValid($this->fileContentMock));
37  }
38 
44  {
45  $this->fileContentMock->expects($this->any())->method('getFileData')
46  ->will($this->returnValue('not_a_base64_encoded_content'));
47  $this->fileContentMock->expects($this->any())->method('getName')
48  ->will($this->returnValue('valid_name'));
49  $this->assertTrue($this->validator->isValid($this->fileContentMock));
50  }
51 
59  {
60  $this->fileContentMock->expects($this->any())->method('getFileData')
61  ->will($this->returnValue(base64_encode('test content')));
62  $this->fileContentMock->expects($this->any())->method('getName')
63  ->will($this->returnValue($fileName));
64  $this->assertTrue($this->validator->isValid($this->fileContentMock));
65  }
66 
70  public function getInvalidNames()
71  {
72  return [
73  ['test\test'],
74  ['test/test'],
75  ['test:test'],
76  ['test"test'],
77  ['test*test'],
78  ['test;test'],
79  ['test?test'],
80  ['test{test'],
81  ['test}test'],
82  ['test|test'],
83  ['test(test'],
84  ['test)test'],
85  ['test<test'],
86  ['test>test'],
87  ];
88  }
89 }
$fileName
Definition: translate.phtml:15