FilterTest.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. use PHPUnit\Framework\TestCase;
  3. use PrivateBin\Filter;
  4. class FilterTest extends TestCase
  5. {
  6. public function testFilterMakesTimesHumanlyReadable()
  7. {
  8. $this->assertEquals('5 minutes', Filter::formatHumanReadableTime('5min'));
  9. $this->assertEquals('90 seconds', Filter::formatHumanReadableTime('90sec'));
  10. $this->assertEquals('1 week', Filter::formatHumanReadableTime('1week'));
  11. $this->assertEquals('6 months', Filter::formatHumanReadableTime('6months'));
  12. }
  13. public function testFilterFailTimesHumanlyReadable()
  14. {
  15. $this->expectException(Exception::class);
  16. $this->expectExceptionCode(30);
  17. Filter::formatHumanReadableTime('five_minutes');
  18. }
  19. public function testFilterMakesSizesHumanlyReadable()
  20. {
  21. $this->assertEquals('1 B', Filter::formatHumanReadableSize(1));
  22. $this->assertEquals('1 000 B', Filter::formatHumanReadableSize(1000));
  23. $this->assertEquals('1.00 KiB', Filter::formatHumanReadableSize(1024));
  24. $this->assertEquals('1.21 KiB', Filter::formatHumanReadableSize(1234));
  25. $exponent = 1024;
  26. $this->assertEquals('1 000.00 KiB', Filter::formatHumanReadableSize(1000 * $exponent));
  27. $this->assertEquals('1.00 MiB', Filter::formatHumanReadableSize(1024 * $exponent));
  28. $this->assertEquals('1.21 MiB', Filter::formatHumanReadableSize(1234 * $exponent));
  29. $exponent *= 1024;
  30. $this->assertEquals('1 000.00 MiB', Filter::formatHumanReadableSize(1000 * $exponent));
  31. $this->assertEquals('1.00 GiB', Filter::formatHumanReadableSize(1024 * $exponent));
  32. $this->assertEquals('1.21 GiB', Filter::formatHumanReadableSize(1234 * $exponent));
  33. $exponent *= 1024;
  34. $this->assertEquals('1 000.00 GiB', Filter::formatHumanReadableSize(1000 * $exponent));
  35. $this->assertEquals('1.00 TiB', Filter::formatHumanReadableSize(1024 * $exponent));
  36. $this->assertEquals('1.21 TiB', Filter::formatHumanReadableSize(1234 * $exponent));
  37. $exponent *= 1024;
  38. $this->assertEquals('1 000.00 TiB', Filter::formatHumanReadableSize(1000 * $exponent));
  39. $this->assertEquals('1.00 PiB', Filter::formatHumanReadableSize(1024 * $exponent));
  40. $this->assertEquals('1.21 PiB', Filter::formatHumanReadableSize(1234 * $exponent));
  41. $exponent *= 1024;
  42. $this->assertEquals('1 000.00 PiB', Filter::formatHumanReadableSize(1000 * $exponent));
  43. $this->assertEquals('1.00 EiB', Filter::formatHumanReadableSize(1024 * $exponent));
  44. $this->assertEquals('1.21 EiB', Filter::formatHumanReadableSize(1234 * $exponent));
  45. $exponent *= 1024;
  46. $this->assertEquals('1 000.00 EiB', Filter::formatHumanReadableSize(1000 * $exponent));
  47. $this->assertEquals('1.00 ZiB', Filter::formatHumanReadableSize(1024 * $exponent));
  48. $this->assertEquals('1.21 ZiB', Filter::formatHumanReadableSize(1234 * $exponent));
  49. $exponent *= 1024;
  50. $this->assertEquals('1 000.00 ZiB', Filter::formatHumanReadableSize(1000 * $exponent));
  51. $this->assertEquals('1.00 YiB', Filter::formatHumanReadableSize(1024 * $exponent));
  52. $this->assertEquals('1.21 YiB', Filter::formatHumanReadableSize(1234 * $exponent));
  53. }
  54. }