Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding tests for bake model.
- Loading branch information
Showing
3 changed files
with
223 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
<?php | ||
/** | ||
* Model template file. | ||
* | ||
* Used by bake to create new Model files. | ||
* | ||
* PHP versions 4 and 5 | ||
* | ||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org) | ||
* Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||
* | ||
* Licensed under The MIT License | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||
* @link http://cakephp.org | ||
* @package cake | ||
* @subpackage cake.console.libs.templates.objects | ||
* @since CakePHP(tm) v 1.3 | ||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) | ||
*/ | ||
|
||
echo "<?php\n"; ?> | ||
class <?php echo $name ?> extends <?php echo $plugin; ?>AppModel { | ||
var $name = '<?php echo $name; ?>'; | ||
<?php if ($useDbConfig != 'default'): ?> | ||
var $useDbConfig = '<?php echo $useDbConfig; ?>'; | ||
<?php endif;?> | ||
<?php if (($useTable && $useTable !== Inflector::tableize($name)) || $useTable === false): | ||
$table = "'$useTable'"; | ||
if (!$useTable): | ||
$table = 'false'; | ||
endif; | ||
echo "\tvar \$useTable = $table;\n"; | ||
endif; ?> | ||
<?php if ($primaryKey !== 'id'): ?> | ||
var $primaryKey = '<?php echo $primaryKey; ?>'; | ||
<?php endif; ?> | ||
<?php | ||
if (!empty($validate)): | ||
echo "\tvar \$validate = array(\n"; | ||
foreach ($validate as $field => $validations): | ||
echo "\t\t'$field' => array(\n"; | ||
foreach ($validations as $key => $validator): | ||
echo "\t\t\t'$key' => array('rule' => array('$validator')),\n"; | ||
endforeach; | ||
echo "\t\t),\n"; | ||
endforeach; | ||
echo "\t);\n"; | ||
endif; | ||
|
||
foreach (array('hasOne', 'belongsTo') as $assocType): | ||
if (!empty($associations[$assocType])): | ||
$typeCount = count($associations[$assocType]); | ||
echo "\n\tvar \$$assocType = array("; | ||
foreach ($associations[$assocType] as $i => $relation): | ||
$out = "\n\t\t'{$relation['alias']}' => array(\n"; | ||
$out .= "\t\t\t'className' => '{$relation['className']}',\n"; | ||
$out .= "\t\t\t'foreignKey' => '{$relation['foreignKey']}',\n"; | ||
$out .= "\t\t\t'conditions' => '',\n"; | ||
$out .= "\t\t\t'fields' => '',\n"; | ||
$out .= "\t\t\t'order' => ''\n"; | ||
$out .= "\t\t)"; | ||
if ($i + 1 < $typeCount) { | ||
$out .= ","; | ||
} | ||
echo $out; | ||
endforeach; | ||
echo "\n\t);\n"; | ||
endif; | ||
endforeach; | ||
|
||
if (!empty($associations['hasMany'])): | ||
$belongsToCount = count($associations['hasMany']); | ||
echo "\n\tvar \$hasMany = array("; | ||
foreach ($associations['hasMany'] as $i => $relation): | ||
$out = "\n\t\t'{$relation['alias']}' => array(\n"; | ||
$out .= "\t\t\t'className' => '{$relation['className']}',\n"; | ||
$out .= "\t\t\t'foreignKey' => '{$relation['foreignKey']}',\n"; | ||
$out .= "\t\t\t'dependent' => false,\n"; | ||
$out .= "\t\t\t'conditions' => '',\n"; | ||
$out .= "\t\t\t'fields' => '',\n"; | ||
$out .= "\t\t\t'order' => '',\n"; | ||
$out .= "\t\t\t'limit' => '',\n"; | ||
$out .= "\t\t\t'offset' => '',\n"; | ||
$out .= "\t\t\t'exclusive' => '',\n"; | ||
$out .= "\t\t\t'finderQuery' => '',\n"; | ||
$out .= "\t\t\t'counterQuery' => ''\n"; | ||
$out .= "\t\t)"; | ||
if ($i + 1 < $belongsToCount) { | ||
$out .= ","; | ||
} | ||
echo $out; | ||
endforeach; | ||
echo "\n\t);\n\n"; | ||
endif; | ||
|
||
if (!empty($associations['hasAndBelongsToMany'])): | ||
$habtmCount = count($associations['hasAndBelongsToMany']); | ||
echo "\n\tvar \$hasAndBelongsToMany = array("; | ||
foreach ($associations['hasAndBelongsToMany'] as $i => $relation): | ||
$out = "\n\t\t'{$relation['alias']}' => array(\n"; | ||
$out .= "\t\t\t'className' => '{$relation['className']}',\n"; | ||
$out .= "\t\t\t'joinTable' => '{$relation['joinTable']}',\n"; | ||
$out .= "\t\t\t'foreignKey' => '{$relation['foreignKey']}',\n"; | ||
$out .= "\t\t\t'associationForeignKey' => '{$relation['associationForeignKey']}',\n"; | ||
$out .= "\t\t\t'unique' => true,\n"; | ||
$out .= "\t\t\t'conditions' => '',\n"; | ||
$out .= "\t\t\t'fields' => '',\n"; | ||
$out .= "\t\t\t'order' => '',\n"; | ||
$out .= "\t\t\t'limit' => '',\n"; | ||
$out .= "\t\t\t'offset' => '',\n"; | ||
$out .= "\t\t\t'finderQuery' => '',\n"; | ||
$out .= "\t\t\t'deleteQuery' => '',\n"; | ||
$out .= "\t\t\t'insertQuery' => ''\n"; | ||
$out .= "\t\t)"; | ||
if ($i + 1 < $habtmCount) { | ||
$out .= ","; | ||
} | ||
echo $out; | ||
endforeach; | ||
echo "\n\t);\n\n"; | ||
endif; | ||
?> | ||
<?php echo '?>'; ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters