1
0

FilterTest.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php declare(strict_types=1);
  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.00 kB', Filter::formatHumanReadableSize(1000));
  23. $this->assertEquals('1.02 kB', Filter::formatHumanReadableSize(1024));
  24. $this->assertEquals('1.23 kB', Filter::formatHumanReadableSize(1234));
  25. $exponent = 1000;
  26. $this->assertEquals('1.00 MB', Filter::formatHumanReadableSize(1000 * $exponent));
  27. $this->assertEquals('1.02 MB', Filter::formatHumanReadableSize(1024 * $exponent));
  28. $this->assertEquals('1.23 MB', Filter::formatHumanReadableSize(1234 * $exponent));
  29. $exponent *= 1000;
  30. $this->assertEquals('1.00 GB', Filter::formatHumanReadableSize(1000 * $exponent));
  31. $this->assertEquals('1.02 GB', Filter::formatHumanReadableSize(1024 * $exponent));
  32. $this->assertEquals('1.23 GB', Filter::formatHumanReadableSize(1234 * $exponent));
  33. $exponent *= 1000;
  34. $this->assertEquals('1.00 TB', Filter::formatHumanReadableSize(1000 * $exponent));
  35. $this->assertEquals('1.02 TB', Filter::formatHumanReadableSize(1024 * $exponent));
  36. $this->assertEquals('1.23 TB', Filter::formatHumanReadableSize(1234 * $exponent));
  37. $exponent *= 1000;
  38. $this->assertEquals('1.00 PB', Filter::formatHumanReadableSize(1000 * $exponent));
  39. $this->assertEquals('1.02 PB', Filter::formatHumanReadableSize(1024 * $exponent));
  40. $this->assertEquals('1.23 PB', Filter::formatHumanReadableSize(1234 * $exponent));
  41. $exponent *= 1000;
  42. $this->assertEquals('1.00 EB', Filter::formatHumanReadableSize(1000 * $exponent));
  43. $this->assertEquals('1.02 EB', Filter::formatHumanReadableSize(1024 * $exponent));
  44. $this->assertEquals('1.23 EB', Filter::formatHumanReadableSize(1234 * $exponent));
  45. $exponent *= 1000;
  46. $this->assertEquals('1.00 ZB', Filter::formatHumanReadableSize(1000 * $exponent));
  47. $this->assertEquals('1.02 ZB', Filter::formatHumanReadableSize(1024 * $exponent));
  48. $this->assertEquals('1.23 ZB', Filter::formatHumanReadableSize(1234 * $exponent));
  49. $exponent *= 1000;
  50. $this->assertEquals('1.00 YB', Filter::formatHumanReadableSize(1000 * $exponent));
  51. $this->assertEquals('1.02 YB', Filter::formatHumanReadableSize(1024 * $exponent));
  52. $this->assertEquals('1.23 YB', Filter::formatHumanReadableSize(1234 * $exponent));
  53. }
  54. }