Skip to content

Commit

Permalink
Fix failing tests in Network package.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Jun 11, 2013
1 parent 77a8e47 commit d78e213
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 21 deletions.
3 changes: 2 additions & 1 deletion lib/Cake/Network/Email/Email.php
Expand Up @@ -20,6 +20,7 @@
use Cake\Error;
use Cake\Log\Log;
use Cake\Network\Http\FormData\Part;
use Cake\Utility\File;
use Cake\Utility\Hash;
use Cake\Utility\String;
use Cake\Utility\Validation;
Expand Down Expand Up @@ -1251,7 +1252,7 @@ protected function _wrap($message, $wrapLength = Email::LINE_LENGTH_MUST) {
$message = str_replace(array("\r\n", "\r"), "\n", $message);
$lines = explode("\n", $message);
$formatted = array();
$cut = ($wrapLength == CakeEmail::LINE_LENGTH_MUST) ? true : false;
$cut = ($wrapLength == Email::LINE_LENGTH_MUST) ? true : false;

foreach ($lines as $line) {
if (empty($line)) {
Expand Down
15 changes: 15 additions & 0 deletions lib/Cake/Test/TestApp/View/Emails/html/html.ctp
@@ -0,0 +1,15 @@
<?php
use Cake\Network\Email\Email;
?>
<h1>HTML Ipsum Presents</h1><p><strong>Pellentesque habitant morbi tristique</strong> senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. <em>Aenean ultricies mi vitae est.</em> Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, <code>commodo vitae</code>, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. <a href="#">Donec non enim</a> in turpis pulvinar facilisis. Ut felis.</p><h2>Header Level 2</h2><ol><li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li><li>Aliquam tincidunt mauris eu risus.</li></ol><blockquote><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus turpis elit sit amet quam. Vivamus pretium ornare est.</p></blockquote><h3>Header Level 3</h3><ul><li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li><li>Aliquam tincidunt mauris eu risus.</li></ul>
<pre><code>
#header h1 a {
display: block;
width: 300px;
height: 80px;
}</code></pre>
<table>
<th align="right" valign="top"
style="font-weight: bold">The tag is across multiple lines - <?php echo str_repeat('x', Email::LINE_LENGTH_MUST); ?></th>
</table>
<p>Some more <?php echo str_repeat('x', Email::LINE_LENGTH_MUST); ?> <b>Bold</b> test.</p>
32 changes: 15 additions & 17 deletions lib/Cake/Test/TestCase/Network/Email/EmailTest.php
Expand Up @@ -42,7 +42,7 @@ public function formatAddress($address) {
* Wrap to protected method
*
*/
public function wrap($text, $length = CakeEmail::LINE_LENGTH_MUST) {
public function wrap($text, $length = Email::LINE_LENGTH_MUST) {
return parent::_wrap($text, $length);
}

Expand Down Expand Up @@ -1037,27 +1037,25 @@ public function testSendWithLog() {
* @return void
*/
public function testSendWithLogAndScope() {
CakeLog::config('email', array(
Configure::write('Log.email', array(
'engine' => 'FileLog',
'path' => TMP,
'types' => array('cake_test_emails'),
'file' => 'cake_test_emails',
'scopes' => array('email')
));
CakeLog::drop('default');
Log::reset();
$this->CakeEmail->transport('Debug');
$this->CakeEmail->to('me@cakephp.org');
$this->CakeEmail->from('cake@cakephp.org');
$this->CakeEmail->subject('My title');
$this->CakeEmail->config(array('log' => array('level' => 'cake_test_emails', 'scope' => 'email')));
$this->CakeEmail->config(array('log' => array('scope' => 'email')));
$result = $this->CakeEmail->send("Logging This");

App::uses('File', 'Utility');
$File = new File(TMP . 'cake_test_emails.log');
$log = $File->read();
$this->assertTrue(strpos($log, $result['headers']) !== false);
$this->assertTrue(strpos($log, $result['message']) !== false);
$File->delete();
CakeLog::drop('email');
}

/**
Expand Down Expand Up @@ -1920,7 +1918,7 @@ protected function _getEmailByNewStyleCharset($charset, $headerCharset) {
}

public function testWrapLongLine() {
$message = '<a href="http://cakephp.org">' . str_repeat('x', CakeEmail::LINE_LENGTH_MUST) . "</a>";
$message = '<a href="http://cakephp.org">' . str_repeat('x', Email::LINE_LENGTH_MUST) . "</a>";

$this->CakeEmail->reset();
$this->CakeEmail->transport('Debug');
Expand All @@ -1929,32 +1927,32 @@ public function testWrapLongLine() {
$this->CakeEmail->subject('Wordwrap Test');
$this->CakeEmail->config(array('empty'));
$result = $this->CakeEmail->send($message);
$expected = "<a\r\n" . 'href="http://cakephp.org">' . str_repeat('x', CakeEmail::LINE_LENGTH_MUST - 26) . "\r\n" .
$expected = "<a\r\n" . 'href="http://cakephp.org">' . str_repeat('x', Email::LINE_LENGTH_MUST - 26) . "\r\n" .
str_repeat('x', 26) . "\r\n</a>\r\n\r\n";
$this->assertEquals($expected, $result['message']);
$this->assertLineLengths($result['message']);

$str1 = "a ";
$str2 = " b";
$length = strlen($str1) + strlen($str2);
$message = $str1 . str_repeat('x', CakeEmail::LINE_LENGTH_MUST - $length - 1) . $str2;
$message = $str1 . str_repeat('x', Email::LINE_LENGTH_MUST - $length - 1) . $str2;

$result = $this->CakeEmail->send($message);
$expected = "{$message}\r\n\r\n";
$this->assertEquals($expected, $result['message']);
$this->assertLineLengths($result['message']);

$message = $str1 . str_repeat('x', CakeEmail::LINE_LENGTH_MUST - $length) . $str2;
$message = $str1 . str_repeat('x', Email::LINE_LENGTH_MUST - $length) . $str2;

$result = $this->CakeEmail->send($message);
$expected = "{$message}\r\n\r\n";
$this->assertEquals($expected, $result['message']);
$this->assertLineLengths($result['message']);

$message = $str1 . str_repeat('x', CakeEmail::LINE_LENGTH_MUST - $length + 1) . $str2;
$message = $str1 . str_repeat('x', Email::LINE_LENGTH_MUST - $length + 1) . $str2;

$result = $this->CakeEmail->send($message);
$expected = $str1 . str_repeat('x', CakeEmail::LINE_LENGTH_MUST - $length + 1) . sprintf("\r\n%s\r\n\r\n", trim($str2));
$expected = $str1 . str_repeat('x', Email::LINE_LENGTH_MUST - $length + 1) . sprintf("\r\n%s\r\n\r\n", trim($str2));
$this->assertEquals($expected, $result['message']);
$this->assertLineLengths($result['message']);
}
Expand All @@ -1967,7 +1965,7 @@ public function testWrapWithTagsAcrossLines() {
</table>
HTML;
$length = strlen($str);
$message = $str . str_repeat('x', CakeEmail::LINE_LENGTH_MUST + 1);
$message = $str . str_repeat('x', Email::LINE_LENGTH_MUST + 1);

$this->CakeEmail->reset();
$this->CakeEmail->transport('Debug');
Expand All @@ -1986,7 +1984,7 @@ public function testWrapWithTagsAcrossLines() {
public function testWrapIncludeLessThanSign() {
$str = 'foo<bar';
$length = strlen($str);
$message = $str . str_repeat('x', CakeEmail::LINE_LENGTH_MUST - $length + 1);
$message = $str . str_repeat('x', Email::LINE_LENGTH_MUST - $length + 1);

$this->CakeEmail->reset();
$this->CakeEmail->transport('Debug');
Expand Down Expand Up @@ -2028,8 +2026,8 @@ public function testWrapForJapaneseEncoding() {
public function assertLineLengths($message) {
$lines = explode("\r\n", $message);
foreach ($lines as $line) {
$this->assertTrue(strlen($line) <= CakeEmail::LINE_LENGTH_MUST,
'Line length exceeds the max. limit of CakeEmail::LINE_LENGTH_MUST');
$this->assertTrue(strlen($line) <= Email::LINE_LENGTH_MUST,
'Line length exceeds the max. limit of Email::LINE_LENGTH_MUST');
}
}

Expand Down
6 changes: 3 additions & 3 deletions lib/Cake/Test/TestCase/Network/SocketTest.php
Expand Up @@ -136,7 +136,7 @@ public function testInvalidConnection($data) {
*/
public function testSocketHost() {
try {
$this->Socket = new CakeSocket();
$this->Socket = new Socket();
$this->Socket->connect();
$this->assertEquals('127.0.0.1', $this->Socket->address());
$this->assertEquals(gethostbyaddr('127.0.0.1'), $this->Socket->host());
Expand Down Expand Up @@ -180,7 +180,7 @@ public function testSocketReading() {
$this->assertEquals(null, $this->Socket->read(26));

$config = array('host' => 'google.com', 'port' => 80, 'timeout' => 1);
$this->Socket = new CakeSocket($config);
$this->Socket = new Socket($config);
$this->assertTrue($this->Socket->connect());
$this->assertEquals(null, $this->Socket->read(26));
$this->assertEquals('2: ' . __d('cake_dev', 'Connection timed out'), $this->Socket->lastError());
Expand All @@ -201,7 +201,7 @@ public function testTimeOutConnection() {
$this->assertTrue($this->Socket->connect());

$config = array('host' => '127.0.0.1', 'timeout' => 0.00001);
$this->Socket = new CakeSocket($config);
$this->Socket = new Socket($config);
$this->assertFalse($this->Socket->read(1024 * 1024));
$this->assertEquals('2: ' . __d('cake_dev', 'Connection timed out'), $this->Socket->lastError());
} catch (Error\SocketException $e) {
Expand Down

0 comments on commit d78e213

Please sign in to comment.