1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127:
<?php
namespace Nethgui\Test\Unit\Nethgui\System;
class NethPlatformTest extends \PHPUnit_Framework_TestCase
{
protected $object;
private $globalsMock;
protected function setUp()
{
$mockUser = $this->getMockBuilder('\Nethgui\Authorization\UserInterface')
->disableOriginalConstructor()
->setMethods(array('authenticate', 'getAuthorizationAttribute', 'asAuthorizationString','isAuthenticated', 'getCredential', 'getCredentials', 'hasCredential', 'getLanguageCode'))
->getMock();
$mockSession = $this->getMockBuilder('\Nethgui\Utility\SessionInterface')
->disableOriginalConstructor()
->setMethods(array('retrieve', 'store', 'login', 'logout'))
->getMock();
$mockSession->expects($this->atLeastOnce())
->method('retrieve')
->with($this->anything())
->will($this->returnValue(new \ArrayObject()));
$pdpMock = $this->getMock('Nethgui\Authorization\PolicyDecisionPointInterface');
$pdpMock->expects($this->any())
->method('authorize')
->will($this->returnValue(\Nethgui\Authorization\LazyAccessControlResponse::createSuccessResponse()));
$this->globalsMock = $this->getMock('\Nethgui\Utility\PhpWrapper');
$this->object = new \Nethgui\System\NethPlatform($mockUser);
$this->object->setSession($mockSession);
$this->object->setPhpWrapper($this->globalsMock);
$this->object->setPolicyDecisionPoint($pdpMock);
}
public function exec_successCallback($command, &$output, &$retval)
{
$output = array('');
$retval = 0;
return array_slice($output, -1, 1);
}
public function exec_failureCallback($command, &$output, &$retval)
{
$output = array('');
$retval = 128;
return array_slice($output, -1, 1);
}
public function testGetDatabase()
{
$db = $this->object->getDatabase('testdb');
$this->assertInstanceOf('Nethgui\System\EsmithDatabase', $db);
}
public function testSignalEventSuccess()
{
$this->globalsMock
->expects($this->once())
->method('exec')
->with(new \PHPUnit_Framework_Constraint_StringEndsWith("'myEventName'"))
->will($this->returnCallBack(array($this, 'exec_successCallback')));
$process = $this->object->signalEvent("myEventName");
$this->assertEquals(0, $process->getExitCode());
}
public function testSignalEventFail()
{
$this->globalsMock
->expects($this->once())
->method('exec')
->with(new \PHPUnit_Framework_Constraint_StringEndsWith("'myEventName'"))
->will($this->returnCallBack(array($this, 'exec_failureCallback')));
$process = $this->object->signalEvent("myEventName");
$this->assertEquals(128, $process->getExitCode());
}
public function testGetMapAdapter()
{
$adapter = $this->object->getMapAdapter(
array($this, 'readCallback'), array($this, 'writeCallback'), array(
array('testdb', 'testkey1'),
array('testdb', 'testkey2', 'testpropA'),
array('testdb', 'testkey3', 'testpropB'),
)
);
$this->assertInstanceOf('\Nethgui\Adapter\AdapterInterface', $adapter);
}
public function readCallback($key1, $propA, $propB)
{
return implode(',', array($key1, $propA, $propB));
}
public function writeCallback($value)
{
return explode(',', $value);
}
public function testGetIdentityAdapter()
{
$this->assertInstanceOf('\Nethgui\Adapter\AdapterInterface', $this->object->getIdentityAdapter('testdb', 'testkey'));
$this->assertInstanceOf('ArrayAccess', $this->object->getIdentityAdapter('testdb', 'testkey', NULL, ','));
}
}