LocalStorageTest.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. <?php
  2. namespace App\Tests\Unit\Service\File\Storage;
  3. use App\Entity\Access\Access;
  4. use App\Entity\Core\File;
  5. use App\Entity\Organization\Organization;
  6. use App\Entity\Person\Person;
  7. use App\Enum\Core\FileStatusEnum;
  8. use App\Enum\Core\FileTypeEnum;
  9. use App\Enum\Core\FileVisibilityEnum;
  10. use App\Repository\Access\AccessRepository;
  11. use App\Service\File\Factory\ImageFactory;
  12. use App\Service\File\Storage\LocalStorage;
  13. use App\Service\Utils\FileUtils;
  14. use App\Service\Utils\UrlBuilder;
  15. use Doctrine\ORM\EntityManagerInterface;
  16. use Gaufrette\Filesystem;
  17. use JetBrains\PhpStorm\Pure;
  18. use Knp\Bundle\GaufretteBundle\FilesystemMap;
  19. use Liip\ImagineBundle\Imagine\Cache\CacheManager;
  20. use Liip\ImagineBundle\Imagine\Data\DataManager;
  21. use PHPUnit\Framework\MockObject\MockObject;
  22. use PHPUnit\Framework\TestCase;
  23. class TestableLocalStorage extends LocalStorage
  24. {
  25. public const FS_KEY = parent::FS_KEY;
  26. public function getPrefix(mixed $owner, bool $isTemporary, ?FileTypeEnum $type = null): string
  27. {
  28. return parent::getPrefix($owner, $isTemporary, $type);
  29. }
  30. #[Pure]
  31. public function getOrganizationAndPersonFromOwner(mixed $owner): array
  32. {
  33. return parent::getOrganizationAndPersonFromOwner($owner);
  34. }
  35. }
  36. class LocalStorageTest extends TestCase
  37. {
  38. private FilesystemMap $filesystemMap;
  39. private EntityManagerInterface $entityManager;
  40. private AccessRepository $accessRepository;
  41. private DataManager $dataManager;
  42. private CacheManager $cacheManager;
  43. private ImageFactory $imageFactory;
  44. private Filesystem $filesystem;
  45. private FileUtils $fileUtils;
  46. private UrlBuilder $urlBuilder;
  47. public function setUp(): void
  48. {
  49. $this->filesystemMap = $this->getMockBuilder(FilesystemMap::class)->disableOriginalConstructor()->getMock();
  50. $this->entityManager = $this->getMockBuilder(EntityManagerInterface::class)->disableOriginalConstructor()->getMock();
  51. $this->accessRepository = $this->getMockBuilder(AccessRepository::class)->disableOriginalConstructor()->getMock();
  52. $this->dataManager = $this->getMockBuilder(DataManager::class)->disableOriginalConstructor()->getMock();
  53. $this->cacheManager = $this->getMockBuilder(CacheManager::class)->disableOriginalConstructor()->getMock();
  54. $this->imageFactory = $this->getMockBuilder(ImageFactory::class)->disableOriginalConstructor()->getMock();
  55. $this->fileUtils = $this->getMockBuilder(FileUtils::class)->disableOriginalConstructor()->getMock();
  56. $this->urlBuilder = $this->getMockBuilder(UrlBuilder::class)->disableOriginalConstructor()->getMock();
  57. $this->filesystem = $this->getMockBuilder(Filesystem::class)->disableOriginalConstructor()->getMock();
  58. $this->filesystemMap->method('get')->with(TestableLocalStorage::FS_KEY)->willReturn($this->filesystem);
  59. }
  60. public function getMockForMethod(string $methodName): TestableLocalStorage|MockObject
  61. {
  62. return $this->getMockBuilder(TestableLocalStorage::class)
  63. ->setConstructorArgs([
  64. $this->filesystemMap,
  65. $this->entityManager,
  66. $this->accessRepository,
  67. $this->dataManager,
  68. $this->cacheManager,
  69. $this->imageFactory,
  70. $this->fileUtils,
  71. $this->urlBuilder,
  72. ])
  73. ->setMethodsExcept([$methodName])
  74. ->getMock();
  75. }
  76. /**
  77. * @see LocalStorage::exists()
  78. */
  79. public function testExists(): void
  80. {
  81. $fileStorage = $this->getMockForMethod('exists');
  82. $file = $this->getMockBuilder(File::class)->getMock();
  83. $file->method('getSlug')->willReturn('foo');
  84. $this->filesystem->expects(self::once())->method('has')->with('foo')->willReturn(true);
  85. $this->assertTrue($fileStorage->exists($file));
  86. }
  87. /**
  88. * @see LocalStorage::exists()
  89. */
  90. public function testExistsInexistant(): void
  91. {
  92. $fileStorage = $this->getMockForMethod('exists');
  93. $file = $this->getMockBuilder(File::class)->getMock();
  94. $file->method('getSlug')->willReturn('foo');
  95. $this->filesystem->expects(self::once())->method('has')->with('foo')->willReturn(false);
  96. $this->assertFalse($fileStorage->exists($file));
  97. }
  98. /**
  99. * @see LocalStorage::listByOwner()
  100. */
  101. public function testListByOwner(): void
  102. {
  103. $fileStorage = $this->getMockForMethod('listByOwner');
  104. $owner = $this->getMockBuilder(Organization::class)->getMock();
  105. $fileStorage->method('getPrefix')->with($owner, false, FileTypeEnum::LICENCE_CMF)->willReturn('foo');
  106. $this->filesystem->method('listKeys')->with('foo')->willReturn(['foo/a.txt', 'foo/b.pdf']);
  107. $this->assertEquals(
  108. ['foo/a.txt', 'foo/b.pdf'],
  109. $fileStorage->listByOwner($owner, FileTypeEnum::LICENCE_CMF)
  110. );
  111. }
  112. /**
  113. * @see LocalStorage::read()
  114. */
  115. public function testReadPdf(): void
  116. {
  117. $fileStorage = $this->getMockForMethod('read');
  118. $file = $this->getMockBuilder(File::class)->getMock();
  119. $file->method('getSlug')->willReturn('foo');
  120. $this->filesystem->method('read')->with('foo')->willReturn('12345679');
  121. $this->assertEquals(
  122. '12345679',
  123. $fileStorage->read($file)
  124. );
  125. }
  126. /**
  127. * @see LocalStorage::prepareFile()
  128. */
  129. public function testPrepareFile(): void
  130. {
  131. $fileStorage = $this->getMockForMethod('prepareFile');
  132. $owner = $this->getMockBuilder(Organization::class)->getMock();
  133. $author = $this->getMockBuilder(Access::class)->getMock();
  134. $author->method('getId')->willReturn(123);
  135. $fileStorage->method('getOrganizationAndPersonFromOwner')->with($owner)->willReturn([$owner, null]);
  136. $this->entityManager->expects(self::once())->method('persist');
  137. $this->entityManager->expects(self::once())->method('flush');
  138. $file = $fileStorage->prepareFile(
  139. $owner,
  140. 'file.ext',
  141. FileTypeEnum::LICENCE_CMF,
  142. $author,
  143. true,
  144. FileVisibilityEnum::ONLY_ORGANIZATION,
  145. 'application/pdf'
  146. );
  147. $this->assertEquals($owner, $file->getOrganization());
  148. $this->assertEquals(null, $file->getPerson());
  149. $this->assertEquals('file.ext', $file->getName());
  150. $this->assertEquals(null, $file->getSlug());
  151. $this->assertEquals(FileTypeEnum::LICENCE_CMF, $file->getType());
  152. $this->assertTrue($file->getIsTemporaryFile());
  153. $this->assertEquals(FileVisibilityEnum::ONLY_ORGANIZATION, $file->getVisibility());
  154. $this->assertEquals('application/pdf', $file->getMimeType());
  155. $this->assertEquals(123, $file->getCreatedBy());
  156. }
  157. /**
  158. * @see LocalStorage::prepareFile()
  159. */
  160. public function testPrepareFileDefaultValues(): void
  161. {
  162. $fileStorage = $this->getMockForMethod('prepareFile');
  163. $owner = $this->getMockBuilder(Person::class)->getMock();
  164. $author = $this->getMockBuilder(Access::class)->getMock();
  165. $fileStorage->method('getOrganizationAndPersonFromOwner')->with($owner)->willReturn([null, $owner]);
  166. $this->entityManager->expects(self::once())->method('persist');
  167. $this->entityManager->expects(self::once())->method('flush');
  168. $this->fileUtils->method('guessMimeTypeFromFilename')->with('file.txt')->willReturn('text/plain');
  169. $file = $fileStorage->prepareFile($owner, 'file.txt', FileTypeEnum::NONE, $author);
  170. $this->assertEquals(null, $file->getOrganization());
  171. $this->assertEquals($owner, $file->getPerson());
  172. $this->assertEquals('file.txt', $file->getName());
  173. $this->assertEquals(FileTypeEnum::NONE, $file->getType());
  174. $this->assertFalse($file->getIsTemporaryFile());
  175. $this->assertEquals(FileVisibilityEnum::NOBODY, $file->getVisibility());
  176. $this->assertEquals('text/plain', $file->getMimeType());
  177. }
  178. /**
  179. * @see LocalStorage::prepareFile()
  180. */
  181. public function testPrepareFileNoFlush(): void
  182. {
  183. $fileStorage = $this->getMockForMethod('prepareFile');
  184. $owner = $this->getMockBuilder(Organization::class)->getMock();
  185. $author = $this->getMockBuilder(Access::class)->getMock();
  186. $fileStorage->method('getOrganizationAndPersonFromOwner')->with($owner)->willReturn([$owner, null]);
  187. $this->entityManager->expects(self::once())->method('persist');
  188. $this->entityManager->expects(self::never())->method('flush');
  189. $this->fileUtils->method('guessMimeTypeFromFilename')->willReturn('text/plain');
  190. $fileStorage->prepareFile(
  191. $owner,
  192. 'file.txt',
  193. FileTypeEnum::NONE,
  194. $author,
  195. false,
  196. FileVisibilityEnum::NOBODY,
  197. 'text/plain',
  198. false
  199. );
  200. }
  201. /**
  202. * @see LocalStorage::write()
  203. */
  204. public function testWriteNewFile(): void
  205. {
  206. $fileStorage = $this->getMockForMethod('write');
  207. $organization = $this->getMockBuilder(Organization::class)->getMock();
  208. $author = $this->getMockBuilder(Access::class)->getMock();
  209. $author->method('getId')->willReturn(123);
  210. $file = $this->getMockBuilder(File::class)->getMock();
  211. $file->method('getName')->willReturn('foo.txt');
  212. $file->method('getOrganization')->willReturn($organization);
  213. $file->method('getPerson')->willReturn(null);
  214. $file->method('getIsTemporaryFile')->willReturn(false);
  215. $file->method('getSlug')->willReturn(null);
  216. $file->method('getType')->willReturn(FileTypeEnum::NONE);
  217. $fileStorage
  218. ->method('getPrefix')
  219. ->with($organization, false, FileTypeEnum::NONE)
  220. ->willReturn('prefix/');
  221. $content = '123456789';
  222. $size = strlen($content);
  223. $this->filesystem
  224. ->expects(self::once())
  225. ->method('write')
  226. ->with(self::matchesRegularExpression('/^prefix\/\w{16,24}\/foo.txt/'), $content, true)
  227. ->willReturn($size);
  228. $file->expects(self::once())->method('setSize')->with($size)->willReturnSelf();
  229. $file->expects(self::once())->method('setStatus')->with(FileStatusEnum::READY)->willReturnSelf();
  230. $file->expects(self::once())
  231. ->method('setSlug')
  232. ->with(self::matchesRegularExpression('/^prefix\/\w{16,24}\/foo.txt/'))
  233. ->willReturnSelf();
  234. $file->expects(self::once())->method('setCreateDate')->with(self::isInstanceOf(\DateTime::class))->willReturnSelf();
  235. $file->expects(self::once())->method('setCreatedBy')->with(123)->willReturnSelf();
  236. $file->expects(self::never())->method('setUpdateDate');
  237. $file->expects(self::never())->method('setUpdatedBy');
  238. $this->entityManager->expects(self::once())->method('flush');
  239. $returned = $fileStorage->write($file, $content, $author);
  240. $this->assertSame($file, $returned);
  241. }
  242. /**
  243. * @see LocalStorage::write()
  244. */
  245. public function testWriteExistingFile(): void
  246. {
  247. $fileStorage = $this->getMockForMethod('write');
  248. $person = $this->getMockBuilder(Person::class)->getMock();
  249. $author = $this->getMockBuilder(Access::class)->getMock();
  250. $author->method('getId')->willReturn(123);
  251. $key = 'prefix/uid/bar.txt';
  252. $file = $this->getMockBuilder(File::class)->getMock();
  253. $file->method('getName')->willReturn('bar.txt');
  254. $file->method('getOrganization')->willReturn(null);
  255. $file->method('getPerson')->willReturn($person);
  256. $file->method('getIsTemporaryFile')->willReturn(true);
  257. $file->method('getSlug')->willReturn($key);
  258. $file->method('getType')->willReturn(FileTypeEnum::NONE);
  259. $fileStorage->expects(self::never())->method('getPrefix');
  260. $content = '123 Soleil';
  261. $size = strlen($content);
  262. $this->filesystem
  263. ->expects(self::once())
  264. ->method('write')
  265. ->with($key, $content, true)
  266. ->willReturn($size);
  267. $this->filesystem->method('has')->with($key)->willReturn(true);
  268. $file->expects(self::once())->method('setSize')->with($size)->willReturnSelf();
  269. $file->expects(self::once())->method('setStatus')->with(FileStatusEnum::READY)->willReturnSelf();
  270. $file->expects(self::never())->method('setSlug');
  271. $file->expects(self::never())->method('setCreateDate');
  272. $file->expects(self::never())->method('setCreatedBy');
  273. $file->expects(self::once())->method('setUpdateDate')->with(self::isInstanceOf(\DateTime::class))->willReturnSelf();
  274. $file->expects(self::once())->method('setUpdatedBy')->with(123)->willReturnSelf();
  275. $this->entityManager->expects(self::once())->method('flush');
  276. $returned = $fileStorage->write($file, $content, $author);
  277. $this->assertEquals($file, $returned);
  278. }
  279. /**
  280. * @see LocalStorage::write()
  281. */
  282. public function testWriteExistingButMissingFile(): void
  283. {
  284. $fileStorage = $this->getMockForMethod('write');
  285. $person = $this->getMockBuilder(Person::class)->getMock();
  286. $author = $this->getMockBuilder(Access::class)->getMock();
  287. $key = 'prefix/uid/bar.txt';
  288. $file = $this->getMockBuilder(File::class)->getMock();
  289. $file->method('getName')->willReturn('bar.txt');
  290. $file->method('getOrganization')->willReturn(null);
  291. $file->method('getPerson')->willReturn($person);
  292. $file->method('getIsTemporaryFile')->willReturn(true);
  293. $file->method('getSlug')->willReturn($key);
  294. $file->method('getType')->willReturn(FileTypeEnum::NONE);
  295. $this->filesystem->expects(self::never())->method('write');
  296. $this->entityManager->expects(self::never())->method('flush');
  297. $this->filesystem->method('has')->with($key)->willReturn(false);
  298. $this->expectException(\RuntimeException::class);
  299. $this->expectExceptionMessage('The file `'.$key.'` does not exist in the file storage');
  300. $fileStorage->write($file, '12346', $author);
  301. }
  302. /**
  303. * @see LocalStorage::write()
  304. */
  305. public function testWriteWithAccessOwner(): void
  306. {
  307. $fileStorage = $this->getMockForMethod('write');
  308. $access = $this->getMockBuilder(Access::class)->getMock();
  309. $person = $this->getMockBuilder(Person::class)->getMock();
  310. $organization = $this->getMockBuilder(Organization::class)->getMock();
  311. $author = $this->getMockBuilder(Access::class)->getMock();
  312. $author->method('getId')->willReturn(123);
  313. $file = $this->getMockBuilder(File::class)->getMock();
  314. $file->method('getName')->willReturn('bar.txt');
  315. $file->method('getOrganization')->willReturn($organization);
  316. $file->method('getPerson')->willReturn($person);
  317. $file->method('getIsTemporaryFile')->willReturn(true);
  318. $file->method('getSlug')->willReturn(null);
  319. $file->method('getType')->willReturn(FileTypeEnum::NONE);
  320. $this->accessRepository
  321. ->expects(self::once())
  322. ->method('findOneBy')
  323. ->with(['organization' => $organization, 'person' => $person])
  324. ->willReturn($access);
  325. $fileStorage
  326. ->expects(self::once())
  327. ->method('getPrefix')
  328. ->with($access, true, FileTypeEnum::NONE)
  329. ->willReturn('prefix/');
  330. $content = '1';
  331. $this->filesystem->method('write')->willReturn(1);
  332. $fileStorage->write($file, $content, $author);
  333. }
  334. /**
  335. * @see LocalStorage::write()
  336. */
  337. public function testWriteWithNoName(): void
  338. {
  339. $fileStorage = $this->getMockForMethod('write');
  340. $author = $this->getMockBuilder(Access::class)->getMock();
  341. $file = $this->getMockBuilder(File::class)->getMock();
  342. $file->method('getName')->willReturn('');
  343. $this->expectException(\RuntimeException::class);
  344. $this->expectExceptionMessage('File has no filename');
  345. $fileStorage->write($file, '...', $author);
  346. }
  347. /**
  348. * @see LocalStorage::makeFile()
  349. */
  350. public function testMakeFile(): void
  351. {
  352. $fileStorage = $this->getMockForMethod('makeFile');
  353. $organization = $this->getMockBuilder(Organization::class)->getMock();
  354. $author = $this->getMockBuilder(Access::class)->getMock();
  355. $file = $this->getMockBuilder(File::class)->getMock();
  356. $fileStorage
  357. ->expects(self::once())
  358. ->method('prepareFile')
  359. ->with($organization, 'foo.txt', FileTypeEnum::NONE, $author, true, FileVisibilityEnum::ONLY_ORGANIZATION, 'mime/type')
  360. ->willReturn($file);
  361. $fileStorage
  362. ->expects(self::once())
  363. ->method('write')
  364. ->with($file, '...', $author)
  365. ->willReturn($file);
  366. $fileStorage->makeFile(
  367. $organization,
  368. 'foo.txt',
  369. FileTypeEnum::NONE,
  370. '...',
  371. $author,
  372. true,
  373. FileVisibilityEnum::ONLY_ORGANIZATION,
  374. 'mime/type');
  375. }
  376. /**
  377. * @see LocalStorage::softDelete()
  378. */
  379. public function testSoftdelete(): void
  380. {
  381. $fileStorage = $this->getMockForMethod('softDelete');
  382. $author = $this->getMockBuilder(Access::class)->getMock();
  383. $author->method('getId')->willReturn(123);
  384. $file = $this->getMockBuilder(File::class)->getMock();
  385. $file->method('getSlug')->willReturn('key');
  386. $file->expects(self::once())->method('setStatus')->with(FileStatusEnum::DELETED)->willReturnSelf();
  387. $file->expects(self::once())->method('setSize')->with(0)->willReturnSelf();
  388. $file->expects(self::once())->method('setUpdatedBy')->with(123)->willReturnSelf();
  389. $returned = $fileStorage->softDelete($file, $author);
  390. $this->assertEquals($file, $returned);
  391. }
  392. /**
  393. * @see LocalStorage::hardDelete()
  394. */
  395. public function testHardDelete(): void
  396. {
  397. $fileStorage = $this->getMockForMethod('hardDelete');
  398. $file = $this->getMockBuilder(File::class)->getMock();
  399. $file->method('getSlug')->willReturn('key');
  400. $this->filesystem->expects(self::once())->method('delete')->with('key')->willReturn(true);
  401. $fileStorage->hardDelete($file);
  402. }
  403. /**
  404. * @see LocalStorage::hardDelete()
  405. */
  406. public function testHardDeleteFailed(): void
  407. {
  408. $fileStorage = $this->getMockForMethod('hardDelete');
  409. $file = $this->getMockBuilder(File::class)->getMock();
  410. $file->method('getSlug')->willReturn('key');
  411. $this->filesystem->expects(self::once())->method('delete')->with('key')->willReturn(false);
  412. $this->expectException(\RuntimeException::class);
  413. $this->expectExceptionMessage('File `'.$file->getSlug().'` could\'nt be deleted');
  414. $fileStorage->hardDelete($file);
  415. }
  416. /**
  417. * @see LocalStorage::getPrefix()
  418. */
  419. public function testGetPrefixAccess(): void
  420. {
  421. $fileStorage = $this->getMockForMethod('getPrefix');
  422. $organization = $this->getMockBuilder(Organization::class)->getMock();
  423. $organization->method('getId')->willReturn(2);
  424. $access = $this->getMockBuilder(Access::class)->getMock();
  425. $access->method('getOrganization')->willReturn($organization);
  426. $access->method('getId')->willReturn(1);
  427. $prefix = $fileStorage->getPrefix($access, false);
  428. $this->assertEquals('organization/2/1', $prefix);
  429. }
  430. /**
  431. * @see LocalStorage::getPrefix()
  432. */
  433. public function testGetPrefixOrganization(): void
  434. {
  435. $fileStorage = $this->getMockForMethod('getPrefix');
  436. $organization = $this->getMockBuilder(Organization::class)->getMock();
  437. $organization->method('getId')->willReturn(1);
  438. $prefix = $fileStorage->getPrefix($organization, false);
  439. $this->assertEquals('organization/1', $prefix);
  440. }
  441. /**
  442. * @see LocalStorage::getPrefix()
  443. */
  444. public function testGetPrefixPerson(): void
  445. {
  446. $fileStorage = $this->getMockForMethod('getPrefix');
  447. $person = $this->getMockBuilder(Person::class)->getMock();
  448. $person->method('getId')->willReturn(1);
  449. $prefix = $fileStorage->getPrefix($person, false);
  450. $this->assertEquals('person/1', $prefix);
  451. }
  452. /**
  453. * @see LocalStorage::getPrefix()
  454. */
  455. public function testGetPrefixTemp(): void
  456. {
  457. $fileStorage = $this->getMockForMethod('getPrefix');
  458. $organization = $this->getMockBuilder(Organization::class)->getMock();
  459. $organization->method('getId')->willReturn(1);
  460. $prefix = $fileStorage->getPrefix($organization, true);
  461. $this->assertEquals('temp/organization/1', $prefix);
  462. }
  463. /**
  464. * @see LocalStorage::getPrefix()
  465. */
  466. public function testGetPrefixWithType(): void
  467. {
  468. $fileStorage = $this->getMockForMethod('getPrefix');
  469. $organization = $this->getMockBuilder(Organization::class)->getMock();
  470. $organization->method('getId')->willReturn(1);
  471. $prefix = $fileStorage->getPrefix($organization, false, FileTypeEnum::LICENCE_CMF);
  472. $this->assertEquals('organization/1/licence_cmf', $prefix);
  473. }
  474. /**
  475. * @see LocalStorage::getOrganizationAndPersonFromOwner()
  476. */
  477. public function testGetOrganizationAndPersonFromOwner(): void
  478. {
  479. $fileStorage = $this->getMockForMethod('getOrganizationAndPersonFromOwner');
  480. $organization = $this->getMockBuilder(Organization::class)->getMock();
  481. $organization->method('getId')->willReturn(2);
  482. $person = $this->getMockBuilder(Person::class)->getMock();
  483. $person->method('getId')->willReturn(1);
  484. $access = $this->getMockBuilder(Access::class)->getMock();
  485. $access->method('getOrganization')->willReturn($organization);
  486. $access->method('getPerson')->willReturn($person);
  487. $access->method('getId')->willReturn(1);
  488. $this->assertEquals([$organization, $person], $fileStorage->getOrganizationAndPersonFromOwner($access));
  489. $this->assertEquals([$organization, null], $fileStorage->getOrganizationAndPersonFromOwner($organization));
  490. $this->assertEquals([null, $person], $fileStorage->getOrganizationAndPersonFromOwner($person));
  491. }
  492. }