Skip to content

Commit

Permalink
Add functional tests for EmailAssertTrait
Browse files Browse the repository at this point in the history
  • Loading branch information
jadb committed Aug 26, 2016
1 parent 2373385 commit 96effcc
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
49 changes: 49 additions & 0 deletions tests/TestCase/TestSuite/EmailAssertTraitTest.php
@@ -0,0 +1,49 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since 3.3.1
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Test\TestCase\TestSuite;

use Cake\TestSuite\EmailAssertTrait;
use Cake\TestSuite\TestCase;
use TestApp\Mailer\TestUserMailer;

class EmailAssertTraitTest extends TestCase
{

use EmailAssertTrait;

public function testFunctional()
{
$mailer = $this->getMockForMailer(TestUserMailer::class);
$email = $mailer->getEmailForAssertion();
$this->assertSame($this->_email, $email);

$mailer->invite('lorenzo@cakephp.org');
$this->assertEmailSubject('CakePHP');
$this->assertEmailFrom('jadb@cakephp.org');
$this->assertEmailTo('lorenzo@cakephp.org');
$this->assertEmailToContains('lorenzo@cakephp.org');
$this->assertEmailToContains('lorenzo@cakephp.org', 'lorenzo@cakephp.org');
$this->assertEmailCcContains('markstory@cakephp.org');
$this->assertEmailCcContains('admad@cakephp.org', 'Adnan');
$this->assertEmailBccContains('dereuromark@cakephp.org');
$this->assertEmailBccContains('antograssiot@cakephp.org');
$this->assertEmailTextMessageContains('Hello lorenzo@cakephp.org');
$this->assertEmailAttachmentsContains('TestUserMailer.php');
$this->assertEmailAttachmentsContains('TestMailer.php', [
'file' => dirname(dirname(__DIR__)) . DS . 'test_app' . DS . 'TestApp' . DS . 'Mailer' . DS . 'TestMailer.php',
'mimetype' => 'application/octet-stream',
]);
}
}
4 changes: 4 additions & 0 deletions tests/bootstrap.php
Expand Up @@ -19,6 +19,8 @@
use Cake\Core\Configure;
use Cake\Datasource\ConnectionManager;
use Cake\Log\Log;
use Cake\Mailer\Email;
use Cake\Mailer\Transport\DebugTransport;

require_once 'vendor/autoload.php';

Expand Down Expand Up @@ -103,6 +105,8 @@
'defaults' => 'php'
]);

Email::configTransport('debug', ['className' => DebugTransport::class]);

Log::config([
// 'queries' => [
// 'className' => 'Console',
Expand Down
39 changes: 39 additions & 0 deletions tests/test_app/TestApp/Mailer/TestUserMailer.php
@@ -0,0 +1,39 @@
<?php
/**
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @since 3.4.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace TestApp\Mailer;

/**
* Test Suite Test App Mailer class.
*/
class TestUserMailer extends TestMailer
{

public function invite($email)
{
$this->_email
->subject('CakePHP')
->from('jadb@cakephp.org')
->to($email)
->cc('markstory@cakephp.org')
->addCc('admad@cakephp.org', 'Adnan')
->bcc('dereuromark@cakephp.org', 'Mark')
->addBcc('antograssiot@cakephp.org')
->attachments([
dirname(__FILE__) . DS . 'TestMailer.php',
dirname(__FILE__) . DS . 'TestUserMailer.php'
])
->send('Hello ' . $email);
}
}

0 comments on commit 96effcc

Please sign in to comment.