Skip to content

Commit 7753ab5

Browse files
committed
ensure that a manually set lastModified date is preserved
1 parent d33cc29 commit 7753ab5

File tree

1 file changed

+33
-30
lines changed

1 file changed

+33
-30
lines changed

tests/10_Writing/AddMethodsTest.php

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,26 @@ public function testAddNode()
3030
// should take the primaryType
3131

3232
$new = $this->node->addNode('newNode');
33-
$this->assertNotNull($this->sharedFixture['session']->getNode($this->node->getPath() . '/newNode'), 'Node newNode was not created');
34-
$this->sharedFixture['session']->save();
33+
$this->assertNotNull($this->session->getNode($this->node->getPath() . '/newNode'), 'Node newNode was not created');
34+
$this->session->save();
3535
$this->assertFalse($new->isNew(), 'Node was not saved');
3636

3737
$this->renewSession();
3838

39-
$this->assertNotNull($this->sharedFixture['session']->getNode($this->node->getPath() . '/newNode'), 'Node newNode was not properly saved');
39+
$this->assertNotNull($this->session->getNode($this->node->getPath() . '/newNode'), 'Node newNode was not properly saved');
4040

4141
}
4242

4343
public function testAddNodeWithPath()
4444
{
4545
$new = $this->node->addNode('test:namespacedNode/newNode', 'nt:unstructured');
46-
$this->assertNotNull($this->sharedFixture['session']->getNode($this->node->getPath() . '/test:namespacedNode/newNode'), 'Node newNode was not created');
47-
$this->sharedFixture['session']->save();
46+
$this->assertNotNull($this->session->getNode($this->node->getPath() . '/test:namespacedNode/newNode'), 'Node newNode was not created');
47+
$this->session->save();
4848
$this->assertFalse($new->isNew(), 'Node was not saved');
4949

5050
$this->renewSession();
5151

52-
$this->assertNotNull($this->sharedFixture['session']->getNode($this->node->getPath() . '/test:namespacedNode/newNode'), 'Node newNode was not properly saved');
52+
$this->assertNotNull($this->session->getNode($this->node->getPath() . '/test:namespacedNode/newNode'), 'Node newNode was not properly saved');
5353
}
5454

5555
public function testAddNodeFileType()
@@ -59,30 +59,33 @@ public function testAddNodeFileType()
5959
$contentNode = $newNode->addNode('jcr:content', 'nt:resource');
6060
$contentNode->setProperty('jcr:mimeType', 'text/plain', Type::STRING);
6161
$contentNode->setProperty('jcr:data', 'Hello', Type::BINARY);
62-
$contentNode->setProperty('jcr:lastModified', new \DateTime(), Type::DATE);
62+
$contentNode->setProperty('jcr:lastModified', new \DateTime('2010-12-12'), Type::DATE);
6363

6464
$this->assertNotNull($newNode, 'Node newFileNode was not created');
6565
$this->assertTrue($newNode->isNew(), 'Node newFileNode is not marked dirty');
66-
$this->sharedFixture['session']->save();
66+
$this->session->save();
6767
$this->assertFalse($newNode->isNew(), 'Node newFileNode was not saved');
6868

6969
$this->renewSession();
7070

71-
$newNode = $this->sharedFixture['session']->getNode($path . '/newFileNode');
71+
$newNode = $this->session->getNode($path . '/newFileNode');
7272
$this->assertNotNull($newNode, 'Node newFileNode was not created');
7373
$this->assertEquals('nt:file', $newNode->getPrimaryNodeType()->getName(), 'Node newFileNode was not created');
74+
$lastModified = $newNode->getNode('jcr:content')->getPropertyValue('jcr:lastModified');
75+
$this->assertInstanceOf('\DateTime', $lastModified);
76+
$this->assertEquals('2010-12-12', $lastModified->format('Y-m-d'));
7477
}
7578

7679
public function testAddNodeUnstructuredType()
7780
{
7881
$new = $this->node->addNode('newUnstructuredNode', 'nt:unstructured');
79-
$this->assertNotNull($this->sharedFixture['session']->getNode($this->node->getPath() . '/newUnstructuredNode'), 'Node newUnstructuredNode was not created');
80-
$this->sharedFixture['session']->save();
82+
$this->assertNotNull($this->session->getNode($this->node->getPath() . '/newUnstructuredNode'), 'Node newUnstructuredNode was not created');
83+
$this->session->save();
8184
$this->assertFalse($new->isNew(), 'Node was not saved');
8285

8386
$this->renewSession();
8487

85-
$this->assertNotNull($this->sharedFixture['session']->getNode($this->node->getPath() . '/newUnstructuredNode'), 'Node newUnstructuredNode was not created');
88+
$this->assertNotNull($this->session->getNode($this->node->getPath() . '/newUnstructuredNode'), 'Node newUnstructuredNode was not created');
8689

8790
}
8891

@@ -105,12 +108,12 @@ public function testAddNodeAutoNamedEmptyNamehint()
105108
$name = $newnode->getName();
106109
$this->assertEquals(0, substr_count(':', $name));
107110

108-
$this->sharedFixture['session']->save();
111+
$this->session->save();
109112
$this->assertFalse($new->isNew(), 'Node was not saved');
110113

111114
$this->renewSession();
112115

113-
$this->assertNotNull($this->sharedFixture['session']->getNode($this->node->getPath() . '/jcr:content/' . $name), 'Node newNode was not properly saved');
116+
$this->assertNotNull($this->session->getNode($this->node->getPath() . '/jcr:content/' . $name), 'Node newNode was not properly saved');
114117
}
115118

116119
public function testAddNodeAutoNamedNullNamehint()
@@ -123,12 +126,12 @@ public function testAddNodeAutoNamedNullNamehint()
123126
$newnode = current($nodes);
124127
$name = $newnode->getName();
125128

