Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
17.86% covered (danger)
17.86%
10 / 56
75.00% covered (warning)
75.00%
3 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
phpbb_upload_imagesize_test
17.86% covered (danger)
17.86%
10 / 56
75.00% covered (warning)
75.00%
3 / 4
12.87
0.00% covered (danger)
0.00%
0 / 1
 setUp
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 data_get_imagesize
0.00% covered (danger)
0.00%
0 / 46
0.00% covered (danger)
0.00%
0 / 1
2
 test_get_imagesize
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 test_get_imagesize_remote
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 *
5 * This file is part of the phpBB Forum Software package.
6 *
7 * @copyright (c) phpBB Limited <https://www.phpbb.com>
8 * @license GNU General Public License, version 2 (GPL-2.0)
9 *
10 * For full copyright and license information, please see
11 * the docs/CREDITS.txt file.
12 *
13 */
14
15class phpbb_upload_imagesize_test extends \phpbb_test_case
16{
17    /** @var \FastImageSize\FastImageSize */
18    protected $imagesize;
19
20    /** @var string Path to fixtures */
21    protected $path;
22
23    protected function setUp(): void
24    {
25        parent::setUp();
26        $this->imagesize = new \FastImageSize\FastImageSize();
27        $this->path = __DIR__ . '/fixture/';
28    }
29
30    public static function data_get_imagesize()
31    {
32        return array(
33            array('foobar', 'image/bmp', false),
34            array('png', 'image/png', array('width' => 1, 'height' => 1, 'type' => IMAGETYPE_PNG)),
35            array('gif', 'image/png', false),
36            array('png', '', array('width' => 1, 'height' => 1, 'type' => IMAGETYPE_PNG)),
37            array('gif', 'image/gif', array('width' => 1, 'height' => 1, 'type' => IMAGETYPE_GIF)),
38            array('jpg', 'image/gif', false),
39            array('gif', '', array('width' => 1, 'height' => 1, 'type' => IMAGETYPE_GIF)),
40            array('jpg', 'image/jpg', array('width' => 1, 'height' => 1, 'type' => IMAGETYPE_JPEG)),
41            array('jpg', 'image/jpeg', array('width' => 1, 'height' => 1, 'type' => IMAGETYPE_JPEG)),
42            array('png', 'image/jpg', false),
43            array('jpg', '', array('width' => 1, 'height' => 1, 'type' => IMAGETYPE_JPEG)),
44            array('psd', 'image/psd', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_PSD)),
45            array('psd', 'image/photoshop', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_PSD)),
46            array('jpg', 'image/psd', false),
47            array('psd', '', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_PSD)),
48            array('bmp', 'image/bmp', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_BMP)),
49            array('png', 'image/bmp', false),
50            array('bmp', '', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_BMP)),
51            array('tif', 'image/tif', array('width' => 1, 'height' => 1, 'type' => IMAGETYPE_TIFF_II)),
52            array('png', 'image/tif', false),
53            array('tif', '', array('width' => 1, 'height' => 1, 'type' => IMAGETYPE_TIFF_II)),
54            array('tif_compressed', 'image/tif', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_TIFF_II)),
55            array('png', 'image/tiff', false),
56            array('tif_compressed', '', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_TIFF_II)),
57            array('tif_msb', 'image/tif', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_TIFF_MM)),
58            array('tif_msb', '', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_TIFF_MM)),
59            array('wbmp', 'image/wbmp', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_WBMP)),
60            array('wbmp', 'image/vnd.wap.wbmp', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_WBMP)),
61            array('png', 'image/vnd.wap.wbmp', false),
62            array('wbmp', '', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_WBMP)),
63            array('iff', 'image/iff', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_IFF)),
64            array('iff', 'image/x-iff', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_IFF)),
65            array('iff_maya', 'iamge/iff', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_IFF)),
66            array('png', 'image/iff', false),
67            array('png', 'image/x-iff', false),
68            array('iff', '', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_IFF)),
69            array('iff_maya', '', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_IFF)),
70            array('jp2', 'image/jp2', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_JPEG2000)),
71            array('jp2', 'image/jpx', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_JPEG2000)),
72            array('jp2', 'image/jpm', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_JPEG2000)),
73            array('jpg', 'image/jp2', false),
74            array('jpx', 'image/jpx', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_JPEG2000)),
75            array('jp2', '', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_JPEG2000)),
76            array('jpx', '', array('width' => 2, 'height' => 1, 'type' => IMAGETYPE_JPEG2000)),
77        );
78    }
79
80    /**
81     * @dataProvider data_get_imagesize
82     */
83    public function test_get_imagesize($file, $mime_type, $expected)
84    {
85        $this->assertEquals($expected, $this->imagesize->getImageSize($this->path . $file, $mime_type));
86    }
87
88    public function test_get_imagesize_remote()
89    {
90        $this->assertSame(array(
91            'width'        => 80,
92            'height'    => 80,
93            'type'        => IMAGETYPE_JPEG,
94        ),
95        $this->imagesize->getImageSize('https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg'));
96    }
97}