Completed
Push — v2 ( 2062ad...f15f0a )
by Joschi
05:09
created

MicroformatsFeedTrait::getPropertyObject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 2
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\Domain\Value\ValueInterface;
43
use Jkphl\Micrometa\Infrastructure\Factory\MicroformatsFactory;
44
use Jkphl\Micrometa\Infrastructure\Parser\Microformats;
45
use Jkphl\Micrometa\Ports\Item\Item;
46
47
/**
48
 * Trait MicroformatsFeedTrait
49
 *
50
 * @package Jkphl\Micrometa
51
 * @subpackage Jkphl\Micrometa\Tests
52
 */
53
trait MicroformatsFeedTrait
54
{
55
    /**
56
     * Create and return an h-feed Microformats applocation item
57
     *
58
     * @return ApplicationItem h-feed application item
59
     */
60
    protected function getApplicationFeedItem()
61
    {
62
        $authorItem = $this->getAuthorApplicationItem();
63
        $entryItem = $this->getEntryApplicationItem($authorItem);
64
        $feedItem = new ApplicationItem(
65
            Microformats::FORMAT,
66
            new PropertyListFactory(),
67
            (object)['profile' => MicroformatsFactory::MF2_PROFILE_URI, 'name' => 'h-feed'],
68
            [
69
                $this->getPropertyObject('name', new StringValue('John Doe\'s Blog')),
70
                $this->getPropertyObject('author', $authorItem),
71
                $this->getPropertyObject('custom-property', new StringValue('Property for alias testing')),
72
            ],
73
            [$entryItem, $entryItem],
74
            'feed-id',
75
            'feed-language',
76
            'feed-value'
77
        );
78
79
        return $feedItem;
80
    }
81
82
    /**
83
     * Return a property object
84
     *
85
     * @param string $name Name
86
     * @param ValueInterface $value Value
87
     * @return object Property object
88
     */
89
    protected function getPropertyObject($name, ValueInterface $value)
90
    {
91
        return (object)[
92
            'profile' => MicroformatsFactory::MF2_PROFILE_URI,
93
            'name' => $name,
94
            'values' => [$value]
95
        ];
96
    }
97
98
    /**
99
     * Return an author application item
100
     *
101
     * @return ApplicationItem Author application item
102
     */
103
    protected function getAuthorApplicationItem()
104
    {
105
        return new ApplicationItem(
106
            Microformats::FORMAT,
107
            new PropertyListFactory(),
108
            (object)['profile' => MicroformatsFactory::MF2_PROFILE_URI, 'name' => 'h-card'],
109
            [
110
                (object)[
111
                    'profile' => MicroformatsFactory::MF2_PROFILE_URI,
112
                    'name' => 'name',
113
                    'values' => [
114
                        new StringValue('John Doe')
115
                    ]
116
                ],
117
                (object)[
118
                    'profile' => MicroformatsFactory::MF2_PROFILE_URI,
119
                    'name' => 'email',
120
                    'values' => [
121
                        new StringValue('[email protected]')
122
                    ]
123
                ]
124
            ]
125
        );
126
    }
127
128
    /**
129
     * Return an entry application item
130
     *
131
     * @param ApplicationItem $authorItem Author application item
132
     * @return ApplicationItem Entry application item
133
     */
134
    protected function getEntryApplicationItem(ApplicationItem $authorItem)
135
    {
136
        return new ApplicationItem(
137
            Microformats::FORMAT,
138
            new PropertyListFactory(),
139
            (object)['profile' => MicroformatsFactory::MF2_PROFILE_URI, 'name' => 'h-entry'],
140
            [
141
                (object)[
142
                    'profile' => MicroformatsFactory::MF2_PROFILE_URI,
143
                    'name' => 'name',
144
                    'values' => [
145
                        new StringValue('Famous blog post')
146
                    ]
147
                ],
148
                (object)[
149
                    'profile' => MicroformatsFactory::MF2_PROFILE_URI,
150
                    'name' => 'author',
151
                    'values' => [
152
                        $authorItem
153
                    ]
154
                ]
155
            ]
156
        );
157
    }
158
159
    /**
160
     * Create and return an h-feed Microformats item
161
     *
162
     * @return Item h-feed item
163
     */
164
    protected function getFeedItem()
165
    {
166
        return new Item($this->getApplicationFeedItem());
167
    }
168
}
169