summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLukas Reschke <lukas@statuscode.ch>2016-11-02 21:10:51 +0100
committerLukas Reschke <lukas@statuscode.ch>2016-11-02 21:10:51 +0100
commita8b7df9cc19991bdb936539950400760dfafd29a (patch)
treeb27d49ee528593d49281157718cea3face001ce2 /tests
parent2c4035e80679b6ebf8e56d86f88701f3ddb65bec (diff)
downloadnextcloud-server-a8b7df9cc19991bdb936539950400760dfafd29a.tar.gz
nextcloud-server-a8b7df9cc19991bdb936539950400760dfafd29a.zip
Add tests
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/DB/QueryBuilder/QueryBuilderTest.php126
-rw-r--r--tests/lib/Security/CSRF/TokenStorage/SessionStorageTest.php13
2 files changed, 139 insertions, 0 deletions
diff --git a/tests/lib/DB/QueryBuilder/QueryBuilderTest.php b/tests/lib/DB/QueryBuilder/QueryBuilderTest.php
index 171b44fe92d..22808f586ef 100644
--- a/tests/lib/DB/QueryBuilder/QueryBuilderTest.php
+++ b/tests/lib/DB/QueryBuilder/QueryBuilderTest.php
@@ -1216,4 +1216,130 @@ class QueryBuilderTest extends \Test\TestCase {
$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());
+ }
}
diff --git a/tests/lib/Security/CSRF/TokenStorage/SessionStorageTest.php b/tests/lib/Security/CSRF/TokenStorage/SessionStorageTest.php
index 550fa49e1b2..d1e76684507 100644
--- a/tests/lib/Security/CSRF/TokenStorage/SessionStorageTest.php
+++ b/tests/lib/Security/CSRF/TokenStorage/SessionStorageTest.php
@@ -21,6 +21,8 @@
namespace Test\Security\CSRF\TokenStorage;
+use OCP\ISession;
+
class SessionStorageTest extends \Test\TestCase {
/** @var \OCP\ISession */
private $session;
@@ -106,4 +108,15 @@ class SessionStorageTest extends \Test\TestCase {
->willReturn(false);
$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());
+ }
}