StyleManagerTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 80
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A testSetImageAttributes() 0 15 1
A testGetImagesSizesData() 0 13 1
A testGetPictureData() 0 13 1
A testGetStyleData() 0 22 1
1
<?php
2
/**
3
 * This file is part of the IrishDan\ResponsiveImageBundle package.
4
 *
5
 * (c) Daniel Byrne <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE file that was distributed with this source
8
 * code.
9
 */
10
11
namespace IrishDan\ResponsiveImageBundle\Tests;
12
13
use IrishDan\ResponsiveImageBundle\Tests\Entity\TestImage;
14
use IrishDan\ResponsiveImageBundle\File\FileManager;
15
16
17
class StyleManagerTest extends ResponsiveImageTestCase
18
{
19
    private $image;
20
    private $styleManager;
21
22
    public function setUp()
23
    {
24
        $this->image = new TestImage();
25
        $this->image->setPath('dummy.jpg');
26
27
        $this->styleManager = $this->getService('responsive_image.style_manager');
28
    }
29
30
    public function testSetImageAttributes()
31
    {
32
        // Test with cropped styles
33
        $this->styleManager->setImageAttributes($this->image, 'thumb', 'src/dummy.jpg');
34
35
        $this->assertEquals(180, $this->image->getWidth());
36
        $this->assertEquals(180, $this->image->getHeight());
37
        $this->assertEquals('src/dummy.jpg', $this->image->getSrc());
38
39
        // Test with scaled styled
40
        $this->styleManager->setImageAttributes($this->image, 'test_scale');
41
42
        $this->assertEquals(344, $this->image->getWidth());
43
        $this->assertEquals(800, $this->image->getHeight());
44
    }
45
46
    public function testGetImagesSizesData()
47
    {
48
        $sizesData = $this->styleManager->getImageSizesData($this->image, 'blog_sizes');
49
50
        // Check the returned array structure.
51
        $this->assertArrayHasKey('fallback', $sizesData);
52
        $this->assertArrayHasKey('sizes', $sizesData);
53
        $this->assertArrayHasKey('srcsets', $sizesData);
54
55
        $this->assertEquals('(min-width: 1100px) 10vw', $sizesData['sizes'][0]);
56
        $this->assertEquals(180, $sizesData['srcsets']['styles/thumb/dummy.jpg']);
57
        $this->assertEquals(300, $sizesData['srcsets']['styles/big_thumb/dummy.jpg']);
58
    }
59
60
    public function testGetPictureData()
61
    {
62
        $mq = $this->styleManager->getPictureData($this->image, 'thumb_picture');
63
64
        // Check the returned array structure.
65
        $this->assertArrayHasKey('fallback', $mq);
66
        $this->assertArrayHasKey('sources', $mq);
67
68
        // Check the data.
69
        $this->assertEquals('styles/thumb/dummy.jpg', $mq['fallback']);
70
        $this->assertArrayHasKey('min-width: 0px', $mq['sources']);
71
        $this->assertArrayHasKey('min-width: 1100px', $mq['sources']);
72
    }
73
74
    public function testGetStyleData()
75
    {
76
        // Non existant style returns FALSE.
77
        $style = $this->styleManager->getStyleData('nonExistingStyle');
78
        $this->assertFalse($style);
79
80
        // Existing array returns array.
81
        $style = $this->styleManager->getStyleData('thumb');
82
        $this->assertTrue(is_array($style));
83
84
        // Style info.
85
        $parameters = $this->getParameters('responsive_image');
86
87
        $expected = $parameters['image_styles']['thumb'];
88
        $this->assertEquals($expected, $style);
89
90
        // Test a custom styles.
91
        $style = $this->styleManager->getStyleData('custom_scale_30_100');
92
        $this->assertArrayHasKey('effect', $style);
93
        $this->assertArrayHasKey('width', $style);
94
        $this->assertArrayHasKey('height', $style);
95
    }
96
}
97