From bd7bd5d8917bc53aa06dae01dc09670f1c770121 Mon Sep 17 00:00:00 2001 From: "renan.saddam" Date: Thu, 16 Apr 2009 18:12:01 +0000 Subject: [PATCH 01/19] Fixing issue when generating textarea with null value. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8146 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/view/helper.php | 2 +- cake/tests/cases/libs/view/helpers/form.test.php | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/cake/libs/view/helper.php b/cake/libs/view/helper.php index fc12c7ac2..076622c73 100644 --- a/cake/libs/view/helper.php +++ b/cake/libs/view/helper.php @@ -591,7 +591,7 @@ class Helper extends Overloadable { if (is_array($result)) { $view =& ClassRegistry::getObject('view'); - if (isset($result[$view->fieldSuffix])) { + if (array_key_exists($view->fieldSuffix, $result)) { $result = $result[$view->fieldSuffix]; } } diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index b06f2b7e9..9358df259 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -2553,8 +2553,8 @@ class FormHelperTest extends CakeTestCase { '/label' ); $this->assertTags($result, $expected); - - + + $result = $this->Form->radio('Model.field', array('option A', 'option B'), array('name' => 'data[Model][custom]')); $expected = array( 'fieldset' => array(), @@ -4247,6 +4247,14 @@ class FormHelperTest extends CakeTestCase { '/textarea', ); $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 @@ -4564,8 +4572,8 @@ class FormHelperTest extends CakeTestCase { )); $expected = array( 'form' => array( - 'id' => 'ContactAddForm', - 'method' => 'post', + 'id' => 'ContactAddForm', + 'method' => 'post', 'action' => '/controller/action/?param1=value1&param2=value2' ), 'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'), From bbfee7ba179a07e1f544d436ab8fa70d3fc599d1 Mon Sep 17 00:00:00 2001 From: davidpersson Date: Fri, 17 Apr 2009 13:26:07 +0000 Subject: [PATCH 02/19] Updating Xml class to always use #document as the very root node and to create a node below it if the root option is set. Adding test. Fixes #6294 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8147 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/xml.php | 12 +++++++++--- cake/tests/cases/libs/xml.test.php | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/cake/libs/xml.php b/cake/libs/xml.php index d7eab9f53..b4edf2fff 100644 --- a/cake/libs/xml.php +++ b/cake/libs/xml.php @@ -823,13 +823,19 @@ class Xml extends XmlNode { $this->{$key} = $options[$key]; } $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 (is_string($input)) { - $this->load($input); + $Root->load($input); } elseif (is_array($input) || is_object($input)) { - $this->append($input, $options); + $Root->append($input, $options); } } // if (Configure::read('App.encoding') !== null) { diff --git a/cake/tests/cases/libs/xml.test.php b/cake/tests/cases/libs/xml.test.php index 4ee508a68..f452b54df 100644 --- a/cake/tests/cases/libs/xml.test.php +++ b/cake/tests/cases/libs/xml.test.php @@ -256,6 +256,26 @@ class XmlTest extends CakeTestCase { $result = $xml->toString(array('header' => false, 'cdata' => false)); $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 = ''; + $expected .= ''; + + $Xml = new Xml($input, array('root' => 'collection')); + $result = $Xml->toString(array('header' => false)); + $this->assertEqual($expected, $result); + } /** * testCloneNode * From 6e91ee7ad4897cbcf1a2b65a1c5244953a3c4f8c Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 20 Apr 2009 07:36:26 +0000 Subject: [PATCH 03/19] Adding tests to disprove #6306 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8148 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/tests/cases/libs/router.test.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cake/tests/cases/libs/router.test.php b/cake/tests/cases/libs/router.test.php index 7cbc98161..f0bfb1441 100644 --- a/cake/tests/cases/libs/router.test.php +++ b/cake/tests/cases/libs/router.test.php @@ -1316,9 +1316,18 @@ class RouterTest extends CakeTestCase { $expected = '/others/edit/1'; $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'; $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 From 0cc3d5149f1e9f9442d46a2b37ea99dee9de422f Mon Sep 17 00:00:00 2001 From: gwoo Date: Wed, 22 Apr 2009 16:05:13 +0000 Subject: [PATCH 04/19] fixes #6277, relaxing character length comparison for UUID git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8149 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/model.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index 05b655975..0af80bafb 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -1210,7 +1210,7 @@ class Model extends Overloadable { foreach ($this->_schema as $field => $properties) { if ($this->primaryKey === $field) { $fInfo = $this->_schema[$field]; - $isUUID = ($fInfo['length'] === 36 && + $isUUID = ($fInfo['length'] == 36 && ($fInfo['type'] === 'string' || $fInfo['type'] === 'binary') ); if (empty($this->data[$this->alias][$this->primaryKey]) && $isUUID) { @@ -1279,7 +1279,7 @@ class Model extends Overloadable { )); $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'] === 'binary' ) From fd0c39fcc6f57551c6eec75895bb3af87f18af43 Mon Sep 17 00:00:00 2001 From: gwoo Date: Wed, 22 Apr 2009 16:47:34 +0000 Subject: [PATCH 05/19] fixes #6293, Deleting non-existing record causes save() to fail. Thanks to msadouni for the patch and test! git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8150 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/model.php | 2 +- cake/tests/cases/libs/model/model.test.php | 42 ++++++++++++++++++---- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index 0af80bafb..5238bb242 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -1853,7 +1853,7 @@ class Model extends Overloadable { if ($this->getID() === false || $this->useTable === false) { return false; } - if ($this->__exists !== null && $reset !== true) { + if (!empty($this->__exists) && $reset !== true) { return $this->__exists; } $conditions = array($this->alias . '.' . $this->primaryKey => $this->getID()); diff --git a/cake/tests/cases/libs/model/model.test.php b/cake/tests/cases/libs/model/model.test.php index 42170ae0c..595335172 100644 --- a/cake/tests/cases/libs/model/model.test.php +++ b/cake/tests/cases/libs/model/model.test.php @@ -63,10 +63,10 @@ class ModelTest extends CakeTestCase { 'core.dependency', 'core.story', 'core.stories_tag', 'core.cd', 'core.book', 'core.basket', 'core.overall_favorite', 'core.account', 'core.content', 'core.content_account', '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_nonstandard_primary_key', - 'core.counter_cache_post_nonstandard_primary_key', 'core.uuidportfolio', - 'core.uuiditems_uuidportfolio', 'core.uuiditems_uuidportfolio_numericid', 'core.fruit', + 'core.counter_cache_user', 'core.counter_cache_post', + 'core.counter_cache_user_nonstandard_primary_key', + 'core.counter_cache_post_nonstandard_primary_key', 'core.uuidportfolio', + 'core.uuiditems_uuidportfolio', 'core.uuiditems_uuidportfolio_numericid', 'core.fruit', 'core.fruits_uuid_tag', 'core.uuid_tag' ); /** @@ -3921,7 +3921,7 @@ class ModelTest extends CakeTestCase { $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. * * @access public @@ -3929,7 +3929,7 @@ class ModelTest extends CakeTestCase { */ function testCounterCacheWithNonstandardPrimaryKey() { $this->loadFixtures( - 'CounterCacheUserNonstandardPrimaryKey', + 'CounterCacheUserNonstandardPrimaryKey', 'CounterCachePostNonstandardPrimaryKey' ); @@ -4027,6 +4027,36 @@ class ModelTest extends CakeTestCase { array('Article' => array('id' => 1, 'title' => 'First Article' )) ); $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 From 82cb895f505e3f50ef14473bc0d11310eadf0fc0 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 23 Apr 2009 17:26:56 +0000 Subject: [PATCH 06/19] Correcting test case simulation. Closes #6211 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8151 3807eeeb-6ff5-0310-8944-8be069107fe0 --- .../cases/libs/controller/components/auth.test.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cake/tests/cases/libs/controller/components/auth.test.php b/cake/tests/cases/libs/controller/components/auth.test.php index f10eae7a7..e65ec4c08 100644 --- a/cake/tests/cases/libs/controller/components/auth.test.php +++ b/cake/tests/cases/libs/controller/components/auth.test.php @@ -839,16 +839,22 @@ class AuthTest extends CakeTestCase { $this->assertEqual($expected, $this->Controller->Session->read('Auth.redirect')); // QueryString parameters + $_back = $_GET; + $_GET = array( + 'url' => '/posts/index/29?print=true&refer=menu', + 'print' => 'true', + 'refer' => 'menu' + ); $this->Controller->Session->del('Auth'); $url = '/posts/index/29?print=true&refer=menu'; - $this->Controller->params = Router::parse($url); - $this->Controller->params['url']['url'] = Router::normalize($url); + $this->Controller->params = Dispatcher::parseParams($url); $this->Controller->Auth->initialize($this->Controller); $this->Controller->Auth->loginAction = array('controller' => 'AuthTest', 'action' => 'login'); $this->Controller->Auth->userModel = 'AuthUser'; $this->Controller->Auth->startup($this->Controller); $expected = Router::normalize('posts/index/29?print=true&refer=menu'); $this->assertEqual($expected, $this->Controller->Session->read('Auth.redirect')); + $_GET = $_back; //external authed action $_SERVER['HTTP_REFERER'] = 'http://webmail.example.com/view/message'; From 650d1e7c789e6242add3872b6e9966838b6d2091 Mon Sep 17 00:00:00 2001 From: jperras Date: Fri, 24 Apr 2009 18:20:51 +0000 Subject: [PATCH 07/19] Removing hard coded HELO hostname of 'cake' in EmailComponent; better compliance with RFC-821 3.5. Test cases added. Fixes #6264. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8152 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/controller/components/email.php | 8 +- .../libs/controller/components/email.test.php | 222 +++++++++++------- 2 files changed, 148 insertions(+), 82 deletions(-) diff --git a/cake/libs/controller/components/email.php b/cake/libs/controller/components/email.php index c8a368b3d..71b013a14 100644 --- a/cake/libs/controller/components/email.php +++ b/cake/libs/controller/components/email.php @@ -673,7 +673,13 @@ class EmailComponent extends Object{ 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; } diff --git a/cake/tests/cases/libs/controller/components/email.test.php b/cake/tests/cases/libs/controller/components/email.test.php index cfe806c06..4258c952c 100644 --- a/cake/tests/cases/libs/controller/components/email.test.php +++ b/cake/tests/cases/libs/controller/components/email.test.php @@ -25,6 +25,41 @@ * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License */ 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; + } +} /** * EmailTestController class * @@ -52,7 +87,7 @@ class EmailTestController extends Controller { * @var array * @access public */ - var $components = array('Email'); + var $components = array('EmailTest'); /** * pageTitle property * @@ -98,7 +133,7 @@ class EmailComponentTest extends CakeTestCase { @$this->Controller->Component->init($this->Controller); 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)); $this->_viewPaths = Configure::read('viewPaths'); @@ -125,9 +160,9 @@ class EmailComponentTest extends CakeTestCase { * @return void */ function testBadSmtpSend() { - $this->Controller->Email->smtpOptions['host'] = 'blah'; - $this->Controller->Email->delivery = 'smtp'; - $this->assertFalse($this->Controller->Email->send('Should not work')); + $this->Controller->EmailTest->smtpOptions['host'] = 'blah'; + $this->Controller->EmailTest->delivery = 'smtp'; + $this->assertFalse($this->Controller->EmailTest->send('Should not work')); } /** * testSmtpSend method @@ -139,18 +174,18 @@ class EmailComponentTest extends CakeTestCase { if (!$this->skipIf(!@fsockopen('localhost', 25), '%s No SMTP server running on localhost')) { return; } - $this->Controller->Email->reset(); - $this->Controller->Email->to = 'postmaster@localhost'; - $this->Controller->Email->from = 'noreply@example.com'; - $this->Controller->Email->subject = 'Cake SMTP test'; - $this->Controller->Email->replyTo = 'noreply@example.com'; - $this->Controller->Email->template = null; + $this->Controller->EmailTest->reset(); + $this->Controller->EmailTest->to = 'postmaster@localhost'; + $this->Controller->EmailTest->from = 'noreply@example.com'; + $this->Controller->EmailTest->subject = 'Cake SMTP test'; + $this->Controller->EmailTest->replyTo = 'noreply@example.com'; + $this->Controller->EmailTest->template = null; - $this->Controller->Email->delivery = 'smtp'; - $this->assertTrue($this->Controller->Email->send('This is the body of the message')); + $this->Controller->EmailTest->delivery = 'smtp'; + $this->assertTrue($this->Controller->EmailTest->send('This is the body of the message')); - $this->Controller->Email->_debug = true; - $this->Controller->Email->sendAs = 'text'; + $this->Controller->EmailTest->_debug = true; + $this->Controller->EmailTest->sendAs = 'text'; $expect = <<Host: localhost Port: 25 @@ -174,7 +209,7 @@ This is the body of the message 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)); } /** @@ -186,20 +221,22 @@ TEMPDOC; function testAuthenticatedSmtpSend() { $this->skipIf(!@fsockopen('localhost', 25), '%s No SMTP server running on localhost'); - $this->Controller->Email->reset(); - $this->Controller->Email->to = 'postmaster@localhost'; - $this->Controller->Email->from = 'noreply@example.com'; - $this->Controller->Email->subject = 'Cake SMTP test'; - $this->Controller->Email->replyTo = 'noreply@example.com'; - $this->Controller->Email->template = null; - $this->Controller->Email->smtpOptions['username'] = 'test'; - $this->Controller->Email->smtpOptions['password'] = 'testing'; + $this->Controller->EmailTest->reset(); + $this->Controller->EmailTest->to = 'postmaster@localhost'; + $this->Controller->EmailTest->from = 'noreply@example.com'; + $this->Controller->EmailTest->subject = 'Cake SMTP test'; + $this->Controller->EmailTest->replyTo = 'noreply@example.com'; + $this->Controller->EmailTest->template = null; + $this->Controller->EmailTest->smtpOptions['username'] = 'test'; + $this->Controller->EmailTest->smtpOptions['password'] = 'testing'; - $this->Controller->Email->delivery = 'smtp'; - $result = $this->Controller->Email->send('This is the body of the message'); - $code = substr($this->Controller->Email->smtpError, 0, 3); + $this->Controller->EmailTest->delivery = 'smtp'; + $result = $this->Controller->EmailTest->send('This is the body of the message'); + $code = substr($this->Controller->EmailTest->smtpError, 0, 3); $this->skipIf(!$code, '%s Authentication not enabled on server'); - $this->assertTrue(!$result && $code == '535'); + + $this->assertFalse($result); + $this->assertEqual($code, '535'); } /** * testSendFormats method @@ -208,13 +245,13 @@ TEMPDOC; * @return void */ function testSendFormats() { - $this->Controller->Email->reset(); - $this->Controller->Email->to = 'postmaster@localhost'; - $this->Controller->Email->from = 'noreply@example.com'; - $this->Controller->Email->subject = 'Cake SMTP test'; - $this->Controller->Email->replyTo = 'noreply@example.com'; - $this->Controller->Email->template = null; - $this->Controller->Email->delivery = 'debug'; + $this->Controller->EmailTest->reset(); + $this->Controller->EmailTest->to = 'postmaster@localhost'; + $this->Controller->EmailTest->from = 'noreply@example.com'; + $this->Controller->EmailTest->subject = 'Cake SMTP test'; + $this->Controller->EmailTest->replyTo = 'noreply@example.com'; + $this->Controller->EmailTest->template = null; + $this->Controller->EmailTest->delivery = 'debug'; $message = <<To: postmaster@localhost @@ -234,20 +271,20 @@ This is the body of the message MSGBLOC; - $this->Controller->Email->sendAs = 'text'; + $this->Controller->EmailTest->sendAs = 'text'; $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->Controller->Email->sendAs = 'html'; + $this->Controller->EmailTest->sendAs = 'html'; $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)); // 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); - $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)); } /** @@ -257,13 +294,13 @@ MSGBLOC; * @return void */ function testTemplates() { - $this->Controller->Email->reset(); - $this->Controller->Email->to = 'postmaster@localhost'; - $this->Controller->Email->from = 'noreply@example.com'; - $this->Controller->Email->subject = 'Cake SMTP test'; - $this->Controller->Email->replyTo = 'noreply@example.com'; + $this->Controller->EmailTest->reset(); + $this->Controller->EmailTest->to = 'postmaster@localhost'; + $this->Controller->EmailTest->from = 'noreply@example.com'; + $this->Controller->EmailTest->subject = 'Cake SMTP test'; + $this->Controller->EmailTest->replyTo = 'noreply@example.com'; - $this->Controller->Email->delivery = 'debug'; + $this->Controller->EmailTest->delivery = 'debug'; $header = <<Controller->Email->layout = 'default'; - $this->Controller->Email->template = 'default'; + $this->Controller->EmailTest->layout = 'default'; + $this->Controller->EmailTest->template = 'default'; $text = <<Controller->Email->sendAs = 'text'; + $this->Controller->EmailTest->sendAs = 'text'; $expect = '
' . str_replace('{CONTENTTYPE}', 'text/plain; charset=UTF-8', $header) . $text . "\n" . '
'; - $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->Controller->Email->sendAs = 'html'; + $this->Controller->EmailTest->sendAs = 'html'; $expect = '
' . str_replace('{CONTENTTYPE}', 'text/html; charset=UTF-8', $header) . $html . "\n" . '
'; - $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->Controller->Email->sendAs = 'both'; + $this->Controller->EmailTest->sendAs = 'both'; $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/html; charset=UTF-8' . "\n" . 'Content-Transfer-Encoding: 7bit' . "\n\n" . $html . "\n\n"; $expect = '
' . $expect . '--alt---' . "\n\n" . '
'; - $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)); $html = <<Controller->Email->sendAs = 'html'; + $this->Controller->EmailTest->sendAs = 'html'; $expect = '
' . str_replace('{CONTENTTYPE}', 'text/html; charset=UTF-8', $header) . $html . "\n" . '
'; - $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)); return; @@ -362,11 +399,34 @@ This email was sent using the CakePHP Framework, http://cakephp.org. TEXTBLOC; - $this->Controller->Email->sendAs = 'text'; + $this->Controller->EmailTest->sendAs = 'text'; $expect = '
' . str_replace('{CONTENTTYPE}', 'text/plain; charset=UTF-8', $header) . $text . "\n" . '
'; - $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)); } +/** + * 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 * @@ -374,15 +434,15 @@ TEXTBLOC; * @return void */ function testSendDebug() { - $this->Controller->Email->reset(); - $this->Controller->Email->to = 'postmaster@localhost'; - $this->Controller->Email->from = 'noreply@example.com'; - $this->Controller->Email->subject = 'Cake SMTP test'; - $this->Controller->Email->replyTo = 'noreply@example.com'; - $this->Controller->Email->template = null; + $this->Controller->EmailTest->reset(); + $this->Controller->EmailTest->to = 'postmaster@localhost'; + $this->Controller->EmailTest->from = 'noreply@example.com'; + $this->Controller->EmailTest->subject = 'Cake SMTP test'; + $this->Controller->EmailTest->replyTo = 'noreply@example.com'; + $this->Controller->EmailTest->template = null; - $this->Controller->Email->delivery = 'debug'; - $this->assertTrue($this->Controller->Email->send('This is the body of the message')); + $this->Controller->EmailTest->delivery = 'debug'; + $this->assertTrue($this->Controller->EmailTest->send('This is the body of the message')); } /** * testContentStripping method @@ -394,7 +454,7 @@ TEXTBLOC; $content = "Previous content\n--alt-\nContent-TypeContent-Type:: text/html; charsetcharset==utf-8\nContent-Transfer-Encoding: 7bit"; $content .= "\n\n

My own html content

"; - $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

My own html content

"; $this->assertEqual($result, $expected); } @@ -405,28 +465,28 @@ TEXTBLOC; * @return void */ function testMultibyte() { - $this->Controller->Email->reset(); - $this->Controller->Email->to = 'postmaster@localhost'; - $this->Controller->Email->from = 'noreply@example.com'; - $this->Controller->Email->subject = 'هذه رسالة بعنوان طويل مرسل للمستلم'; - $this->Controller->Email->replyTo = 'noreply@example.com'; - $this->Controller->Email->template = null; - $this->Controller->Email->delivery = 'debug'; + $this->Controller->EmailTest->reset(); + $this->Controller->EmailTest->to = 'postmaster@localhost'; + $this->Controller->EmailTest->from = 'noreply@example.com'; + $this->Controller->EmailTest->subject = 'هذه رسالة بعنوان طويل مرسل للمستلم'; + $this->Controller->EmailTest->replyTo = 'noreply@example.com'; + $this->Controller->EmailTest->template = null; + $this->Controller->EmailTest->delivery = 'debug'; $subject = '=?UTF-8?B?2YfYsNmHINix2LPYp9mE2Kkg2KjYudmG2YjYp9mGINi32YjZitmEINmF2LE=?=' . "\r\n" . ' =?UTF-8?B?2LPZhCDZhNmE2YXYs9iq2YTZhQ==?='; - $this->Controller->Email->sendAs = 'text'; - $this->assertTrue($this->Controller->Email->send('This is the body of the message')); + $this->Controller->EmailTest->sendAs = 'text'; + $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); $this->assertEqual(trim($matches[1]), $subject); - $this->Controller->Email->sendAs = 'html'; - $this->assertTrue($this->Controller->Email->send('This is the body of the message')); + $this->Controller->EmailTest->sendAs = 'html'; + $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); $this->assertEqual(trim($matches[1]), $subject); - $this->Controller->Email->sendAs = 'both'; - $this->assertTrue($this->Controller->Email->send('This is the body of the message')); + $this->Controller->EmailTest->sendAs = 'both'; + $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); $this->assertEqual(trim($matches[1]), $subject); } From 97abf8477096fe5afae3319bab0ba5a916be217e Mon Sep 17 00:00:00 2001 From: jperras Date: Sat, 25 Apr 2009 00:01:57 +0000 Subject: [PATCH 08/19] EmailComponent:: now is set to null after calling EmailComponent::reset(). Test cases added; fixes #6314. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8153 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/controller/components/email.php | 1 + .../libs/controller/components/email.test.php | 82 +++++++++++++++++++ 2 files changed, 83 insertions(+) diff --git a/cake/libs/controller/components/email.php b/cake/libs/controller/components/email.php index 71b013a14..90dc72055 100644 --- a/cake/libs/controller/components/email.php +++ b/cake/libs/controller/components/email.php @@ -345,6 +345,7 @@ class EmailComponent extends Object{ $this->bcc = array(); $this->subject = null; $this->additionalParams = null; + $this->smtpError = null; $this->__header = array(); $this->__boundary = null; $this->__message = array(); diff --git a/cake/tests/cases/libs/controller/components/email.test.php b/cake/tests/cases/libs/controller/components/email.test.php index 4258c952c..08f033aac 100644 --- a/cake/tests/cases/libs/controller/components/email.test.php +++ b/cake/tests/cases/libs/controller/components/email.test.php @@ -59,6 +59,51 @@ class EmailTestComponent extends EmailComponent { 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 @@ -490,6 +535,43 @@ TEXTBLOC; preg_match('/Subject: (.*)Header:/s', $this->Controller->Session->read('Message.email.message'), $matches); $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 * From 9ab6339392d8f08eed150db553d0faaf2f64dd99 Mon Sep 17 00:00:00 2001 From: gwoo Date: Sat, 25 Apr 2009 01:06:46 +0000 Subject: [PATCH 09/19] fixes #6240, DboOracle: fix cache sources and php version compatibility git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8154 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/datasources/dbo/dbo_oracle.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cake/libs/model/datasources/dbo/dbo_oracle.php b/cake/libs/model/datasources/dbo/dbo_oracle.php index d35b5900a..f7ec6f06e 100644 --- a/cake/libs/model/datasources/dbo/dbo_oracle.php +++ b/cake/libs/model/datasources/dbo/dbo_oracle.php @@ -454,6 +454,7 @@ class DboOracle extends DboSource { while($r = $this->fetchRow()) { $sources[] = strtolower($r[0]['name']); } + parent::listSources($sources); return $sources; } /** @@ -834,8 +835,7 @@ class DboOracle extends DboSource { switch($column) { case 'date': - $date = new DateTime($data); - $data = $date->format('Y-m-d H:i:s'); + $data = date('Y-m-d H:i:s', strtotime($data)); $data = "TO_DATE('$data', 'YYYY-MM-DD HH24:MI:SS')"; break; case 'integer' : From 8bb11e49d7fb1fb708caba36b3ede5c35e6f424a Mon Sep 17 00:00:00 2001 From: jperras Date: Sat, 25 Apr 2009 01:17:21 +0000 Subject: [PATCH 10/19] Fixing counterCache behavior when updating an existing record's counterScope value. Thanks for the patch, mattcurry. Fixes #6270. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8155 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/model.php | 17 ++++++++--------- cake/tests/cases/libs/model/model.test.php | 4 ++++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index 5238bb242..1becede48 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -1374,16 +1374,15 @@ class Model extends Overloadable { $conditions = ($recursive == 1) ? (array)$assoc['counterScope'] : array(); if (isset($keys['old'][$foreignKey])) { - if ($keys['old'][$foreignKey] == $keys[$foreignKey]) { - continue; + if ($keys['old'][$foreignKey] != $keys[$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['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]; diff --git a/cake/tests/cases/libs/model/model.test.php b/cake/tests/cases/libs/model/model.test.php index 595335172..77149c1cc 100644 --- a/cake/tests/cases/libs/model/model.test.php +++ b/cake/tests/cases/libs/model/model.test.php @@ -3990,6 +3990,10 @@ class ModelTest extends CakeTestCase { $TestModel2->saveField('published', true); $result = $TestModel->findById(1); $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 From b68c78fc0f86f669027dc90cdc09dbde999ba4e3 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 25 Apr 2009 02:16:05 +0000 Subject: [PATCH 11/19] Fixing lost querystring params when user request without a session is performed. Test case updated. Fixes #6211 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8156 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/controller/components/auth.php | 5 +++++ cake/tests/cases/libs/controller/components/auth.test.php | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cake/libs/controller/components/auth.php b/cake/libs/controller/components/auth.php index d2f2bede9..a8744ce25 100644 --- a/cake/libs/controller/components/auth.php +++ b/cake/libs/controller/components/auth.php @@ -337,6 +337,11 @@ class AuthComponent extends Object { if (!$this->user()) { if (!$this->RequestHandler->isAjax()) { $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); $controller->redirect($loginAction); return false; diff --git a/cake/tests/cases/libs/controller/components/auth.test.php b/cake/tests/cases/libs/controller/components/auth.test.php index e65ec4c08..3cdb25bb7 100644 --- a/cake/tests/cases/libs/controller/components/auth.test.php +++ b/cake/tests/cases/libs/controller/components/auth.test.php @@ -841,7 +841,7 @@ class AuthTest extends CakeTestCase { // QueryString parameters $_back = $_GET; $_GET = array( - 'url' => '/posts/index/29?print=true&refer=menu', + 'url' => '/posts/index/29', 'print' => 'true', 'refer' => 'menu' ); From c8cf1a2c5bed17c6c24df5484a957abf354bde3a Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 28 Apr 2009 01:32:20 +0000 Subject: [PATCH 12/19] Updating __mergeVars to correctly merge parent and child component configurations. Applied patch from 'neilcrookes'. Test case added. Fixes #6325 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8157 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/controller/controller.php | 2 +- .../cases/libs/controller/controller.test.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php index 19a9aef76..5c33e1a49 100644 --- a/cake/libs/controller/controller.php +++ b/cake/libs/controller/controller.php @@ -393,7 +393,7 @@ class Controller extends Object { if ($var === 'components') { $normal = Set::normalize($this->{$var}); $app = Set::normalize($appVars[$var]); - $this->{$var} = Set::merge($normal, $app); + $this->{$var} = Set::merge($app, $normal); } else { $this->{$var} = Set::merge($this->{$var}, array_diff($appVars[$var], $this->{$var})); } diff --git a/cake/tests/cases/libs/controller/controller.test.php b/cake/tests/cases/libs/controller/controller.test.php index 53b1663ed..8c7b3204c 100644 --- a/cake/tests/cases/libs/controller/controller.test.php +++ b/cake/tests/cases/libs/controller/controller.test.php @@ -940,6 +940,22 @@ class ControllerTest extends CakeTestCase { $this->assertTrue(isset($TestController->ControllerPost)); $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 * AppController when you make an instance of Controller From 9f15226e4605ba4b6c5ba918b64d7209ceb77540 Mon Sep 17 00:00:00 2001 From: nate Date: Tue, 28 Apr 2009 13:23:37 +0000 Subject: [PATCH 13/19] Fixes #6318: Incorrect whitespace handling/parsing of XML documents git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8158 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/xml.php | 3 ++- cake/tests/cases/libs/xml.test.php | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/cake/libs/xml.php b/cake/libs/xml.php index b4edf2fff..845068514 100644 --- a/cake/libs/xml.php +++ b/cake/libs/xml.php @@ -880,10 +880,11 @@ class Xml extends XmlNode { */ function parse() { $this->__initParser(); + $this->__rawData = trim($this->__rawData); $this->__header = trim(str_replace( 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); diff --git a/cake/tests/cases/libs/xml.test.php b/cake/tests/cases/libs/xml.test.php index f452b54df..eec558641 100644 --- a/cake/tests/cases/libs/xml.test.php +++ b/cake/tests/cases/libs/xml.test.php @@ -389,6 +389,30 @@ class XmlTest extends CakeTestCase { $result = $node->removeAttribute('missing'); $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 = '1.0'; + $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 */ /* function testChildFilter() { $input = array( From 48386b791f61e1ce8f99e1198c09a36de3059635 Mon Sep 17 00:00:00 2001 From: "renan.saddam" Date: Tue, 28 Apr 2009 22:20:04 +0000 Subject: [PATCH 14/19] Fixing cake_test_fixture and dbo_mssql tests. Refs #6135. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8159 3807eeeb-6ff5-0310-8944-8be069107fe0 --- .../cases/libs/cake_test_fixture.test.php | 4 +-- .../model/datasources/dbo/dbo_mssql.test.php | 29 +------------------ 2 files changed, 3 insertions(+), 30 deletions(-) diff --git a/cake/tests/cases/libs/cake_test_fixture.test.php b/cake/tests/cases/libs/cake_test_fixture.test.php index 5e17ed25b..03a712a56 100644 --- a/cake/tests/cases/libs/cake_test_fixture.test.php +++ b/cake/tests/cases/libs/cake_test_fixture.test.php @@ -51,8 +51,8 @@ class CakeTestFixtureTestFixture extends CakeTestFixture { */ var $fields = array( 'id' => array('type' => 'integer', 'key' => 'primary'), - 'name' => array('type' => 'text', 'length' => '255'), - 'created' => array('type' => 'datetime'), + 'name' => array('type' => 'string', 'length' => '255'), + 'created' => array('type' => 'datetime') ); /** * Records property diff --git a/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php b/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php index d2c3411f7..319f2f134 100644 --- a/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php @@ -36,32 +36,6 @@ require_once LIBS.'model'.DS.'datasources'.DS.'dbo'.DS.'dbo_mssql.php'; * @subpackage cake.tests.cases.libs.model.datasources.dbo */ 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 * @@ -346,10 +320,9 @@ class DboMssqlTest extends CakeTestCase { * @access public */ function testUpdateAllSyntax() { - $model = ClassRegistry::init('MssqlTestModel'); $fields = array('MssqlTestModel.client_id' => '[MssqlTestModel].[client_id] + 1'); $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(); $this->assertNoPattern('/MssqlTestModel/', $result); From 7eaf331213a13f6263d17e45d947dae6adad46e4 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 29 Apr 2009 12:40:15 +0000 Subject: [PATCH 15/19] Updating doc block for FormHelper::input(). Fixes #6328 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8160 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/view/helpers/form.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index 2a4ff3420..5cff4816d 100644 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -559,7 +559,8 @@ class FormHelper extends AppHelper { /** * 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'``` * - 'label' - control the label From 975ddaa4be67da028ea9f34d774852ff2c98cb73 Mon Sep 17 00:00:00 2001 From: "renan.saddam" Date: Wed, 29 Apr 2009 16:26:03 +0000 Subject: [PATCH 16/19] Fixes #6135: Primary Key detection and load record fixtures on mssql. Tests added. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8161 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/datasources/datasource.php | 9 ++- cake/libs/model/datasources/dbo/dbo_mssql.php | 60 ++++++++++++-- .../model/datasources/dbo/dbo_mssql.test.php | 79 +++++++++++++------ 3 files changed, 114 insertions(+), 34 deletions(-) diff --git a/cake/libs/model/datasources/datasource.php b/cake/libs/model/datasources/datasource.php index 6736f62a6..4fa8fba2e 100644 --- a/cake/libs/model/datasources/datasource.php +++ b/cake/libs/model/datasources/datasource.php @@ -241,13 +241,14 @@ class DataSource extends Object { if ($this->cacheSources === false) { return null; } - if (isset($this->__descriptions[$model->tablePrefix . $model->table])) { - return $this->__descriptions[$model->tablePrefix . $model->table]; + $table = $this->fullTableName($model, false); + if (isset($this->__descriptions[$table])) { + return $this->__descriptions[$table]; } - $cache = $this->__cacheDescription($model->tablePrefix . $model->table); + $cache = $this->__cacheDescription($table); if ($cache !== null) { - $this->__descriptions[$model->tablePrefix . $model->table] =& $cache; + $this->__descriptions[$table] =& $cache; return $cache; } return null; diff --git a/cake/libs/model/datasources/dbo/dbo_mssql.php b/cake/libs/model/datasources/dbo/dbo_mssql.php index 88938ba3b..c1bbd9e9c 100644 --- a/cake/libs/model/datasources/dbo/dbo_mssql.php +++ b/cake/libs/model/datasources/dbo/dbo_mssql.php @@ -221,7 +221,7 @@ class DboMssql extends DboSource { 'null' => (strtoupper($column[0]['Null']) == 'YES'), 'default' => preg_replace("/^[(]{1,2}'?([^')]*)?'?[)]{1,2}$/", "$1", $column[0]['Default']), 'length' => intval($column[0]['Length']), - 'key' => ($column[0]['Key'] == '1') + 'key' => ($column[0]['Key'] == '1') ? 'primary' : false ); if ($fields[$field]['default'] === 'null') { $fields[$field]['default'] = null; @@ -341,17 +341,18 @@ class DboMssql extends DboSource { if (!empty($values)) { $fields = array_combine($fields, $values); } + $primaryKey = $this->_getPrimaryKey($model); - if (array_key_exists($model->primaryKey, $fields)) { - if (empty($fields[$model->primaryKey])) { - unset($fields[$model->primaryKey]); + if (array_key_exists($primaryKey, $fields)) { + if (empty($fields[$primaryKey])) { + unset($fields[$primaryKey]); } 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)); - if (array_key_exists($model->primaryKey, $fields) && !empty($fields[$model->primaryKey])) { - $this->_execute("SET IDENTITY_INSERT " . $this->fullTableName($model) . " OFF"); + if (array_key_exists($primaryKey, $fields) && !empty($fields[$primaryKey])) { + $this->_execute('SET IDENTITY_INSERT ' . $this->fullTableName($model) . ' OFF'); } return $result; } @@ -631,6 +632,29 @@ class DboMssql extends DboSource { 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 * @@ -680,5 +704,27 @@ class DboMssql extends DboSource { } 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; + } } ?> \ No newline at end of file diff --git a/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php b/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php index 319f2f134..c92a67e9d 100644 --- a/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php @@ -94,6 +94,16 @@ class DboMssqlTestDb extends DboMssql { function getLastQuery() { 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 @@ -116,6 +126,32 @@ class MssqlTestModel extends Model { * @access public */ 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 * @@ -143,33 +179,14 @@ class MssqlTestModel extends Model { return $conditions; } /** - * schema method + * setSchema method * + * @param array $schema * @access public * @return void */ - function schema() { - $this->_schema = array( - '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; + function setSchema($schema) { + $this->_schema = $schema; } } /** @@ -329,5 +346,21 @@ class DboMssqlTest extends CakeTestCase { $this->assertPattern('/^UPDATE \[mssql_test_models\]/', $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); + } } ?> \ No newline at end of file From f25cf632066cc840cabf6e915258e0e040285bef Mon Sep 17 00:00:00 2001 From: "renan.saddam" Date: Wed, 29 Apr 2009 16:39:42 +0000 Subject: [PATCH 17/19] Adding missing test from last commit. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8162 3807eeeb-6ff5-0310-8944-8be069107fe0 --- .../model/datasources/dbo/dbo_mssql.test.php | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php b/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php index c92a67e9d..1cd3268fa 100644 --- a/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php @@ -362,5 +362,36 @@ class DboMssqlTest extends CakeTestCase { $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); + } } ?> \ No newline at end of file From cf3f92c402a79baa04e831fa83a84871745f05d5 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 30 Apr 2009 23:38:14 +0000 Subject: [PATCH 18/19] Updating testsuite console to search $pluginPaths for plugins. Fixing readability of help in 80 col displays. Fixes #6329. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8163 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/console/libs/testsuite.php | 50 +++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/cake/console/libs/testsuite.php b/cake/console/libs/testsuite.php index 72cefbcc2..b11a7ea11 100644 --- a/cake/console/libs/testsuite.php +++ b/cake/console/libs/testsuite.php @@ -156,30 +156,30 @@ class TestSuiteShell extends Shell { function help() { $this->out('Usage: '); $this->out("\tcake testsuite category test_type file"); - $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_file - file name with folder prefix and without the (test|group).php suffix"); + $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_file - file name with folder prefix and without the (test|group).php suffix"); $this->out(''); $this->out('Examples: '); - $this->out("\t\t cake testsuite app all"); - $this->out("\t\t cake testsuite core all"); + $this->out("\t\tcake testsuite app all"); + $this->out("\t\tcake testsuite core all"); $this->out(''); - $this->out("\t\t cake testsuite app case behaviors/debuggable"); - $this->out("\t\t cake testsuite app case models/my_model"); - $this->out("\t\t cake testsuite app case controllers/my_controller"); + $this->out("\t\tcake testsuite app case behaviors/debuggable"); + $this->out("\t\tcake testsuite app case models/my_model"); + $this->out("\t\tcake testsuite app case controllers/my_controller"); $this->out(''); - $this->out("\t\t cake testsuite core case file"); - $this->out("\t\t cake testsuite core case router"); - $this->out("\t\t cake testsuite core case set"); + $this->out("\t\tcake testsuite core case file"); + $this->out("\t\tcake testsuite core case router"); + $this->out("\t\tcake testsuite core case set"); $this->out(''); - $this->out("\t\t cake testsuite app group mygroup"); - $this->out("\t\t cake testsuite core group acl"); - $this->out("\t\t cake testsuite core group socket"); + $this->out("\t\tcake testsuite app group mygroup"); + $this->out("\t\tcake testsuite core group acl"); + $this->out("\t\tcake testsuite core group socket"); $this->out(''); - $this->out("\t\t cake testsuite bugs case models/bug // for the plugin 'bugs' and its test case 'bug'"); - $this->out("\t\t cake testsuite bugs group bug // for the plugin bugs and its test group '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\t cake testsuite bugs_me group bug // for the plugin bugs_me and its test group 'bug'"); + $this->out("\t\tcake testsuite bugs case models/bug"); + $this->out("\t\t // for the plugin 'bugs' and its test case 'models/bug'"); + $this->out("\t\tcake testsuite bugs group bug"); + $this->out("\t\t // for the plugin bugs and its test group 'bug'"); $this->out(''); $this->out('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)) { - $folder = $paths[$category]; + $folder = $paths[$category] . 'tests'; } 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 From 38b7a34a8e74aeb7324febde4d10a9b87854bb83 Mon Sep 17 00:00:00 2001 From: gwoo Date: Fri, 1 May 2009 08:24:24 -0700 Subject: [PATCH 19/19] adding gitignore with "vendors" --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..1562dcf95 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +vendors \ No newline at end of file