|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\Framework\Logger\Test\Unit\Handler; |
| 7 | + |
| 8 | +class BaseTest extends \PHPUnit_Framework_TestCase |
| 9 | +{ |
| 10 | + /** |
| 11 | + * @var \Magento\Framework\Logger\Handler\Base|\PHPUnit_Framework_MockObject_MockObject |
| 12 | + */ |
| 13 | + private $model; |
| 14 | + |
| 15 | + /** |
| 16 | + * @var \ReflectionMethod |
| 17 | + */ |
| 18 | + private $sanitizeMethod; |
| 19 | + |
| 20 | + protected function setUp() |
| 21 | + { |
| 22 | + $driverMock = $this->getMockBuilder(\Magento\Framework\Filesystem\DriverInterface::class) |
| 23 | + ->disableOriginalConstructor() |
| 24 | + ->getMock(); |
| 25 | + $this->model = new \Magento\Framework\Logger\Handler\Base($driverMock); |
| 26 | + |
| 27 | + $class = new \ReflectionClass($this->model); |
| 28 | + $this->sanitizeMethod = $class->getMethod('sanitizeFileName'); |
| 29 | + $this->sanitizeMethod->setAccessible(true); |
| 30 | + } |
| 31 | + |
| 32 | + public function testSanitizeEmpty() |
| 33 | + { |
| 34 | + $this->assertEquals('', $this->sanitizeMethod->invokeArgs($this->model, [''])); |
| 35 | + } |
| 36 | + |
| 37 | + public function testSanitizeSimpleFilename() |
| 38 | + { |
| 39 | + $this->assertEquals('custom.log', $this->sanitizeMethod->invokeArgs($this->model, ['custom.log'])); |
| 40 | + } |
| 41 | + |
| 42 | + public function testSanitizeLeadingSlashFilename() |
| 43 | + { |
| 44 | + $this->assertEquals( |
| 45 | + 'customfolder/custom.log', |
| 46 | + $this->sanitizeMethod->invokeArgs($this->model, ['/customfolder/custom.log']) |
| 47 | + ); |
| 48 | + } |
| 49 | + |
| 50 | + public function testSanitizeParentLevelFolder() |
| 51 | + { |
| 52 | + $this->assertEquals( |
| 53 | + 'var/hack/custom.log', |
| 54 | + $this->sanitizeMethod->invokeArgs($this->model, ['../../../var/hack/custom.log']) |
| 55 | + ); |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * @expectedException \InvalidArgumentException |
| 60 | + * @expectedExceptionMessage Filename expected to be a string |
| 61 | + */ |
| 62 | + public function testSanitizeFileException() |
| 63 | + { |
| 64 | + $this->sanitizeMethod->invokeArgs($this->model, [['filename' => 'notValid']]); |
| 65 | + } |
| 66 | +} |
0 commit comments