TYPO3 CMS  TYPO3_6-2
TreeNodeTest.php
Go to the documentation of this file.
1 <?php
3 
23 
25  // Utility functions
27 
32  private function determineFixturesPath() {
33  // We have to take the whole relative path as otherwise this test fails on Windows systems
34  return PATH_site . 'typo3/sysext/backend/Tests/Unit/Tree/Fixtures/';
35  }
36 
37  protected function setUpNodeTestData() {
38  $fixture = new \TYPO3\CMS\Backend\Tree\TreeNode();
39  $fixture->setId('Root');
40  $nodeCollection = new \TYPO3\CMS\Backend\Tree\TreeNodeCollection();
41  for ($i = 0; $i < 10; ++$i) {
42  $node = new \TYPO3\CMS\Backend\Tree\TreeNode();
43  $node->setId($i);
44  $node->setParentNode($fixture);
45  $subNodeCollection = new \TYPO3\CMS\Backend\Tree\TreeNodeCollection();
46  for ($j = 0; $j < 5; ++$j) {
47  $subNode = new \TYPO3\CMS\Backend\Tree\TreeRepresentationNode();
48  $subNode->setId($j);
49  $subNode->setLabel('SubTest');
50  $subNode->setType('Type');
51  $subNode->setClass('Class');
52  $subNode->setIcon('Icon');
53  $subNode->setCallbackAction('Callback Action');
54  $subNode->setParentNode($node);
55  $subNodeCollection->append($subNode);
56  }
57  $node->setChildNodes($subNodeCollection);
58  $nodeCollection->append($node);
59  }
60  $fixture->setChildNodes($nodeCollection);
61  return $fixture;
62  }
63 
65  // Test cases
67 
70  public function serializeFixture() {
71  $expected = trim(file_get_contents($this->determineFixturesPath() . 'serialized.txt'));
72  $fixture = $this->setUpNodeTestData();
73  $serializedString = trim($fixture->serialize());
74  $this->assertSame($expected, $serializedString);
75  }
76 
80  public function deserializeFixture() {
81  $source = trim(file_get_contents($this->determineFixturesPath() . 'serialized.txt'));
82  $node = new \TYPO3\CMS\Backend\Tree\TreeNode();
83  $node->unserialize($source);
84  $serializedString = $node->serialize();
85  $this->assertSame($source, $serializedString);
86  }
87 
91  public function compareNodes() {
92  $node = new \TYPO3\CMS\Backend\Tree\TreeNode(array('id' => '15'));
93  $otherNode = new \TYPO3\CMS\Backend\Tree\TreeNode(array('id' => '5'));
94  $compareResult = $node->compareTo($otherNode);
95  $otherNode->setId('25');
96  $compareResult = $node->compareTo($otherNode);
97  $this->assertSame(-1, $compareResult);
98  $otherNode->setId('15');
99  $compareResult = $node->compareTo($otherNode);
100  $this->assertSame(0, $compareResult);
101  }
102 
103 }