forked from OpenMage/magento-lts
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix;: return correct php.ini value w/o unit set (#16)
* Return numeric php.ini value * Fixed comparison
- Loading branch information
Showing
2 changed files
with
156 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace OpenMage\Tests\Unit\Mage\Uploader\Helper; | ||
|
||
use Mage; | ||
use Mage_Uploader_Helper_File; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class FileTest extends TestCase | ||
{ | ||
/** | ||
* @var Mage_Uploader_Helper_File | ||
*/ | ||
private Mage_Uploader_Helper_File $subject; | ||
|
||
public function setUp(): void | ||
{ | ||
Mage::app(); | ||
Mage::getConfig()->setNode('global/mime/types/test-new-node', 'application/octet-stream'); | ||
$this->subject = Mage::helper('uploader/file'); | ||
} | ||
|
||
/** | ||
* @dataProvider provideGetMimeTypeFromExtensionListData | ||
* @param array $expectedResult | ||
* @param string|array $extensionsList | ||
* @return void | ||
*/ | ||
public function testGetMimeTypeFromExtensionList(array $expectedResult, $extensionsList): void | ||
{ | ||
self::assertSame($expectedResult, $this->subject->getMimeTypeFromExtensionList($extensionsList)); | ||
} | ||
|
||
/** | ||
* @return string[][] | ||
*/ | ||
public function provideGetMimeTypeFromExtensionListData(): array | ||
{ | ||
return [ | ||
'string exists' => [ | ||
[ | ||
0 => 'application/vnd.lotus-1-2-3' | ||
], | ||
'123' | ||
], | ||
'string not exists' => [ | ||
[ | ||
0 => 'application/octet-stream' | ||
], | ||
'not-exists' | ||
], | ||
'array' => [ | ||
[ | ||
0 => 'application/vnd.lotus-1-2-3', | ||
1 => 'application/octet-stream', | ||
2 => 'application/octet-stream', | ||
], | ||
[ | ||
'123', | ||
'not-exists', | ||
'test-new-node', | ||
] | ||
], | ||
]; | ||
} | ||
|
||
public function testGetPostMaxSize(): void | ||
{ | ||
self::assertIsString($this->subject->getPostMaxSize()); | ||
} | ||
|
||
public function testGetUploadMaxSize(): void | ||
{ | ||
self::assertIsString($this->subject->getUploadMaxSize()); | ||
} | ||
|
||
public function testGetDataMaxSize(): void | ||
{ | ||
$mock = $this->getMockBuilder(Mage_Uploader_Helper_File::class) | ||
->setMethods(['getPostMaxSize', 'getUploadMaxSize']) | ||
->getMock(); | ||
|
||
$mock->expects($this->once())->method('getPostMaxSize')->willReturn('1G'); | ||
$mock->expects($this->once())->method('getUploadMaxSize')->willReturn('1M'); | ||
self::assertSame('1M', $mock->getDataMaxSize()); | ||
} | ||
|
||
/** | ||
* @dataProvider provideGetDataMaxSizeInBytesData | ||
* @param int $expectedResult | ||
* @param string $maxSize | ||
* @return void | ||
*/ | ||
public function testGetDataMaxSizeInBytes(int $expectedResult, string $maxSize): void | ||
{ | ||
$mock = $this->getMockBuilder(Mage_Uploader_Helper_File::class) | ||
->setMethods(['getDataMaxSize']) | ||
->getMock(); | ||
|
||
$mock->expects($this->once())->method('getDataMaxSize')->willReturn($maxSize); | ||
self::assertSame($expectedResult, $mock->getDataMaxSizeInBytes()); | ||
} | ||
|
||
/** | ||
* @return string[][] | ||
*/ | ||
public function provideGetDataMaxSizeInBytesData(): array | ||
{ | ||
return [ | ||
'no unit' => [ | ||
1024, | ||
'1024' | ||
], | ||
'byte' => [ | ||
1, | ||
'1B' | ||
], | ||
'kilobyte' => [ | ||
1024, | ||
'1K' | ||
], | ||
'megabyte' => [ | ||
1048576, | ||
'1M' | ||
], | ||
'gigabyte' => [ | ||
1073741824, | ||
'1G' | ||
], | ||
'terabyte' => [ | ||
1099511627776, | ||
'1T' | ||
], | ||
]; | ||
} | ||
} |