Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 171 lines (145 sloc) 5.122 kB
be00b4d @Seldaek Refactored unit tests so that they follow the diretory structure of src/
Seldaek authored
1 <?php
2
3 namespace Jackalope;
4
5 class ItemTest extends TestCase
6 {
5c373cd @dbu unit tests for item and some more for the session
dbu authored
7 /**
8 * create the item and mock any of the constructor parameters not specified explicitly
9 */
10 protected function getItem($factory = null, $path = null, $session = null, $objectManager = null, $new = false)
be00b4d @Seldaek Refactored unit tests so that they follow the diretory structure of src/
Seldaek authored
11 {
5c373cd @dbu unit tests for item and some more for the session
dbu authored
12 if (! $factory) {
7eb1faa @lsmith77 fix tests
lsmith77 authored
13 $factory = $this->getMockBuilder('Jackalope\FactoryInterface')->disableOriginalConstructor()->getMock();
5c373cd @dbu unit tests for item and some more for the session
dbu authored
14 }
15 if (! $path) {
16 $path = '/';
17 }
18 if (! $session) {
19 $session = $this->getSessionMock();
20 }
21 if (! $objectManager) {
22 $objectManager = $this->getObjectManagerMock();
23 }
24 return new TestItem($factory, $path, $session, $objectManager, $new);
be00b4d @Seldaek Refactored unit tests so that they follow the diretory structure of src/
Seldaek authored
25 }
26
5c373cd @dbu unit tests for item and some more for the session
dbu authored
27 /**
28 * a mock that will additionally expect getNodeByPath once with $path and return the string 'placeholder'
29 */
30 protected function getObjectManagerMockWithPath($path)
31 {
7eb1faa @lsmith77 fix tests
lsmith77 authored
32 $factory = $this->getMockBuilder('Jackalope\FactoryInterface')->disableOriginalConstructor()->getMock();
5c373cd @dbu unit tests for item and some more for the session
dbu authored
33 $om = $this->getMock('\Jackalope\ObjectManager', array('getNodeTypes', 'getNodeByPath'), array($factory, $this->getTransportStub('/jcr:root'), $this->getSessionMock()));
34 $om->expects($this->once())
35 ->method('getNodeByPath')
36 ->with($this->equalTo($path))
37 ->will($this->returnValue('placeholder'));
38
39 return $om;
40 }
41
42 public function testPath()
43 {
44 $item = $this->getItem();
45 $item->setPath('/b');
46 $this->assertEquals('/b', $item->getPath());
47 }
48
49 public function testName()
50 {
51 $item = $this->getItem(null, '/path/itemname');
52 $this->assertEquals('itemname', $item->getName());
53 $item->setPath('/other/name');
54 $this->assertEquals('name', $item->getName());
55 }
56
57 public function testGetAncestor()
58 {
59 $om = $this->getObjectManagerMockWithPath('/path');
60 $item = $this->getItem(null, '/path/name', null, $om);
61
62 $self = $item->getAncestor(2);
63 $this->assertSame($item, $self);
64
65 $ancestor = $item->getAncestor(1);
66 $this->assertSame('placeholder', $ancestor);
67 }
68
69 public function testGetAncestorRoot()
70 {
71 $om = $this->getObjectManagerMockWithPath('/');
72
73 $item = $this->getItem(null, '/path/name', null, $om);
74
75 $ancestor = $item->getAncestor(0);
76 $this->assertSame('placeholder', $ancestor);
77 }
78
79 /**
80 * @expectedException \PHPCR\ItemNotFoundException
81 */
82 public function testGetAncestorTooDeep()
83 {
84 $item = $this->getItem(null, '/path/name');
85 $ancestor = $item->getAncestor(3);
86 }
87
88 /**
89 * @expectedException \PHPCR\ItemNotFoundException
90 */
91 public function testGetAncestorTooLow()
92 {
93 $item = $this->getItem(null, '/path/name');
94 $ancestor = $item->getAncestor(-1);
95 }
96
97 public function testGetParent()
98 {
99 $om = $this->getObjectManagerMockWithPath('/path');
100 $item = $this->getItem(null, '/path/name', null, $om);
101 $parent = $item->getParent();
102 $this->assertSame('placeholder', $parent);
103 }
104
105 public function testGetDepth()
106 {
107 $item = $this->getItem(null, '/path/name');
108 $this->assertEquals(2, $item->getDepth());
109 $item = $this->getItem(null, '/');
110 $this->assertEquals(0, $item->getDepth());
111 }
112
113 public function testGetSession()
114 {
115 $session = $this->getSessionMock();
7eb1faa @lsmith77 fix tests
lsmith77 authored
116 $item = $this->getItem(null, null, $session);
5c373cd @dbu unit tests for item and some more for the session
dbu authored
117 $this->assertEquals($session, $item->getSession());
118 }
119
120 public function testIsSame()
121 {
122 $this->markTestSkipped('TODO: do some mean stuff');
123 }
124
125 public function testAccept()
126 {
127 $item = $this->getItem();
128 $visitor = $this->getMock('\PHPCR\ItemVisitorInterface');
129 $visitor->expects($this->once())
130 ->method('visit');
131 $item->accept($visitor);
132 }
133
134 public function testRemove()
135 {
a161e7f @lsmith77 added use statements
lsmith77 authored
136 $factory = new Factory;
5c373cd @dbu unit tests for item and some more for the session
dbu authored
137 $om = $this->getMock('\Jackalope\ObjectManager', array('getNodeTypes', 'removeItem'), array($factory, $this->getTransportStub('/jcr:root'), $this->getSessionMock()));
138 $om->expects($this->once())
139 ->method('removeItem')
140 ->with($this->equalTo('/path'));
141
142 $item = $this->getItem(null, '/path', null, $om);
143 $item->remove();
144 $this->assertTrue($item->isDeleted());
145 }
146
147 /**
148 * @expectedException \PHPCR\RepositoryException
149 */
150 public function testRemoveRoot()
151 {
7eb1faa @lsmith77 fix tests
lsmith77 authored
152 $item = $this->getItem(null, '/');
5c373cd @dbu unit tests for item and some more for the session
dbu authored
153 $item->remove();
154 }
155
156 // TODO: test the whole state model processes (probably in separate test case)
157 }
158
159 class TestItem extends Item
160 {
7eb1faa @lsmith77 fix tests
lsmith77 authored
161 public function __construct(FactoryInterface $factory, $path, Session $session, ObjectManager $objectManager, $new = false)
5c373cd @dbu unit tests for item and some more for the session
dbu authored
162 {
163 parent::__construct($factory,$path,$session,$objectManager,$new);
164 }
7eb1faa @lsmith77 fix tests
lsmith77 authored
165
5c373cd @dbu unit tests for item and some more for the session
dbu authored
166 public function refresh($keep)
167 {
168 // tested in extending classes
169 }
be00b4d @Seldaek Refactored unit tests so that they follow the diretory structure of src/
Seldaek authored
170 }
Something went wrong with that request. Please try again.