Completed
Push — v2 ( b41681...2062ad )
by Joschi
04:41
created

MicroformatsFeedTrait::getAuthorApplicationItem()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
cc 1
eloc 15
nc 1
nop 0
1
<?php
2
3
/**
4
 * micrometa
5
 *
6
 * @category Jkphl
7
 * @package Jkphl\Micrometa
8
 * @subpackage Jkphl\Micrometa\Tests
9
 * @author Joschi Kuphal <[email protected]> / @jkphl
10
 * @copyright Copyright © 2017 Joschi Kuphal <[email protected]> / @jkphl
11
 * @license http://opensource.org/licenses/MIT The MIT License (MIT)
12
 */
13
14
/***********************************************************************************
15
 *  The MIT License (MIT)
16
 *
17
 *  Copyright © 2017 Joschi Kuphal <[email protected]> / @jkphl
18
 *
19
 *  Permission is hereby granted, free of charge, to any person obtaining a copy of
20
 *  this software and associated documentation files (the "Software"), to deal in
21
 *  the Software without restriction, including without limitation the rights to
22
 *  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
23
 *  the Software, and to permit persons to whom the Software is furnished to do so,
24
 *  subject to the following conditions:
25
 *
26
 *  The above copyright notice and this permission notice shall be included in all
27
 *  copies or substantial portions of the Software.
28
 *
29
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
31
 *  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
32
 *  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
33
 *  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
34
 *  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
 ***********************************************************************************/
36
37
namespace Jkphl\Micrometa\Tests;
38
39
use Jkphl\Micrometa\Application\Factory\PropertyListFactory;
40
use Jkphl\Micrometa\Application\Item\Item as ApplicationItem;
41
use Jkphl\Micrometa\Application\Value\StringValue;
42
use Jkphl\Micrometa\Infrastructure\Factory\MicroformatsFactory;
43
use Jkphl\Micrometa\Infrastructure\Parser\Microformats;
44
use Jkphl\Micrometa\Ports\Item\Item;
45
46
/**
47
 * Trait MicroformatsFeedTrait
48
 *
49
 * @package Jkphl\Micrometa
50
 * @subpackage Jkphl\Micrometa\Tests
51
 */
52
trait MicroformatsFeedTrait
53
{
54
    /**
55
     * Create and return an h-feed Microformats applocation item
56
     *
57
     * @return ApplicationItem h-feed application item
58
     */
59
    protected function getApplicationFeedItem()
60
    {
61
        $authorItem = $this->getAuthorApplicationItem();
62
        $entryItem = $this->getEntryApplicationItem($authorItem);
63
        $feedItem = new ApplicationItem(
64
            Microformats::FORMAT,
65
            new PropertyListFactory(),
66
            (object)['profile' => MicroformatsFactory::MF2_PROFILE_URI, 'name' => 'h-feed'],
67
            [
68
                (object)[
69
                    'profile' => MicroformatsFactory::MF2_PROFILE_URI,
70
                    'name' => 'name',
71
                    'values' => [
72
                        new StringValue('John Doe\'s Blog')
73
                    ]
74
                ],
75
                (object)[
76
                    'profile' => MicroformatsFactory::MF2_PROFILE_URI,
77
                    'name' => 'author',
78
                    'values' => [
79
                        $authorItem
80
                    ]
81
                ],
82
                (object)[
83
                    'profile' => MicroformatsFactory::MF2_PROFILE_URI,
84
                    'name' => 'custom-property',
85
                    'values' => [
86
                        new StringValue('Property for alias testing')
87
                    ]
88
                ],
89
            ],
90
            [$entryItem, $entryItem],
91
            'feed-id',
92
            'feed-language',
93
            'feed-value'
94
        );
95
96
        return $feedItem;
97
    }
98
99
    /**
100
     * Return an author application item
101
     *
102
     * @return ApplicationItem Author application item
103
     */
104
    protected function getAuthorApplicationItem()
105
    {
106
        return new ApplicationItem(
107
            Microformats::FORMAT,
108
            new PropertyListFactory(),
109
            (object)['profile' => MicroformatsFactory::MF2_PROFILE_URI, 'name' => 'h-card'],
110
            [
111
                (object)[
112
                    'profile' => MicroformatsFactory::MF2_PROFILE_URI,
113
                    'name' => 'name',
114
                    'values' => [
115
                        new StringValue('John Doe')
116
                    ]
117
                ],
118
                (object)[
119
                    'profile' => MicroformatsFactory::MF2_PROFILE_URI,
120
                    'name' => 'email',
121
                    'values' => [
122
                        new StringValue('[email protected]')
123
                    ]
124
                ]
125
            ]
126
        );
127
    }
128
129
    /**
130
     * Return an entry application item
131
     *
132
     * @param ApplicationItem $authorItem Author application item
133
     * @return ApplicationItem Entry application item
134
     */
135
    protected function getEntryApplicationItem(ApplicationItem $authorItem)
136
    {
137
        return new ApplicationItem(
138
            Microformats::FORMAT,
139
            new PropertyListFactory(),
140
            (object)['profile' => MicroformatsFactory::MF2_PROFILE_URI, 'name' => 'h-entry'],
141
            [
142
                (object)[
143
                    'profile' => MicroformatsFactory::MF2_PROFILE_URI,
144
                    'name' => 'name',
145
                    'values' => [
146
                        new StringValue('Famous blog post')
147
                    ]
148
                ],
149
                (object)[
150
                    'profile' => MicroformatsFactory::MF2_PROFILE_URI,
151
                    'name' => 'author',
152
                    'values' => [
153
                        $authorItem
154
                    ]
155
                ]
156
            ]
157
        );
158
    }
159
160
    /**
161
     * Create and return an h-feed Microformats item
162
     *
163
     * @return Item h-feed item
164
     */
165
    protected function getFeedItem()
166
    {
167
        return new Item($this->getApplicationFeedItem());
168
    }
169
}
170