TYPO3 CMS  TYPO3_6-2
QueryFactoryTest.php
Go to the documentation of this file.
1 <?php
3 
21 
25  protected $className = 'Vendor\\Ext\\Domain\\Model\\ClubMate';
26 
30  protected $queryFactory = NULL;
31 
35  protected $dataMapper = NULL;
36 
40  protected $dataMap;
41 
42  protected function setUp() {
43  $this->dataMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMap', array('getIsStatic', 'getRootLevel'), array('Vendor\\Ext\\Domain\\Model\\ClubMate', 'tx_ext_domain_model_clubmate'));
44 
45  $this->queryFactory = $this->getAccessibleMock('TYPO3\CMS\Extbase\Persistence\Generic\QueryFactory', array('dummy'));
46  $this->queryFactory->_set('configurationManager',
47  $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface')
48  );
49 
50  $this->dataMapper = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper', array('getDataMap', 'convertClassNameToTableName'));
51  $this->dataMapper->expects($this->any())->method('getDataMap')->will($this->returnValue($this->dataMap));
52  $this->queryFactory->_set('dataMapper', $this->dataMapper);
53  }
54 
56  return array(
57  'Respect storage page is set when entity is neither marked as static nor as rootLevel.' => array(FALSE, FALSE, TRUE),
58  'Respect storage page is set when entity is marked as static and rootLevel.' => array(TRUE, TRUE, FALSE),
59  'Respect storage page is set when entity is marked as static but not rootLevel.' => array(TRUE, FALSE, FALSE),
60  'Respect storage page is set when entity is not marked as static but as rootLevel.' => array(FALSE, TRUE, FALSE),
61  );
62  }
63 
72  public function createDoesNotRespectStoragePageIfStaticOrRootLevelIsTrue($static, $rootLevel, $expectedResult) {
74  $objectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
75  $this->queryFactory->_set('objectManager', $objectManager);
76 
77  $this->dataMap->expects($this->any())->method('getIsStatic')->will($this->returnValue($static));
78  $this->dataMap->expects($this->any())->method('getRootLevel')->will($this->returnValue($rootLevel));
79 
80  $query = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\QueryInterface');
81  $objectManager->expects($this->at(0))->method('get')
82  ->with('TYPO3\\CMS\\Extbase\\Persistence\\QueryInterface')
83  ->will($this->returnValue($query));
84 
85  $querySettings = new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings();
86  $objectManager->expects($this->at(1))->method('get')
87  ->with('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QuerySettingsInterface')
88  ->will($this->returnValue($querySettings));
89  $query->expects($this->once())->method('setQuerySettings')->with($querySettings);
90  $this->queryFactory->create($this->className);
91 
92  $this->assertSame(
93  $expectedResult,
94  $querySettings->getRespectStoragePage()
95  );
96  }
97 }
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)