Merge branch '1.2' into 1.3

This commit is contained in:
gwoo 2009-05-01 08:26:02 -07:00
commit db71202aac
21 changed files with 572 additions and 201 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
vendors

View file

@ -156,30 +156,30 @@ class TestSuiteShell extends Shell {
function help() { function help() {
$this->out('Usage: '); $this->out('Usage: ');
$this->out("\tcake testsuite category test_type file"); $this->out("\tcake testsuite category test_type file");
$this->out("\t\t - category - \"app\", \"core\" or name of a plugin"); $this->out("\t\t- category - \"app\", \"core\" or name of a plugin");
$this->out("\t\t - test_type - \"case\", \"group\" or \"all\""); $this->out("\t\t- test_type - \"case\", \"group\" or \"all\"");
$this->out("\t\t - test_file - file name with folder prefix and without the (test|group).php suffix"); $this->out("\t\t- test_file - file name with folder prefix and without the (test|group).php suffix");
$this->out(''); $this->out('');
$this->out('Examples: '); $this->out('Examples: ');
$this->out("\t\t cake testsuite app all"); $this->out("\t\tcake testsuite app all");
$this->out("\t\t cake testsuite core all"); $this->out("\t\tcake testsuite core all");
$this->out(''); $this->out('');
$this->out("\t\t cake testsuite app case behaviors/debuggable"); $this->out("\t\tcake testsuite app case behaviors/debuggable");
$this->out("\t\t cake testsuite app case models/my_model"); $this->out("\t\tcake testsuite app case models/my_model");
$this->out("\t\t cake testsuite app case controllers/my_controller"); $this->out("\t\tcake testsuite app case controllers/my_controller");
$this->out(''); $this->out('');
$this->out("\t\t cake testsuite core case file"); $this->out("\t\tcake testsuite core case file");
$this->out("\t\t cake testsuite core case router"); $this->out("\t\tcake testsuite core case router");
$this->out("\t\t cake testsuite core case set"); $this->out("\t\tcake testsuite core case set");
$this->out(''); $this->out('');
$this->out("\t\t cake testsuite app group mygroup"); $this->out("\t\tcake testsuite app group mygroup");
$this->out("\t\t cake testsuite core group acl"); $this->out("\t\tcake testsuite core group acl");
$this->out("\t\t cake testsuite core group socket"); $this->out("\t\tcake testsuite core group socket");
$this->out(''); $this->out('');
$this->out("\t\t cake testsuite bugs case models/bug // for the plugin 'bugs' and its test case 'bug'"); $this->out("\t\tcake testsuite bugs case models/bug");
$this->out("\t\t cake testsuite bugs group bug // for the plugin bugs and its test group 'bug'"); $this->out("\t\t // for the plugin 'bugs' and its test case 'models/bug'");
$this->out("\t\t cake testsuite bugs_me case models/bug // for the plugin 'bugs_me' and its test case 'bug'"); $this->out("\t\tcake testsuite bugs group bug");
$this->out("\t\t cake testsuite bugs_me group bug // for the plugin bugs_me and its test group 'bug'"); $this->out("\t\t // for the plugin bugs and its test group 'bug'");
$this->out(''); $this->out('');
$this->out('Code Coverage Analysis: '); $this->out('Code Coverage Analysis: ');
$this->out("\n\nAppend 'cov' to any of the above in order to enable code coverage analysis"); $this->out("\n\nAppend 'cov' to any of the above in order to enable code coverage analysis");
@ -312,11 +312,19 @@ class TestSuiteShell extends Shell {
); );
if (array_key_exists($category, $paths)) { if (array_key_exists($category, $paths)) {
$folder = $paths[$category]; $folder = $paths[$category] . 'tests';
} else { } else {
$folder = APP.'plugins'.DS.Inflector::underscore($category).DS; $scoredCategory = Inflector::underscore($category);
$folder = APP . 'plugins' . DS . $scoredCategory . DS;
$pluginPaths = Configure::read('pluginPaths');
foreach ($pluginPaths as $path) {
if (file_exists($path . $scoredCategory . DS . 'tests')) {
$folder = $path . $scoredCategory . DS . 'tests';
break;
}
}
} }
return $folder.'tests'; return $folder;
} }
/** /**
* Sets some get vars needed for TestManager * Sets some get vars needed for TestManager

View file

@ -337,6 +337,11 @@ class AuthComponent extends Object {
if (!$this->user()) { if (!$this->user()) {
if (!$this->RequestHandler->isAjax()) { if (!$this->RequestHandler->isAjax()) {
$this->Session->setFlash($this->authError, 'default', array(), 'auth'); $this->Session->setFlash($this->authError, 'default', array(), 'auth');
if (!empty($controller->params['url']) && count($controller->params['url']) >= 2) {
$query = $controller->params['url'];
unset($query['url']);
$url .= Router::queryString($query, array());
}
$this->Session->write('Auth.redirect', $url); $this->Session->write('Auth.redirect', $url);
$controller->redirect($loginAction); $controller->redirect($loginAction);
return false; return false;

View file

@ -345,6 +345,7 @@ class EmailComponent extends Object{
$this->bcc = array(); $this->bcc = array();
$this->subject = null; $this->subject = null;
$this->additionalParams = null; $this->additionalParams = null;
$this->smtpError = null;
$this->__header = array(); $this->__header = array();
$this->__boundary = null; $this->__boundary = null;
$this->__message = array(); $this->__message = array();
@ -673,7 +674,13 @@ class EmailComponent extends Object{
return false; return false;
} }
if (!$this->__smtpSend('HELO cake', '250')) { if (isset($this->smtpOptions['host'])) {
$host = $this->smtpOptions['host'];
} else {
$host = env('HTTP_HOST');
}
if (!$this->__smtpSend("HELO {$host}", '250')) {
return false; return false;
} }

View file

@ -393,7 +393,7 @@ class Controller extends Object {
if ($var === 'components') { if ($var === 'components') {
$normal = Set::normalize($this->{$var}); $normal = Set::normalize($this->{$var});
$app = Set::normalize($appVars[$var]); $app = Set::normalize($appVars[$var]);
$this->{$var} = Set::merge($normal, $app); $this->{$var} = Set::merge($app, $normal);
} else { } else {
$this->{$var} = Set::merge($this->{$var}, array_diff($appVars[$var], $this->{$var})); $this->{$var} = Set::merge($this->{$var}, array_diff($appVars[$var], $this->{$var}));
} }

View file

@ -241,13 +241,14 @@ class DataSource extends Object {
if ($this->cacheSources === false) { if ($this->cacheSources === false) {
return null; return null;
} }
if (isset($this->__descriptions[$model->tablePrefix . $model->table])) { $table = $this->fullTableName($model, false);
return $this->__descriptions[$model->tablePrefix . $model->table]; if (isset($this->__descriptions[$table])) {
return $this->__descriptions[$table];
} }
$cache = $this->__cacheDescription($model->tablePrefix . $model->table); $cache = $this->__cacheDescription($table);
if ($cache !== null) { if ($cache !== null) {
$this->__descriptions[$model->tablePrefix . $model->table] =& $cache; $this->__descriptions[$table] =& $cache;
return $cache; return $cache;
} }
return null; return null;

View file

@ -221,7 +221,7 @@ class DboMssql extends DboSource {
'null' => (strtoupper($column[0]['Null']) == 'YES'), 'null' => (strtoupper($column[0]['Null']) == 'YES'),
'default' => preg_replace("/^[(]{1,2}'?([^')]*)?'?[)]{1,2}$/", "$1", $column[0]['Default']), 'default' => preg_replace("/^[(]{1,2}'?([^')]*)?'?[)]{1,2}$/", "$1", $column[0]['Default']),
'length' => intval($column[0]['Length']), 'length' => intval($column[0]['Length']),
'key' => ($column[0]['Key'] == '1') 'key' => ($column[0]['Key'] == '1') ? 'primary' : false
); );
if ($fields[$field]['default'] === 'null') { if ($fields[$field]['default'] === 'null') {
$fields[$field]['default'] = null; $fields[$field]['default'] = null;
@ -341,17 +341,18 @@ class DboMssql extends DboSource {
if (!empty($values)) { if (!empty($values)) {
$fields = array_combine($fields, $values); $fields = array_combine($fields, $values);
} }
$primaryKey = $this->_getPrimaryKey($model);
if (array_key_exists($model->primaryKey, $fields)) { if (array_key_exists($primaryKey, $fields)) {
if (empty($fields[$model->primaryKey])) { if (empty($fields[$primaryKey])) {
unset($fields[$model->primaryKey]); unset($fields[$primaryKey]);
} else { } else {
$this->_execute("SET IDENTITY_INSERT " . $this->fullTableName($model) . " ON"); $this->_execute('SET IDENTITY_INSERT ' . $this->fullTableName($model) . ' ON');
} }
} }
$result = parent::create($model, array_keys($fields), array_values($fields)); $result = parent::create($model, array_keys($fields), array_values($fields));
if (array_key_exists($model->primaryKey, $fields) && !empty($fields[$model->primaryKey])) { if (array_key_exists($primaryKey, $fields) && !empty($fields[$primaryKey])) {
$this->_execute("SET IDENTITY_INSERT " . $this->fullTableName($model) . " OFF"); $this->_execute('SET IDENTITY_INSERT ' . $this->fullTableName($model) . ' OFF');
} }
return $result; return $result;
} }
@ -631,6 +632,29 @@ class DboMssql extends DboSource {
return false; return false;
} }
} }
/**
* Inserts multiple values into a table
*
* @param string $table
* @param string $fields
* @param array $values
* @access protected
*/
function insertMulti($table, $fields, $values) {
$primaryKey = $this->_getPrimaryKey($table);
$hasPrimaryKey = $primaryKey != null && (
(is_array($fields) && in_array($primaryKey, $fields)
|| (is_string($fields) && strpos($fields, $this->startQuote . $primaryKey . $this->endQuote) !== false))
);
if ($hasPrimaryKey) {
$this->_execute('SET IDENTITY_INSERT ' . $this->fullTableName($table) . ' ON');
}
parent::insertMulti($table, $fields, $values);
if ($hasPrimaryKey) {
$this->_execute('SET IDENTITY_INSERT ' . $this->fullTableName($table) . ' OFF');
}
}
/** /**
* Generate a database-native column schema string * Generate a database-native column schema string
* *
@ -680,5 +704,27 @@ class DboMssql extends DboSource {
} }
return $join; return $join;
} }
/**
* Makes sure it will return the primary key
*
* @param mixed $model
* @access protected
* @return string
*/
function _getPrimaryKey($model) {
if (is_object($model)) {
$schema = $model->schema();
} else {
$schema = $this->describe($model);
}
foreach ($schema as $field => $props) {
if (isset($props['key']) && $props['key'] == 'primary') {
return $field;
}
}
return null;
}
} }
?> ?>

