1
0

AppDataTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. public function setUp() {
  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. $dataFolder = $this->createMock(Folder::class);
  51. $appFolder = $this->createMock(Folder::class);
  52. $this->rootFolder->expects($this->once())
  53. ->method('get')
  54. ->with($this->equalTo('appdata_iid'))
  55. ->willReturn($dataFolder);
  56. $dataFolder->expects($this->once())
  57. ->method('get')
  58. ->with($this->equalTo('myApp'))
  59. ->willReturn($appFolder);
  60. return [$dataFolder, $appFolder];
  61. }
  62. public function testGetFolder() {
  63. $folders = $this->setupAppFolder();
  64. $appFolder = $folders[1];
  65. $folder = $this->createMock(Folder::class);
  66. $appFolder->expects($this->once())
  67. ->method('get')
  68. ->with($this->equalTo('folder'))
  69. ->willReturn($folder);
  70. $result = $this->appData->getFolder('folder');
  71. $this->assertInstanceOf(ISimpleFolder::class, $result);
  72. }
  73. public function testNewFolder() {
  74. $folders = $this->setupAppFolder();
  75. $appFolder = $folders[1];
  76. $folder = $this->createMock(Folder::class);
  77. $appFolder->expects($this->once())
  78. ->method('newFolder')
  79. ->with($this->equalTo('folder'))
  80. ->willReturn($folder);
  81. $result = $this->appData->newFolder('folder');
  82. $this->assertInstanceOf(ISimpleFolder::class, $result);
  83. }
  84. public function testGetDirectoryListing() {
  85. $folders = $this->setupAppFolder();
  86. $appFolder = $folders[1];
  87. $file = $this->createMock(File::class);
  88. $folder = $this->createMock(Folder::class);
  89. $node = $this->createMock(Node::class);
  90. $appFolder->expects($this->once())
  91. ->method('getDirectoryListing')
  92. ->willReturn([$file, $folder, $node]);
  93. $result = $this->appData->getDirectoryListing();
  94. $this->assertCount(1, $result);
  95. $this->assertInstanceOf(ISimpleFolder::class, $result[0]);
  96. }
  97. }