Completed
Push — master ( 8931ba...9baa96 )
by Roeland
47:53
created

AvatarTest::testExistsPNG()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 8
Ratio 100 %
Metric Value
dl 8
loc 8
rs 9.4286
cc 1
eloc 6
nc 1
nop 0
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')
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<OCP\Files\Folder>.

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.

Loading history...
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);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<OCP\Files\Folder>.

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.

Loading history...
46
47
		$this->assertEquals($expected->data(), $this->avatar->get(128)->data());
48
	}
49
50
	public function testGetAvatarNoSizeMatch() {
51
		$this->folder->method('nodeExists')
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<OCP\Files\Folder>.

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.

Loading history...
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);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<OCP\Files\Folder>.

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.

Loading history...
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())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<OCP\Files\Folder>.

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.

Loading history...
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')
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<OCP\Files\Folder>.

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.

Loading history...
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')
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<OCP\Files\Folder>.

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.

Loading history...
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')
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<OCP\Files\Folder>.

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.

Loading history...
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())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<OCP\Files\Folder>.

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.

Loading history...
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