FilterTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. /**
  14. * @expectedException Exception
  15. * @expectedExceptionCode 30
  16. */
  17. public function testFilterFailTimesHumanlyReadable()
  18. {
  19. Filter::formatHumanReadableTime('five_minutes');
  20. }
  21. public function testFilterMakesSizesHumanlyReadable()
  22. {
  23. $this->assertEquals('1 B', Filter::formatHumanReadableSize(1));
  24. $this->assertEquals('1 000 B', Filter::formatHumanReadableSize(1000));
  25. $this->assertEquals('1.00 KiB', Filter::formatHumanReadableSize(1024));
  26. $this->assertEquals('1.21 KiB', Filter::formatHumanReadableSize(1234));
  27. $exponent = 1024;
  28. $this->assertEquals('1 000.00 KiB', Filter::formatHumanReadableSize(1000 * $exponent));
  29. $this->assertEquals('1.00 MiB', Filter::formatHumanReadableSize(1024 * $exponent));
  30. $this->assertEquals('1.21 MiB', Filter::formatHumanReadableSize(1234 * $exponent));
  31. $exponent *= 1024;
  32. $this->assertEquals('1 000.00 MiB', Filter::formatHumanReadableSize(1000 * $exponent));
  33. $this->assertEquals('1.00 GiB', Filter::formatHumanReadableSize(1024 * $exponent));
  34. $this->assertEquals('1.21 GiB', Filter::formatHumanReadableSize(1234 * $exponent));
  35. $exponent *= 1024;
  36. $this->assertEquals('1 000.00 GiB', Filter::formatHumanReadableSize(1000 * $exponent));
  37. $this->assertEquals('1.00 TiB', Filter::formatHumanReadableSize(1024 * $exponent));
  38. $this->assertEquals('1.21 TiB', Filter::formatHumanReadableSize(1234 * $exponent));
  39. $exponent *= 1024;
  40. $this->assertEquals('1 000.00 TiB', Filter::formatHumanReadableSize(1000 * $exponent));
  41. $this->assertEquals('1.00 PiB', Filter::formatHumanReadableSize(1024 * $exponent));
  42. $this->assertEquals('1.21 PiB', Filter::formatHumanReadableSize(1234 * $exponent));
  43. $exponent *= 1024;
  44. $this->assertEquals('1 000.00 PiB', Filter::formatHumanReadableSize(1000 * $exponent));
  45. $this->assertEquals('1.00 EiB', Filter::formatHumanReadableSize(1024 * $exponent));
  46. $this->assertEquals('1.21 EiB', Filter::formatHumanReadableSize(1234 * $exponent));
  47. $exponent *= 1024;
  48. $this->assertEquals('1 000.00 EiB', Filter::formatHumanReadableSize(1000 * $exponent));
  49. $this->assertEquals('1.00 ZiB', Filter::formatHumanReadableSize(1024 * $exponent));
  50. $this->assertEquals('1.21 ZiB', Filter::formatHumanReadableSize(1234 * $exponent));
  51. $exponent *= 1024;
  52. $this->assertEquals('1 000.00 ZiB', Filter::formatHumanReadableSize(1000 * $exponent));
  53. $this->assertEquals('1.00 YiB', Filter::formatHumanReadableSize(1024 * $exponent));
  54. $this->assertEquals('1.21 YiB', Filter::formatHumanReadableSize(1234 * $exponent));
  55. }
  56. }