|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @see https://github.com/zendframework/zend-view for the canonical source repository |
| 4 | + * @copyright Copyright (c) 2017 Zend Technologies USA Inc. (http://www.zend.com) |
| 5 | + * @license https://github.com/zendframework/zend-view/blob/master/LICENSE.md New BSD License |
| 6 | + */ |
| 7 | + |
| 8 | +namespace ZendTest\View\Helper; |
| 9 | + |
| 10 | +use PHPUnit_Framework_TestCase as TestCase; |
| 11 | +use Zend\ServiceManager\ServiceManager; |
| 12 | +use Zend\View\Exception; |
| 13 | +use Zend\View\Helper\Asset; |
| 14 | +use Zend\View\HelperPluginManager; |
| 15 | + |
| 16 | +class AssetTest extends TestCase |
| 17 | +{ |
| 18 | + /** @var array */ |
| 19 | + protected $resourceMap = [ |
| 20 | + 'css/style.css' => 'css/style-3a97ff4ee3.css', |
| 21 | + 'js/vendor.js' => 'js/vendor-a507086eba.js', |
| 22 | + ]; |
| 23 | + |
| 24 | + /** @var Asset */ |
| 25 | + protected $asset; |
| 26 | + |
| 27 | + protected function setUp() |
| 28 | + { |
| 29 | + parent::setUp(); |
| 30 | + |
| 31 | + $this->asset = new Asset(); |
| 32 | + $this->asset->setResourceMap($this->resourceMap); |
| 33 | + } |
| 34 | + |
| 35 | + public function testHelperPluginManagerReturnsAssetHelper() |
| 36 | + { |
| 37 | + $helpers = $this->getHelperPluginManager(); |
| 38 | + $asset = $helpers->get('asset'); |
| 39 | + |
| 40 | + $this->assertInstanceOf(Asset::class, $asset); |
| 41 | + } |
| 42 | + |
| 43 | + public function testHelperPluginManagerReturnsAssetHelperByClassName() |
| 44 | + { |
| 45 | + $helpers = $this->getHelperPluginManager(); |
| 46 | + $asset = $helpers->get(Asset::class); |
| 47 | + |
| 48 | + $this->assertInstanceOf(Asset::class, $asset); |
| 49 | + } |
| 50 | + |
| 51 | + public function testInvalidAssetName() |
| 52 | + { |
| 53 | + $this->setExpectedException(Exception\InvalidArgumentException::class, 'Asset is not defined.'); |
| 54 | + |
| 55 | + $this->asset->__invoke('unknown'); |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * @dataProvider assets |
| 60 | + * |
| 61 | + * @param string $name |
| 62 | + * @param string $expected |
| 63 | + */ |
| 64 | + public function testInvokeResult($name, $expected) |
| 65 | + { |
| 66 | + $result = $this->asset->__invoke($name); |
| 67 | + |
| 68 | + $this->assertEquals($expected, $result); |
| 69 | + } |
| 70 | + |
| 71 | + public function assets() |
| 72 | + { |
| 73 | + $data = []; |
| 74 | + foreach ($this->resourceMap as $key => $value) { |
| 75 | + $data[] = [$key, $value]; |
| 76 | + } |
| 77 | + return $data; |
| 78 | + } |
| 79 | + |
| 80 | + protected function getHelperPluginManager(array $config = []) |
| 81 | + { |
| 82 | + $services = $this->prophesize(ServiceManager::class); |
| 83 | + $services->get('config')->willReturn($config); |
| 84 | + |
| 85 | + return new HelperPluginManager($services->reveal()); |
| 86 | + } |
| 87 | +} |
0 commit comments