EntityDirLocatorTest.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace Elgg;
  3. class EntityDirLocatorTest extends \PHPUnit_Framework_TestCase {
  4. public $guids = array(
  5. 1,
  6. 4999,
  7. 5000,
  8. 5001,
  9. 7500,
  10. 10000,
  11. 13532,
  12. 17234
  13. );
  14. public function testConstructorGUIDs() {
  15. // good guids
  16. foreach ($this->guids as $guid) {
  17. $dir = new \Elgg\EntityDirLocator($guid);
  18. $this->assertInstanceOf('\Elgg\EntityDirLocator', $dir);
  19. }
  20. // bad guids
  21. $bad_guids = array(
  22. "abc",
  23. null,
  24. false,
  25. 0,
  26. -123
  27. );
  28. foreach ($bad_guids as $guid) {
  29. $this->setExpectedException('InvalidArgumentException', "GUIDs must be integers > 0.");
  30. $dir = new \Elgg\EntityDirLocator($guid);
  31. }
  32. }
  33. public function testGetPath() {
  34. $size = \Elgg\EntityDirLocator::BUCKET_SIZE;
  35. foreach ($this->guids as $guid) {
  36. $test = new \Elgg\EntityDirLocator($guid);
  37. // we start at 1 since there are no guids of 0
  38. if ($guid < 5000) {
  39. $path = "1/$guid/";
  40. } elseif ($guid < 10000) {
  41. $path = "5000/$guid/";
  42. } elseif ($guid < 15000) {
  43. $path = "10000/$guid/";
  44. } elseif ($guid < 20000) {
  45. $path = "15000/$guid/";
  46. }
  47. $this->assertSame($path, $test->getPath());
  48. }
  49. }
  50. public function testToString() {
  51. $guid = 431;
  52. $path = new \Elgg\EntityDirLocator($guid);
  53. $root = "/tmp/elgg/";
  54. $this->assertSame($root . '1/431/', $root . $path);
  55. }
  56. }