testContactDomainPropertyModel()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 13
nc 1
nop 0
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * apparat-object
5
 *
6
 * @category    Apparat
7
 * @package     Apparat\Object
8
 * @subpackage  Apparat\Object\Test
9
 * @author      Joschi Kuphal <[email protected]> / @jkphl
10
 * @copyright   Copyright © 2016 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 © 2016 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 Apparat\Object\Tests;
38
39
use Apparat\Object\Application\Model\Properties\Domain\Article;
40
use Apparat\Object\Domain\Model\Properties\PropertiesInterface;
41
use Apparat\Object\Infrastructure\Model\Object\Object;
42
43
/**
44
 * System properties test
45
 *
46
 * @package Apparat\Object
47
 * @subpackage Apparat\Object\Tests
48
 */
49
class DomainPropertiesTest extends AbstractRepositoryEnabledTest
50
{
51
    /**
52
     * Example object locator
53
     *
54
     * @var string
55
     */
56
    const ARTICLE_LOCATOR = '/2015/12/21/1-article/1';
57
    /**
58
     * Example object locator
59
     *
60
     * @var string
61
     */
62
    const CONTACT_LOCATOR = '/2016/01/08/2-contact/2';
63
    /**
64
     * Property traversal separator
65
     *
66
     * @var string
67
     */
68
    const SEPARATOR = PropertiesInterface::PROPERTY_TRAVERSAL_SEPARATOR;
69
70
    /**
71
     * Test mutation by altering domain properties
72
     */
73
    public function testDomainPropertyMutation()
74
    {
75
        $object = Object::load(getenv('REPOSITORY_URL').self::ARTICLE_LOCATOR);
76
        $this->assertTrue(is_array($object->getPropertyData()));
77
        $objectUrl = $object->getAbsoluteUrl();
78
        $objectRevision = $object->getRevision();
79
80
        // Set a serializable property
81
        $featuredUrl = 'http://lorempixel.com/1024/768/?70947';
82
        $object->setDomain(Article::FEATURED, $featuredUrl);
83
        $object->setDomain('a'.self::SEPARATOR.'b'.self::SEPARATOR.'c', 'mutated');
84
        $this->assertEquals($featuredUrl, $object->getPropertyData(true)['domain']['featured']);
85
86
        $this->assertEquals(preg_replace('%\/(.?+)$%', '/.$1-2', $objectUrl), $object->getAbsoluteUrl());
87
        $this->assertEquals($objectRevision->getRevision() + 1, $object->getRevision()->getRevision());
88
        $this->assertTrue($object->hasBeenModified());
89
        $this->assertTrue($object->hasBeenMutated());
90
    }
91
92
    /**
93
     * Test a domain property model violation
94
     *
95
     * @expectedException \Apparat\Object\Application\Model\Properties\Domain\DomainException
96
     * @expectedExceptionCode 1465130534
97
     */
98
    public function testDomainPropertyModel()
99
    {
100
        $object = Object::load(getenv('REPOSITORY_URL').self::CONTACT_LOCATOR);
101
        $object->setDomain('givenName', 'apparat');
102
        $object->setDomain('givenName'.self::SEPARATOR.'subproperty', 'violation');
103
    }
104
105
    /**
106
     * Test a domain property model violation
107
     */
108
    public function testContactDomainPropertyModel()
109
    {
110
        $object = Object::load(getenv('REPOSITORY_URL').self::CONTACT_LOCATOR);
111
        $object->setDomain('givenName', 'John');
112
        $object->setDomain('givenName', 'John'); // Intentional re-set!
113
        $object->setDomain('familyName', 'Doe');
114
        $object->setDomain('nickname', 'Houdini');
115
        $object->setDomain('additionalName', 'Mike');
116
        $object->setDomain('honorificPrefix', 'Prof.');
117
        $object->setDomain('honorificSuffix', 'jr.');
118
        $object->setDomain('email', ['[email protected]', '[email protected]']);
119
        $object->setDomain('logo', ['logo.jpg', '/2016/06/05/2-image']);
120
        $object->setDomain('org', '/2016/06/05/2-contact');
121
        $object->setDomain('bday', '2016-06-05T00:00:00Z');
122
//        print_r($object->getPropertyData());
123
    }
124
}
125