ExternalFilesTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace Elgg\Assets;
  3. class ExternalFilesTest extends \PHPUnit_Framework_TestCase {
  4. public function testPreservesInputConfigData() {
  5. $config = new \stdClass();
  6. $list = new \ElggPriorityList();
  7. $obj1 = (object)array(
  8. 'name' => 'bar1',
  9. 'url' => '#',
  10. 'loaded' => false,
  11. 'location' => 'custom_location'
  12. );
  13. $obj2 = (object)array(
  14. 'name' => 'bar2',
  15. 'url' => 'http://elgg.org/',
  16. 'loaded' => true,
  17. 'location' => 'custom_location'
  18. );
  19. $list->add($obj1, 600);
  20. $list->add($obj2, 300);
  21. $config->externals = array(
  22. 'foo' => $list
  23. );
  24. $config->externals_map = array(
  25. 'foo' => array(
  26. 'bar1' => $obj1,
  27. 'bar2' => $obj2,
  28. )
  29. );
  30. $externalFiles = new \Elgg\Assets\ExternalFiles($config);
  31. $this->assertEquals(array(
  32. 300 => 'http://elgg.org/'
  33. ), $externalFiles->getLoadedFiles('foo', 'custom_location'));
  34. $externalFiles->load('foo', 'bar1');
  35. $this->assertEquals(array(
  36. 300 => 'http://elgg.org/',
  37. 600 => '#'
  38. ), $externalFiles->getLoadedFiles('foo', 'custom_location'));
  39. }
  40. public function testRegisterItemsAndLoad() {
  41. $externalFiles = new \Elgg\Assets\ExternalFiles();
  42. $externalFiles->load('foo', 'bar2');
  43. $externalFiles->register('foo', 'bar1', '#', 'custom_location', 600);
  44. $externalFiles->register('foo', 'bar2', 'http://www.elgg.org/', '', 200);
  45. $externalFiles->register('foo', 'bar2', 'http://elgg.org/', 'custom_location', 300);
  46. $externalFiles->register('foo', 'bar3', 'http://community.elgg.org/', 'custom_location', 'abc');
  47. $this->assertFalse($externalFiles->register('foo', '', 'ipsum', 'dolor'));
  48. $this->assertFalse($externalFiles->register('foo', 'lorem', '', 'dolor'));
  49. $this->assertEquals(array(
  50. 300 => 'http://elgg.org/'
  51. ), $externalFiles->getLoadedFiles('foo', 'custom_location'));
  52. $externalFiles->load('foo', 'bar1');
  53. $this->assertEquals(array(
  54. 300 => 'http://elgg.org/',
  55. 600 => '#'
  56. ), $externalFiles->getLoadedFiles('foo', 'custom_location'));
  57. $externalFiles->load('foo', 'bar3');
  58. $this->assertEquals(array(
  59. 300 => 'http://elgg.org/',
  60. 500 => 'http://community.elgg.org/',
  61. 600 => '#'
  62. ), $externalFiles->getLoadedFiles('foo', 'custom_location'));
  63. $this->assertTrue($externalFiles->unregister('foo', 'bar1'));
  64. $this->assertEquals(array(
  65. 300 => 'http://elgg.org/',
  66. 500 => 'http://community.elgg.org/'
  67. ), $externalFiles->getLoadedFiles('foo', 'custom_location'));
  68. $this->assertFalse($externalFiles->unregister('foo', 'bar1'));
  69. $externalFiles->load('foo', 'bar5');
  70. $this->assertEquals(array(
  71. 0 => ''
  72. ), $externalFiles->getLoadedFiles('foo', ''));
  73. $this->assertEquals(array(), $externalFiles->getLoadedFiles('nonexistent', 'custom_location'));
  74. }
  75. }