diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/db/querybuilder/querybuildertest.php | 83 | ||||
-rw-r--r-- | tests/lib/security/trusteddomainhelper.php | 2 | ||||
-rw-r--r-- | tests/lib/systemtag/systemtagmanagertest.php | 6 | ||||
-rw-r--r-- | tests/lib/systemtag/systemtagobjectmappertest.php | 2 | ||||
-rw-r--r-- | tests/lib/util.php | 18 |
5 files changed, 96 insertions, 15 deletions
diff --git a/tests/lib/db/querybuilder/querybuildertest.php b/tests/lib/db/querybuilder/querybuildertest.php index ca3901ad049..c8e029d9e40 100644 --- a/tests/lib/db/querybuilder/querybuildertest.php +++ b/tests/lib/db/querybuilder/querybuildertest.php @@ -48,12 +48,12 @@ class QueryBuilderTest extends \Test\TestCase { $this->queryBuilder = new QueryBuilder($this->connection); } - protected function createTestingRows() { + protected function createTestingRows($appId = 'testFirstResult') { $qB = $this->connection->getQueryBuilder(); for ($i = 1; $i < 10; $i++) { $qB->insert('*PREFIX*appconfig') ->values([ - 'appid' => $qB->expr()->literal('testFirstResult'), + 'appid' => $qB->expr()->literal($appId), 'configkey' => $qB->expr()->literal('testing' . $i), 'configvalue' => $qB->expr()->literal(100 - $i), ]) @@ -80,11 +80,11 @@ class QueryBuilderTest extends \Test\TestCase { return $rows; } - protected function deleteTestingRows() { + protected function deleteTestingRows($appId = 'testFirstResult') { $qB = $this->connection->getQueryBuilder(); $qB->delete('*PREFIX*appconfig') - ->where($qB->expr()->eq('appid', $qB->expr()->literal('testFirstResult'))) + ->where($qB->expr()->eq('appid', $qB->expr()->literal($appId))) ->execute(); } @@ -272,6 +272,34 @@ class QueryBuilderTest extends \Test\TestCase { $this->deleteTestingRows(); } + public function testSelectDistinct() { + $this->deleteTestingRows('testFirstResult1'); + $this->deleteTestingRows('testFirstResult2'); + $this->createTestingRows('testFirstResult1'); + $this->createTestingRows('testFirstResult2'); + + $this->queryBuilder->selectDistinct('appid'); + + $this->queryBuilder->from('*PREFIX*appconfig') + ->where($this->queryBuilder->expr()->in( + 'appid', + [$this->queryBuilder->expr()->literal('testFirstResult1'), $this->queryBuilder->expr()->literal('testFirstResult2')] + )) + ->orderBy('appid', 'DESC'); + + $query = $this->queryBuilder->execute(); + $rows = $query->fetchAll(); + $query->closeCursor(); + + $this->assertEquals( + [['appid' => 'testFirstResult2'], ['appid' => 'testFirstResult1']], + $rows + ); + + $this->deleteTestingRows('testFirstResult1'); + $this->deleteTestingRows('testFirstResult2'); + } + public function dataAddSelect() { $queryBuilder = new QueryBuilder(\OC::$server->getDatabaseConnection()); return [ @@ -1086,6 +1114,31 @@ class QueryBuilderTest extends \Test\TestCase { ); } + public function testGetLastInsertId() { + $qB = $this->connection->getQueryBuilder(); + + try { + $qB->getLastInsertId(); + $this->fail('getLastInsertId() should throw an exception, when being called before insert()'); + } catch (\BadMethodCallException $e) { + $this->assertTrue(true); + } + + $qB->insert('appconfig') + ->values([ + 'appid' => $qB->expr()->literal('testFirstResult'), + 'configkey' => $qB->expr()->literal('testing' . 50), + 'configvalue' => $qB->expr()->literal(100 - 50), + ]) + ->execute(); + + $actual = $qB->getLastInsertId(); + + $this->assertNotNull($actual); + $this->assertInternalType('int', $actual); + $this->assertEquals($this->connection->lastInsertId('*PREFIX*appconfig'), $actual); + } + public function dataGetTableName() { return [ ['*PREFIX*table', null, '`*PREFIX*table`'], @@ -1112,7 +1165,27 @@ class QueryBuilderTest extends \Test\TestCase { $this->assertSame( $expected, - $this->invokePrivate($this->queryBuilder, 'getTableName', [$tableName]) + $this->queryBuilder->getTableName($tableName) + ); + } + + public function dataGetColumnName() { + return [ + ['column', '', '`column`'], + ['column', 'a', 'a.`column`'], + ]; + } + + /** + * @dataProvider dataGetColumnName + * @param string $column + * @param string $prefix + * @param string $expected + */ + public function testGetColumnName($column, $prefix, $expected) { + $this->assertSame( + $expected, + $this->queryBuilder->getColumnName($column, $prefix) ); } } diff --git a/tests/lib/security/trusteddomainhelper.php b/tests/lib/security/trusteddomainhelper.php index c8d5ffa587b..52a8f1be630 100644 --- a/tests/lib/security/trusteddomainhelper.php +++ b/tests/lib/security/trusteddomainhelper.php @@ -64,6 +64,8 @@ class TrustedDomainHelperTest extends \Test\TestCase { // do not trust invalid localhosts [$trustedHostTestList, 'localhost:1:2', false], [$trustedHostTestList, 'localhost: evil.host', false], + // do not trust casting + [[1], '1', false], ]; } diff --git a/tests/lib/systemtag/systemtagmanagertest.php b/tests/lib/systemtag/systemtagmanagertest.php index 8498b85519f..97c072f33f6 100644 --- a/tests/lib/systemtag/systemtagmanagertest.php +++ b/tests/lib/systemtag/systemtagmanagertest.php @@ -250,7 +250,7 @@ class SystemTagManagerTest extends TestCase { $tag1 = $this->tagManager->createTag('one', true, false); $tag2 = $this->tagManager->createTag('two', false, true); - $tagList = $this->tagManager->getTagsById([$tag1->getId(), $tag2->getId()]); + $tagList = $this->tagManager->getTagsByIds([$tag1->getId(), $tag2->getId()]); $this->assertCount(2, $tagList); @@ -270,7 +270,7 @@ class SystemTagManagerTest extends TestCase { */ public function testGetNonExistingTagsById() { $tag1 = $this->tagManager->createTag('one', true, false); - $this->tagManager->getTagsById([$tag1->getId(), 100, 101]); + $this->tagManager->getTagsByIds([$tag1->getId(), 100, 101]); } /** @@ -278,7 +278,7 @@ class SystemTagManagerTest extends TestCase { */ public function testGetInvalidTagIdFormat() { $tag1 = $this->tagManager->createTag('one', true, false); - $this->tagManager->getTagsById([$tag1->getId() . 'suffix']); + $this->tagManager->getTagsByIds([$tag1->getId() . 'suffix']); } public function updateTagProvider() { diff --git a/tests/lib/systemtag/systemtagobjectmappertest.php b/tests/lib/systemtag/systemtagobjectmappertest.php index 43d0b8c6960..4ea80c216ed 100644 --- a/tests/lib/systemtag/systemtagobjectmappertest.php +++ b/tests/lib/systemtag/systemtagobjectmappertest.php @@ -74,7 +74,7 @@ class SystemTagObjectMapperTest extends TestCase { $this->tag3 = new SystemTag(3, 'testtag3', false, false); $this->tagManager->expects($this->any()) - ->method('getTagsById') + ->method('getTagsByIds') ->will($this->returnCallback(function($tagIds) { $result = []; if (in_array(1, $tagIds)) { diff --git a/tests/lib/util.php b/tests/lib/util.php index 9b82be36955..fa559c17c80 100644 --- a/tests/lib/util.php +++ b/tests/lib/util.php @@ -95,16 +95,22 @@ class Test_Util extends \Test\TestCase { } function testSanitizeHTML() { - $badArray = array( + $badArray = [ 'While it is unusual to pass an array', 'this function actually <blink>supports</blink> it.', - 'And therefore there needs to be a <script>alert("Unit"+\'test\')</script> for it!' - ); - $goodArray = array( + 'And therefore there needs to be a <script>alert("Unit"+\'test\')</script> for it!', + [ + 'And It Even May <strong>Nest</strong>', + ], + ]; + $goodArray = [ 'While it is unusual to pass an array', 'this function actually <blink>supports</blink> it.', - 'And therefore there needs to be a <script>alert("Unit"+'test')</script> for it!' - ); + 'And therefore there needs to be a <script>alert("Unit"+'test')</script> for it!', + [ + 'And It Even May <strong>Nest</strong>' + ], + ]; $result = OC_Util::sanitizeHTML($badArray); $this->assertEquals($goodArray, $result); |