EmailAssertTraitTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (https://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. (https://cakefoundation.org)
  11. * @link https://cakephp.org CakePHP(tm) Project
  12. * @since 3.3.3
  13. * @license https://opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\TestSuite;
  16. use Cake\Mailer\Email;
  17. use Cake\Mailer\TransportFactory;
  18. use Cake\Mailer\Transport\DebugTransport;
  19. use Cake\TestSuite\EmailAssertTrait;
  20. use Cake\TestSuite\TestCase;
  21. use TestApp\Mailer\TestUserMailer;
  22. class EmailAssertTraitTest extends TestCase
  23. {
  24. use EmailAssertTrait;
  25. public function setUp()
  26. {
  27. parent::setUp();
  28. TransportFactory::setConfig('debug', ['className' => DebugTransport::class]);
  29. }
  30. public function tearDown()
  31. {
  32. parent::tearDown();
  33. TransportFactory::drop('debug');
  34. }
  35. public function testFunctional()
  36. {
  37. $mailer = $this->getMockForMailer(TestUserMailer::class);
  38. $email = $mailer->getEmailForAssertion();
  39. $this->assertSame($this->_email, $email);
  40. $mailer->invite('lorenzo@cakephp.org');
  41. $this->assertEmailSubject('CakePHP');
  42. $this->assertEmailFrom('jadb@cakephp.org');
  43. $this->assertEmailTo('lorenzo@cakephp.org');
  44. $this->assertEmailToContains('lorenzo@cakephp.org');
  45. $this->assertEmailToContains('lorenzo@cakephp.org', 'lorenzo@cakephp.org');
  46. $this->assertEmailCcContains('markstory@cakephp.org');
  47. $this->assertEmailCcContains('admad@cakephp.org', 'Adnan');
  48. $this->assertEmailBccContains('dereuromark@cakephp.org');
  49. $this->assertEmailBccContains('antograssiot@cakephp.org');
  50. $this->assertEmailTextMessageContains('Hello lorenzo@cakephp.org');
  51. $this->assertEmailAttachmentsContains('TestUserMailer.php');
  52. $this->assertEmailAttachmentsContains('TestMailer.php', [
  53. 'file' => dirname(dirname(__DIR__)) . DS . 'test_app' . DS . 'TestApp' . DS . 'Mailer' . DS . 'TestMailer.php',
  54. 'mimetype' => 'text/x-php',
  55. ]);
  56. }
  57. }