Failed Conditions
Push — master ( 34a070...6c283c )
by Adrien
05:56
created

ImageTest::testGetPermissions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 18
nc 1
nop 0
dl 0
loc 25
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ApplicationTest\Model;
6
7
use Application\Model\Image;
8
use Application\Model\User;
9
use PHPUnit\Framework\TestCase;
10
11
class ImageTest extends TestCase
12
{
13
    public function tearDown(): void
14
    {
15
        User::setCurrent(null);
16
    }
17
18
    public function testGetPath(): void
19
    {
20
        $image = new Image();
21
        $image->setFilename('photo.jpg');
22
23
        self::assertSame('photo.jpg', $image->getFilename());
24
        $appPath = realpath('.');
25
        $expected = $appPath . '/data/images/photo.jpg';
26
        self::assertSame($expected, $image->getPath());
27
    }
28
29
    public function testCopyIntoWithoutFile(): void
30
    {
31
        $original = new Image();
32
        $original->setWidth(456);
33
        $original->setHeight(456);
34
35
        self::assertSame(456, $original->getWidth());
36
        self::assertSame(456, $original->getHeight());
37
    }
38
39
    public function testGetPermissions(): void
40
    {
41
        $image = new Image();
42
        $actual = $image->getPermissions();
43
        $expected = [
44
            'create' => false,
45
            'read' => true,
46
            'update' => false,
47
            'delete' => false,
48
        ];
49
        self::assertEquals($expected, $actual, 'should be able to get permissions as anonymous');
50
51
        // Make it the current user as creator
52
        $user = new User();
53
        User::setCurrent($user);
54
        $image->timestampCreation();
55
56
        $actual2 = $image->getPermissions();
57
        $expected2 = [
58
            'create' => false,
59
            'read' => true,
60
            'update' => false,
61
            'delete' => false,
62
        ];
63
        self::assertEquals($expected2, $actual2, 'should be able to get permissions as creator');
64
    }
65
}
66