Completed
Push — master ( 28c8cd...7e44c6 )
by André
18:53
created

testParseObjectElementNotEmbedded()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 0
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File containing a ParserToolsTest class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Publish\Core\REST\Common\Tests\Input;
10
11
use eZ\Publish\Core\REST\Common\Input\ParserTools;
12
use eZ\Publish\Core\REST\Common\Input\ParsingDispatcher;
13
use PHPUnit\Framework\TestCase;
14
15
class ParserToolsTest extends TestCase
16
{
17
    public function testIsEmbeddedObjectReturnsTrue()
18
    {
19
        $parserTools = $this->getParserTools();
20
21
        $this->assertTrue(
22
            $parserTools->isEmbeddedObject(
23
                array(
24
                    '_href' => '/foo/bar',
25
                    '_media-type' => 'application/some-type',
26
                    'id' => 23,
27
                )
28
            )
29
        );
30
    }
31
32
    public function testIsEmbeddedObjectReturnsFalse()
33
    {
34
        $parserTools = $this->getParserTools();
35
36
        $this->assertFalse(
37
            $parserTools->isEmbeddedObject(
38
                array(
39
                    '_href' => '/foo/bar',
40
                    '_media-type' => 'application/some-type',
41
                )
42
            )
43
        );
44
    }
45
46
    public function testParseObjectElementEmbedded()
47
    {
48
        $parserTools = $this->getParserTools();
49
50
        $dispatcherMock = $this->createMock(ParsingDispatcher::class);
51
        $dispatcherMock->expects($this->once())
52
            ->method('parse')
53
            ->with(
54
                $this->isType('array'),
55
                $this->equalTo('application/my-type')
56
            );
57
58
        $parsingInput = array(
59
            '_href' => '/foo/bar',
60
            '_media-type' => 'application/my-type',
61
            'someContent' => array(),
62
        );
63
64
        $this->assertEquals(
65
            '/foo/bar',
66
            $parserTools->parseObjectElement($parsingInput, $dispatcherMock)
67
        );
68
    }
69
70
    public function testParseObjectElementNotEmbedded()
71
    {
72
        $parserTools = $this->getParserTools();
73
74
        $dispatcherMock = $this->createMock(ParsingDispatcher::class);
75
        $dispatcherMock->expects($this->never())
76
            ->method('parse');
77
78
        $parsingInput = array(
79
            '_href' => '/foo/bar',
80
            '_media-type' => 'application/my-type',
81
            '#someTextContent' => 'foo',
82
        );
83
84
        $this->assertEquals(
85
            '/foo/bar',
86
            $parserTools->parseObjectElement($parsingInput, $dispatcherMock)
87
        );
88
    }
89
90
    public function testNormalParseBooleanValue()
91
    {
92
        $tools = $this->getParserTools();
93
94
        $this->assertTrue($tools->parseBooleanValue('true'));
95
        $this->assertTrue($tools->parseBooleanValue(true));
96
        $this->assertFalse($tools->parseBooleanValue('false'));
97
        $this->assertFalse($tools->parseBooleanValue(false));
98
    }
99
100
    /**
101
     * @expectedException \RuntimeException
102
     */
103
    public function testUnexpectedValueParseBooleanValue()
104
    {
105
        $this->getParserTools()->parseBooleanValue('whatever but not a boolean');
106
    }
107
108
    protected function getParserTools()
109
    {
110
        return new ParserTools();
111
    }
112
}
113