blob: 241e49a026f5b163a5c097985e84ad4f36e11bb7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
<?php
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test\Files\AppData;
use OC\Files\AppData\AppData;
use OC\SystemConfig;
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\IAppData;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
use OCP\Files\SimpleFS\ISimpleFolder;
class AppDataTest extends \Test\TestCase {
/** @var IRootFolder|\PHPUnit\Framework\MockObject\MockObject */
private $rootFolder;
/** @var SystemConfig|\PHPUnit\Framework\MockObject\MockObject */
private $systemConfig;
/** @var IAppData */
private $appData;
protected function setUp(): void {
parent::setUp();
$this->rootFolder = $this->createMock(IRootFolder::class);
$this->systemConfig = $this->createMock(SystemConfig::class);
$this->appData = new AppData($this->rootFolder, $this->systemConfig, 'myApp');
$this->systemConfig->expects($this->any())
->method('getValue')
->with('instanceid', null)
->willReturn('iid');
}
private function setupAppFolder() {
$appFolder = $this->createMock(Folder::class);
$this->rootFolder->expects($this->any())
->method('get')
->with($this->equalTo('appdata_iid/myApp'))
->willReturn($appFolder);
return $appFolder;
}
public function testGetFolder() {
$folder = $this->createMock(Folder::class);
$this->rootFolder->expects($this->once())
->method('get')
->with($this->equalTo('appdata_iid/myApp/folder'))
->willReturn($folder);
$result = $this->appData->getFolder('folder');
$this->assertInstanceOf(ISimpleFolder::class, $result);
}
public function testNewFolder() {
$appFolder = $this->setupAppFolder();
$folder = $this->createMock(Folder::class);
$appFolder->expects($this->once())
->method('newFolder')
->with($this->equalTo('folder'))
->willReturn($folder);
$result = $this->appData->newFolder('folder');
$this->assertInstanceOf(ISimpleFolder::class, $result);
}
public function testGetDirectoryListing() {
$appFolder = $this->setupAppFolder();
$file = $this->createMock(File::class);
$folder = $this->createMock(Folder::class);
$node = $this->createMock(Node::class);
$appFolder->expects($this->once())
->method('getDirectoryListing')
->willReturn([$file, $folder, $node]);
$result = $this->appData->getDirectoryListing();
$this->assertCount(1, $result);
$this->assertInstanceOf(ISimpleFolder::class, $result[0]);
}
}
|