~jsing/wordpress/openstack-objectstorage-revert

« back to all changes in this revision

Viewing changes to vendor/sebastian/comparator/tests/DOMNodeComparatorTest.php

  • Committer: Jacek Nykis
  • Date: 2015-02-11 15:35:31 UTC
  • Revision ID: jacek.nykis@canonical.com-20150211153531-hmy6zi0ov2qfkl0b
Initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/*
 
3
 * This file is part of the Comparator package.
 
4
 *
 
5
 * (c) Sebastian Bergmann <sebastian@phpunit.de>
 
6
 *
 
7
 * For the full copyright and license information, please view the LICENSE
 
8
 * file that was distributed with this source code.
 
9
 */
 
10
 
 
11
namespace SebastianBergmann\Comparator;
 
12
 
 
13
use DOMNode;
 
14
use DOMDocument;
 
15
 
 
16
/**
 
17
 * @coversDefaultClass SebastianBergmann\Comparator\DOMNodeComparator
 
18
 *
 
19
 * @package    Comparator
 
20
 * @author     Jeff Welch <whatthejeff@gmail.com>
 
21
 * @copyright  Sebastian Bergmann <sebastian@phpunit.de>
 
22
 * @license    http://www.opensource.org/licenses/BSD-3-Clause  The BSD 3-Clause License
 
23
 * @link       http://www.github.com/sebastianbergmann/comparator
 
24
 */
 
25
class DOMNodeComparatorTest extends \PHPUnit_Framework_TestCase
 
26
{
 
27
    private $comparator;
 
28
 
 
29
    protected function setUp()
 
30
    {
 
31
        $this->comparator = new DOMNodeComparator;
 
32
    }
 
33
 
 
34
    public function acceptsSucceedsProvider()
 
35
    {
 
36
        $document = new DOMDocument;
 
37
        $node = new DOMNode;
 
38
 
 
39
        return array(
 
40
          array($document, $document),
 
41
          array($node, $node),
 
42
          array($document, $node),
 
43
          array($node, $document)
 
44
        );
 
45
    }
 
46
 
 
47
    public function acceptsFailsProvider()
 
48
    {
 
49
        $document = new DOMDocument;
 
50
 
 
51
        return array(
 
52
          array($document, null),
 
53
          array(null, $document),
 
54
          array(null, null)
 
55
        );
 
56
    }
 
57
 
 
58
    public function assertEqualsSucceedsProvider()
 
59
    {
 
60
        return array(
 
61
          array(
 
62
            $this->createDOMDocument('<root></root>'),
 
63
            $this->createDOMDocument('<root/>')
 
64
          ),
 
65
          array(
 
66
            $this->createDOMDocument('<root attr="bar"></root>'),
 
67
            $this->createDOMDocument('<root attr="bar"/>')
 
68
          ),
 
69
          array(
 
70
            $this->createDOMDocument('<root><foo attr="bar"></foo></root>'),
 
71
            $this->createDOMDocument('<root><foo attr="bar"/></root>')
 
72
          ),
 
73
          array(
 
74
            $this->createDOMDocument("<root>\n  <child/>\n</root>"),
 
75
            $this->createDOMDocument('<root><child/></root>')
 
76
          ),
 
77
        );
 
78
    }
 
79
 
 
80
    public function assertEqualsFailsProvider()
 
81
    {
 
82
        return array(
 
83
          array(
 
84
            $this->createDOMDocument('<root></root>'),
 
85
            $this->createDOMDocument('<bar/>')
 
86
          ),
 
87
          array(
 
88
            $this->createDOMDocument('<foo attr1="bar"/>'),
 
89
            $this->createDOMDocument('<foo attr1="foobar"/>')
 
90
          ),
 
91
          array(
 
92
            $this->createDOMDocument('<foo> bar </foo>'),
 
93
            $this->createDOMDocument('<foo />')
 
94
          ),
 
95
          array(
 
96
            $this->createDOMDocument('<foo xmlns="urn:myns:bar"/>'),
 
97
            $this->createDOMDocument('<foo xmlns="urn:notmyns:bar"/>')
 
98
          ),
 
99
          array(
 
100
            $this->createDOMDocument('<foo> bar </foo>'),
 
101
            $this->createDOMDocument('<foo> bir </foo>')
 
102
          )
 
103
        );
 
104
    }
 
105
 
 
106
    private function createDOMDocument($content)
 
107
    {
 
108
        $document = new DOMDocument;
 
109
        $document->preserveWhiteSpace = false;
 
110
        $document->loadXML($content);
 
111
 
 
112
        return $document;
 
113
    }
 
114
 
 
115
    /**
 
116
     * @covers       ::accepts
 
117
     * @dataProvider acceptsSucceedsProvider
 
118
     */
 
119
    public function testAcceptsSucceeds($expected, $actual)
 
120
    {
 
121
        $this->assertTrue(
 
122
          $this->comparator->accepts($expected, $actual)
 
123
        );
 
124
    }
 
125
 
 
126
    /**
 
127
     * @covers       ::accepts
 
128
     * @dataProvider acceptsFailsProvider
 
129
     */
 
130
    public function testAcceptsFails($expected, $actual)
 
131
    {
 
132
        $this->assertFalse(
 
133
          $this->comparator->accepts($expected, $actual)
 
134
        );
 
135
    }
 
136
 
 
137
    /**
 
138
     * @covers       ::assertEquals
 
139
     * @dataProvider assertEqualsSucceedsProvider
 
140
     */
 
141
    public function testAssertEqualsSucceeds($expected, $actual)
 
142
    {
 
143
        $exception = null;
 
144
 
 
145
        try {
 
146
            $this->comparator->assertEquals($expected, $actual);
 
147
        }
 
148
 
 
149
        catch (ComparisonFailure $exception) {
 
150
        }
 
151
 
 
152
        $this->assertNull($exception, 'Unexpected ComparisonFailure');
 
153
    }
 
154
 
 
155
    /**
 
156
     * @covers       ::assertEquals
 
157
     * @dataProvider assertEqualsFailsProvider
 
158
     */
 
159
    public function testAssertEqualsFails($expected, $actual)
 
160
    {
 
161
        $this->setExpectedException(
 
162
          'SebastianBergmann\\Comparator\\ComparisonFailure',
 
163
          'Failed asserting that two DOM'
 
164
        );
 
165
        $this->comparator->assertEquals($expected, $actual);
 
166
    }
 
167
}