HttpAssetTest.php 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /*
  3. * This file is part of the Assetic package, an OpenSky project.
  4. *
  5. * (c) 2010-2011 OpenSky Project Inc
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Assetic\Test\Asset;
  11. use Assetic\Asset\HttpAsset;
  12. class HttpAssetTest extends \PHPUnit_Framework_TestCase
  13. {
  14. const JQUERY = 'https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js';
  15. public function testGetLastModified()
  16. {
  17. $asset = new HttpAsset(self::JQUERY);
  18. $this->assertInternalType('integer', $asset->getLastModified(), '->getLastModified() returns an integer');
  19. }
  20. public function testProtocolRelativeUrl()
  21. {
  22. $asset = new HttpAsset(substr(self::JQUERY, 6));
  23. $asset->load();
  24. $this->assertNotEmpty($asset->getContent());
  25. }
  26. public function testMalformedUrl()
  27. {
  28. $this->setExpectedException('InvalidArgumentException');
  29. new HttpAsset(__FILE__);
  30. }
  31. public function testInvalidUrl()
  32. {
  33. $this->setExpectedException('RuntimeException');
  34. $asset = new HttpAsset('http://invalid.com/foobar');
  35. $asset->load();
  36. }
  37. public function testSourceMetadata()
  38. {
  39. $asset = new HttpAsset(self::JQUERY);
  40. $this->assertEquals('https://ajax.googleapis.com', $asset->getSourceRoot(), '->__construct() set the source root');
  41. $this->assertEquals('ajax/libs/jquery/1.6.1/jquery.min.js', $asset->getSourcePath(), '->__construct() set the source path');
  42. }
  43. }