Project:
zfdatagrid
Code Location:
http://zfdatagrid.googlecode.com/svn/trunk/tests/trunk/tests
Outline
- > Cn APPLICATION_PATH
-
>
C
Bvb_GridTestHelper
- F $grid
- F $controller
- F $db
- F $_temp
- M setUp()
- M deployGrid($select = null)
TestHelper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php /** * Zend Framework * * LICENSE * * This source file is subject to the new BSD license that is bundled * with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://framework.zend.com/license/new-bsd * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to license@zend.com so we can send you a copy immediately. * * @category Zend * @package Zend * @subpackage UnitTests * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License * @version $Id: TestHelper.php 23522 2010-12-16 20:33:22Z andries $ */ /* * Include PHPUnit dependencies */ @require_once 'PHPUnit/Framework.php'; @require_once 'PHPUnit/Autoload.php'; // >= of PHPUnit 3.5.5 /* * Set error reporting to the level to which Zend Framework code must comply. */ error_reporting(E_ALL | E_STRICT); /* * Determine the root, library, and tests directories of the framework * distribution. */ $zfRoot = realpath(dirname(dirname(__FILE__))); $zfCoreLibrary = "$zfRoot/library"; $zfCoreTests = "$zfRoot/tests"; /* * Prepend the Zend Framework library/ and tests/ directories to the * include_path. This allows the tests to run out of the box and helps prevent * loading other copies of the framework code and tests that would supersede * this copy. */ $path = array( $zfCoreLibrary, $zfCoreTests, get_include_path() ); set_include_path(implode(PATH_SEPARATOR, $path)); require_once 'Zend/Loader/Autoloader.php'; $autoloader = Zend_Loader_Autoloader::getInstance (); $autoloader->setFallbackAutoloader ( true ); $autoloader->suppressNotFoundWarnings ( true ); define('APPLICATION_PATH', $zfRoot.'/application'); $c = Zend_Controller_Front::getInstance(); $c->setRequest(new Zend_Controller_Request_Http()); $c->setResponse(new Zend_Controller_Response_Cli()); unset($zfRoot, $zfCoreLibrary, $zfCoreTests, $path); class Bvb_GridTestHelper extends Zend_Test_PHPUnit_ControllerTestCase { /** * * @var Bvb_Grid */ protected $grid; protected $controller; protected $db; protected $_temp; public function setUp() { date_default_timezone_set('Europe/Lisbon'); $this->_temp = realpath(APPLICATION_PATH.'/../tests/_temp/').'/'; include_once APPLICATION_PATH.'/models/Model.php'; // Assign and instantiate in one step: $this->bootstrap = new Zend_Application( 'general', APPLICATION_PATH . '/config.ini' ); $this->controller = Zend_Controller_Front::getInstance(); $this->db = $this->bootstrap->getBootstrap()->getPluginResource('db')->getDbAdapter(); $this->controller->setControllerDirectory(APPLICATION_PATH . '/application/controllers'); $this->controller->setDefaultModule('defualt'); $this->controller->setDefaultControllerName('site'); $this->grid = Bvb_Grid::factory('Table'); $this->grid->setParam('module', 'default'); $this->grid->setParam('controller', 'site'); $this->grid->setView(new Zend_View(array())); parent::setUp(); } public function deployGrid($select = null) { if ($select === null) { $select = $this->db->select()->from('unit'); } $this->grid->setSource(new Bvb_Grid_Source_Zend_Select($select)); $grid = $this->grid->deploy(); $this->controller->getResponse()->setBody($grid); return $grid; } }
