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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
<?php
/**
* Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
namespace Test\Files\Node;
use OC\Files\FileInfo;
class RootTest extends \Test\TestCase {
/** @var \OC\User\User */
private $user;
/** @var \OC\Files\Mount\Manager */
private $manager;
protected function setUp() {
parent::setUp();
$config = $this->getMockBuilder('\OCP\IConfig')
->disableOriginalConstructor()
->getMock();
$urlgenerator = $this->getMockBuilder('\OCP\IURLGenerator')
->disableOriginalConstructor()
->getMock();
$this->user = new \OC\User\User('', new \Test\Util\User\Dummy, null, $config, $urlgenerator);
$this->manager = $this->getMockBuilder('\OC\Files\Mount\Manager')
->disableOriginalConstructor()
->getMock();
}
protected function getFileInfo($data) {
return new FileInfo('', null, '', $data, null);
}
public function testGet() {
/**
* @var \OC\Files\Storage\Storage $storage
*/
$storage = $this->getMockBuilder('\OC\Files\Storage\Storage')
->disableOriginalConstructor()
->getMock();
/**
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
$view = $this->getMockBuilder('\OC\Files\View')
->disableOriginalConstructor()
->getMock();
$root = new \OC\Files\Node\Root($this->manager, $view, $this->user);
$view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
->will($this->returnValue($this->getFileInfo(array('fileid' => 10, 'path' => 'bar/foo', 'name', 'mimetype' => 'text/plain'))));
$root->mount($storage, '');
$node = $root->get('/bar/foo');
$this->assertEquals(10, $node->getId());
$this->assertInstanceOf('\OC\Files\Node\File', $node);
}
/**
* @expectedException \OCP\Files\NotFoundException
*/
public function testGetNotFound() {
/**
* @var \OC\Files\Storage\Storage $storage
*/
$storage = $this->getMockBuilder('\OC\Files\Storage\Storage')
->disableOriginalConstructor()
->getMock();
/**
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
$view = $this->getMockBuilder('\OC\Files\View')
->disableOriginalConstructor()
->getMock();
$root = new \OC\Files\Node\Root($this->manager, $view, $this->user);
$view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
->will($this->returnValue(false));
$root->mount($storage, '');
$root->get('/bar/foo');
}
/**
* @expectedException \OCP\Files\NotPermittedException
*/
public function testGetInvalidPath() {
/**
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
$view = $this->getMockBuilder('\OC\Files\View')
->disableOriginalConstructor()
->getMock();
$root = new \OC\Files\Node\Root($this->manager, $view, $this->user);
$root->get('/../foo');
}
/**
* @expectedException \OCP\Files\NotFoundException
*/
public function testGetNoStorages() {
/**
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
$view = $this->getMockBuilder('\OC\Files\View')
->disableOriginalConstructor()
->getMock();
$root = new \OC\Files\Node\Root($this->manager, $view, $this->user);
$root->get('/bar/foo');
}
}
|