BxDolStorageExtTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. use PHPUnit\Framework\Attributes\DataProvider;
  3. class BxDolStorageExtTestDouble extends BxDolStorage
  4. {
  5. public function __construct($aObject)
  6. {
  7. $this->_aObject = $aObject;
  8. }
  9. public function isValidExtPublic($sExt)
  10. {
  11. return $this->isValidExt($sExt);
  12. }
  13. public function genPathPublic($s, $iLevels)
  14. {
  15. return $this->genPath($s, $iLevels);
  16. }
  17. }
  18. /**
  19. * Upload extension policy and generated storage paths (no disk I/O).
  20. */
  21. class BxDolStorageExtTest extends \PHPUnit\Framework\TestCase
  22. {
  23. #[DataProvider('providerForValidExt')]
  24. public function testIsValidExt($aObject, $sExt, $bOut)
  25. {
  26. $o = new BxDolStorageExtTestDouble($aObject);
  27. $this->assertSame($bOut, $o->isValidExtPublic($sExt));
  28. }
  29. static public function providerForValidExt()
  30. {
  31. return [
  32. [['ext_mode' => 'allow-deny', 'ext_allow' => 'jpg,png', 'ext_deny' => ''], 'jpg', true],
  33. [['ext_mode' => 'allow-deny', 'ext_allow' => 'jpg,png', 'ext_deny' => ''], 'exe', false],
  34. [['ext_mode' => 'allow-deny', 'ext_allow' => '', 'ext_deny' => ''], 'jpg', false],
  35. [['ext_mode' => 'deny-allow', 'ext_allow' => '', 'ext_deny' => 'exe,php'], 'jpg', true],
  36. [['ext_mode' => 'deny-allow', 'ext_allow' => '', 'ext_deny' => 'exe,php'], 'php', false],
  37. [['ext_mode' => 'deny-allow', 'ext_allow' => '', 'ext_deny' => ''], 'php', true],
  38. [['ext_mode' => 'unknown', 'ext_allow' => 'jpg', 'ext_deny' => ''], 'jpg', false],
  39. ];
  40. }
  41. #[DataProvider('providerForGenPath')]
  42. public function testGenPath($s, $iLevels, $sOut)
  43. {
  44. $o = new BxDolStorageExtTestDouble(['ext_mode' => 'allow-deny', 'ext_allow' => '', 'ext_deny' => '']);
  45. $this->assertSame($sOut, $o->genPathPublic($s, $iLevels));
  46. }
  47. static public function providerForGenPath()
  48. {
  49. return [
  50. ['abc', 2, 'a/ab/'],
  51. ['abc', 1, 'a/'],
  52. ['abc', 0, ''],
  53. ['abcdef', 3, 'a/ab/abc/'],
  54. ];
  55. }
  56. }