View file

@ -454,6 +454,7 @@ class DboOracle extends DboSource {
while($r = $this->fetchRow()) { while($r = $this->fetchRow()) {
$sources[] = strtolower($r[0]['name']); $sources[] = strtolower($r[0]['name']);
} }
parent::listSources($sources);
return $sources; return $sources;
} }
/** /**
@ -834,8 +835,7 @@ class DboOracle extends DboSource {
switch($column) { switch($column) {
case 'date': case 'date':
$date = new DateTime($data); $data = date('Y-m-d H:i:s', strtotime($data));
$data = $date->format('Y-m-d H:i:s');
$data = "TO_DATE('$data', 'YYYY-MM-DD HH24:MI:SS')"; $data = "TO_DATE('$data', 'YYYY-MM-DD HH24:MI:SS')";
break; break;
case 'integer' : case 'integer' :

View file

@ -1210,7 +1210,7 @@ class Model extends Overloadable {
foreach ($this->_schema as $field => $properties) { foreach ($this->_schema as $field => $properties) {
if ($this->primaryKey === $field) { if ($this->primaryKey === $field) {
$fInfo = $this->_schema[$field]; $fInfo = $this->_schema[$field];
$isUUID = ($fInfo['length'] === 36 && $isUUID = ($fInfo['length'] == 36 &&
($fInfo['type'] === 'string' || $fInfo['type'] === 'binary') ($fInfo['type'] === 'string' || $fInfo['type'] === 'binary')
); );
if (empty($this->data[$this->alias][$this->primaryKey]) && $isUUID) { if (empty($this->data[$this->alias][$this->primaryKey]) && $isUUID) {
@ -1279,7 +1279,7 @@ class Model extends Overloadable {
)); ));
$isUUID = !empty($this->{$join}->primaryKey) && ( $isUUID = !empty($this->{$join}->primaryKey) && (
$this->{$join}->_schema[$this->{$join}->primaryKey]['length'] === 36 && ( $this->{$join}->_schema[$this->{$join}->primaryKey]['length'] == 36 && (
$this->{$join}->_schema[$this->{$join}->primaryKey]['type'] === 'string' || $this->{$join}->_schema[$this->{$join}->primaryKey]['type'] === 'string' ||
$this->{$join}->_schema[$this->{$join}->primaryKey]['type'] === 'binary' $this->{$join}->_schema[$this->{$join}->primaryKey]['type'] === 'binary'
) )
@ -1374,16 +1374,15 @@ class Model extends Overloadable {
$conditions = ($recursive == 1) ? (array)$assoc['counterScope'] : array(); $conditions = ($recursive == 1) ? (array)$assoc['counterScope'] : array();
if (isset($keys['old'][$foreignKey])) { if (isset($keys['old'][$foreignKey])) {
if ($keys['old'][$foreignKey] == $keys[$foreignKey]) { if ($keys['old'][$foreignKey] != $keys[$foreignKey]) {
continue; $conditions[$fkQuoted] = $keys['old'][$foreignKey];
$count = intval($this->find('count', compact('conditions', 'recursive')));
$this->{$parent}->updateAll(
array($assoc['counterCache'] => $count),
array($this->{$parent}->escapeField() => $keys['old'][$foreignKey])
);
} }
$conditions[$fkQuoted] = $keys['old'][$foreignKey];
$count = intval($this->find('count', compact('conditions', 'recursive')));
$this->{$parent}->updateAll(
array($assoc['counterCache'] => $count),
array($this->{$parent}->escapeField() => $keys['old'][$foreignKey])
);
} }
$conditions[$fkQuoted] = $keys[$foreignKey]; $conditions[$fkQuoted] = $keys[$foreignKey];
@ -1853,7 +1852,7 @@ class Model extends Overloadable {
if ($this->getID() === false || $this->useTable === false) { if ($this->getID() === false || $this->useTable === false) {
return false; return false;
} }
if ($this->__exists !== null && $reset !== true) { if (!empty($this->__exists) && $reset !== true) {
return $this->__exists; return $this->__exists;
} }
$conditions = array($this->alias . '.' . $this->primaryKey => $this->getID()); $conditions = array($this->alias . '.' . $this->primaryKey => $this->getID());

View file

@ -591,7 +591,7 @@ class Helper extends Overloadable {
if (is_array($result)) { if (is_array($result)) {
$view =& ClassRegistry::getObject('view'); $view =& ClassRegistry::getObject('view');
if (isset($result[$view->fieldSuffix])) { if (array_key_exists($view->fieldSuffix, $result)) {
$result = $result[$view->fieldSuffix]; $result = $result[$view->fieldSuffix];
} }
} }

View file

@ -563,7 +563,8 @@ class FormHelper extends AppHelper {
/** /**
* Generates a form input element complete with label and wrapper div * Generates a form input element complete with label and wrapper div
* *
* Options - See each field type method for more information. * Options - See each field type method for more information. Any options that are part of
* $attributes or $options for the different type methods can be included in $options for input().
* *
* - 'type' - Force the type of widget you want. e.g. ```type => 'select'``` * - 'type' - Force the type of widget you want. e.g. ```type => 'select'```
* - 'label' - control the label * - 'label' - control the label

View file

@ -823,13 +823,19 @@ class Xml extends XmlNode {
$this->{$key} = $options[$key]; $this->{$key} = $options[$key];
} }
$this->__tags = $options['tags']; $this->__tags = $options['tags'];
parent::__construct($options['root']); parent::__construct('#document');
if ($options['root'] !== '#document') {
$Root = $this->createNode($options['root']);
} else {
$Root =& $this;
}
if (!empty($input)) { if (!empty($input)) {
if (is_string($input)) { if (is_string($input)) {
$this->load($input); $Root->load($input);
} elseif (is_array($input) || is_object($input)) { } elseif (is_array($input) || is_object($input)) {
$this->append($input, $options); $Root->append($input, $options);
} }
} }
// if (Configure::read('App.encoding') !== null) { // if (Configure::read('App.encoding') !== null) {
@ -874,10 +880,11 @@ class Xml extends XmlNode {
*/ */
function parse() { function parse() {
$this->__initParser(); $this->__initParser();
$this->__rawData = trim($this->__rawData);
$this->__header = trim(str_replace( $this->__header = trim(str_replace(
a('<' . '?', '?' . '>'), a('<' . '?', '?' . '>'),
a('', ''), a('', ''),
substr(trim($this->__rawData), 0, strpos($this->__rawData, "\n")) substr($this->__rawData, 0, strpos($this->__rawData, '?' . '>'))
)); ));
xml_parse_into_struct($this->__parser, $this->__rawData, $vals); xml_parse_into_struct($this->__parser, $this->__rawData, $vals);

View file

@ -51,8 +51,8 @@ class CakeTestFixtureTestFixture extends CakeTestFixture {
*/ */
var $fields = array( var $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'), 'id' => array('type' => 'integer', 'key' => 'primary'),
'name' => array('type' => 'text', 'length' => '255'), 'name' => array('type' => 'string', 'length' => '255'),
'created' => array('type' => 'datetime'), 'created' => array('type' => 'datetime')
); );
/** /**
* Records property * Records property

View file

@ -839,16 +839,22 @@ class AuthTest extends CakeTestCase {
$this->assertEqual($expected, $this->Controller->Session->read('Auth.redirect')); $this->assertEqual($expected, $this->Controller->Session->read('Auth.redirect'));
// QueryString parameters // QueryString parameters
$_back = $_GET;
$_GET = array(
'url' => '/posts/index/29',
'print' => 'true',
'refer' => 'menu'
);
$this->Controller->Session->del('Auth'); $this->Controller->Session->del('Auth');
$url = '/posts/index/29?print=true&refer=menu'; $url = '/posts/index/29?print=true&refer=menu';
$this->Controller->params = Router::parse($url); $this->Controller->params = Dispatcher::parseParams($url);
$this->Controller->params['url']['url'] = Router::normalize($url);
$this->Controller->Auth->initialize($this->Controller); $this->Controller->Auth->initialize($this->Controller);
$this->Controller->Auth->loginAction = array('controller' => 'AuthTest', 'action' => 'login'); $this->Controller->Auth->loginAction = array('controller' => 'AuthTest', 'action' => 'login');
$this->Controller->Auth->userModel = 'AuthUser'; $this->Controller->Auth->userModel = 'AuthUser';
$this->Controller->Auth->startup($this->Controller); $this->Controller->Auth->startup($this->Controller);
$expected = Router::normalize('posts/index/29?print=true&refer=menu'); $expected = Router::normalize('posts/index/29?print=true&refer=menu');
$this->assertEqual($expected, $this->Controller->Session->read('Auth.redirect')); $this->assertEqual($expected, $this->Controller->Session->read('Auth.redirect'));
$_GET = $_back;
//external authed action //external authed action
$_SERVER['HTTP_REFERER'] = 'http://webmail.example.com/view/message'; $_SERVER['HTTP_REFERER'] = 'http://webmail.example.com/view/message';

View file

@ -25,6 +25,86 @@
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/ */
App::import('Component', 'Email'); App::import('Component', 'Email');
/**
* EmailTestComponent class
*
* @package cake
* @subpackage cake.tests.cases.libs.controller.components
*/
class EmailTestComponent extends EmailComponent {
/**
* smtpSend method override for testing
*
* @access public
* @return mixed
*/
function smtpSend($data, $code = '250') {
return parent::__smtpSend($data, $code);
}
/**
* Convenience setter method for testing.
*
* @access public
* @return void
*/
function setConnectionSocket(&$socket) {
$this->__smtpConnection = $socket;
}
/**
* Convenience getter method for testing.
*
* @access public
* @return mixed
*/
function getConnectionSocket() {
return $this->__smtpConnection;
}
/**
* Convenience setter for testing.
*
* @access public
* @return void
*/
function setHeaders($headers) {
$this->__header += $headers;
}
/**
* Convenience getter for testing.
*
* @access public
* @return array
*/
function getHeaders() {
return $this->__header;
}
/**
* Convenience setter for testing.
*
* @access public
* @return void
*/
function setBoundary() {
$this->__createBoundary();
}
/**
* Convenience getter for testing.
*
* @access public
* @return string
*/
function getBoundary() {
return $this->__boundary;
}
/**
* Convenience getter for testing.
*
* @access public
* @return string
*/
function getMessage() {
return $this->__message;
}
}
/** /**
* EmailTestController class * EmailTestController class
* *
@ -52,7 +132,7 @@ class EmailTestController extends Controller {
* @var array * @var array
* @access public * @access public
*/ */
var $components = array('Email'); var $components = array('EmailTest');
/** /**
* pageTitle property * pageTitle property
* *
@ -98,7 +178,7 @@ class EmailComponentTest extends CakeTestCase {
@$this->Controller->Component->init($this->Controller); @$this->Controller->Component->init($this->Controller);
set_error_handler('simpleTestErrorHandler'); set_error_handler('simpleTestErrorHandler');
$this->Controller->Email->initialize($this->Controller, array()); $this->Controller->EmailTest->initialize($this->Controller, array());
ClassRegistry::addObject('view', new View($this->Controller)); ClassRegistry::addObject('view', new View($this->Controller));
$this->_viewPaths = Configure::read('viewPaths'); $this->_viewPaths = Configure::read('viewPaths');
@ -125,9 +205,9 @@ class EmailComponentTest extends CakeTestCase {
* @return void * @return void
*/ */
function testBadSmtpSend() { function testBadSmtpSend() {
$this->Controller->Email->smtpOptions['host'] = 'blah'; $this->Controller->EmailTest->smtpOptions['host'] = 'blah';
$this->Controller->Email->delivery = 'smtp'; $this->Controller->EmailTest->delivery = 'smtp';
$this->assertFalse($this->Controller->Email->send('Should not work')); $this->assertFalse($this->Controller->EmailTest->send('Should not work'));
} }
/** /**
* testSmtpSend method * testSmtpSend method
@ -139,18 +219,18 @@ class EmailComponentTest extends CakeTestCase {
if (!$this->skipIf(!@fsockopen('localhost', 25), '%s No SMTP server running on localhost')) { if (!$this->skipIf(!@fsockopen('localhost', 25), '%s No SMTP server running on localhost')) {
return; return;
} }
$this->Controller->Email->reset(); $this->Controller->EmailTest->reset();
$this->Controller->Email->to = 'postmaster@localhost'; $this->Controller->EmailTest->to = 'postmaster@localhost';
$this->Controller->Email->from = 'noreply@example.com'; $this->Controller->EmailTest->from = 'noreply@example.com';
$this->Controller->Email->subject = 'Cake SMTP test'; $this->Controller->EmailTest->subject = 'Cake SMTP test';
$this->Controller->Email->replyTo = 'noreply@example.com'; $this->Controller->EmailTest->replyTo = 'noreply@example.com';
$this->Controller->Email->template = null; $this->Controller->EmailTest->template = null;
$this->Controller->Email->delivery = 'smtp'; $this->Controller->EmailTest->delivery = 'smtp';
$this->assertTrue($this->Controller->Email->send('This is the body of the message')); $this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
$this->Controller->Email->_debug = true; $this->Controller->EmailTest->_debug = true;
$this->Controller->Email->sendAs = 'text'; $this->Controller->EmailTest->sendAs = 'text';
$expect = <<<TEMPDOC $expect = <<<TEMPDOC
<pre>Host: localhost <pre>Host: localhost
Port: 25 Port: 25
@ -174,7 +254,7 @@ This is the body of the message
</pre> </pre>
TEMPDOC; TEMPDOC;
$this->assertTrue($this->Controller->Email->send('This is the body of the message')); $this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect)); $this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
} }
/** /**
@ -186,20 +266,22 @@ TEMPDOC;
function testAuthenticatedSmtpSend() { function testAuthenticatedSmtpSend() {
$this->skipIf(!@fsockopen('localhost', 25), '%s No SMTP server running on localhost'); $this->skipIf(!@fsockopen('localhost', 25), '%s No SMTP server running on localhost');
$this->Controller->Email->reset(); $this->Controller->EmailTest->reset();
$this->Controller->Email->to = 'postmaster@localhost'; $this->Controller->EmailTest->to = 'postmaster@localhost';
$this->Controller->Email->from = 'noreply@example.com'; $this->Controller->EmailTest->from = 'noreply@example.com';
$this->Controller->Email->subject = 'Cake SMTP test'; $this->Controller->EmailTest->subject = 'Cake SMTP test';
$this->Controller->Email->replyTo = 'noreply@example.com'; $this->Controller->EmailTest->replyTo = 'noreply@example.com';
$this->Controller->Email->template = null; $this->Controller->EmailTest->template = null;
$this->Controller->Email->smtpOptions['username'] = 'test'; $this->Controller->EmailTest->smtpOptions['username'] = 'test';
$this->Controller->Email->smtpOptions['password'] = 'testing'; $this->Controller->EmailTest->smtpOptions['password'] = 'testing';
$this->Controller->Email->delivery = 'smtp'; $this->Controller->EmailTest->delivery = 'smtp';
$result = $this->Controller->Email->send('This is the body of the message'); $result = $this->Controller->EmailTest->send('This is the body of the message');
$code = substr($this->Controller->Email->smtpError, 0, 3); $code = substr($this->Controller->EmailTest->smtpError, 0, 3);
$this->skipIf(!$code, '%s Authentication not enabled on server'); $this->skipIf(!$code, '%s Authentication not enabled on server');
$this->assertTrue(!$result && $code == '535');
$this->assertFalse($result);
$this->assertEqual($code, '535');
} }
/** /**
* testSendFormats method * testSendFormats method
@ -208,13 +290,13 @@ TEMPDOC;
* @return void * @return void
*/ */
function testSendFormats() { function testSendFormats() {
$this->Controller->Email->reset(); $this->Controller->EmailTest->reset();
$this->Controller->Email->to = 'postmaster@localhost'; $this->Controller->EmailTest->to = 'postmaster@localhost';
$this->Controller->Email->from = 'noreply@example.com'; $this->Controller->EmailTest->from = 'noreply@example.com';
$this->Controller->Email->subject = 'Cake SMTP test'; $this->Controller->EmailTest->subject = 'Cake SMTP test';
$this->Controller->Email->replyTo = 'noreply@example.com'; $this->Controller->EmailTest->replyTo = 'noreply@example.com';
$this->Controller->Email->template = null; $this->Controller->EmailTest->template = null;
$this->Controller->Email->delivery = 'debug'; $this->Controller->EmailTest->delivery = 'debug';
$message = <<<MSGBLOC $message = <<<MSGBLOC
<pre>To: postmaster@localhost <pre>To: postmaster@localhost
@ -234,20 +316,20 @@ This is the body of the message
</pre> </pre>
MSGBLOC; MSGBLOC;
$this->Controller->Email->sendAs = 'text'; $this->Controller->EmailTest->sendAs = 'text';
$expect = str_replace('{CONTENTTYPE}', 'text/plain; charset=UTF-8', $message); $expect = str_replace('{CONTENTTYPE}', 'text/plain; charset=UTF-8', $message);
$this->assertTrue($this->Controller->Email->send('This is the body of the message')); $this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect)); $this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
$this->Controller->Email->sendAs = 'html'; $this->Controller->EmailTest->sendAs = 'html';
$expect = str_replace('{CONTENTTYPE}', 'text/html; charset=UTF-8', $message); $expect = str_replace('{CONTENTTYPE}', 'text/html; charset=UTF-8', $message);
$this->assertTrue($this->Controller->Email->send('This is the body of the message')); $this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect)); $this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
// TODO: better test for format of message sent? // TODO: better test for format of message sent?
$this->Controller->Email->sendAs = 'both'; $this->Controller->EmailTest->sendAs = 'both';
$expect = str_replace('{CONTENTTYPE}', 'multipart/alternative; boundary="alt-"' . "\n", $message); $expect = str_replace('{CONTENTTYPE}', 'multipart/alternative; boundary="alt-"' . "\n", $message);
$this->assertTrue($this->Controller->Email->send('This is the body of the message')); $this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect)); $this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
} }
/** /**
@ -257,13 +339,13 @@ MSGBLOC;
* @return void * @return void
*/ */
function testTemplates() { function testTemplates() {
$this->Controller->Email->reset(); $this->Controller->EmailTest->reset();
$this->Controller->Email->to = 'postmaster@localhost'; $this->Controller->EmailTest->to = 'postmaster@localhost';
$this->Controller->Email->from = 'noreply@example.com'; $this->Controller->EmailTest->from = 'noreply@example.com';
$this->Controller->Email->subject = 'Cake SMTP test'; $this->Controller->EmailTest->subject = 'Cake SMTP test';
$this->Controller->Email->replyTo = 'noreply@example.com'; $this->Controller->EmailTest->replyTo = 'noreply@example.com';
$this->Controller->Email->delivery = 'debug'; $this->Controller->EmailTest->delivery = 'debug';
$header = <<<HEADBLOC $header = <<<HEADBLOC
To: postmaster@localhost To: postmaster@localhost
@ -282,8 +364,8 @@ Message:
HEADBLOC; HEADBLOC;
$this->Controller->Email->layout = 'default'; $this->Controller->EmailTest->layout = 'default';
$this->Controller->Email->template = 'default'; $this->Controller->EmailTest->template = 'default';
$text = <<<TEXTBLOC $text = <<<TEXTBLOC
@ -310,22 +392,22 @@ TEXTBLOC;
HTMLBLOC; HTMLBLOC;
$this->Controller->Email->sendAs = 'text'; $this->Controller->EmailTest->sendAs = 'text';
$expect = '<pre>' . str_replace('{CONTENTTYPE}', 'text/plain; charset=UTF-8', $header) . $text . "\n" . '</pre>'; $expect = '<pre>' . str_replace('{CONTENTTYPE}', 'text/plain; charset=UTF-8', $header) . $text . "\n" . '</pre>';
$this->assertTrue($this->Controller->Email->send('This is the body of the message')); $this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect)); $this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
$this->Controller->Email->sendAs = 'html'; $this->Controller->EmailTest->sendAs = 'html';
$expect = '<pre>' . str_replace('{CONTENTTYPE}', 'text/html; charset=UTF-8', $header) . $html . "\n" . '</pre>'; $expect = '<pre>' . str_replace('{CONTENTTYPE}', 'text/html; charset=UTF-8', $header) . $html . "\n" . '</pre>';
$this->assertTrue($this->Controller->Email->send('This is the body of the message')); $this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect)); $this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
$this->Controller->Email->sendAs = 'both'; $this->Controller->EmailTest->sendAs = 'both';
$expect = str_replace('{CONTENTTYPE}', 'multipart/alternative; boundary="alt-"' . "\n", $header); $expect = str_replace('{CONTENTTYPE}', 'multipart/alternative; boundary="alt-"' . "\n", $header);
$expect .= '--alt-' . "\n" . 'Content-Type: text/plain; charset=UTF-8' . "\n" . 'Content-Transfer-Encoding: 7bit' . "\n\n" . $text . "\n\n"; $expect .= '--alt-' . "\n" . 'Content-Type: text/plain; charset=UTF-8' . "\n" . 'Content-Transfer-Encoding: 7bit' . "\n\n" . $text . "\n\n";
$expect .= '--alt-' . "\n" . 'Content-Type: text/html; charset=UTF-8' . "\n" . 'Content-Transfer-Encoding: 7bit' . "\n\n" . $html . "\n\n"; $expect .= '--alt-' . "\n" . 'Content-Type: text/html; charset=UTF-8' . "\n" . 'Content-Transfer-Encoding: 7bit' . "\n\n" . $html . "\n\n";
$expect = '<pre>' . $expect . '--alt---' . "\n\n" . '</pre>'; $expect = '<pre>' . $expect . '--alt---' . "\n\n" . '</pre>';
$this->assertTrue($this->Controller->Email->send('This is the body of the message')); $this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect)); $this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
$html = <<<HTMLBLOC $html = <<<HTMLBLOC
@ -344,9 +426,9 @@ HTMLBLOC;
HTMLBLOC; HTMLBLOC;
$this->Controller->Email->sendAs = 'html'; $this->Controller->EmailTest->sendAs = 'html';
$expect = '<pre>' . str_replace('{CONTENTTYPE}', 'text/html; charset=UTF-8', $header) . $html . "\n" . '</pre>'; $expect = '<pre>' . str_replace('{CONTENTTYPE}', 'text/html; charset=UTF-8', $header) . $html . "\n" . '</pre>';
$this->assertTrue($this->Controller->Email->send('This is the body of the message', 'default', 'thin')); $this->assertTrue($this->Controller->EmailTest->send('This is the body of the message', 'default', 'thin'));
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect)); $this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
return; return;
@ -362,11 +444,34 @@ This email was sent using the CakePHP Framework, http://cakephp.org.
TEXTBLOC; TEXTBLOC;
$this->Controller->Email->sendAs = 'text'; $this->Controller->EmailTest->sendAs = 'text';
$expect = '<pre>' . str_replace('{CONTENTTYPE}', 'text/plain; charset=UTF-8', $header) . $text . "\n" . '</pre>'; $expect = '<pre>' . str_replace('{CONTENTTYPE}', 'text/plain; charset=UTF-8', $header) . $text . "\n" . '</pre>';
$this->assertTrue($this->Controller->Email->send('This is the body of the message', 'wide', 'default')); $this->assertTrue($this->Controller->EmailTest->send('This is the body of the message', 'wide', 'default'));
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect)); $this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
} }
/**
* testSmtpSendSocket method
*
* @access public
* @return void
*/
function testSmtpSendSocket() {
$this->skipIf(!@fsockopen('localhost', 25), '%s No SMTP server running on localhost');
$this->Controller->EmailTest->reset();
$socket =& new CakeSocket(array_merge(array('protocol'=>'smtp'), $this->Controller->EmailTest->smtpOptions));
$this->Controller->EmailTest->setConnectionSocket($socket);
$this->assertTrue($this->Controller->EmailTest->getConnectionSocket());
$response = $this->Controller->EmailTest->smtpSend('HELO', '250');
$this->assertPattern('/501 Syntax: HELO hostname/', $this->Controller->EmailTest->smtpError);
$this->Controller->EmailTest->smtpError = null;
$response = $this->Controller->EmailTest->smtpSend('HELO somehostname', '250');
$this->assertNoPattern('/501 Syntax: HELO hostname/', $this->Controller->EmailTest->smtpError);
}
/** /**
* testSendDebug method * testSendDebug method
* *
@ -374,15 +479,15 @@ TEXTBLOC;
* @return void * @return void
*/ */
function testSendDebug() { function testSendDebug() {
$this->Controller->Email->reset(); $this->Controller->EmailTest->reset();
$this->Controller->Email->to = 'postmaster@localhost'; $this->Controller->EmailTest->to = 'postmaster@localhost';
$this->Controller->Email->from = 'noreply@example.com'; $this->Controller->EmailTest->from = 'noreply@example.com';
$this->Controller->Email->subject = 'Cake SMTP test'; $this->Controller->EmailTest->subject = 'Cake SMTP test';
$this->Controller->Email->replyTo = 'noreply@example.com'; $this->Controller->EmailTest->replyTo = 'noreply@example.com';
$this->Controller->Email->template = null; $this->Controller->EmailTest->template = null;
$this->Controller->Email->delivery = 'debug'; $this->Controller->EmailTest->delivery = 'debug';
$this->assertTrue($this->Controller->Email->send('This is the body of the message')); $this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
} }
/** /**
* testContentStripping method * testContentStripping method
@ -394,7 +499,7 @@ TEXTBLOC;
$content = "Previous content\n--alt-\nContent-TypeContent-Type:: text/html; charsetcharset==utf-8\nContent-Transfer-Encoding: 7bit"; $content = "Previous content\n--alt-\nContent-TypeContent-Type:: text/html; charsetcharset==utf-8\nContent-Transfer-Encoding: 7bit";
$content .= "\n\n<p>My own html content</p>"; $content .= "\n\n<p>My own html content</p>";
$result = $this->Controller->Email->__strip($content, true); $result = $this->Controller->EmailTest->__strip($content, true);
$expected = "Previous content\n--alt-\n text/html; utf-8\n 7bit\n\n<p>My own html content</p>"; $expected = "Previous content\n--alt-\n text/html; utf-8\n 7bit\n\n<p>My own html content</p>";
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
} }
@ -405,31 +510,68 @@ TEXTBLOC;
* @return void * @return void
*/ */
function testMultibyte() { function testMultibyte() {
$this->Controller->Email->reset(); $this->Controller->EmailTest->reset();
$this->Controller->Email->to = 'postmaster@localhost'; $this->Controller->EmailTest->to = 'postmaster@localhost';
$this->Controller->Email->from = 'noreply@example.com'; $this->Controller->EmailTest->from = 'noreply@example.com';
$this->Controller->Email->subject = 'هذه رسالة بعنوان طويل مرسل للمستلم'; $this->Controller->EmailTest->subject = 'هذه رسالة بعنوان طويل مرسل للمستلم';
$this->Controller->Email->replyTo = 'noreply@example.com'; $this->Controller->EmailTest->replyTo = 'noreply@example.com';
$this->Controller->Email->template = null; $this->Controller->EmailTest->template = null;
$this->Controller->Email->delivery = 'debug'; $this->Controller->EmailTest->delivery = 'debug';
$subject = '=?UTF-8?B?2YfYsNmHINix2LPYp9mE2Kkg2KjYudmG2YjYp9mGINi32YjZitmEINmF2LE=?=' . "\r\n" . ' =?UTF-8?B?2LPZhCDZhNmE2YXYs9iq2YTZhQ==?='; $subject = '=?UTF-8?B?2YfYsNmHINix2LPYp9mE2Kkg2KjYudmG2YjYp9mGINi32YjZitmEINmF2LE=?=' . "\r\n" . ' =?UTF-8?B?2LPZhCDZhNmE2YXYs9iq2YTZhQ==?=';
$this->Controller->Email->sendAs = 'text'; $this->Controller->EmailTest->sendAs = 'text';
$this->assertTrue($this->Controller->Email->send('This is the body of the message')); $this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
preg_match('/Subject: (.*)Header:/s', $this->Controller->Session->read('Message.email.message'), $matches); preg_match('/Subject: (.*)Header:/s', $this->Controller->Session->read('Message.email.message'), $matches);
$this->assertEqual(trim($matches[1]), $subject); $this->assertEqual(trim($matches[1]), $subject);
$this->Controller->Email->sendAs = 'html'; $this->Controller->EmailTest->sendAs = 'html';
$this->assertTrue($this->Controller->Email->send('This is the body of the message')); $this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
preg_match('/Subject: (.*)Header:/s', $this->Controller->Session->read('Message.email.message'), $matches); preg_match('/Subject: (.*)Header:/s', $this->Controller->Session->read('Message.email.message'), $matches);
$this->assertEqual(trim($matches[1]), $subject); $this->assertEqual(trim($matches[1]), $subject);
$this->Controller->Email->sendAs = 'both'; $this->Controller->EmailTest->sendAs = 'both';
$this->assertTrue($this->Controller->Email->send('This is the body of the message')); $this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
preg_match('/Subject: (.*)Header:/s', $this->Controller->Session->read('Message.email.message'), $matches); preg_match('/Subject: (.*)Header:/s', $this->Controller->Session->read('Message.email.message'), $matches);
$this->assertEqual(trim($matches[1]), $subject); $this->assertEqual(trim($matches[1]), $subject);
} }
/**
* testReset method
*
* @access public
* @return void
*/
function testReset() {
$this->Controller->EmailTest->template = 'test_template';
$this->Controller->EmailTest->to = 'test.recipient@example.com';
$this->Controller->EmailTest->from = 'test.sender@example.com';
$this->Controller->EmailTest->replyTo = 'test.replyto@example.com';
$this->Controller->EmailTest->return = 'test.return@example.com';
$this->Controller->EmailTest->cc = array('cc1@example.com', 'cc2@example.com');
$this->Controller->EmailTest->bcc = array('bcc1@example.com', 'bcc2@example.com');
$this->Controller->EmailTest->subject = 'Test subject';
$this->Controller->EmailTest->additionalParams = 'X-additional-header';
$this->Controller->EmailTest->delivery = 'smtp';
$this->Controller->EmailTest->smtpOptions['host'] = 'blah';
$this->assertFalse($this->Controller->EmailTest->send('Should not work'));
$this->Controller->EmailTest->reset();
$this->assertNull($this->Controller->EmailTest->template);
$this->assertNull($this->Controller->EmailTest->to);
$this->assertNull($this->Controller->EmailTest->from);
$this->assertNull($this->Controller->EmailTest->replyTo);
$this->assertNull($this->Controller->EmailTest->return);
$this->assertIdentical($this->Controller->EmailTest->cc, array());
$this->assertIdentical($this->Controller->EmailTest->bcc, array());
$this->assertNull($this->Controller->EmailTest->subject);
$this->assertNull($this->Controller->EmailTest->additionalParams);
$this->assertIdentical($this->Controller->EmailTest->getHeaders(), array());
$this->assertNull($this->Controller->EmailTest->getBoundary());
$this->assertIdentical($this->Controller->EmailTest->getMessage(), array());
$this->assertNull($this->Controller->EmailTest->smtpError);
}
/** /**
* osFix method * osFix method
* *

View file

@ -940,6 +940,22 @@ class ControllerTest extends CakeTestCase {
$this->assertTrue(isset($TestController->ControllerPost)); $this->assertTrue(isset($TestController->ControllerPost));
$this->assertTrue(isset($TestController->ControllerComment)); $this->assertTrue(isset($TestController->ControllerComment));
} }
/**
* test that options from child classes replace those in the parent classes.
*
* @access public
* @return void
**/
function testChildComponentOptionsSupercedeParents() {
if ($this->skipIf(defined('APP_CONTROLLER_EXISTS'), '%s Need a non-existent AppController')) {
return;
}
$TestController =& new TestController();
$expected = array('foo');
$TestController->components = array('Cookie' => $expected);
$TestController->constructClasses();
$this->assertEqual($TestController->components['Cookie'], $expected);
}
/** /**
* Ensure that __mergeVars is not being greedy and merging with * Ensure that __mergeVars is not being greedy and merging with
* AppController when you make an instance of Controller * AppController when you make an instance of Controller

View file

@ -36,32 +36,6 @@ require_once LIBS.'model'.DS.'datasources'.DS.'dbo'.DS.'dbo_mssql.php';
* @subpackage cake.tests.cases.libs.model.datasources.dbo * @subpackage cake.tests.cases.libs.model.datasources.dbo
*/ */
class DboMssqlTestDb extends DboMssql { class DboMssqlTestDb extends DboMssql {
/**
* Contructor
*
* @return void
* @access public
*/
function __construct() {
}
/**
* connect method
*
* @return boolean
* @access public
*/
function connect() {
$this->connected = true;
return true;
}
/**
* lastError method
*
* @return void
* @access public
*/
function lastError() {
}
/** /**
* simulated property * simulated property
* *
@ -120,6 +94,16 @@ class DboMssqlTestDb extends DboMssql {
function getLastQuery() { function getLastQuery() {
return $this->simulated[count($this->simulated) - 1]; return $this->simulated[count($this->simulated) - 1];
} }
/**
* getPrimaryKey method
*
* @param mixed $model
* @access public
* @return void
*/
function getPrimaryKey($model) {
return parent::_getPrimaryKey($model);
}
} }
/** /**
* MssqlTestModel class * MssqlTestModel class
@ -142,6 +126,32 @@ class MssqlTestModel extends Model {
* @access public * @access public
*/ */
var $useTable = false; var $useTable = false;
/**
* _schema property
*
* @var array
* @access protected
*/
var $_schema = array(
'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8', 'key' => 'primary'),
'client_id' => array('type' => 'integer', 'null' => '', 'default' => '0', 'length' => '11'),
'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
'login' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
'passwd' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'),
'addr_1' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'),
'addr_2' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '25'),
'zip_code' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
'city' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
'country' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
'phone' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
'fax' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
'url' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'),
'email' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
'comments' => array('type' => 'text', 'null' => '1', 'default' => '', 'length' => ''),
'last_login'=> array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => ''),
'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
);
/** /**
* find method * find method
* *
@ -169,33 +179,14 @@ class MssqlTestModel extends Model {
return $conditions; return $conditions;
} }
/** /**
* schema method * setSchema method
* *
* @param array $schema
* @access public * @access public
* @return void * @return void
*/ */
function schema() { function setSchema($schema) {
$this->_schema = array( $this->_schema = $schema;
'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
'client_id' => array('type' => 'integer', 'null' => '', 'default' => '0', 'length' => '11'),
'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
'login' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
'passwd' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'),
'addr_1' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'),
'addr_2' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '25'),
'zip_code' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
'city' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
'country' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
'phone' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
'fax' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
'url' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'),
'email' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
'comments' => array('type' => 'text', 'null' => '1', 'default' => '', 'length' => ''),
'last_login'=> array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => ''),
'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
);
return $this->_schema;
} }
} }
/** /**
@ -346,15 +337,61 @@ class DboMssqlTest extends CakeTestCase {
* @access public * @access public
*/ */
function testUpdateAllSyntax() { function testUpdateAllSyntax() {
$model = ClassRegistry::init('MssqlTestModel');
$fields = array('MssqlTestModel.client_id' => '[MssqlTestModel].[client_id] + 1'); $fields = array('MssqlTestModel.client_id' => '[MssqlTestModel].[client_id] + 1');
$conditions = array('MssqlTestModel.updated <' => date('2009-01-01 00:00:00')); $conditions = array('MssqlTestModel.updated <' => date('2009-01-01 00:00:00'));
$this->db->update($model, $fields, null, $conditions); $this->db->update($this->model, $fields, null, $conditions);
$result = $this->db->getLastQuery(); $result = $this->db->getLastQuery();
$this->assertNoPattern('/MssqlTestModel/', $result); $this->assertNoPattern('/MssqlTestModel/', $result);
$this->assertPattern('/^UPDATE \[mssql_test_models\]/', $result); $this->assertPattern('/^UPDATE \[mssql_test_models\]/', $result);
$this->assertPattern('/SET \[client_id\] = \[client_id\] \+ 1/', $result); $this->assertPattern('/SET \[client_id\] = \[client_id\] \+ 1/', $result);
} }
/**
* testGetPrimaryKey method
*
* @return void
* @access public
*/
function testGetPrimaryKey() {
$result = $this->db->getPrimaryKey($this->model);
$this->assertEqual($result, 'id');
$schema = $this->model->schema();
unset($schema['id']['key']);
$this->model->setSchema($schema);
$result = $this->db->getPrimaryKey($this->model);
$this->assertNull($result);
}
/**
* testInsertMulti
*
* @return void
* @access public
*/
function testInsertMulti() {
$fields = array('id', 'name', 'login');
$values = array('(1, \'Larry\', \'PhpNut\')', '(2, \'Renan\', \'renan.saddam\')');
$this->db->simulated = array();
$this->db->insertMulti($this->model, $fields, $values);
$result = $this->db->simulated;
$expected = array(
'SET IDENTITY_INSERT [mssql_test_models] ON',
'INSERT INTO [mssql_test_models] ([id], [name], [login]) VALUES (1, \'Larry\', \'PhpNut\')',
'INSERT INTO [mssql_test_models] ([id], [name], [login]) VALUES (2, \'Renan\', \'renan.saddam\')',
'SET IDENTITY_INSERT [mssql_test_models] OFF'
);
$this->assertEqual($result, $expected);
$fields = array('name', 'login');
$values = array('(\'Larry\', \'PhpNut\')', '(\'Renan\', \'renan.saddam\')');
$this->db->simulated = array();
$this->db->insertMulti($this->model, $fields, $values);
$result = $this->db->simulated;
$expected = array(
'INSERT INTO [mssql_test_models] ([name], [login]) VALUES (\'Larry\', \'PhpNut\')',
'INSERT INTO [mssql_test_models] ([name], [login]) VALUES (\'Renan\', \'renan.saddam\')'
);
$this->assertEqual($result, $expected);
}
} }
?> ?>

