From 01f6744e350549fad83f061b8ee4d9164811b44e Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Fri, 27 May 2011 01:30:42 -0430 Subject: [PATCH 1/9] Removing unneeded line in ConnectionManager --- lib/Cake/Model/ConnectionManager.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/Cake/Model/ConnectionManager.php b/lib/Cake/Model/ConnectionManager.php index 1fbc25751..12f3b97ab 100644 --- a/lib/Cake/Model/ConnectionManager.php +++ b/lib/Cake/Model/ConnectionManager.php @@ -20,7 +20,6 @@ */ App::uses('DataSource', 'Model/Datasource'); -config('database'); /** * Manages loaded instances of DataSource objects @@ -54,7 +53,7 @@ class ConnectionManager { protected static $_connectionsEnum = array(); /** - * Indicates if the init code for this class has alredy been executed + * Indicates if the init code for this class has already been executed * * @var boolean */ From faa8b3d324edf6c2b1f20bed4778b8aa0f627b08 Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Fri, 27 May 2011 01:40:25 -0430 Subject: [PATCH 2/9] Avoiding the load of default connection in Sanitize test --- lib/Cake/Test/Case/Utility/SanitizeTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Test/Case/Utility/SanitizeTest.php b/lib/Cake/Test/Case/Utility/SanitizeTest.php index a27e7d472..3f8428d6a 100644 --- a/lib/Cake/Test/Case/Utility/SanitizeTest.php +++ b/lib/Cake/Test/Case/Utility/SanitizeTest.php @@ -170,12 +170,12 @@ class SanitizeTest extends CakeTestCase { $array = array(array('\\$', array('key' => 'test & "quote" \'other\' ;.$ \\$ symbol.' . "\r" . 'another line'))); $expected = array(array('$', array('key' => 'test & "quote" \'other\' ;.$ $ symbol.another line'))); - $result = Sanitize::clean($array, array('encode' => false, 'escape' => false)); + $result = Sanitize::clean($array, array('encode' => false, 'escape' => false, 'connection' => 'test')); $this->assertEqual($expected, $result); $string = ''; $expected = ''; - $result = Sanitize::clean($string); + $result = Sanitize::clean($string, array('connection' => 'test')); $this->assertEqual($string, $expected); $data = array( @@ -198,7 +198,7 @@ class SanitizeTest extends CakeTestCase { ) ) ); - $result = Sanitize::clean($data); + $result = Sanitize::clean($data, array('connection' => 'test')); $this->assertEqual($result, $data); } From ad456bd479891df5e7d685d28b7676f63484cb49 Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Fri, 27 May 2011 01:41:13 -0430 Subject: [PATCH 3/9] Removing code that should not have existed in the first place --- lib/Cake/Test/Case/Utility/SanitizeTest.php | 51 --------------- lib/Cake/Utility/Sanitize.php | 69 --------------------- 2 files changed, 120 deletions(-) diff --git a/lib/Cake/Test/Case/Utility/SanitizeTest.php b/lib/Cake/Test/Case/Utility/SanitizeTest.php index 3f8428d6a..a702d9655 100644 --- a/lib/Cake/Test/Case/Utility/SanitizeTest.php +++ b/lib/Cake/Test/Case/Utility/SanitizeTest.php @@ -465,55 +465,4 @@ HTML; $result = Sanitize::stripTags($string, 'h2', 'a', 'img'); $this->assertEqual($expected, $result); } - -/** - * testFormatColumns method - * - * @access public - * @return void - */ - function testFormatColumns() { - $this->autoFixtures = true; - $this->fixtureManager->load($this); - $this->loadFixtures('DataTest', 'Article'); - - $this->DataTest = new SanitizeDataTest(array('alias' => 'DataTest')); - $data = array('DataTest' => array( - 'id' => 'z', - 'count' => '12a', - 'float' => '2.31456', - 'updated' => '2008-01-01' - ) - ); - $this->DataTest->set($data); - $expected = array('DataTest' => array( - 'id' => '0', - 'count' => '12', - 'float' => 2.31456, - 'updated' => '2008-01-01 00:00:00', - )); - Sanitize::formatColumns($this->DataTest); - $result = $this->DataTest->data; - $this->assertEqual($expected, $result); - - $this->Article = new SanitizeArticle(array('alias' => 'Article')); - $data = array('Article' => array( - 'id' => 'ZB', - 'user_id' => '12', - 'title' => 'title of article', - 'body' => 'body text', - 'published' => 'QQQQQQQ', - )); - $this->Article->set($data); - $expected = array('Article' => array( - 'id' => '0', - 'user_id' => '12', - 'title' => 'title of article', - 'body' => 'body text', - 'published' => 'QQQQQQQ', - )); - Sanitize::formatColumns($this->Article); - $result = $this->Article->data; - $this->assertEqual($expected, $result); - } } diff --git a/lib/Cake/Utility/Sanitize.php b/lib/Cake/Utility/Sanitize.php index f521654f3..11ebec756 100644 --- a/lib/Cake/Utility/Sanitize.php +++ b/lib/Cake/Utility/Sanitize.php @@ -257,73 +257,4 @@ class Sanitize { return $data; } } - -/** - * Formats column data from definition in DBO's $columns array - * - * @param Model $model The model containing the data to be formatted - */ - public static function formatColumns($model) { - foreach ($model->data as $name => $values) { - if ($name == $model->alias) { - $curModel = $model; - } elseif (isset($model->{$name}) && is_object($model->{$name}) && is_subclass_of($model->{$name}, 'Model')) { - $curModel = $model->{$name}; - } else { - $curModel = null; - } - - if ($curModel != null) { - foreach ($values as $column => $data) { - $colType = $curModel->getColumnType($column); - - if ($colType != null) { - $db = ConnectionManager::getDataSource($curModel->useDbConfig); - $colData = $db->columns[$colType]; - - if (isset($colData['limit']) && strlen(strval($data)) > $colData['limit']) { - $data = substr(strval($data), 0, $colData['limit']); - } - - if (isset($colData['formatter']) || isset($colData['format'])) { - - switch (strtolower($colData['formatter'])) { - case 'date': - $data = date($colData['format'], strtotime($data)); - break; - case 'sprintf': - $data = sprintf($colData['format'], $data); - break; - case 'intval': - $data = intval($data); - break; - case 'floatval': - $data = floatval($data); - break; - } - } - $model->data[$name][$column]=$data; - /* - switch ($colType) { - case 'integer': - case 'int': - return $data; - break; - case 'string': - case 'text': - case 'binary': - case 'date': - case 'time': - case 'datetime': - case 'timestamp': - case 'date': - return "'" . $data . "'"; - break; - } - */ - } - } - } - } - } } From 1f6c5fbc87d12f9353bdbcf4022d158a7a8f49af Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Fri, 27 May 2011 01:47:22 -0430 Subject: [PATCH 4/9] Removing dead code --- lib/Cake/Test/Case/TestSuite/CakeTestFixtureTest.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib/Cake/Test/Case/TestSuite/CakeTestFixtureTest.php b/lib/Cake/Test/Case/TestSuite/CakeTestFixtureTest.php index 551e7452a..428244892 100644 --- a/lib/Cake/Test/Case/TestSuite/CakeTestFixtureTest.php +++ b/lib/Cake/Test/Case/TestSuite/CakeTestFixtureTest.php @@ -356,10 +356,7 @@ class CakeTestFixtureTest extends CakeTestCase { * @return void */ function testImportWithRecords() { - - $defaultDb = ConnectionManager::getDataSource('default'); $testSuiteDb = ConnectionManager::getDataSource('test'); - $defaultConfig = $defaultDb->config; $testSuiteConfig = $testSuiteDb->config; ConnectionManager::create('new_test_suite', array_merge($testSuiteConfig, array('prefix' => 'new_' . $testSuiteConfig['prefix']))); $newTestSuiteDb = ConnectionManager::getDataSource('new_test_suite'); @@ -368,7 +365,6 @@ class CakeTestFixtureTest extends CakeTestCase { $Source->create($newTestSuiteDb); $Source->insert($newTestSuiteDb); - $defaultDb->config = $newTestSuiteDb->config; $Fixture = new CakeTestFixtureDefaultImportFixture(); $Fixture->fields = $Fixture->records = null; @@ -380,8 +376,6 @@ class CakeTestFixtureTest extends CakeTestCase { $this->assertFalse(empty($Fixture->records[0]), 'No records loaded on importing fixture.'); $this->assertTrue(isset($Fixture->records[0]['name']), 'No name loaded for first record'); - $defaultDb->config = $defaultConfig; - $Source->drop($newTestSuiteDb); } From 2c32d34fafab86caafaa7eb8e62207ea7bc8da12 Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Fri, 27 May 2011 01:48:28 -0430 Subject: [PATCH 5/9] Removing more dead code --- lib/Cake/Test/Case/TestSuite/CakeTestFixtureTest.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib/Cake/Test/Case/TestSuite/CakeTestFixtureTest.php b/lib/Cake/Test/Case/TestSuite/CakeTestFixtureTest.php index 428244892..4c15f181b 100644 --- a/lib/Cake/Test/Case/TestSuite/CakeTestFixtureTest.php +++ b/lib/Cake/Test/Case/TestSuite/CakeTestFixtureTest.php @@ -322,9 +322,7 @@ class CakeTestFixtureTest extends CakeTestCase { * @return void */ function testImport() { - $defaultDb = ConnectionManager::getDataSource('default'); $testSuiteDb = ConnectionManager::getDataSource('test'); - $defaultConfig = $defaultDb->config; $testSuiteConfig = $testSuiteDb->config; ConnectionManager::create('new_test_suite', array_merge($testSuiteConfig, array('prefix' => 'new_' . $testSuiteConfig['prefix']))); $newTestSuiteDb = ConnectionManager::getDataSource('new_test_suite'); @@ -333,16 +331,12 @@ class CakeTestFixtureTest extends CakeTestCase { $Source->create($newTestSuiteDb); $Source->insert($newTestSuiteDb); - $defaultDb->config = $newTestSuiteDb->config; - $Fixture = new CakeTestFixtureDefaultImportFixture(); $Fixture->fields = $Fixture->records = null; $Fixture->import = array('model' => 'FixtureImportTestModel', 'connection' => 'new_test_suite'); $Fixture->init(); $this->assertEqual(array_keys($Fixture->fields), array('id', 'name', 'created')); - $defaultDb->config = $defaultConfig; - $keys = array_flip(ClassRegistry::keys()); $this->assertFalse(array_key_exists('fixtureimporttestmodel', $keys)); From b320e4323f0a69a504a4284b529c4660fd0dbe3d Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Fri, 27 May 2011 02:13:35 -0430 Subject: [PATCH 6/9] Improving ConnectionManager tests --- lib/Cake/Model/ConnectionManager.php | 4 +- .../Test/Case/Model/ConnectionManagerTest.php | 44 ++++++++++++------- .../Model/Datasource/Database/DboDummy.php | 2 +- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/lib/Cake/Model/ConnectionManager.php b/lib/Cake/Model/ConnectionManager.php index 12f3b97ab..c5e7f89c2 100644 --- a/lib/Cake/Model/ConnectionManager.php +++ b/lib/Cake/Model/ConnectionManager.php @@ -113,7 +113,7 @@ class ConnectionManager { if (empty(self::$_init)) { self::init(); } - return array_keys(self::$_dataSources); + return array_keys((array)self::$config); } /** @@ -132,7 +132,7 @@ class ConnectionManager { return $name; } } - return ''; + return null; } /** diff --git a/lib/Cake/Test/Case/Model/ConnectionManagerTest.php b/lib/Cake/Test/Case/Model/ConnectionManagerTest.php index 6c56e6a8e..65c7fbf57 100644 --- a/lib/Cake/Test/Case/Model/ConnectionManagerTest.php +++ b/lib/Cake/Test/Case/Model/ConnectionManagerTest.php @@ -55,11 +55,22 @@ class ConnectionManagerTest extends CakeTestCase { * @return void */ function testGetDataSource() { + App::build(array( + 'Model/Datasource' => array( + CAKE . 'Test' . DS . 'test_app' . DS . 'Model' . DS . 'Datasource' . DS + ) + )); + + $name = 'test_get_datasource'; + $config = array('datasource' => 'Test2Source'); + + $connection = ConnectionManager::create($name, $config); $connections = ConnectionManager::enumConnectionObjects(); $this->assertTrue((bool)(count(array_keys($connections) >= 1))); - $source = ConnectionManager::getDataSource(key($connections)); + $source = ConnectionManager::getDataSource('test_get_datasource'); $this->assertTrue(is_object($source)); + ConnectionManager::drop('test_get_datasource'); } /** @@ -91,7 +102,7 @@ class ConnectionManagerTest extends CakeTestCase { $this->assertEqual($connection->configKeyName, $name); $this->assertEqual($connection->config, $config); - App::build(); + ConnectionManager::drop($name); } /** @@ -115,7 +126,7 @@ class ConnectionManagerTest extends CakeTestCase { $this->assertEqual($connection->configKeyName, $name); $this->assertEqual($connection->config, $config); - App::build(); + ConnectionManager::drop($name); } /** @@ -138,7 +149,7 @@ class ConnectionManagerTest extends CakeTestCase { $this->assertTrue(class_exists('DboDummy')); $this->assertEqual($connection->configKeyName, $name); - App::build(); + ConnectionManager::drop($name); } /** @@ -164,7 +175,7 @@ class ConnectionManagerTest extends CakeTestCase { $this->assertTrue(class_exists('TestLocalDriver')); $this->assertEqual($connection->configKeyName, $name); $this->assertEqual($connection->config, $config); - App::build(); + ConnectionManager::drop($name); } /** @@ -176,9 +187,7 @@ class ConnectionManagerTest extends CakeTestCase { function testSourceList() { $sources = ConnectionManager::sourceList(); $this->assertTrue(count($sources) >= 1); - - $connections = array('default', 'test', 'test'); - $this->assertTrue(count(array_intersect($sources, $connections)) >= 1); + $this->assertTrue(in_array('test', array_keys($sources))); } /** @@ -189,15 +198,14 @@ class ConnectionManagerTest extends CakeTestCase { */ function testGetSourceName() { $connections = ConnectionManager::enumConnectionObjects(); - $name = key($connections); - $source = ConnectionManager::getDataSource($name); + $source = ConnectionManager::getDataSource('test'); $result = ConnectionManager::getSourceName($source); - $this->assertEqual($result, $name); + $this->assertEqual('test', $result); $source = new StdClass(); $result = ConnectionManager::getSourceName($source); - $this->assertEqual($result, null); + $this->assertNull($result); } /** @@ -243,7 +251,7 @@ class ConnectionManagerTest extends CakeTestCase { $connections = ConnectionManager::enumConnectionObjects(); $this->assertTrue((bool)(count(array_keys($connections) >= 1))); - $source = ConnectionManager::getDataSource(key($connections)); + $source = ConnectionManager::getDataSource('test'); $this->assertTrue(is_object($source)); $config = $source->config; @@ -285,39 +293,45 @@ class ConnectionManagerTest extends CakeTestCase { ConnectionManager::create('connection1', array('datasource' => 'Test2Source')); $connections = ConnectionManager::enumConnectionObjects(); $this->assertEqual($expected, $connections['connection1']); + ConnectionManager::drop('connection1'); ConnectionManager::create('connection2', array('datasource' => 'Test2Source')); $connections = ConnectionManager::enumConnectionObjects(); $this->assertEqual($expected, $connections['connection2']); + ConnectionManager::drop('connection2'); ConnectionManager::create('connection3', array('datasource' => 'TestPlugin.TestSource')); $connections = ConnectionManager::enumConnectionObjects(); $expected['datasource'] = 'TestPlugin.TestSource'; $this->assertEqual($expected, $connections['connection3']); + ConnectionManager::drop('connection3'); ConnectionManager::create('connection4', array('datasource' => 'TestPlugin.TestSource')); $connections = ConnectionManager::enumConnectionObjects(); $this->assertEqual($expected, $connections['connection4']); + ConnectionManager::drop('connection4'); ConnectionManager::create('connection5', array('datasource' => 'Test2OtherSource')); $connections = ConnectionManager::enumConnectionObjects(); $expected['datasource'] = 'Test2OtherSource'; - $this->assertEqual($expected, $connections['connection5']); + ConnectionManager::drop('connection5'); ConnectionManager::create('connection6', array('datasource' => 'Test2OtherSource')); $connections = ConnectionManager::enumConnectionObjects(); $this->assertEqual($expected, $connections['connection6']); + ConnectionManager::drop('connection6'); ConnectionManager::create('connection7', array('datasource' => 'TestPlugin.TestOtherSource')); $connections = ConnectionManager::enumConnectionObjects(); $expected['datasource'] = 'TestPlugin.TestOtherSource'; - $this->assertEqual($expected, $connections['connection7']); + ConnectionManager::drop('connection7'); ConnectionManager::create('connection8', array('datasource' => 'TestPlugin.TestOtherSource')); $connections = ConnectionManager::enumConnectionObjects(); $this->assertEqual($expected, $connections['connection8']); + ConnectionManager::drop('connection8'); } /** diff --git a/lib/Cake/Test/test_app/Plugin/TestPlugin/Model/Datasource/Database/DboDummy.php b/lib/Cake/Test/test_app/Plugin/TestPlugin/Model/Datasource/Database/DboDummy.php index 779eeb709..550d2e8ae 100644 --- a/lib/Cake/Test/test_app/Plugin/TestPlugin/Model/Datasource/Database/DboDummy.php +++ b/lib/Cake/Test/test_app/Plugin/TestPlugin/Model/Datasource/Database/DboDummy.php @@ -1,5 +1,5 @@ Date: Fri, 27 May 2011 02:18:36 -0430 Subject: [PATCH 7/9] Avoiding the use of default connection in schema shell tests --- lib/Cake/Test/Case/Console/Command/SchemaShellTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Cake/Test/Case/Console/Command/SchemaShellTest.php b/lib/Cake/Test/Case/Console/Command/SchemaShellTest.php index b42987188..d11a613e7 100644 --- a/lib/Cake/Test/Case/Console/Command/SchemaShellTest.php +++ b/lib/Cake/Test/Case/Console/Command/SchemaShellTest.php @@ -213,6 +213,7 @@ class SchemaShellTest extends CakeTestCase { public function testDumpWithFileWriting() { $this->Shell->params = array( 'name' => 'i18n', + 'connection' => 'test', 'write' => TMP . 'tests' . DS . 'i18n.sql' ); $this->Shell->expects($this->once())->method('_stop'); From e669a81e0a7b5ca423db292dc32bb4042e978d2c Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Fri, 27 May 2011 02:28:38 -0430 Subject: [PATCH 8/9] Reverting change in ConnectionManager, sourceList() will only return the instantiated datasources Fixing remaining tests failing due to contamination of loaded plugin is app --- lib/Cake/Model/ConnectionManager.php | 4 +++- lib/Cake/Test/Case/Controller/ScaffoldTest.php | 3 ++- lib/Cake/Test/Case/Model/ConnectionManagerTest.php | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Model/ConnectionManager.php b/lib/Cake/Model/ConnectionManager.php index c5e7f89c2..148df62e8 100644 --- a/lib/Cake/Model/ConnectionManager.php +++ b/lib/Cake/Model/ConnectionManager.php @@ -106,6 +106,8 @@ class ConnectionManager { /** * Gets the list of available DataSource connections + * This will only return the datasources instantiated by this manager + * It differs from enumConnectionObjects, since the latter will return all configured connections * * @return array List of available connections */ @@ -113,7 +115,7 @@ class ConnectionManager { if (empty(self::$_init)) { self::init(); } - return array_keys((array)self::$config); + return array_keys(self::$_dataSources); } /** diff --git a/lib/Cake/Test/Case/Controller/ScaffoldTest.php b/lib/Cake/Test/Case/Controller/ScaffoldTest.php index 5ba9d2e93..223bcd571 100644 --- a/lib/Cake/Test/Case/Controller/ScaffoldTest.php +++ b/lib/Cake/Test/Case/Controller/ScaffoldTest.php @@ -366,7 +366,7 @@ class ScaffoldViewTest extends CakeTestCase { 'action' => 'admin_add', 'admin' => true )); - $Controller->plugin = 'test_plugin'; + $Controller->plugin = 'TestPlugin'; $ScaffoldView = new TestScaffoldView($Controller); $result = $ScaffoldView->testGetFilename('admin_add'); @@ -826,6 +826,7 @@ class ScaffoldTest extends CakeTestCase { * @return void */ function testHabtmFieldAdditionWithScaffoldForm() { + CakePlugin::unload(); $params = array( 'plugin' => null, 'pass' => array(1), diff --git a/lib/Cake/Test/Case/Model/ConnectionManagerTest.php b/lib/Cake/Test/Case/Model/ConnectionManagerTest.php index 65c7fbf57..3f0658c44 100644 --- a/lib/Cake/Test/Case/Model/ConnectionManagerTest.php +++ b/lib/Cake/Test/Case/Model/ConnectionManagerTest.php @@ -185,6 +185,7 @@ class ConnectionManagerTest extends CakeTestCase { * @return void */ function testSourceList() { + ConnectionManager::getDataSource('test'); $sources = ConnectionManager::sourceList(); $this->assertTrue(count($sources) >= 1); $this->assertTrue(in_array('test', array_keys($sources))); From 8a98ee24860bd0a358eb04565ccc3c87ccda5b2b Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Fri, 17 Jun 2011 17:51:31 -0430 Subject: [PATCH 9/9] Adding a Debug transport class to help users test their apps when sending emails --- lib/Cake/Network/Email/CakeEmail.php | 2 +- lib/Cake/Network/Email/DebugTransport.php | 50 +++++++++++++ .../Case/Network/Email/DebugTransportTest.php | 74 +++++++++++++++++++ 3 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 lib/Cake/Network/Email/DebugTransport.php create mode 100644 lib/Cake/Test/Case/Network/Email/DebugTransportTest.php diff --git a/lib/Cake/Network/Email/CakeEmail.php b/lib/Cake/Network/Email/CakeEmail.php index 545581ba1..91dff9d3d 100644 --- a/lib/Cake/Network/Email/CakeEmail.php +++ b/lib/Cake/Network/Email/CakeEmail.php @@ -1061,7 +1061,7 @@ class CakeEmail { $this->_htmlMessage = ''; $this->_message = ''; $this->_emailFormat = 'text'; - $this->_transportName = 'mail'; + $this->_transportName = 'Mail'; $this->_transportClass = null; $this->_attachments = array(); $this->_config = 'default'; diff --git a/lib/Cake/Network/Email/DebugTransport.php b/lib/Cake/Network/Email/DebugTransport.php new file mode 100644 index 000000000..f359b8f98 --- /dev/null +++ b/lib/Cake/Network/Email/DebugTransport.php @@ -0,0 +1,50 @@ +getHeaders(array( + 'from' => true, + 'sender' => true, + 'replyTo' => true, + 'readReceipt' => true, + 'returnPath' => true, + 'to' => true, + 'cc' => true, + 'bcc' => true, + 'subject' => true + )); + $headers = $this->_headersToString($headers); + return $headers . "\n\n" . implode((array)$email->message(), "\n"); + } + +} diff --git a/lib/Cake/Test/Case/Network/Email/DebugTransportTest.php b/lib/Cake/Test/Case/Network/Email/DebugTransportTest.php new file mode 100644 index 000000000..a84a86233 --- /dev/null +++ b/lib/Cake/Test/Case/Network/Email/DebugTransportTest.php @@ -0,0 +1,74 @@ + + * Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org) + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice + * + * @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org) + * @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests + * @package cake.tests.cases.libs.email + * @since CakePHP(tm) v 2.0.0 + * @license MIT License (http://www.opensource.org/licenses/mit-license.php) + */ +App::uses('CakeEmail', 'Network/Email'); +App::uses('AbstractTransport', 'Network/Email'); +App::uses('DebugTransport', 'Network/Email'); + +/** + * Test case + * + */ +class DebugTransportTest extends CakeTestCase { + +/** + * Setup + * + * @return void + */ + public function setUp() { + $this->DebugTransport = new DebugTransport(); + $this->DebugTransport->config(); + } + +/** + * testSend method + * + * @return void + */ + public function testSend() { + $this->getMock('CakeEmail', array('message'), array(), 'DebugCakeEmail'); + $email = new DebugCakeEmail(); + $email->from('noreply@cakephp.org', 'CakePHP Test'); + $email->to('cake@cakephp.org', 'CakePHP'); + $email->cc(array('mark@cakephp.org' => 'Mark Story', 'juan@cakephp.org' => 'Juan Basso')); + $email->bcc('phpnut@cakephp.org'); + $email->messageID('<4d9946cf-0a44-4907-88fe-1d0ccbdd56cb@localhost>'); + $email->subject('Testing Message'); + $email->expects($this->any())->method('message')->will($this->returnValue(array('First Line', 'Second Line', ''))); + + $data = "From: CakePHP Test \r\n"; + $data .= "To: CakePHP \r\n"; + $data .= "Cc: Mark Story , Juan Basso \r\n"; + $data .= "Bcc: phpnut@cakephp.org\r\n"; + $data .= "X-Mailer: CakePHP Email\r\n"; + $data .= "Date: " . date(DATE_RFC2822) . "\r\n"; + $data .= "Message-ID: <4d9946cf-0a44-4907-88fe-1d0ccbdd56cb@localhost>\r\n"; + $data .= "Subject: Testing Message\r\n"; + $data .= "MIME-Version: 1.0\r\n"; + $data .= "Content-Type: text/plain; charset=UTF-8\r\n"; + $data .= "Content-Transfer-Encoding: 7bit"; + $data .= "\n\n"; + $data .= "First Line\n"; + $data .= "Second Line\n"; + + $result = $this->DebugTransport->send($email); + $this->assertEquals($data, $result); + } + +} \ No newline at end of file