LocalStorageTest.php 22 KB

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