FileMetadataMapperTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2022 Carl Schwan <carl@carlschwan.eu>
  5. * @license AGPL-3.0-or-later
  6. *
  7. * This code is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Affero General Public License, version 3,
  9. * as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License, version 3,
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>
  18. *
  19. */
  20. namespace Test\Metadata;
  21. use OC\Metadata\FileMetadataMapper;
  22. use OC\Metadata\FileMetadata;
  23. use PHPUnit\Framework\MockObject\MockObject;
  24. /**
  25. * @group DB
  26. * @package Test\DB\QueryBuilder
  27. */
  28. class FileMetadataMapperTest extends \Test\TestCase {
  29. /** @var IDBConnection */
  30. protected $connection;
  31. /** @var SystemConfig|MockObject */
  32. protected $config;
  33. /** @var FileMetadataMapper|MockObject */
  34. protected $mapper;
  35. protected function setUp(): void {
  36. parent::setUp();
  37. $this->connection = \OC::$server->getDatabaseConnection();
  38. $this->mapper = new FileMetadataMapper($this->connection);
  39. }
  40. public function testFindForGroupForFiles() {
  41. $file1 = new FileMetadata();
  42. $file1->setId(1);
  43. $file1->setGroupName('size');
  44. $file1->setMetadata([]);
  45. $file2 = new FileMetadata();
  46. $file2->setId(2);
  47. $file2->setGroupName('size');
  48. $file2->setMetadata(['width' => 293, 'height' => 23]);
  49. // not added, it's the default
  50. $file3 = new FileMetadata();
  51. $file3->setId(3);
  52. $file3->setGroupName('size');
  53. $file3->setMetadata([]);
  54. $file4 = new FileMetadata();
  55. $file4->setId(4);
  56. $file4->setGroupName('size');
  57. $file4->setMetadata(['complex' => ["yes", "maybe" => 34.0]]);
  58. $this->mapper->insert($file1);
  59. $this->mapper->insert($file2);
  60. $this->mapper->insert($file4);
  61. $files = $this->mapper->findForGroupForFiles([1, 2, 3, 4], 'size');
  62. $this->assertEquals($files[1]->getMetadata(), $file1->getMetadata());
  63. $this->assertEquals($files[2]->getMetadata(), $file2->getMetadata());
  64. $this->assertEquals($files[3]->getMetadata(), $file3->getMetadata());
  65. $this->assertEquals($files[4]->getMetadata(), $file4->getMetadata());
  66. $this->mapper->clear(1);
  67. $this->mapper->clear(2);
  68. $this->mapper->clear(4);
  69. }
  70. }