126-
$this->sharedFixture['session']->save();
129+
$this->session->save();
127130
$this->assertFalse($new->isNew(), 'Node was not saved');
128131

129132
$this->renewSession();
130133

131-
$this->assertNotNull($this->sharedFixture['session']->getNode($this->node->getPath() . '/jcr:content/' . $name), 'Node newNode was not properly saved');
134+
$this->assertNotNull($this->session->getNode($this->node->getPath() . '/jcr:content/' . $name), 'Node newNode was not properly saved');
132135
}
133136

134137
public function testAddNodeAutoNamedValidNamespaceNamehint()
@@ -142,12 +145,12 @@ public function testAddNodeAutoNamedValidNamespaceNamehint()
142145
$name = $newnode->getName();
143146
$this->assertEquals('jcr:', substr($name, 0, 4));
144147

145-
$this->sharedFixture['session']->save();
148+
$this->session->save();
146149
$this->assertFalse($new->isNew(), 'Node was not saved');
147150

148151
$this->renewSession();
149152

150-
$this->assertNotNull($this->sharedFixture['session']->getNode($this->node->getPath() . '/jcr:content/' . $name), 'Node newNode was not properly saved');
153+
$this->assertNotNull($this->session->getNode($this->node->getPath() . '/jcr:content/' . $name), 'Node newNode was not properly saved');
151154
}
152155

153156
public function testAddPropertyOnUnstructured()
@@ -157,22 +160,22 @@ public function testAddPropertyOnUnstructured()
157160
$node->setProperty('testprop', 'val');
158161
$node->setProperty('refprop', $this->node->getNode('ref'));
159162

160-
$this->sharedFixture['session']->save();
163+
$this->session->save();
161164
$this->assertFalse($node->isNew(), 'Node was not saved');
162165

163166
$this->renewSession();
164-
$node = $this->sharedFixture['session']->getNode($path . '/unstructuredNode');
167+
$node = $this->session->getNode($path . '/unstructuredNode');
165168

166169
$this->assertNotNull($node, 'Node was not created');
167170
$this->assertEquals('val', $node->getPropertyValue('testprop'), 'Property was not saved correctly');
168171

169172
$node->setProperty('test2', 'val2');
170173

171-
$this->sharedFixture['session']->save();
174+
$this->session->save();
172175
$this->assertFalse($node->isNew(), 'Node was not saved');
173176
$this->assertFalse($node->getProperty('test2')->isNew(), 'Property was not saved');
174177
$this->renewSession();
175-
$node = $this->sharedFixture['session']->getNode($path . '/unstructuredNode');
178+
$node = $this->session->getNode($path . '/unstructuredNode');
176179

177180
$this->assertEquals('val2', $node->getPropertyValue('test2'), 'Property was not added correctly');
178181
}
@@ -184,22 +187,22 @@ public function testAddMultiValuePropertyOnUnstructured()
184187
$node = $this->node->addNode('unstructuredNode2', 'nt:unstructured');
185188
$node->setProperty('test', array('val', 'val2'));
186189

187-
$this->sharedFixture['session']->save();
190+
$this->session->save();
188191
$this->assertFalse($node->isNew(), 'Node was not saved');
189192

190193
$this->renewSession();
191-
$node = $this->sharedFixture['session']->getNode($path . '/unstructuredNode2');
194+
$node = $this->session->getNode($path . '/unstructuredNode2');
192195

193196
$this->assertNotNull($node, 'Node was not created');
194197
$this->assertEquals(array('val', 'val2'), $node->getPropertyValue('test'), 'Property was not saved correctly');
195198

196199
$node->setProperty('test2', array('val3', 'val4'));
197200

198-
$this->sharedFixture['session']->save();
201+
$this->session->save();
199202
$this->assertFalse($node->isNew(), 'Node was not saved');
200203
$this->assertFalse($node->getProperty('test2')->isNew(), 'Property was not saved');
201204
$this->renewSession();
202-
$node = $this->sharedFixture['session']->getNode($path . '/unstructuredNode2');
205+
$node = $this->session->getNode($path . '/unstructuredNode2');
203206

204207
$this->assertEquals(array('val3', 'val4'), $node->getPropertyValue('test2'), 'Property was not added correctly');
205208
}
@@ -250,7 +253,7 @@ public function testAddNodeInParallel()
250253
{
251254
$path = $this->node->getPath();
252255

253-
$session1 = $this->sharedFixture['session'];
256+
$session1 = $this->session;
254257
$session2 = self::$loader->getSession();
255258

256259
$node1 = $session1->getNode($path);
@@ -321,9 +324,9 @@ public function testAddNodeChild()
321324
$newChild = $newNode->addNode('child', 'nt:unstructured');
322325
$path = $newChild->getPath();
323326

324-
$this->assertTrue($this->sharedFixture['session']->nodeExists('/tests_write_manipulation_add/testAddNodeChild/parent/child'), 'Child node not found [Session]');
327+
$this->assertTrue($this->session->nodeExists('/tests_write_manipulation_add/testAddNodeChild/parent/child'), 'Child node not found [Session]');
325328

326-
$this->sharedFixture['session']->save();
329+
$this->session->save();
327330
$this->assertFalse($newChild->isNew(), 'Node was not saved');
328331

329332
// dispatch to backend
@@ -345,7 +348,7 @@ public function testAddNodeChildProperties()
345348

346349
$this->saveAndRenewSession();
347350

348-
$child = $this->sharedFixture['session']->getNode($path);
351+
$child = $this->session->getNode($path);
349352
$this->assertInstanceOf('PHPCR\NodeInterface', $child);
350353
}
351354

0 commit comments

Comments
 (0)