FilterTest.php 3.2 KB

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