ExtBase:
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Persistence / Repository_testcase.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Christopher Hlubek <hlubek@networkteam.com>
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 class Tx_ExtBase_Persistence_Repository_testcase extends Tx_ExtBase_Base_testcase {
26 public function __construct() {
27 require_once(t3lib_extMgm::extPath('blogexample', 'Classes/Domain/Model/BlogRepository.php'));
28 }
29
30 public function test_FindDelegatesToObjectRelationalMapperBuildQueryAndFetch() {
31 $repository = new Tx_BlogExample_Domain_Model_BlogRepository();
32 $repository->dataMapper = $this->getMock('Tx_ExtBase_Persistence_Mapper_ObjectRelationalMapper', array('buildQuery', 'fetch'), array(), '', FALSE);
33 $repository->dataMapper->expects($this->once())
34 ->method('buildQuery')
35 ->with($this->equalTo('Tx_BlogExample_Domain_Model_Blog'), $this->equalTo('foo'))
36 ->will($this->returnValue('query'));
37 $repository->dataMapper->expects($this->once())
38 ->method('fetch')
39 ->with($this->equalTo('Tx_BlogExample_Domain_Model_Blog'), $this->equalTo('query'))
40 ->will($this->returnValue(array()));
41
42 $result = $repository->findByConditions('foo');
43 $this->assertEquals(array(), $result);
44 }
45
46 public function test_MagicFindByPropertyUsesGenericFind() {
47 $repository = $this->getMock('Tx_BlogExample_Domain_Model_BlogRepository', array('findByConditions'), array('Tx_BlogExample_Domain_Model_Blog'));
48 $repository->expects($this->once())
49 ->method('findByConditions')
50 ->with($this->equalTo(array('name' => 'foo')))
51 ->will($this->returnValue(array()));
52
53 $repository->findByName('foo');
54 }
55
56 public function test_MagicFindOneByPropertyUsesGenericFind() {
57 $repository = $this->getMock('TX_Blogexample_Domain_Model_BlogRepository', array('findByConditions'), array('Tx_BlogExample_Domain_Model_Blog'));
58 $repository->expects($this->once())
59 ->method('findByConditions')
60 ->with($this->equalTo(array('name' => 'foo')), $this->equalTo(''), $this->equalTo(''), $this->equalTo(1))
61 ->will($this->returnValue(array()));
62
63 $repository->findOneByName('foo');
64 }
65 }
66 ?>