CollectionTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\View\Test\Unit\Asset;
  7. class CollectionTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\Framework\View\Asset\Collection
  11. */
  12. protected $_object;
  13. /**
  14. * @var \Magento\Framework\View\Asset\AssetInterface
  15. */
  16. protected $_asset;
  17. protected function setUp()
  18. {
  19. $this->_object = new \Magento\Framework\View\Asset\Collection();
  20. $this->_asset = new \Magento\Framework\View\Asset\Remote('http://127.0.0.1/magento/test.css');
  21. $this->_object->add('asset', $this->_asset);
  22. }
  23. public function testAdd()
  24. {
  25. $assetNew = new \Magento\Framework\View\Asset\Remote('http://127.0.0.1/magento/test.js');
  26. $this->_object->add('asset_new', $assetNew);
  27. $this->assertSame(['asset' => $this->_asset, 'asset_new' => $assetNew], $this->_object->getAll());
  28. }
  29. public function testHas()
  30. {
  31. $this->assertTrue($this->_object->has('asset'));
  32. $this->assertFalse($this->_object->has('non_existing_asset'));
  33. }
  34. public function testAddSameInstance()
  35. {
  36. $this->_object->add('asset_clone', $this->_asset);
  37. $this->assertSame(['asset' => $this->_asset, 'asset_clone' => $this->_asset], $this->_object->getAll());
  38. }
  39. public function testAddOverrideExisting()
  40. {
  41. $assetOverridden = new \Magento\Framework\View\Asset\Remote('http://127.0.0.1/magento/test_overridden.css');
  42. $this->_object->add('asset', $assetOverridden);
  43. $this->assertSame(['asset' => $assetOverridden], $this->_object->getAll());
  44. }
  45. public function testRemove()
  46. {
  47. $this->_object->remove('asset');
  48. $this->assertSame([], $this->_object->getAll());
  49. }
  50. public function testGetAll()
  51. {
  52. $this->assertSame(['asset' => $this->_asset], $this->_object->getAll());
  53. }
  54. }