EmailAssertTraitTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP(tm) Project
  12. * @since 3.3.3
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\TestSuite;
  16. use Cake\Mailer\Email;
  17. use Cake\Mailer\Transport\DebugTransport;
  18. use Cake\TestSuite\EmailAssertTrait;
  19. use Cake\TestSuite\TestCase;
  20. use TestApp\Mailer\TestUserMailer;
  21. class EmailAssertTraitTest extends TestCase
  22. {
  23. use EmailAssertTrait;
  24. public function setUp()
  25. {
  26. parent::setUp();
  27. Email::configTransport('debug', ['className' => DebugTransport::class]);
  28. }
  29. public function tearDown()
  30. {
  31. parent::tearDown();
  32. Email::dropTransport('debug');
  33. }
  34. public function testFunctional()
  35. {
  36. $mailer = $this->getMockForMailer(TestUserMailer::class);
  37. $email = $mailer->getEmailForAssertion();
  38. $this->assertSame($this->_email, $email);
  39. $mailer->invite('lorenzo@cakephp.org');
  40. $this->assertEmailSubject('CakePHP');
  41. $this->assertEmailFrom('jadb@cakephp.org');
  42. $this->assertEmailTo('lorenzo@cakephp.org');
  43. $this->assertEmailToContains('lorenzo@cakephp.org');
  44. $this->assertEmailToContains('lorenzo@cakephp.org', 'lorenzo@cakephp.org');
  45. $this->assertEmailCcContains('markstory@cakephp.org');
  46. $this->assertEmailCcContains('admad@cakephp.org', 'Adnan');
  47. $this->assertEmailBccContains('dereuromark@cakephp.org');
  48. $this->assertEmailBccContains('antograssiot@cakephp.org');
  49. $this->assertEmailTextMessageContains('Hello lorenzo@cakephp.org');
  50. $this->assertEmailAttachmentsContains('TestUserMailer.php');
  51. $this->assertEmailAttachmentsContains('TestMailer.php', [
  52. 'file' => dirname(dirname(__DIR__)) . DS . 'test_app' . DS . 'TestApp' . DS . 'Mailer' . DS . 'TestMailer.php',
  53. 'mimetype' => 'application/octet-stream',
  54. ]);
  55. }
  56. }