ExtBase:
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Persistence / Mapper / DataMap_testcase.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 require_once(PATH_tslib . 'class.tslib_content.php');
26
27 class Tx_ExtBase_Persistence_Mapper_DataMap_testcase extends Tx_ExtBase_Base_testcase {
28
29 public function setUp() {
30 require_once(t3lib_extMgm::extPath('blogexample') . 'Classes/Domain/Model/Blog.php');
31
32 $GLOBALS['TSFE']->fe_user = $this->getMock('tslib_feUserAuth');
33 $GLOBALS['TSFE'] = $this->getMock('tslib_fe', array('includeTCA'));
34 $this->setupTca();
35 $GLOBALS['TSFE']->expects($this->any())
36 ->method('includeTCA')
37 ->will($this->returnValue(NULL));
38
39
40 $GLOBALS['TSFE']->fe_user->user['uid'] = 999;
41 $GLOBALS['TSFE']->id = 42;
42 }
43
44 public function setupTCA() {
45 global $TCA;
46 global $_EXTKEY;
47 $TCA['tx_blogexample_domain_model_blog'] = array (
48 'ctrl' => array (
49 'title' => 'LLL:EXT:blogexample/Resources/Language/locallang_db.xml:tx_blogexample_domain_model_blog',
50 'label' => 'name',
51 'tstamp' => 'tstamp',
52 'prependAtCopy' => 'LLL:EXT:lang/locallang_general.xml:LGL.prependAtCopy',
53 'delete' => 'deleted',
54 'enablecolumns' => array (
55 'disabled' => 'hidden'
56 ),
57 'iconfile' => t3lib_extMgm::extRelPath($_EXTKEY).'Resources/Icons/icon_tx_blogexample_domain_model_blog.gif'
58 ),
59 'interface' => array(
60 'showRecordFieldList' => 'hidden, name, description, logo, posts'
61 ),
62 'columns' => array(
63 'hidden' => array(
64 'exclude' => 1,
65 'label' => 'LLL:EXT:lang/locallang_general.xml:LGL.hidden',
66 'config' => array(
67 'type' => 'check'
68 )
69 ),
70 'name' => array(
71 'exclude' => 0,
72 'label' => 'LLL:EXT:blogexample/Resources/Language/locallang_db.xml:tx_blogexample_domain_model_blog.name',
73 'config' => array(
74 'type' => 'input',
75 'size' => 20,
76 'eval' => 'trim,required',
77 'max' => 256
78 )
79 ),
80 'description' => array(
81 'exclude' => 1,
82 'label' => 'LLL:EXT:blogexample/Resources/Language/locallang_db.xml:tx_blogexample_domain_model_blog.description',
83 'config' => array(
84 'type' => 'text',
85 'eval' => 'required',
86 'rows' => 30,
87 'cols' => 80,
88 )
89 ),
90 'logo' => array(
91 'exclude' => 1,
92 'label' => 'LLL:EXT:blogexample/Resources/Language/locallang_db.xml:tx_blogexample_domain_model_blog.logo',
93 'config' => array(
94 'type' => 'group',
95 'internal_type' => 'file',
96 'allowed' => $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'],
97 'max_size' => 3000,
98 'uploadfolder' => 'uploads/pics',
99 'show_thumbs' => 1,
100 'size' => 1,
101 'maxitems' => 1,
102 'minitems' => 0
103 )
104 ),
105 'posts' => array(
106 'exclude' => 1,
107 'label' => 'LLL:EXT:blogexample/Resources/Language/locallang_db.xml:tx_blogexample_domain_model_blog.posts',
108 'config' => array(
109 'type' => 'inline',
110 // TODO is 'foreign_class' in $TCA the best way?
111 'foreign_class' => 'Tx_BlogExample_Domain_Model_Post',
112 'foreign_table' => 'tx_blogexample_domain_model_post',
113 'foreign_field' => 'blog',
114 'foreign_table_field' => 'blog_table',
115 'appearance' => array(
116 'newRecordLinkPosition' => 'bottom',
117 'collapseAll' => 1,
118 'expandSingle' => 1,
119 ),
120 )
121 ),
122 'author' => array(
123 'exclude' => 1,
124 'label' => 'LLL:EXT:blogexample/Resources/Language/locallang_db.xml:tx_blogexample_domain_model_blog.author',
125 'config' => array(
126 'type' => 'select',
127 'foreign_class' => 'Tx_BlogExample_Domain_Model_Author',
128 'foreign_table' => 'tx_blogexample_domain_model_author',
129 'maxitems' => 1,
130 )
131 ),
132 ),
133 'types' => array(
134 '1' => array('showitem' => 'hidden, name, description, logo, posts')
135 ),
136 'palettes' => array(
137 '1' => array('showitem' => '')
138 )
139 );
140 }
141
142 public function test_DataMapCanBeInitialized() {
143 $dataMap = new Tx_ExtBase_Persistence_Mapper_DataMap('Tx_BlogExample_Domain_Model_Blog');
144 $dataMap->initialize();
145 $columnMaps = $dataMap->getColumnMaps();
146 $this->assertEquals(12, count($columnMaps), 'The data map was not initialized (wrong number of column maps set).');
147 }
148
149 public function test_DeletedColumnNameCanBeResolved() {
150 $dataMap = new Tx_ExtBase_Persistence_Mapper_DataMap('Tx_BlogExample_Domain_Model_Blog');
151 $deletedColumnName = $dataMap->getDeletedColumnName();
152 $this->assertEquals($deletedColumnName, 'deleted', 'The deleted column name could not be resolved.');
153 }
154
155 public function test_HiddenColumnNameCanBeResolved() {
156 $dataMap = new Tx_ExtBase_Persistence_Mapper_DataMap('Tx_BlogExample_Domain_Model_Blog');
157 $hiddenColumnName = $dataMap->getHiddenColumnName();
158 $this->assertEquals($hiddenColumnName, 'hidden', 'The hidden column name could not be resolved.');
159 }
160
161 public function test_ColumnCanBeAdded() {
162 $dataMap = new Tx_ExtBase_Persistence_Mapper_DataMap('Tx_BlogExample_Domain_Model_Blog');
163 $dataMap->addColumn('test_column');
164 $columnMaps = $dataMap->getColumnMaps();
165 $columnMap = array_pop($columnMaps);
166 $this->assertType('Tx_ExtBase_Persistence_Mapper_ColumnMap', $columnMap, 'The column could not be added.');
167 }
168
169 public function test_ColumnListCanBeRetrieved() {
170 $dataMap = new Tx_ExtBase_Persistence_Mapper_DataMap('Tx_BlogExample_Domain_Model_Blog');
171 $dataMap->addColumn('column1');
172 $dataMap->addColumn('column2');
173 $dataMap->addColumn('column3');
174 $dataMap->addColumn('column4');
175 $columnList = $dataMap->getColumnList();
176 $this->assertEquals($columnList, 'column1,column2,column3,column4', 'The column list could not be retrieved.');
177 }
178
179 public function test_PersistablePropertyCanBeChecked() {
180 $dataMap = new Tx_ExtBase_Persistence_Mapper_DataMap('Tx_BlogExample_Domain_Model_Blog');
181 $dataMap->addColumn('configured_property');
182 $this->assertTrue($dataMap->isPersistableProperty('configuredProperty'), 'The persistable property was marked as unpersistable.');
183 $this->assertFalse($dataMap->isPersistableProperty('unconfiguredProperty'), 'The unpersistable property was marked asersistable.');
184 }
185
186 public function test_HasManyColumnIsRegisteredForForeignTable() {
187 $dataMap = new Tx_ExtBase_Persistence_Mapper_DataMap('Tx_BlogExample_Domain_Model_Blog');
188 $dataMap->initialize();
189 $this->assertEquals(Tx_ExtBase_Persistence_Mapper_ColumnMap::RELATION_HAS_MANY, $dataMap->getColumnMap('posts')->getTypeOfRelation(), 'The posts relation was not of type HAS_MANY.');
190 }
191
192 public function test_HasOneColumnIsRegisteredForForeignTableWithMaxsizeOne() {
193 $dataMap = new Tx_ExtBase_Persistence_Mapper_DataMap('Tx_BlogExample_Domain_Model_Blog');
194 $dataMap->initialize();
195 $this->assertEquals(Tx_ExtBase_Persistence_Mapper_ColumnMap::RELATION_HAS_ONE, $dataMap->getColumnMap('author')->getTypeOfRelation(), 'The author relation was not of type HAS_ONE.');
196 }
197 }
198 ?>