Passed
Pull Request — develop (#1)
by Andreas
03:30
created

getContent_FieldsMissing_ContentExceptionIsThrown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
use Wambo\Catalog\Mapper\ContentMapper;
3
4
/**
5
 * Class ContentMapperTest tests the Wambo\Catalog\Mapper\ContentMapper class.
6
 */
7
class ContentMapperTest extends PHPUnit_Framework_TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
8
{
9
    /**
10
     * If the given content data is valid a Content model with the given content data should be
11
     * returned
12
     *
13
     * @test
14
     * @dataProvider getValidContentData
15
     *
16
     * @param array $contentData Product content data
17
     */
18
    public function getContent_ValidContentDataGiven_ContentWithSummaryAndDescriptionIsReturned($contentData)
19
    {
20
        // arrange
21
        $productMapper = new ContentMapper();
22
23
        // act
24
        $content = $productMapper->getContent($contentData);
25
26
        // assert
27
        $this->assertNotEmpty($content->getSummaryText(), "The summary of the content model should not be empty");
28
        $this->assertNotEmpty($content->getProductDescription(),
29
            "The description of the content model should not be empty");
30
    }
31
32
    /**
33
     * If the given content data is valid a Content model with the given content data should be
34
     * returned
35
     *
36
     * @test
37
     * @dataProvider                   getContentDataWithMissingAttributes
38
     * @expectedException Wambo\Catalog\Error\ContentException
39
     * @expectedExceptionMessageRegExp /The field '.+' is missing in the given content data/
40
     *
41
     * @param array $contentData Product content data
42
     */
43
    public function getContent_FieldsMissing_ContentExceptionIsThrown($contentData)
44
    {
45
        // arrange
46
        $productMapper = new ContentMapper();
47
48
        // act
49
        $productMapper->getContent($contentData);
50
    }
51
52
    /**
53
     * If some of the given attributes are invalid a ContentException should be thrown
54
     *
55
     * @test
56
     * @dataProvider                   getContentWithInvalidAttributes
57
     * @expectedException Wambo\Catalog\Error\ContentException
58
     * @expectedExceptionMessageRegExp /Failed to create a content model from the given data/
59
     *
60
     * @param array $contentData Product content data
61
     */
62
    public function getContent_InvalidAttributes_ContentExceptionIsThrown($contentData)
63
    {
64
        // arrange
65
        $productMapper = new ContentMapper();
66
67
        // act
68
        $productMapper->getContent($contentData);
69
    }
70
71
    /**
72
     * Get a list of valid content data for testing
73
     *
74
     * @return array
75
     */
76
    public static function getValidContentData()
77
    {
78
        return array(
79
            [
80
                [
81
                    "title" => "Product Title",
82
                    "summary" => "A product summary",
83
                    "description" => "A detailed product description",
84
                ],
85
86
                [
87
                    "title" => "Product Title",
88
                    "summary" => "ABCdefghijklmnopqrstuvwxyzöüä.ABCdefghijklmnopqrstuvwxyzöüä.ABCdefghijklmnopqrstuvwxyzöüä.ABCdefghijklmnopqrstuvwxyzöüä.",
89
                    "description" => "A detailed product description ...",
90
                ]
91
            ]
92
        );
93
    }
94
95
    /**
96
     * Get a list of content data with invalid attributes for testing
97
     *
98
     * @return array
99
     */
100
    public static function getContentWithInvalidAttributes()
101
    {
102
        return array(
103
            [
104
                // title empty or too short
105
                [
106
                    "title" => "",
107
                    "summary" => "Product summary"
108
                ],
109
110
                // title too long
111
                [
112
                    "title" => "ABCdefghijklmnopqrstuvwxyzöüä.ABCdefghijklmnopqrstuvwxyzöüä.ABCdefghijklmnopqrstuvwxyzöüä.",
113
                    "summary" => "Product summary"
114
                ],
115
116
                // summary empty
117
                [
118
                    "summary" => "",
119
                ],
120
121
                // summary too short
122
                [
123
                    "summary" => "A",
124
                ],
125
126
                // summary too long
127
                [
128
                    "summary" => "ABCdefghijklmnopqrstuvwxyzöüä.ABCdefghijklmnopqrstuvwxyzöüä.ABCdefghijklmnopqrstuvwxyzöüä.ABCdefghijklmnopqrstuvwxyzöüä.ABCdefghijklmnopqrstuvwxyzöüä.",
129
                ]
130
            ]
131
        );
132
    }
133
134
    /**
135
     * Get a list of content data object with missing attributes for testing
136
     *
137
     * @return array
138
     */
139
    public static function getContentDataWithMissingAttributes()
140
    {
141
        return array(
142
            [
143
                // title: wrong casing
144
                [
145
                    "Title" => "Product title",
146
                    "summary" => "A product summary",
147
                    "description" => "A detailed product description",
148
                ],
149
150
                // title: missing
151
                [
152
                    "summary" => "A product summary",
153
                    "description" => "A detailed product description",
154
                ],
155
156
                // summary: wrong casing
157
                [
158
                    "title" => "Product title",
159
                    "SUMMARY" => "A product summary",
160
                    "description" => "A detailed product description",
161
                ],
162
163
                // summary: missing
164
                [
165
                    "title" => "Product title",
166
                    "description" => "A detailed product description",
167
                ]
168
            ]
169
        );
170
    }
171
}
172