Subversion Repository Public Repository

Nextrek

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
<?php

use Intervention\Image\Image;

class ImageTest extends PHPUnit_Framework_TestCase
{
    public function tearDown()
    {
        Mockery::close();
    }

    public function testGetCore()
    {
        $image = $this->getTestImage();
        $this->assertEquals('mock', $image->getCore());
    }

    public function testCommandCall()
    {
        $image = $this->getTestImage();
        $result = $image->test(1, 2, 3);
        $this->assertEquals('mock', $result);   
    }

    public function testEncode()
    {
        $image = $this->getTestImage();
        $image->getDriver()->shouldReceive('encode')->with($image, 'png', 90)->once();
        $image->encode('png', 90);
    }

    public function testSave()
    {
        $save_as = __DIR__.'/tmp/test.jpg';
        $image = $this->getTestImage();
        $image->getDriver()->shouldReceive('encode')->with($image, 'jpg', 85)->once()->andReturn('mock');
        $image = $image->save($save_as, 85);
        $this->assertInstanceOf('\Intervention\Image\Image', $image);
        $this->assertFileExists($save_as);
        $this->assertEquals($image->basename, 'test.jpg');
        $this->assertEquals($image->extension, 'jpg');
        $this->assertEquals($image->filename, 'test');
        @unlink($save_as);
    }

    public function testFilter()
    {
        $demoFilter = Mockery::mock('\Intervention\Image\Filters\DemoFilter', array(15));
        $image = $this->getTestImage();
        $demoFilter->shouldReceive('applyFilter')->with($image)->once()->andReturn($image);
        $image->filter($demoFilter);
    }

    public function testMime()
    {
        $image = $this->getTestImage();
        $this->assertEquals('image/png', $image->mime());
    }

    public function testBasePath()
    {
        $image = $this->getTestImage();
        $this->assertEquals('./tmp/foo.png', $image->basePath());
    }

    /**
     * @expectedException \Intervention\Image\Exception\RuntimeException
     */
    public function testGetBackupWithoutBackuo()
    {
        $image = $this->getTestImage();
        $image->getBackup();
    }

    public function testSetGetBackup()
    {
        $image = $this->getTestImage();
        $image->setBackup('foo');
        $backup = $image->getBackup();
        $this->assertEquals('foo', $backup);
    }

    public function testGetBackups()
    {
        $image = $this->getTestImage();
        $backups = $image->getBackups();
        $this->assertEquals(array(), $backups);

        $image = $this->getTestImage();
        $image->setBackup('foo');
        $image->setBackup('bar');
        $image->setBackup('baz');
        $backups = $image->getBackups();
        $this->assertEquals(array('default' => 'baz'), $backups);

        $image = $this->getTestImage();
        $image->setBackup('foo', 'a');
        $image->setBackup('bar', 'b');
        $image->setBackup('baz', 'c');
        $backups = $image->getBackups();
        $this->assertEquals(array('a' => 'foo', 'b' => 'bar', 'c' => 'baz'), $backups);
    }

    private function getTestImage()
    {
        $size = Mockery::mock('\Intervention\Image\Size', array(800, 600));
        $driver = Mockery::mock('\Intervention\Image\AbstractDriver');
        $command = Mockery::mock('\Intervention\Image\Commands\AbstractCommand');
        $command->shouldReceive('hasOutput')->andReturn(true);
        $command->shouldReceive('getOutput')->andReturn('mock');
        $driver->shouldReceive('executeCommand')->andReturn($command);
        $image = new Image($driver, 'mock');
        $image->mime = 'image/png';
        $image->dirname = './tmp';
        $image->basename = 'foo.png';

        return $image;
    }
}

Commits for Nextrek/Aiba_backup/vendor/intervention/image/tests/ImageTest.php

Diff revisions: vs.
Revision Author Commited Message
1464 MOliva picture MOliva Tue 13 Oct, 2020 11:16:56 +0000