AppDataTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * @copyright 2016 Roeland Jago Douma <roeland@famdouma.nl>
  4. *
  5. * @author Roeland Jago Douma <roeland@famdouma.nl>
  6. *
  7. * @license GNU AGPL version 3 or any later version
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. namespace Test\Files\AppData;
  24. use OC\Files\AppData\AppData;
  25. use OC\SystemConfig;
  26. use OCP\Files\File;
  27. use OCP\Files\Folder;
  28. use OCP\Files\IAppData;
  29. use OCP\Files\IRootFolder;
  30. use OCP\Files\Node;
  31. use OCP\Files\SimpleFS\ISimpleFolder;
  32. class AppDataTest extends \Test\TestCase {
  33. /** @var IRootFolder|\PHPUnit\Framework\MockObject\MockObject */
  34. private $rootFolder;
  35. /** @var SystemConfig|\PHPUnit\Framework\MockObject\MockObject */
  36. private $systemConfig;
  37. /** @var IAppData */
  38. private $appData;
  39. protected function setUp(): void {
  40. parent::setUp();
  41. $this->rootFolder = $this->createMock(IRootFolder::class);
  42. $this->systemConfig = $this->createMock(SystemConfig::class);
  43. $this->appData = new AppData($this->rootFolder, $this->systemConfig, 'myApp');
  44. $this->systemConfig->expects($this->any())
  45. ->method('getValue')
  46. ->with('instanceid', null)
  47. ->willReturn('iid');
  48. }
  49. private function setupAppFolder() {
  50. $appFolder = $this->createMock(Folder::class);
  51. $this->rootFolder->expects($this->any())
  52. ->method('get')
  53. ->with($this->equalTo('appdata_iid/myApp'))
  54. ->willReturn($appFolder);
  55. return $appFolder;
  56. }
  57. public function testGetFolder() {
  58. $folder = $this->createMock(Folder::class);
  59. $this->rootFolder->expects($this->once())
  60. ->method('get')
  61. ->with($this->equalTo('appdata_iid/myApp/folder'))
  62. ->willReturn($folder);
  63. $result = $this->appData->getFolder('folder');
  64. $this->assertInstanceOf(ISimpleFolder::class, $result);
  65. }
  66. public function testNewFolder() {
  67. $appFolder = $this->setupAppFolder();
  68. $folder = $this->createMock(Folder::class);
  69. $appFolder->expects($this->once())
  70. ->method('newFolder')
  71. ->with($this->equalTo('folder'))
  72. ->willReturn($folder);
  73. $result = $this->appData->newFolder('folder');
  74. $this->assertInstanceOf(ISimpleFolder::class, $result);
  75. }
  76. public function testGetDirectoryListing() {
  77. $appFolder = $this->setupAppFolder();
  78. $file = $this->createMock(File::class);
  79. $folder = $this->createMock(Folder::class);
  80. $node = $this->createMock(Node::class);
  81. $appFolder->expects($this->once())
  82. ->method('getDirectoryListing')
  83. ->willReturn([$file, $folder, $node]);
  84. $result = $this->appData->getDirectoryListing();
  85. $this->assertCount(1, $result);
  86. $this->assertInstanceOf(ISimpleFolder::class, $result[0]);
  87. }
  88. }