Skip to content

Commit

Permalink
Also test setPasswordFile and setServer explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
kenguest committed Jan 27, 2012
1 parent 3f5390f commit bb02714
Showing 1 changed file with 81 additions and 1 deletion.
82 changes: 81 additions & 1 deletion tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function testConfig()
*
* @return void
*/
public function testConfig2()
public function testUnknownConfig()
{
$mock = new HTTP_Request2_Adapter_Mock();
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb'));
Expand Down Expand Up @@ -167,6 +167,16 @@ public function testSetServer()
$this->assertEquals($config, 'http://example.com');
}

public function testSetServerExplicitMethod()
{
$mock = new HTTP_Request2_Adapter_Mock();
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb'));
$osm = new Services_Openstreetmap(array('adapter' => $mock));
$osm->getConfig()->setServer('http://example.com');
$config = $osm->getConfig()->getValue('server');
$this->assertEquals($config, 'http://example.com');
}

public function testSetPasswordFile()
{
$mock = new HTTP_Request2_Adapter_Mock();
Expand All @@ -179,6 +189,18 @@ public function testSetPasswordFile()
$this->assertEquals($config, __DIR__ . '/files/pwd_1line');
}

public function testSetPasswordFileExplicitMethod()
{
$mock = new HTTP_Request2_Adapter_Mock();
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb'));

$osm = new Services_Openstreetmap(array('adapter' => $mock));
$cobj = $osm->getConfig();
$cobj->setPasswordfile( __DIR__ . '/files/pwd_1line');
$config = $cobj->getValue('passwordfile');
$this->assertEquals($config, __DIR__ . '/files/pwd_1line');
}

/**
* @expectedException Services_Openstreetmap_Exception
* @expectedExceptionMessage Could not read password file
Expand All @@ -194,6 +216,21 @@ public function testSetNonExistingPasswordFile()
$osm->getConfig()->setValue('passwordfile', __DIR__ . '/files/credentels');
}

/**
* @expectedException Services_Openstreetmap_Exception
* @expectedExceptionMessage Could not read password file
*
* @return void
*/
public function testSetNonExistingPasswordFileExplicitMethod()
{
$mock = new HTTP_Request2_Adapter_Mock();
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb'));

$osm = new Services_Openstreetmap(array('adapter' => $mock));
$osm->getConfig()->setPasswordfile(__DIR__ . '/files/credentels');
}

public function testEmptyPasswordFile()
{
$mock = new HTTP_Request2_Adapter_Mock();
Expand All @@ -207,6 +244,19 @@ public function testEmptyPasswordFile()
$this->assertNull($osm->getConfig()->getValue('password'));
}

public function testEmptyPasswordFileExplicitMethod()
{
$mock = new HTTP_Request2_Adapter_Mock();
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb'));

$osm = new Services_Openstreetmap(array('adapter' => $mock));
$osm->getConfig()->setPasswordfile(__DIR__ . '/files/pwd_empty');
$config = $osm->getConfig()->getValue('passwordfile');
$this->assertEquals($config, __DIR__ . '/files/pwd_empty');
$this->assertNull($osm->getConfig()->getValue('user'));
$this->assertNull($osm->getConfig()->getValue('password'));
}

public function test1LinePasswordFile()
{
$mock = new HTTP_Request2_Adapter_Mock();
Expand All @@ -219,6 +269,18 @@ public function test1LinePasswordFile()
$this->assertEquals($config->getValue('password'), 'Wilma4evah');
}

public function test1LinePasswordFileExplicitMethod()
{
$mock = new HTTP_Request2_Adapter_Mock();
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb'));

$osm = new Services_Openstreetmap(array('adapter' => $mock));
$osm->getConfig()->setPasswordfile(__DIR__ . '/files/pwd_1line');
$config = $osm->getConfig();
$this->assertEquals($config->getValue('user'), 'fred@example.com');
$this->assertEquals($config->getValue('password'), 'Wilma4evah');
}

public function testMultiLinedPasswordFile()
{
$mock = new HTTP_Request2_Adapter_Mock();
Expand All @@ -236,6 +298,24 @@ public function testMultiLinedPasswordFile()
$config = $osm->getConfig();
$this->assertEquals($config->getValue('password'), 'Wilma4evah');
}

public function testMultiLinedPasswordFileExplicitMethod()
{
$mock = new HTTP_Request2_Adapter_Mock();
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb'));

$osm = new Services_Openstreetmap(
array(
'adapter' => $mock,
'user' => 'fred@example.com'
)
);
$config = $osm->getConfig();
$this->assertEquals($config->getValue('password'), null);
$config->setPasswordfile(__DIR__ . '/files/pwd_multi');
$config = $osm->getConfig();
$this->assertEquals($config->getValue('password'), 'Wilma4evah');
}
}
// vim:set et ts=4 sw=4:
?>

0 comments on commit bb02714

Please sign in to comment.