2012-03-22 16:16:41 +00:00
|
|
|
<?php
|
2015-10-13 09:34:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2012-03-22 16:16:41 +00:00
|
|
|
namespace Composer\Test\Util;
|
|
|
|
|
2014-05-30 15:14:43 +00:00
|
|
|
use Composer\Config;
|
2012-03-22 16:16:41 +00:00
|
|
|
use Composer\IO\NullIO;
|
2016-02-03 21:39:16 +00:00
|
|
|
use Composer\Util\Platform;
|
2012-03-22 16:16:41 +00:00
|
|
|
use Composer\Util\Svn;
|
|
|
|
|
2013-02-20 15:50:26 +00:00
|
|
|
class SvnTest extends \PHPUnit_Framework_TestCase
|
2012-03-22 16:16:41 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test the credential string.
|
|
|
|
*
|
|
|
|
* @param string $url The SVN url.
|
|
|
|
* @param string $expect The expectation for the test.
|
|
|
|
*
|
|
|
|
* @dataProvider urlProvider
|
|
|
|
*/
|
|
|
|
public function testCredentials($url, $expect)
|
|
|
|
{
|
2014-05-30 15:14:43 +00:00
|
|
|
$svn = new Svn($url, new NullIO, new Config());
|
2013-02-20 15:50:26 +00:00
|
|
|
$reflMethod = new \ReflectionMethod('Composer\\Util\\Svn', 'getCredentialString');
|
|
|
|
$reflMethod->setAccessible(true);
|
|
|
|
|
|
|
|
$this->assertEquals($expect, $reflMethod->invoke($svn));
|
|
|
|
}
|
2012-03-22 16:16:41 +00:00
|
|
|
|
2013-02-20 15:50:26 +00:00
|
|
|
/**
|
|
|
|
* Provide some examples for {@self::testCredentials()}.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function urlProvider()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
array('http://till:test@svn.example.org/', $this->getCmd(" --username 'till' --password 'test' ")),
|
|
|
|
array('http://svn.apache.org/', ''),
|
|
|
|
array('svn://johndoe@example.org', $this->getCmd(" --username 'johndoe' --password '' ")),
|
|
|
|
);
|
2012-03-22 16:16:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testInteractiveString()
|
|
|
|
{
|
|
|
|
$url = 'http://svn.example.org';
|
|
|
|
|
2014-05-30 15:14:43 +00:00
|
|
|
$svn = new Svn($url, new NullIO(), new Config());
|
2013-02-20 15:50:26 +00:00
|
|
|
$reflMethod = new \ReflectionMethod('Composer\\Util\\Svn', 'getCommand');
|
|
|
|
$reflMethod->setAccessible(true);
|
2012-03-22 16:16:41 +00:00
|
|
|
|
|
|
|
$this->assertEquals(
|
2013-02-20 15:50:26 +00:00
|
|
|
$this->getCmd("svn ls --non-interactive 'http://svn.example.org'"),
|
|
|
|
$reflMethod->invokeArgs($svn, array('svn ls', $url))
|
2012-03-22 16:16:41 +00:00
|
|
|
);
|
|
|
|
}
|
2013-02-20 15:50:26 +00:00
|
|
|
|
2014-05-30 15:14:43 +00:00
|
|
|
public function testCredentialsFromConfig()
|
|
|
|
{
|
|
|
|
$url = 'http://svn.apache.org';
|
|
|
|
|
|
|
|
$config = new Config();
|
|
|
|
$config->merge(array(
|
|
|
|
'config' => array(
|
|
|
|
'http-basic' => array(
|
2015-09-28 09:51:14 +00:00
|
|
|
'svn.apache.org' => array('username' => 'foo', 'password' => 'bar'),
|
|
|
|
),
|
|
|
|
),
|
2014-05-30 15:14:43 +00:00
|
|
|
));
|
|
|
|
|
|
|
|
$svn = new Svn($url, new NullIO, $config);
|
|
|
|
$reflMethod = new \ReflectionMethod('Composer\\Util\\Svn', 'getCredentialString');
|
|
|
|
$reflMethod->setAccessible(true);
|
|
|
|
|
|
|
|
$this->assertEquals($this->getCmd(" --username 'foo' --password 'bar' "), $reflMethod->invoke($svn));
|
|
|
|
}
|
|
|
|
|
2014-09-15 11:21:33 +00:00
|
|
|
public function testCredentialsFromConfigWithCacheCredentialsTrue()
|
|
|
|
{
|
2014-09-11 09:48:24 +00:00
|
|
|
$url = 'http://svn.apache.org';
|
|
|
|
|
|
|
|
$config = new Config();
|
|
|
|
$config->merge(
|
|
|
|
array(
|
|
|
|
'config' => array(
|
|
|
|
'http-basic' => array(
|
2015-09-28 09:51:14 +00:00
|
|
|
'svn.apache.org' => array('username' => 'foo', 'password' => 'bar'),
|
|
|
|
),
|
|
|
|
),
|
2014-09-11 09:48:24 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$svn = new Svn($url, new NullIO, $config);
|
2014-09-16 13:16:55 +00:00
|
|
|
$svn->setCacheCredentials(true);
|
2014-09-11 09:48:24 +00:00
|
|
|
$reflMethod = new \ReflectionMethod('Composer\\Util\\Svn', 'getCredentialString');
|
|
|
|
$reflMethod->setAccessible(true);
|
|
|
|
|
|
|
|
$this->assertEquals($this->getCmd(" --username 'foo' --password 'bar' "), $reflMethod->invoke($svn));
|
|
|
|
}
|
|
|
|
|
2014-09-15 11:21:33 +00:00
|
|
|
public function testCredentialsFromConfigWithCacheCredentialsFalse()
|
|
|
|
{
|
2014-09-11 09:48:24 +00:00
|
|
|
$url = 'http://svn.apache.org';
|
|
|
|
|
|
|
|
$config = new Config();
|
|
|
|
$config->merge(
|
|
|
|
array(
|
|
|
|
'config' => array(
|
|
|
|
'http-basic' => array(
|
2015-09-28 09:51:14 +00:00
|
|
|
'svn.apache.org' => array('username' => 'foo', 'password' => 'bar'),
|
|
|
|
),
|
|
|
|
),
|
2014-09-11 09:48:24 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$svn = new Svn($url, new NullIO, $config);
|
2014-09-16 13:16:55 +00:00
|
|
|
$svn->setCacheCredentials(false);
|
2014-09-11 09:48:24 +00:00
|
|
|
$reflMethod = new \ReflectionMethod('Composer\\Util\\Svn', 'getCredentialString');
|
|
|
|
$reflMethod->setAccessible(true);
|
|
|
|
|
|
|
|
$this->assertEquals($this->getCmd(" --no-auth-cache --username 'foo' --password 'bar' "), $reflMethod->invoke($svn));
|
|
|
|
}
|
|
|
|
|
2013-02-20 15:50:26 +00:00
|
|
|
private function getCmd($cmd)
|
|
|
|
{
|
2016-02-03 21:39:16 +00:00
|
|
|
return Platform::isWindows() ? strtr($cmd, "'", '"') : $cmd;
|
2013-02-20 15:50:26 +00:00
|
|
|
}
|
2012-06-14 10:10:01 +00:00
|
|
|
}
|