LocalStorageTest.php 22 KB

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