View file

@ -63,10 +63,10 @@ class ModelTest extends CakeTestCase {
'core.dependency', 'core.story', 'core.stories_tag', 'core.cd', 'core.book', 'core.basket', 'core.dependency', 'core.story', 'core.stories_tag', 'core.cd', 'core.book', 'core.basket',
'core.overall_favorite', 'core.account', 'core.content', 'core.content_account', 'core.overall_favorite', 'core.account', 'core.content', 'core.content_account',
'core.film_file', 'core.test_plugin_article', 'core.test_plugin_comment', 'core.uuiditem', 'core.film_file', 'core.test_plugin_article', 'core.test_plugin_comment', 'core.uuiditem',
'core.counter_cache_user', 'core.counter_cache_post', 'core.counter_cache_user', 'core.counter_cache_post',
'core.counter_cache_user_nonstandard_primary_key', 'core.counter_cache_user_nonstandard_primary_key',
'core.counter_cache_post_nonstandard_primary_key', 'core.uuidportfolio', 'core.counter_cache_post_nonstandard_primary_key', 'core.uuidportfolio',
'core.uuiditems_uuidportfolio', 'core.uuiditems_uuidportfolio_numericid', 'core.fruit', 'core.uuiditems_uuidportfolio', 'core.uuiditems_uuidportfolio_numericid', 'core.fruit',
'core.fruits_uuid_tag', 'core.uuid_tag' 'core.fruits_uuid_tag', 'core.uuid_tag'
); );
/** /**
@ -3921,7 +3921,7 @@ class ModelTest extends CakeTestCase {
$this->assertEqual($users[1]['User']['post_count'], 2); $this->assertEqual($users[1]['User']['post_count'], 2);
} }
/** /**
* Test counter cache with models that use a non-standard (i.e. not using 'id') * Test counter cache with models that use a non-standard (i.e. not using 'id')
* as their primary key. * as their primary key.
* *
* @access public * @access public
@ -3929,7 +3929,7 @@ class ModelTest extends CakeTestCase {
*/ */
function testCounterCacheWithNonstandardPrimaryKey() { function testCounterCacheWithNonstandardPrimaryKey() {
$this->loadFixtures( $this->loadFixtures(
'CounterCacheUserNonstandardPrimaryKey', 'CounterCacheUserNonstandardPrimaryKey',
'CounterCachePostNonstandardPrimaryKey' 'CounterCachePostNonstandardPrimaryKey'
); );
@ -3990,6 +3990,10 @@ class ModelTest extends CakeTestCase {
$TestModel2->saveField('published', true); $TestModel2->saveField('published', true);
$result = $TestModel->findById(1); $result = $TestModel->findById(1);
$this->assertIdentical($result['Syfile']['item_count'], '2'); $this->assertIdentical($result['Syfile']['item_count'], '2');
$TestModel2->save(array('id' => 1, 'syfile_id' => 1, 'published'=> false));
$result = $TestModel->findById(1);
$this->assertIdentical($result['Syfile']['item_count'], '1');
} }
/** /**
* testDel method * testDel method
@ -4027,6 +4031,36 @@ class ModelTest extends CakeTestCase {
array('Article' => array('id' => 1, 'title' => 'First Article' )) array('Article' => array('id' => 1, 'title' => 'First Article' ))
); );
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
// make sure deleting a non-existent record doesn't break save()
// ticket #6293
$this->loadFixtures('Uuid');
$Uuid =& new Uuid();
$data = array(
'B607DAB9-88A2-46CF-B57C-842CA9E3B3B3',
'52C8865C-10EE-4302-AE6C-6E7D8E12E2C8',
'8208C7FE-E89C-47C5-B378-DED6C271F9B8');
foreach ($data as $id) {
$Uuid->save(array('id' => $id));
}
$Uuid->del('52C8865C-10EE-4302-AE6C-6E7D8E12E2C8');
$Uuid->del('52C8865C-10EE-4302-AE6C-6E7D8E12E2C8');
foreach ($data as $id) {
$Uuid->save(array('id' => $id));
}
$result = $Uuid->find('all', array(
'conditions' => array('id' => $data),
'fields' => array('id'),
'order' => 'id'));
$expected = array(
array('Uuid' => array(
'id' => '52C8865C-10EE-4302-AE6C-6E7D8E12E2C8')),
array('Uuid' => array(
'id' => '8208C7FE-E89C-47C5-B378-DED6C271F9B8')),
array('Uuid' => array(
'id' => 'B607DAB9-88A2-46CF-B57C-842CA9E3B3B3')));
$this->assertEqual($result, $expected);
} }
/** /**
* testDeleteAll method * testDeleteAll method

View file

@ -1316,9 +1316,18 @@ class RouterTest extends CakeTestCase {
$expected = '/others/edit/1'; $expected = '/others/edit/1';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$result = Router::url(array('controller' => 'others', 'action' => 'edit', 1, 'protected' => true));; $result = Router::url(array('controller' => 'others', 'action' => 'edit', 1, 'protected' => true));
$expected = '/protected/others/edit/1'; $expected = '/protected/others/edit/1';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$result = Router::url(array('controller' => 'others', 'action' => 'edit', 1, 'protected' => true, 'page' => 1));
$expected = '/protected/others/edit/1/page:1';
$this->assertEqual($result, $expected);
Router::connectNamed(array('random'));
$result = Router::url(array('controller' => 'others', 'action' => 'edit', 1, 'protected' => true, 'random' => 'my-value'));
$expected = '/protected/others/edit/1/random:my-value';
$this->assertEqual($result, $expected);
} }
/** /**
* testRemoveBase method * testRemoveBase method

View file

@ -2553,8 +2553,8 @@ class FormHelperTest extends CakeTestCase {
'/label' '/label'
); );
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
$result = $this->Form->radio('Model.field', array('option A', 'option B'), array('name' => 'data[Model][custom]')); $result = $this->Form->radio('Model.field', array('option A', 'option B'), array('name' => 'data[Model][custom]'));
$expected = array( $expected = array(
'fieldset' => array(), 'fieldset' => array(),
@ -4247,6 +4247,14 @@ class FormHelperTest extends CakeTestCase {
'/textarea', '/textarea',
); );
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
$this->Form->data['Model']['0']['OtherModel']['field'] = null;
$result = $this->Form->textarea('Model.0.OtherModel.field');
$expected = array(
'textarea' => array('name' => 'data[Model][0][OtherModel][field]', 'id' => 'Model0OtherModelField'),
'/textarea'
);
$this->assertTags($result, $expected);
} }
/** /**
* testTextAreaWithStupidCharacters method * testTextAreaWithStupidCharacters method
@ -4564,8 +4572,8 @@ class FormHelperTest extends CakeTestCase {
)); ));
$expected = array( $expected = array(
'form' => array( 'form' => array(
'id' => 'ContactAddForm', 'id' => 'ContactAddForm',
'method' => 'post', 'method' => 'post',
'action' => '/controller/action/?param1=value1&amp;param2=value2' 'action' => '/controller/action/?param1=value1&amp;param2=value2'
), ),
'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'), 'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'),

View file

@ -256,6 +256,26 @@ class XmlTest extends CakeTestCase {
$result = $xml->toString(array('header' => false, 'cdata' => false)); $result = $xml->toString(array('header' => false, 'cdata' => false));
$this->assertEqual($expected, $result); $this->assertEqual($expected, $result);
} }
/**
* Prove that serialization with a given root node works
* as expected.
*
* @access public
* @return void
* @link https://trac.cakephp.org/ticket/6294
*/
function testArraySerializationWithRoot() {
$input = array(
array('Shirt' => array('id' => 1, 'color' => 'green')),
array('Shirt' => array('id' => 2, 'color' => 'blue')),
);
$expected = '<collection><shirt id="1" color="green" />';
$expected .= '<shirt id="2" color="blue" /></collection>';
$Xml = new Xml($input, array('root' => 'collection'));
$result = $Xml->toString(array('header' => false));
$this->assertEqual($expected, $result);
}
/** /**
* testCloneNode * testCloneNode
* *
@ -369,6 +389,30 @@ class XmlTest extends CakeTestCase {
$result = $node->removeAttribute('missing'); $result = $node->removeAttribute('missing');
$this->assertFalse($result); $this->assertFalse($result);
} }
/**
* Tests that XML documents with non-standard spacing (i.e. leading whitespace, whole document
* on one line) still parse properly.
*
* @return void
*/
function testParsingWithNonStandardWhitespace() {
$raw = '<?xml version="1.0" encoding="ISO-8859-1" ?><prices><price>1.0</price></prices>';
$array = array('Prices' => array('price' => 1.0));
$xml = new Xml($raw);
$this->assertEqual($xml->toArray(), $array);
$this->assertEqual($xml->__header, 'xml version="1.0" encoding="ISO-8859-1"');
$xml = new Xml(' ' . $raw);
$this->assertEqual($xml->toArray(), $array);
$this->assertEqual($xml->__header, 'xml version="1.0" encoding="ISO-8859-1"');
$xml = new Xml("\n" . $raw);
$this->assertEqual($xml->toArray(), $array);
$this->assertEqual($xml->__header, 'xml version="1.0" encoding="ISO-8859-1"');
}
/* Not implemented yet */ /* Not implemented yet */
/* function testChildFilter() { /* function testChildFilter() {
$input = array( $input = array(