|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright (c) 2013 Christopher Schäpers <[email protected]> |
|
5
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
|
6
|
|
|
* later. |
|
7
|
|
|
* See the COPYING-README file. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
use OC\Avatar; |
|
11
|
|
|
use OCP\Files\Folder; |
|
12
|
|
|
|
|
13
|
|
|
class AvatarTest extends \Test\TestCase { |
|
14
|
|
|
/** @var Folder */ |
|
15
|
|
|
private $folder; |
|
16
|
|
|
|
|
17
|
|
|
/** @var \OC\Avatar */ |
|
18
|
|
|
private $avatar; |
|
19
|
|
|
|
|
20
|
|
|
public function setUp() { |
|
21
|
|
|
parent::setUp(); |
|
22
|
|
|
|
|
23
|
|
|
$this->folder = $this->getMock('\OCP\Files\Folder'); |
|
24
|
|
|
$l = $this->getMock('\OCP\IL10N'); |
|
25
|
|
|
$l->method('t')->will($this->returnArgument(0)); |
|
26
|
|
|
$this->avatar = new \OC\Avatar($this->folder, $l); |
|
27
|
|
|
|
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function testGetNoAvatar() { |
|
31
|
|
|
$this->assertEquals(false, $this->avatar->get()); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function testGetAvatarSizeMatch() { |
|
35
|
|
|
$this->folder->method('nodeExists') |
|
|
|
|
|
|
36
|
|
|
->will($this->returnValueMap([ |
|
37
|
|
|
['avatar.jpg', true], |
|
38
|
|
|
['avatar.128.jpg', true], |
|
39
|
|
|
])); |
|
40
|
|
|
|
|
41
|
|
|
$expected = new OC_Image(\OC::$SERVERROOT . '/tests/data/testavatar.png'); |
|
42
|
|
|
|
|
43
|
|
|
$file = $this->getMock('\OCP\Files\File'); |
|
44
|
|
|
$file->method('getContent')->willReturn($expected->data()); |
|
45
|
|
|
$this->folder->method('get')->with('avatar.128.jpg')->willReturn($file); |
|
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
$this->assertEquals($expected->data(), $this->avatar->get(128)->data()); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function testGetAvatarNoSizeMatch() { |
|
51
|
|
|
$this->folder->method('nodeExists') |
|
|
|
|
|
|
52
|
|
|
->will($this->returnValueMap([ |
|
53
|
|
|
['avatar.png', true], |
|
54
|
|
|
['avatar.32.png', false], |
|
55
|
|
|
])); |
|
56
|
|
|
|
|
57
|
|
|
$expected = new OC_Image(\OC::$SERVERROOT . '/tests/data/testavatar.png'); |
|
58
|
|
|
$expected2 = new OC_Image(\OC::$SERVERROOT . '/tests/data/testavatar.png'); |
|
59
|
|
|
$expected2->resize(32); |
|
60
|
|
|
|
|
61
|
|
|
$file = $this->getMock('\OCP\Files\File'); |
|
62
|
|
|
$file->method('getContent')->willReturn($expected->data()); |
|
63
|
|
|
$this->folder->method('get')->with('avatar.png')->willReturn($file); |
|
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
$newFile = $this->getMock('\OCP\Files\File'); |
|
66
|
|
|
$newFile->expects($this->once()) |
|
67
|
|
|
->method('putContent') |
|
68
|
|
|
->with($expected2->data()); |
|
69
|
|
|
$this->folder->expects($this->once()) |
|
|
|
|
|
|
70
|
|
|
->method('newFile') |
|
71
|
|
|
->with('avatar.32.png') |
|
72
|
|
|
->willReturn($newFile); |
|
73
|
|
|
|
|
74
|
|
|
$this->assertEquals($expected2->data(), $this->avatar->get(32)->data()); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function testExistsNo() { |
|
78
|
|
|
$this->assertFalse($this->avatar->exists()); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
View Code Duplication |
public function testExiststJPG() { |
|
82
|
|
|
$this->folder->method('nodeExists') |
|
|
|
|
|
|
83
|
|
|
->will($this->returnValueMap([ |
|
84
|
|
|
['avatar.jpg', true], |
|
85
|
|
|
['avatar.png', false], |
|
86
|
|
|
])); |
|
87
|
|
|
$this->assertTrue($this->avatar->exists()); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
View Code Duplication |
public function testExistsPNG() { |
|
91
|
|
|
$this->folder->method('nodeExists') |
|
|
|
|
|
|
92
|
|
|
->will($this->returnValueMap([ |
|
93
|
|
|
['avatar.jpg', false], |
|
94
|
|
|
['avatar.png', true], |
|
95
|
|
|
])); |
|
96
|
|
|
$this->assertTrue($this->avatar->exists()); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function testSetAvatar() { |
|
100
|
|
|
$oldFile = $this->getMock('\OCP\Files\File'); |
|
101
|
|
|
$this->folder->method('get') |
|
|
|
|
|
|
102
|
|
|
->will($this->returnValueMap([ |
|
103
|
|
|
['avatar.jpg', $oldFile], |
|
104
|
|
|
['avatar.png', $oldFile], |
|
105
|
|
|
])); |
|
106
|
|
|
$oldFile->expects($this->exactly(2))->method('delete'); |
|
107
|
|
|
|
|
108
|
|
|
$newFile = $this->getMock('\OCP\Files\File'); |
|
109
|
|
|
$this->folder->expects($this->once()) |
|
|
|
|
|
|
110
|
|
|
->method('newFile') |
|
111
|
|
|
->with('avatar.png') |
|
112
|
|
|
->willReturn($newFile); |
|
113
|
|
|
|
|
114
|
|
|
$image = new OC_Image(\OC::$SERVERROOT . '/tests/data/testavatar.png'); |
|
115
|
|
|
$newFile->expects($this->once()) |
|
116
|
|
|
->method('putContent') |
|
117
|
|
|
->with($image->data()); |
|
118
|
|
|
|
|
119
|
|
|
$this->avatar->set($image->data()); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
} |
|
123
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.