|
1 <?php |
|
2 /** |
|
3 * Zend Framework |
|
4 * |
|
5 * LICENSE |
|
6 * |
|
7 * This source file is subject to the new BSD license that is bundled |
|
8 * with this package in the file LICENSE.txt. |
|
9 * It is also available through the world-wide-web at this URL: |
|
10 * http://framework.zend.com/license/new-bsd |
|
11 * If you did not receive a copy of the license and are unable to |
|
12 * obtain it through the world-wide-web, please send an email |
|
13 * to license@zend.com so we can send you a copy immediately. |
|
14 * |
|
15 * @category Zend |
|
16 * @package Zend_Tool |
|
17 * @subpackage Framework |
|
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
20 * @version $Id: Test.php 20096 2010-01-06 02:05:09Z bkarwin $ |
|
21 */ |
|
22 |
|
23 /** |
|
24 * @see Zend_Tool_Project_Provider_Abstract |
|
25 */ |
|
26 require_once 'Zend/Tool/Project/Provider/Abstract.php'; |
|
27 |
|
28 /** |
|
29 * @see Zend_Tool_Project_Provider_Exception |
|
30 */ |
|
31 require_once 'Zend/Tool/Project/Provider/Exception.php'; |
|
32 |
|
33 /** |
|
34 * @category Zend |
|
35 * @package Zend_Tool |
|
36 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
37 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
38 */ |
|
39 class Zend_Tool_Project_Provider_Test extends Zend_Tool_Project_Provider_Abstract |
|
40 { |
|
41 |
|
42 protected $_specialties = array('Application', 'Library'); |
|
43 |
|
44 /** |
|
45 * isTestingEnabled() |
|
46 * |
|
47 * @param Zend_Tool_Project_Profile $profile |
|
48 * @return bool |
|
49 */ |
|
50 public static function isTestingEnabled(Zend_Tool_Project_Profile $profile) |
|
51 { |
|
52 $profileSearchParams = array('testsDirectory'); |
|
53 $testsDirectory = $profile->search($profileSearchParams); |
|
54 |
|
55 return $testsDirectory->isEnabled(); |
|
56 } |
|
57 |
|
58 /** |
|
59 * createApplicationResource() |
|
60 * |
|
61 * @param Zend_Tool_Project_Profile $profile |
|
62 * @param string $controllerName |
|
63 * @param string $actionName |
|
64 * @param string $moduleName |
|
65 * @return Zend_Tool_Project_Profile_Resource |
|
66 */ |
|
67 public static function createApplicationResource(Zend_Tool_Project_Profile $profile, $controllerName, $actionName, $moduleName = null) |
|
68 { |
|
69 if (!is_string($controllerName)) { |
|
70 throw new Zend_Tool_Project_Provider_Exception('Zend_Tool_Project_Provider_View::createApplicationResource() expects \"controllerName\" is the name of a controller resource to create.'); |
|
71 } |
|
72 |
|
73 if (!is_string($actionName)) { |
|
74 throw new Zend_Tool_Project_Provider_Exception('Zend_Tool_Project_Provider_View::createApplicationResource() expects \"actionName\" is the name of a controller resource to create.'); |
|
75 } |
|
76 |
|
77 $testsDirectoryResource = $profile->search('testsDirectory'); |
|
78 |
|
79 if (($testAppDirectoryResource = $testsDirectoryResource->search('testApplicationDirectory')) === false) { |
|
80 $testAppDirectoryResource = $testsDirectoryResource->createResource('testApplicationDirectory'); |
|
81 } |
|
82 |
|
83 if ($moduleName) { |
|
84 //@todo $moduleName |
|
85 $moduleName = ''; |
|
86 } |
|
87 |
|
88 if (($testAppControllerDirectoryResource = $testAppDirectoryResource->search('testApplicationControllerDirectory')) === false) { |
|
89 $testAppControllerDirectoryResource = $testAppDirectoryResource->createResource('testApplicationControllerDirectory'); |
|
90 } |
|
91 |
|
92 $testAppControllerFileResource = $testAppControllerDirectoryResource->createResource('testApplicationControllerFile', array('forControllerName' => $controllerName)); |
|
93 |
|
94 return $testAppControllerFileResource; |
|
95 } |
|
96 |
|
97 /** |
|
98 * createLibraryResource() |
|
99 * |
|
100 * @param Zend_Tool_Project_Profile $profile |
|
101 * @param string $libraryClassName |
|
102 * @return Zend_Tool_Project_Profile_Resource |
|
103 */ |
|
104 public static function createLibraryResource(Zend_Tool_Project_Profile $profile, $libraryClassName) |
|
105 { |
|
106 $testLibraryDirectoryResource = $profile->search(array('TestsDirectory', 'TestLibraryDirectory')); |
|
107 |
|
108 |
|
109 $fsParts = explode('_', $libraryClassName); |
|
110 |
|
111 $currentDirectoryResource = $testLibraryDirectoryResource; |
|
112 |
|
113 while ($nameOrNamespacePart = array_shift($fsParts)) { |
|
114 |
|
115 if (count($fsParts) > 0) { |
|
116 |
|
117 if (($libraryDirectoryResource = $currentDirectoryResource->search(array('TestLibraryNamespaceDirectory' => array('namespaceName' => $nameOrNamespacePart)))) === false) { |
|
118 $currentDirectoryResource = $currentDirectoryResource->createResource('TestLibraryNamespaceDirectory', array('namespaceName' => $nameOrNamespacePart)); |
|
119 } else { |
|
120 $currentDirectoryResource = $libraryDirectoryResource; |
|
121 } |
|
122 |
|
123 |
|
124 } else { |
|
125 |
|
126 if (($libraryFileResource = $currentDirectoryResource->search(array('TestLibraryFile' => array('forClassName' => $libraryClassName)))) === false) { |
|
127 $libraryFileResource = $currentDirectoryResource->createResource('TestLibraryFile', array('forClassName' => $libraryClassName)); |
|
128 } |
|
129 |
|
130 } |
|
131 |
|
132 } |
|
133 |
|
134 return $libraryFileResource; |
|
135 } |
|
136 |
|
137 public function enable() |
|
138 { |
|
139 |
|
140 } |
|
141 |
|
142 public function disable() |
|
143 { |
|
144 |
|
145 } |
|
146 |
|
147 /** |
|
148 * create() |
|
149 * |
|
150 * @param unknown_type $libraryClassName |
|
151 */ |
|
152 public function create($libraryClassName) |
|
153 { |
|
154 $profile = $this->_loadProfile(); |
|
155 |
|
156 if (!self::isTestingEnabled($profile)) { |
|
157 $this->_registry->getResponse()->appendContent('Testing is not enabled for this project.'); |
|
158 } |
|
159 |
|
160 $testLibraryResource = self::createLibraryResource($profile, $libraryClassName); |
|
161 |
|
162 $response = $this->_registry->getResponse(); |
|
163 |
|
164 if ($this->_registry->getRequest()->isPretend()) { |
|
165 $response->appendContent('Would create a library stub in location ' . $testLibraryResource->getContext()->getPath()); |
|
166 } else { |
|
167 $response->appendContent('Creating a library stub in location ' . $testLibraryResource->getContext()->getPath()); |
|
168 $testLibraryResource->create(); |
|
169 $this->_storeProfile(); |
|
170 } |
|
171 |
|
172 } |
|
173 |
|
174 } |