| 1 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
* This file is part of the symfony package.
|
|
|
5 |
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
6 |
*
|
|
|
7 |
* For the full copyright and license information, please view the LICENSE
|
|
|
8 |
* file that was distributed with this source code.
|
|
|
9 |
*/
|
|
|
10 |
|
|
|
11 |
/**
|
|
|
12 |
* sfTesterPropel implements tests for Propel classes.
|
|
|
13 |
*
|
|
|
14 |
* @package symfony
|
|
|
15 |
* @subpackage test
|
|
|
16 |
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
17 |
* @version SVN: $Id: sfTesterPropel.class.php 21908 2009-09-11 12:06:21Z fabien $
|
|
|
18 |
*/
|
|
|
19 |
class sfTesterPropel extends sfTester
|
|
|
20 |
{
|
|
|
21 |
/**
|
|
|
22 |
* Prepares the tester.
|
|
|
23 |
*/
|
|
|
24 |
public function prepare()
|
|
|
25 |
{
|
|
|
26 |
}
|
|
|
27 |
|
|
|
28 |
/**
|
|
|
29 |
* Initializes the tester.
|
|
|
30 |
*/
|
|
|
31 |
public function initialize()
|
|
|
32 |
{
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
/**
|
|
|
36 |
* Tests a model.
|
|
|
37 |
*
|
|
|
38 |
* @param string $model The model class name
|
|
|
39 |
* @param array|Criteria $criteria A Criteria object or an array of conditions
|
|
|
40 |
* @param string $value The value to test
|
|
|
41 |
*
|
|
|
42 |
* @return sfTestFunctionalBase|sfTester
|
|
|
43 |
*/
|
|
|
44 |
public function check($model, $criteria, $value = true)
|
|
|
45 |
{
|
|
|
46 |
if (null === $criteria)
|
|
|
47 |
{
|
|
|
48 |
$criteria = new Criteria();
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
if (is_array($criteria))
|
|
|
52 |
{
|
|
|
53 |
$conditions = $criteria;
|
|
|
54 |
$criteria = new Criteria();
|
|
|
55 |
foreach ($conditions as $column => $condition)
|
|
|
56 |
{
|
|
|
57 |
$column = call_user_func(array(constant($model.'::PEER'), 'translateFieldName'), $column, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_COLNAME);
|
|
|
58 |
$operator = Criteria::EQUAL;
|
|
|
59 |
if ('!' == $condition[0])
|
|
|
60 |
{
|
|
|
61 |
$operator = false !== strpos($condition, '%') ? Criteria::NOT_LIKE : Criteria::NOT_EQUAL;
|
|
|
62 |
$condition = substr($condition, 1);
|
|
|
63 |
}
|
|
|
64 |
else if (false !== strpos($condition, '%'))
|
|
|
65 |
{
|
|
|
66 |
$operator = Criteria::LIKE;
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
$criteria->add($column, $condition, $operator);
|
|
|
70 |
}
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
$objects = call_user_func(array(constant($model.'::PEER'), 'doSelect'), $criteria);
|
|
|
74 |
|
|
|
75 |
if (false === $value)
|
|
|
76 |
{
|
|
|
77 |
$this->tester->is(count($objects), 0, sprintf('no %s object that matches the criteria has been found', $model));
|
|
|
78 |
}
|
|
|
79 |
else if (true === $value)
|
|
|
80 |
{
|
|
|
81 |
$this->tester->cmp_ok(count($objects), '>', 0, sprintf('%s objects that matches the criteria have been found', $model));
|
|
|
82 |
}
|
|
|
83 |
else if (is_int($value))
|
|
|
84 |
{
|
|
|
85 |
$this->tester->is(count($objects), $value, sprintf('"%s" %s objects have been found', $value, $model));
|
|
|
86 |
}
|
|
|
87 |
else
|
|
|
88 |
{
|
|
|
89 |
throw new InvalidArgumentException('The "check()" method does not takes this kind of argument.');
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
return $this->getObjectToReturn();
|
|
|
93 |
}
|
|
|
94 |
}
|