2012-02-28 10:59:18 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Composer.
|
|
|
|
*
|
|
|
|
* (c) Nils Adermann <naderman@naderman.de>
|
|
|
|
* Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Composer\Test\Downloader;
|
|
|
|
|
|
|
|
class ArchiveDownloaderTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
public function testGetFileName()
|
|
|
|
{
|
|
|
|
$packageMock = $this->getMock('Composer\Package\PackageInterface');
|
|
|
|
$packageMock->expects($this->any())
|
|
|
|
->method('getDistUrl')
|
|
|
|
->will($this->returnValue('http://example.com/script.js'))
|
|
|
|
;
|
|
|
|
|
2012-10-21 15:56:57 +00:00
|
|
|
$downloader = $this->getMockForAbstractClass('Composer\Downloader\ArchiveDownloader', array($this->getMock('Composer\IO\IOInterface'), $this->getMock('Composer\Config')));
|
2012-02-28 10:59:18 +00:00
|
|
|
$method = new \ReflectionMethod($downloader, 'getFileName');
|
|
|
|
$method->setAccessible(true);
|
|
|
|
|
|
|
|
$first = $method->invoke($downloader, $packageMock, '/path');
|
|
|
|
$this->assertRegExp('#/path/[a-z0-9]+\.js#', $first);
|
|
|
|
$this->assertSame($first, $method->invoke($downloader, $packageMock, '/path'));
|
|
|
|
}
|
2012-03-09 18:30:37 +00:00
|
|
|
|
|
|
|
public function testProcessUrl()
|
|
|
|
{
|
2012-10-21 15:56:57 +00:00
|
|
|
$downloader = $this->getMockForAbstractClass('Composer\Downloader\ArchiveDownloader', array($this->getMock('Composer\IO\IOInterface'), $this->getMock('Composer\Config')));
|
2012-03-09 18:30:37 +00:00
|
|
|
$method = new \ReflectionMethod($downloader, 'processUrl');
|
|
|
|
$method->setAccessible(true);
|
|
|
|
|
|
|
|
$expected = 'https://github.com/composer/composer/zipball/master';
|
2012-09-27 18:22:08 +00:00
|
|
|
$url = $method->invoke($downloader, $this->getMock('Composer\Package\PackageInterface'), $expected);
|
2012-03-09 18:30:37 +00:00
|
|
|
|
2012-03-10 08:53:03 +00:00
|
|
|
if (extension_loaded('openssl')) {
|
2012-03-09 18:30:37 +00:00
|
|
|
$this->assertEquals($expected, $url);
|
|
|
|
} else {
|
|
|
|
$this->assertEquals('http://nodeload.github.com/composer/composer/zipball/master', $url);
|
|
|
|
}
|
|
|
|
}
|
2012-02-28 10:59:18 +00:00
|
|
|
}
|