|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Unit Test for \Magento\Framework\Filesystem\Directory\PathValidator |
| 4 | + * |
| 5 | + * Copyright © Magento, Inc. All rights reserved. |
| 6 | + * See COPYING.txt for license details. |
| 7 | + */ |
| 8 | +namespace Magento\Framework\Filesystem\Test\Unit\Directory; |
| 9 | + |
| 10 | +use Magento\Framework\Filesystem\Directory\WriteInterface; |
| 11 | +use Magento\Framework\Filesystem\DriverInterface; |
| 12 | + |
| 13 | +class PathValidatorTest extends \PHPUnit\Framework\TestCase |
| 14 | +{ |
| 15 | + /** |
| 16 | + * \Magento\Framework\Filesystem\Driver |
| 17 | + * |
| 18 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 19 | + */ |
| 20 | + protected $driver; |
| 21 | + |
| 22 | + /** |
| 23 | + * @var \Magento\Framework\Filesystem\Directory\PathValidator |
| 24 | + */ |
| 25 | + protected $pathValidator; |
| 26 | + |
| 27 | + /** |
| 28 | + * Set up |
| 29 | + */ |
| 30 | + protected function setUp() |
| 31 | + { |
| 32 | + $this->driver = $this->createMock(\Magento\Framework\Filesystem\Driver\File::class); |
| 33 | + $this->pathValidator = new \Magento\Framework\Filesystem\Directory\PathValidator( |
| 34 | + $this->driver |
| 35 | + ); |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * Tear down |
| 40 | + */ |
| 41 | + protected function tearDown() |
| 42 | + { |
| 43 | + $this->pathValidator = null; |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * @param string $directoryPath |
| 48 | + * @param string $path |
| 49 | + * @param string $scheme |
| 50 | + * @param bool $absolutePath |
| 51 | + * @param string $prefix |
| 52 | + * @dataProvider validateDataProvider |
| 53 | + */ |
| 54 | + public function testValidate($directoryPath, $path, $scheme, $absolutePath, $prefix) |
| 55 | + { |
| 56 | + $this->driver->expects($this->exactly(2)) |
| 57 | + ->method('getRealPathSafety') |
| 58 | + ->willReturnMap( |
| 59 | + [ |
| 60 | + [$directoryPath, $directoryPath], |
| 61 | + [null, $prefix . $directoryPath . ltrim($path, '/')], |
| 62 | + ] |
| 63 | + ); |
| 64 | + |
| 65 | + $this->assertNull( |
| 66 | + $this->pathValidator->validate($directoryPath, $path, $scheme, $absolutePath) |
| 67 | + ); |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * @return array |
| 72 | + */ |
| 73 | + public function validateDataProvider() |
| 74 | + { |
| 75 | + return [ |
| 76 | + ['/directory/path/', '/directory/path/', '/', false, '/://'], |
| 77 | + ['/directory/path/', '/var/.regenerate', null, false, ''], |
| 78 | + ]; |
| 79 | + } |
| 80 | +} |
0 commit comments