Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch '1.2' of dev@code.cakephp.org:cakephp into 1.2

  • Loading branch information...
commit 12e0652943a94ee2c727a4daaee85a8ae0670340 2 parents 6821e7c + daadac0
Mark Story markstory authored
41 cake/console/libs/schema.php
... ... @@ -1,5 +1,4 @@
1 1 <?php
2   -/* SVN FILE: $Id$ */
3 2 /**
4 3 * Command-line database management utility to automate programmer chores.
5 4 *
@@ -9,20 +8,17 @@
9 8 * PHP versions 4 and 5
10 9 *
11 10 * CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
12   - * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
  11 + * Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
13 12 *
14 13 * Licensed under The MIT License
15 14 * Redistributions of files must retain the above copyright notice.
16 15 *
17 16 * @filesource
18   - * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
  17 + * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
19 18 * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
20 19 * @package cake
21 20 * @subpackage cake.cake.console.libs
22 21 * @since CakePHP(tm) v 1.2.0.5550
23   - * @version $Revision$
24   - * @modifiedby $LastChangedBy$
25   - * @lastmodified $Date$
26 22 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
27 23 */
28 24 App::import('File');
@@ -116,7 +112,7 @@ function view() {
116 112 * @access public
117 113 */
118 114 function generate() {
119   - $this->out('Generating Schema...');
  115 + $this->out(__('Generating Schema...', true));
120 116 $options = array();
121 117 if (isset($this->params['f'])) {
122 118 $options = array('models' => false);
@@ -131,7 +127,7 @@ function generate() {
131 127 $snapshot = true;
132 128 $result = strtolower($this->in("Schema file exists.\n [O]verwrite\n [S]napshot\n [Q]uit\nWould you like to do?", array('o', 's', 'q'), 's'));
133 129 if ($result === 'q') {
134   - $this->_stop();
  130 + return $this->_stop();
135 131 }
136 132 if ($result === 'o') {
137 133 $snapshot = false;
@@ -224,7 +220,7 @@ function dump() {
224 220 */
225 221 function run() {
226 222 if (!isset($this->args[0])) {
227   - $this->err('command not found');
  223 + $this->err(__('Command not found', true));
228 224 $this->_stop();
229 225 }
230 226
@@ -271,8 +267,8 @@ function run() {
271 267 $this->__update($Schema, $table);
272 268 break;
273 269 default:
274   - $this->err(__('command not found', true));
275   - $this->_stop();
  270 + $this->err(__('Command not found', true));
  271 + $this->_stop();
276 272 }
277 273 }
278 274 /**
@@ -281,7 +277,7 @@ function run() {
281 277 *
282 278 * @access private
283 279 */
284   - function __create($Schema, $table = null) {
  280 + function __create(&$Schema, $table = null) {
285 281 $db =& ConnectionManager::getDataSource($this->Schema->connection);
286 282
287 283 $drop = $create = array();
@@ -304,7 +300,7 @@ function __create($Schema, $table = null) {
304 300 $this->out(array_keys($drop));
305 301
306 302 if ('y' == $this->in(__('Are you sure you want to drop the table(s)?', true), array('y', 'n'), 'n')) {
307   - $this->out('Dropping table(s).');
  303 + $this->out(__('Dropping table(s).', true));
308 304 $this->__run($drop, 'drop', $Schema);
309 305 }
310 306
@@ -312,7 +308,7 @@ function __create($Schema, $table = null) {
312 308 $this->out(array_keys($create));
313 309
314 310 if ('y' == $this->in(__('Are you sure you want to create the table(s)?', true), array('y', 'n'), 'y')) {
315   - $this->out('Creating table(s).');
  311 + $this->out(__('Creating table(s).', true));
316 312 $this->__run($create, 'create', $Schema);
317 313 }
318 314
@@ -324,11 +320,15 @@ function __create($Schema, $table = null) {
324 320 *
325 321 * @access private
326 322 */
327   - function __update($Schema, $table = null) {
  323 + function __update(&$Schema, $table = null) {
328 324 $db =& ConnectionManager::getDataSource($this->Schema->connection);
329 325
330   - $this->out('Comparing Database to Schema...');
331   - $Old = $this->Schema->read();
  326 + $this->out(__('Comparing Database to Schema...', true));
  327 + $options = array();
  328 + if (isset($this->params['f'])) {
  329 + $options['models'] = false;
  330 + }
  331 + $Old = $this->Schema->read($options);
332 332 $compare = $this->Schema->compare($Old, $Schema);
333 333
334 334 $contents = array();
@@ -361,7 +361,7 @@ function __update($Schema, $table = null) {
361 361 *
362 362 * @access private
363 363 */
364   - function __run($contents, $event, $Schema) {
  364 + function __run($contents, $event, &$Schema) {
365 365 if (empty($contents)) {
366 366 $this->err(__('Sql could not be run', true));
367 367 return;
@@ -369,7 +369,7 @@ function __run($contents, $event, $Schema) {
369 369 Configure::write('debug', 2);
370 370 $db =& ConnectionManager::getDataSource($this->Schema->connection);
371 371 $db->fullDebug = true;
372   -
  372 +
373 373 foreach ($contents as $table => $sql) {
374 374 if (empty($sql)) {
375 375 $this->out(sprintf(__('%s is up to date.', true), $table));
@@ -403,7 +403,8 @@ function __run($contents, $event, $Schema) {
403 403 * @access public
404 404 */
405 405 function help() {
406   - $this->out("The Schema Shell generates a schema object from \n\t\tthe database and updates the database from the schema.");
  406 + $this->out("The Schema Shell generates a schema object from");
  407 + $this->out("the database and updates the database from the schema.");
407 408 $this->hr();
408 409 $this->out("Usage: cake schema <command> <arg1> <arg2>...");
409 410 $this->hr();
6 cake/libs/controller/components/email.php
@@ -680,10 +680,14 @@ function __smtp() {
680 680 return false;
681 681 }
682 682
  683 + $httpHost = env('HTTP_HOST');
  684 +
683 685 if (isset($this->smtpOptions['client'])) {
684 686 $host = $this->smtpOptions['client'];
  687 + } elseif (!empty($httpHost)) {
  688 + $host = $httpHost;
685 689 } else {
686   - $host = env('HTTP_HOST');
  690 + $host = 'localhost';
687 691 }
688 692
689 693 if (!$this->__smtpSend("HELO {$host}", '250')) {
3  cake/libs/model/datasources/dbo/dbo_mssql.php
@@ -259,6 +259,9 @@ function value($data, $column = null, $safe = false) {
259 259 if ($data === null) {
260 260 return 'NULL';
261 261 }
  262 + if (in_array($column, array('integer', 'float', 'binary')) && $data === '') {
  263 + return 'NULL';
  264 + }
262 265 if ($data === '') {
263 266 return "''";
264 267 }
1  cake/libs/model/schema.php
@@ -172,6 +172,7 @@ function load($options = array()) {
172 172 * - 'connection' - the db connection to use
173 173 * - 'name' - name of the schema
174 174 * - 'models' - a list of models to use, or false to ignore models
  175 + *
175 176 * @param array $options schema object properties
176 177 * @return array Array indexed by name and tables
177 178 * @access public
353 cake/tests/cases/console/libs/schema.test.php
... ... @@ -0,0 +1,353 @@
  1 +<?php
  2 +/**
  3 + * SchemaShellTest Test file
  4 + *
  5 + * PHP versions 4 and 5
  6 + *
  7 + * CakePHP : Rapid Development Framework (http://www.cakephp.org)
  8 + * Copyright 2006-2009, Cake Software Foundation, Inc.
  9 + *
  10 + * Licensed under The MIT License
  11 + * Redistributions of files must retain the above copyright notice.
  12 + *
  13 + * @filesource
  14 + * @copyright Copyright 2006-2009, Cake Software Foundation, Inc.
  15 + * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
  16 + * @package cake
  17 + * @subpackage cake.tests.cases.console.libs.Shells
  18 + * @since CakePHP v 1.3
  19 + * @license http://www.opensource.org/licenses/mit-license.php The MIT License
  20 + */
  21 +App::import('Shell', 'Shell', false);
  22 +App::import('Model', 'Schema', false);
  23 +
  24 +if (!defined('DISABLE_AUTO_DISPATCH')) {
  25 + define('DISABLE_AUTO_DISPATCH', true);
  26 +}
  27 +
  28 +if (!class_exists('ShellDispatcher')) {
  29 + ob_start();
  30 + $argv = false;
  31 + require CAKE . 'console' . DS . 'cake.php';
  32 + ob_end_clean();
  33 +}
  34 +
  35 +if (!class_exists('SchemaShell')) {
  36 + require CAKE . 'console' . DS . 'libs' . DS . 'schema.php';
  37 +}
  38 +
  39 +Mock::generatePartial(
  40 + 'ShellDispatcher', 'TestSchemaShellMockShellDispatcher',
  41 + array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
  42 +);
  43 +Mock::generatePartial(
  44 + 'SchemaShell', 'MockSchemaShell',
  45 + array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop')
  46 +);
  47 +
  48 +Mock::generate('CakeSchema', 'MockSchemaCakeSchema');
  49 +
  50 +/**
  51 + * Test for Schema database management
  52 + *
  53 + * @package cake
  54 + * @subpackage cake.tests.cases.libs
  55 + */
  56 +class SchemaShellTestSchema extends CakeSchema {
  57 +
  58 +/**
  59 + * name property
  60 + *
  61 + * @var string 'MyApp'
  62 + * @access public
  63 + */
  64 + var $name = 'SchemaShellTest';
  65 +
  66 +/**
  67 + * connection property
  68 + *
  69 + * @var string 'test_suite'
  70 + * @access public
  71 + */
  72 + var $connection = 'test_suite';
  73 +
  74 +/**
  75 + * comments property
  76 + *
  77 + * @var array
  78 + * @access public
  79 + */
  80 + var $comments = array(
  81 + 'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
  82 + 'post_id' => array('type' => 'integer', 'null' => false, 'default' => 0),
  83 + 'user_id' => array('type' => 'integer', 'null' => false),
  84 + 'title' => array('type' => 'string', 'null' => false, 'length' => 100),
  85 + 'comment' => array('type' => 'text', 'null' => false, 'default' => null),
  86 + 'published' => array('type' => 'string', 'null' => true, 'default' => 'N', 'length' => 1),
  87 + 'created' => array('type' => 'datetime', 'null' => true, 'default' => null),
  88 + 'updated' => array('type' => 'datetime', 'null' => true, 'default' => null),
  89 + 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)),
  90 + );
  91 +
  92 +/**
  93 + * posts property
  94 + *
  95 + * @var array
  96 + * @access public
  97 + */
  98 + var $articles = array(
  99 + 'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
  100 + 'user_id' => array('type' => 'integer', 'null' => true, 'default' => ''),
  101 + 'title' => array('type' => 'string', 'null' => false, 'default' => 'Title'),
  102 + 'body' => array('type' => 'text', 'null' => true, 'default' => null),
  103 + 'summary' => array('type' => 'text', 'null' => true),
  104 + 'published' => array('type' => 'string', 'null' => true, 'default' => 'Y', 'length' => 1),
  105 + 'created' => array('type' => 'datetime', 'null' => true, 'default' => null),
  106 + 'updated' => array('type' => 'datetime', 'null' => true, 'default' => null),
  107 + 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)),
  108 + );
  109 +}
  110 +
  111 +/**
  112 + * SchemaShellTest class
  113 + *
  114 + * @package cake
  115 + * @subpackage cake.tests.cases.console.libs.Shells
  116 + */
  117 +class SchemaShellTest extends CakeTestCase {
  118 +
  119 + var $fixtures = array('core.article', 'core.user');
  120 +/**
  121 + * startTest method
  122 + *
  123 + * @return void
  124 + * @access public
  125 + */
  126 + function startTest() {
  127 + $this->Dispatcher =& new TestSchemaShellMockShellDispatcher();
  128 + $this->Shell =& new MockSchemaShell($this->Dispatcher);
  129 + $this->Shell->Dispatch =& $this->Dispatcher;
  130 + }
  131 +
  132 +/**
  133 + * endTest method
  134 + *
  135 + * @return void
  136 + * @access public
  137 + */
  138 + function endTest() {
  139 + ClassRegistry::flush();
  140 + }
  141 +
  142 +/**
  143 + * test startup method
  144 + *
  145 + * @return void
  146 + **/
  147 + function testStartup() {
  148 + $this->Shell->startup();
  149 + $this->assertTrue(isset($this->Shell->Schema));
  150 + $this->assertTrue(is_a($this->Shell->Schema, 'CakeSchema'));
  151 + $this->assertEqual(strtolower($this->Shell->Schema->name), APP_DIR);
  152 + $this->assertEqual($this->Shell->Schema->file, 'schema.php');
  153 +
  154 + unset($this->Shell->Schema);
  155 + $this->Shell->params = array(
  156 + 'name' => 'TestSchema'
  157 + );
  158 + $this->Shell->startup();
  159 + $this->assertEqual($this->Shell->Schema->name, 'TestSchema');
  160 + $this->assertEqual($this->Shell->Schema->file, 'test_schema.php');
  161 + $this->assertEqual($this->Shell->Schema->connection, 'default');
  162 + $this->assertEqual($this->Shell->Schema->path, APP . 'config' . DS . 'sql');
  163 +
  164 + unset($this->Shell->Schema);
  165 + $this->Shell->params = array(
  166 + 'file' => 'other_file.php',
  167 + 'connection' => 'test_suite',
  168 + 'path' => '/test/path'
  169 + );
  170 + $this->Shell->startup();
  171 + $this->assertEqual(strtolower($this->Shell->Schema->name), APP_DIR);
  172 + $this->assertEqual($this->Shell->Schema->file, 'other_file.php');
  173 + $this->assertEqual($this->Shell->Schema->connection, 'test_suite');
  174 + $this->assertEqual($this->Shell->Schema->path, '/test/path');
  175 + }
  176 +
  177 +/**
  178 + * Test View - and that it dumps the schema file to stdout
  179 + *
  180 + * @return void
  181 + **/
  182 + function testView() {
  183 + $this->Shell->startup();
  184 + $this->Shell->Schema->path = APP . 'config' . DS . 'schema';
  185 + $this->Shell->params['file'] = 'i18n.php';
  186 + $this->Shell->expectOnce('_stop');
  187 + $this->Shell->view();
  188 + }
  189 +
  190 +/**
  191 + * test dump() with sql file generation
  192 + *
  193 + * @return void
  194 + **/
  195 + function testDumpWithFileWriting() {
  196 + $file =& new File(APP . 'config' . DS . 'sql' . DS . 'i18n.php');
  197 + $contents = $file->read();
  198 + $file =& new File(TMP . 'tests' . DS . 'i18n.php');
  199 + $file->write($contents);
  200 +
  201 + $this->Shell->params = array('name' => 'i18n');
  202 + $this->Shell->args = array('write');
  203 + $this->Shell->startup();
  204 + $this->Shell->Schema->path = TMP . 'tests';
  205 + $this->Shell->dump();
  206 +
  207 + $sql =& new File(TMP . 'tests' . DS . 'i18n.sql');
  208 + $contents = $sql->read();
  209 + $this->assertPattern('/DROP TABLE/', $contents);
  210 + $this->assertPattern('/CREATE TABLE `i18n`/', $contents);
  211 + $this->assertPattern('/id/', $contents);
  212 + $this->assertPattern('/model/', $contents);
  213 + $this->assertPattern('/field/', $contents);
  214 + $this->assertPattern('/locale/', $contents);
  215 + $this->assertPattern('/foreign_key/', $contents);
  216 + $this->assertPattern('/content/', $contents);
  217 +
  218 + $sql->delete();
  219 + $file->delete();
  220 + }
  221 +
  222 +/**
  223 + * test generate with snapshot generation
  224 + *
  225 + * @return void
  226 + */
  227 + function testGenerateSnaphot() {
  228 + $this->Shell->path = TMP;
  229 + $this->Shell->params['file'] = 'schema.php';
  230 + $this->Shell->args = array('snapshot');
  231 + $this->Shell->Schema =& new MockSchemaCakeSchema();
  232 + $this->Shell->Schema->setReturnValue('read', array('schema data'));
  233 + $this->Shell->Schema->setReturnValue('write', true);
  234 +
  235 + $this->Shell->Schema->expectOnce('read');
  236 + $this->Shell->Schema->expectOnce('write', array(array('schema data', 'file' => 'schema_1.php')));
  237 +
  238 + $this->Shell->generate();
  239 + }
  240 +
  241 +/**
  242 + * test generate without a snapshot.
  243 + *
  244 + * @return void
  245 + **/
  246 + function testGenerateNoOverwrite() {
  247 + touch(TMP . 'schema.php');
  248 + $this->Shell->params['file'] = 'schema.php';
  249 + $this->Shell->args = array();
  250 +
  251 + $this->Shell->setReturnValue('in', 'q');
  252 + $this->Shell->Schema =& new MockSchemaCakeSchema();
  253 + $this->Shell->Schema->path = TMP;
  254 + $this->Shell->Schema->expectNever('read');
  255 +
  256 + $result = $this->Shell->generate();
  257 + unlink(TMP . 'schema.php');
  258 + }
  259 +
  260 +/**
  261 + * test generate with overwriting of the schema files.
  262 + *
  263 + * @return void
  264 + **/
  265 + function testGenerateOverwrite() {
  266 + touch(TMP . 'schema.php');
  267 + $this->Shell->params['file'] = 'schema.php';
  268 + $this->Shell->args = array();
  269 +
  270 + $this->Shell->setReturnValue('in', 'o');
  271 + $this->Shell->expectAt(1, 'out', array(new PatternExpectation('/Schema file:\s[a-z\.]+\sgenerated/')));
  272 + $this->Shell->Schema =& new MockSchemaCakeSchema();
  273 + $this->Shell->Schema->path = TMP;
  274 + $this->Shell->Schema->setReturnValue('read', array('schema data'));
  275 + $this->Shell->Schema->setReturnValue('write', true);
  276 +
  277 + $this->Shell->Schema->expectOnce('read');
  278 + $this->Shell->Schema->expectOnce('write', array(array('schema data', 'file' => 'schema.php')));
  279 +
  280 + $this->Shell->generate();
  281 + unlink(TMP . 'schema.php');
  282 + }
  283 +
  284 +/**
  285 + * Test schema run create with no table args.
  286 + *
  287 + * @return void
  288 + **/
  289 + function testRunCreateNoArgs() {
  290 + $this->Shell->params = array(
  291 + 'connection' => 'test_suite',
  292 + 'name' => 'i18n',
  293 + 'path' => APP . 'config' . DS . 'sql'
  294 + );
  295 + $this->Shell->args = array('create');
  296 + $this->Shell->startup();
  297 + $this->Shell->setReturnValue('in', 'y');
  298 + $this->Shell->run();
  299 +
  300 + $db =& ConnectionManager::getDataSource('test_suite');
  301 + $sources = $db->listSources();
  302 + $this->assertTrue(in_array($db->config['prefix'] . 'i18n', $sources));
  303 + }
  304 +
  305 +/**
  306 + * Test schema run create with no table args.
  307 + *
  308 + * @return void
  309 + **/
  310 + function testRunCreateWithTableArgs() {
  311 + $this->Shell->params = array(
  312 + 'connection' => 'test_suite',
  313 + 'name' => 'DbAcl',
  314 + 'path' => APP . 'config' . DS . 'sql'
  315 + );
  316 + $this->Shell->args = array('create', 'acos');
  317 + $this->Shell->startup();
  318 + $this->Shell->setReturnValue('in', 'y');
  319 + $this->Shell->run();
  320 +
  321 + $db =& ConnectionManager::getDataSource('test_suite');
  322 + $sources = $db->listSources();
  323 + $this->assertTrue(in_array($db->config['prefix'] . 'acos', $sources));
  324 + $this->assertFalse(in_array($db->config['prefix'] . 'aros', $sources));
  325 + $this->assertFalse(in_array('aros_acos', $sources));
  326 + }
  327 +
  328 +/**
  329 + * test run update with a table arg.
  330 + *
  331 + * @return void
  332 + **/
  333 + function testRunUpdateWithTable() {
  334 + $this->Shell->params = array(
  335 + 'name' => 'SchemaShellTest',
  336 + 'connection' => 'test_suite',
  337 + 'f' => true
  338 + );
  339 + $this->Shell->args = array('update', 'articles');
  340 + $this->Shell->startup();
  341 + $this->Shell->setReturnValue('in', 'y');
  342 + $this->Shell->run();
  343 +
  344 + $article =& new Model(array('name' => 'Article', 'ds' => 'test_suite'));
  345 + $fields = $article->schema();
  346 + $this->assertTrue(isset($fields['summary']));
  347 +
  348 + $this->_fixtures['core.article']->drop($this->db);
  349 + $this->_fixtures['core.article']->create($this->db);
  350 + }
  351 +
  352 +}
  353 +?>
3  cake/tests/cases/libs/controller/components/email.test.php
@@ -478,10 +478,9 @@ function testSmtpSendSocket() {
478 478 $response = $this->Controller->EmailTest->smtpSend('HELO', '250');
479 479 $this->assertPattern('/501 Syntax: HELO hostname/', $this->Controller->EmailTest->smtpError);
480 480
481   - $this->Controller->EmailTest->smtpError = null;
  481 + $this->Controller->EmailTest->reset();
482 482 $response = $this->Controller->EmailTest->smtpSend('HELO somehostname', '250');
483 483 $this->assertNoPattern('/501 Syntax: HELO hostname/', $this->Controller->EmailTest->smtpError);
484   -
485 484 }
486 485 /**
487 486 * testSendDebug method
12 cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php
@@ -345,6 +345,18 @@ function testQuoting() {
345 345 $expected = "'1,2'";
346 346 $result = $this->db->value('1,2', 'float');
347 347 $this->assertIdentical($expected, $result);
  348 +
  349 + $expected = 'NULL';
  350 + $result = $this->db->value('', 'integer');
  351 + $this->assertIdentical($expected, $result);
  352 +
  353 + $expected = 'NULL';
  354 + $result = $this->db->value('', 'float');
  355 + $this->assertIdentical($expected, $result);
  356 +
  357 + $expected = 'NULL';
  358 + $result = $this->db->value('', 'binary');
  359 + $this->assertIdentical($expected, $result);
348 360 }
349 361 /**
350 362 * testFields method

0 comments on commit 12e0652

Please sign in to comment.
Something went wrong with that request. Please try again.