You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FileMetadataMapperTest.php 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. /**
  24. * @group DB
  25. * @package Test\DB\QueryBuilder
  26. */
  27. class FileMetadataMapperTest extends \Test\TestCase {
  28. /** @var IDBConnection */
  29. protected $connection;
  30. /** @var SystemConfig|\PHPUnit\Framework\MockObject\MockObject */
  31. protected $config;
  32. protected function setUp(): void {
  33. parent::setUp();
  34. $this->connection = \OC::$server->getDatabaseConnection();
  35. $this->mapper = new FileMetadataMapper($this->connection);
  36. }
  37. public function testFindForGroupForFiles() {
  38. $file1 = new FileMetadata();
  39. $file1->setId(1);
  40. $file1->setGroupName('size');
  41. $file1->setMetadata([]);
  42. $file2 = new FileMetadata();
  43. $file2->setId(2);
  44. $file2->setGroupName('size');
  45. $file2->setMetadata(['width' => 293, 'height' => 23]);
  46. // not added, it's the default
  47. $file3 = new FileMetadata();
  48. $file3->setId(3);
  49. $file3->setGroupName('size');
  50. $file3->setMetadata([]);
  51. $file4 = new FileMetadata();
  52. $file4->setId(4);
  53. $file4->setGroupName('size');
  54. $file4->setMetadata(['complex' => ["yes", "maybe" => 34.0]]);
  55. $this->mapper->insert($file1);
  56. $this->mapper->insert($file2);
  57. $this->mapper->insert($file4);
  58. $files = $this->mapper->findForGroupForFiles([1, 2, 3, 4], 'size');
  59. $this->assertEquals($files[1]->getMetadata(), $file1->getMetadata());
  60. $this->assertEquals($files[2]->getMetadata(), $file2->getMetadata());
  61. $this->assertEquals($files[3]->getMetadata(), $file3->getMetadata());
  62. $this->assertEquals($files[4]->getMetadata(), $file4->getMetadata());
  63. $this->mapper->clear(1);
  64. $this->mapper->clear(2);
  65. $this->mapper->clear(4);
  66. }
  67. }