diff options
-rw-r--r-- | tests/lib/DB/QueryBuilder/QueryBuilderTest.php | 126 | ||||
-rw-r--r-- | tests/lib/Security/CSRF/TokenStorage/SessionStorageTest.php | 13 |
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()); + } } |