Add tests

Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
This commit is contained in:
Lukas Reschke 2016-11-02 21:10:51 +01:00
parent 2c4035e806
commit a8b7df9cc1
No known key found for this signature in database
GPG Key ID: B9F6980CF6E759B1
2 changed files with 139 additions and 0 deletions

View File

@ -1216,4 +1216,130 @@ class QueryBuilderTest extends \Test\TestCase {
$this->queryBuilder->getColumnName($column, $prefix) $this->queryBuilder->getColumnName($column, $prefix)
); );
} }
public function testExecuteWithoutLogger() {
$queryBuilder = $this->createMock(\Doctrine\DBAL\Query\QueryBuilder::class);
$queryBuilder
->expects($this->once())
->method('execute')
->willReturn(3);
$this->logger
->expects($this->never())
->method('debug');
$this->config
->expects($this->once())
->method('getValue')
->with('log_query', false)
->willReturn(false);
$this->invokePrivate($this->queryBuilder, 'queryBuilder', [$queryBuilder]);
$this->assertEquals(3, $this->queryBuilder->execute());
}
public function testExecuteWithLoggerAndNamedArray() {
$queryBuilder = $this->createMock(\Doctrine\DBAL\Query\QueryBuilder::class);
$queryBuilder
->expects($this->at(0))
->method('getParameters')
->willReturn([
'foo' => 'bar',
'key' => 'value',
]);
$queryBuilder
->expects($this->at(1))
->method('getSQL')
->willReturn('SELECT * FROM FOO WHERE BAR = ?');
$queryBuilder
->expects($this->once())
->method('execute')
->willReturn(3);
$this->logger
->expects($this->once())
->method('debug')
->with(
'DB QueryBuilder: \'{query}\' with parameters: {params}',
[
'query' => 'SELECT * FROM FOO WHERE BAR = ?',
'params' => 'foo => \'bar\', key => \'value\'',
'app' => 'core',
]
);
$this->config
->expects($this->once())
->method('getValue')
->with('log_query', false)
->willReturn(true);
$this->invokePrivate($this->queryBuilder, 'queryBuilder', [$queryBuilder]);
$this->assertEquals(3, $this->queryBuilder->execute());
}
public function testExecuteWithLoggerAndUnnamedArray() {
$queryBuilder = $this->createMock(\Doctrine\DBAL\Query\QueryBuilder::class);
$queryBuilder
->expects($this->at(0))
->method('getParameters')
->willReturn(['Bar']);
$queryBuilder
->expects($this->at(1))
->method('getSQL')
->willReturn('SELECT * FROM FOO WHERE BAR = ?');
$queryBuilder
->expects($this->once())
->method('execute')
->willReturn(3);
$this->logger
->expects($this->once())
->method('debug')
->with(
'DB QueryBuilder: \'{query}\' with parameters: {params}',
[
'query' => 'SELECT * FROM FOO WHERE BAR = ?',
'params' => '0 => \'Bar\'',
'app' => 'core',
]
);
$this->config
->expects($this->once())
->method('getValue')
->with('log_query', false)
->willReturn(true);
$this->invokePrivate($this->queryBuilder, 'queryBuilder', [$queryBuilder]);
$this->assertEquals(3, $this->queryBuilder->execute());
}
public function testExecuteWithLoggerAndNoParams() {
$queryBuilder = $this->createMock(\Doctrine\DBAL\Query\QueryBuilder::class);
$queryBuilder
->expects($this->at(0))
->method('getParameters')
->willReturn([]);
$queryBuilder
->expects($this->at(1))
->method('getSQL')
->willReturn('SELECT * FROM FOO WHERE BAR = ?');
$queryBuilder
->expects($this->once())
->method('execute')
->willReturn(3);
$this->logger
->expects($this->once())
->method('debug')
->with(
'DB QueryBuilder: \'{query}\'',
[
'query' => 'SELECT * FROM FOO WHERE BAR = ?',
'app' => 'core',
]
);
$this->config
->expects($this->once())
->method('getValue')
->with('log_query', false)
->willReturn(true);
$this->invokePrivate($this->queryBuilder, 'queryBuilder', [$queryBuilder]);
$this->assertEquals(3, $this->queryBuilder->execute());
}
} }

View File

@ -21,6 +21,8 @@
namespace Test\Security\CSRF\TokenStorage; namespace Test\Security\CSRF\TokenStorage;
use OCP\ISession;
class SessionStorageTest extends \Test\TestCase { class SessionStorageTest extends \Test\TestCase {
/** @var \OCP\ISession */ /** @var \OCP\ISession */
private $session; private $session;
@ -106,4 +108,15 @@ class SessionStorageTest extends \Test\TestCase {
->willReturn(false); ->willReturn(false);
$this->assertSame(false, $this->sessionStorage->hasToken()); $this->assertSame(false, $this->sessionStorage->hasToken());
} }
public function testSetSession() {
$session = $this->createMock(ISession::class);
$session
->expects($this->once())
->method('get')
->with('requesttoken')
->willReturn('MyToken');
$this->sessionStorage->setSession($session);
$this->assertSame('MyToken', $this->sessionStorage->getToken());
}
} }