Email = new TestEmail(); Email::configTransport('debug', [ 'className' => 'Debug' ]); } /** * tearDown method * * @return void */ public function tearDown() { parent::tearDown(); Log::drop('email'); Email::drop('test'); Email::dropTransport('debug'); Email::dropTransport('test_smtp'); } /** * testFrom method * * @return void */ public function testFrom() { $this->assertSame(['test@example.com' => 'Mark'], $this->Email->from()); $this->Email->from('cake@cakephp.org'); $expected = ['cake@cakephp.org' => 'cake@cakephp.org']; $this->assertSame($expected, $this->Email->from()); $this->Email->from(['cake@cakephp.org']); $this->assertSame($expected, $this->Email->from()); $this->Email->from('cake@cakephp.org', 'CakePHP'); $expected = ['cake@cakephp.org' => 'CakePHP']; $this->assertSame($expected, $this->Email->from()); $result = $this->Email->from(['cake@cakephp.org' => 'CakePHP']); $this->assertSame($expected, $this->Email->from()); $this->assertSame($this->Email, $result); $this->setExpectedException('InvalidArgumentException'); $result = $this->Email->from(['cake@cakephp.org' => 'CakePHP', 'fail@cakephp.org' => 'From can only be one address']); } /** * EmailTest::testAddAttachment() * * @return void */ public function testAddAttachment() { $file = Plugin::path('Tools') . 'tests' . DS . 'test_files' . DS . 'img' . DS . 'hotel.png'; $this->assertTrue(file_exists($file)); $this->Email->addAttachment($file); $res = $this->Email->getProtected('attachments'); $expected = [ 'hotel.png' => [ 'file' => $file, 'mimetype' => 'image/png', ] ]; $this->assertEquals($expected, $res); $this->Email->addAttachment($file, 'my_image.jpg'); $res = $this->Email->getProtected('attachments'); $expected = [ 'file' => $file, 'mimetype' => 'image/jpeg', ]; $this->assertEquals($expected, $res['my_image.jpg']); } /** * EmailTest::testAddAttachment() * * @return void */ public function testAddAttachmentSend() { $file = Plugin::path('Tools') . 'tests' . DS . 'test_files' . DS . 'img' . DS . 'hotel.png'; $this->assertTrue(file_exists($file)); //Configure::write('debug', 0); $this->Email->to(Configure::read('Config.adminEmail')); $this->Email->addAttachment($file); $res = $this->Email->send('test_default', 'default'); $error = $this->Email->getError(); if ($error) { $this->out($error); } $this->assertEquals('', $this->Email->getError()); $this->assertTrue((bool)$res); $this->Email->reset(); $this->Email->to(Configure::read('Config.adminEmail')); $this->Email->addAttachment($file, 'x.jpg'); $res = $this->Email->send('test_custom_filename'); //Configure::write('debug', 2); //$this->assertEquals('', $this->Email->getError()); //$this->assertTrue($res); } /** * EmailTest::testAddBlobAttachment() * * @return void */ public function testAddBlobAttachment() { $file = Plugin::path('Tools') . 'tests' . DS . 'test_files' . DS . 'img' . DS . 'hotel.png'; $content = file_get_contents($file); $this->Email->addBlobAttachment($content, 'hotel.png'); $res = $this->Email->getProtected('attachments'); $this->assertTrue(!empty($res['hotel.png']['data'])); unset($res['hotel.png']['data']); $expected = [ 'hotel.png' => [ //'data' => $content, 'mimetype' => 'image/png', ] ]; $this->assertEquals($expected, $res); $this->Email->addBlobAttachment($content, 'hotel.gif', 'image/jpeg'); $res = $this->Email->getProtected('attachments'); $this->assertTrue(!empty($res['hotel.gif']['data'])); unset($res['hotel.gif']['data']); $expected = [ //'data' => $content, 'mimetype' => 'image/jpeg', ]; $this->assertEquals($expected, $res['hotel.gif']); $this->assertSame(2, count($res)); } /** * EmailTest::testAddEmbeddedAttachment() * * @return void */ public function testAddEmbeddedAttachment() { $file = Plugin::path('Tools') . 'tests' . DS . 'test_files' . DS . 'img' . DS . 'hotel.png'; $this->assertTrue(file_exists($file)); $this->Email = new TestEmail(); $this->Email->emailFormat('both'); $cid = $this->Email->addEmbeddedAttachment($file); $cid2 = $this->Email->addEmbeddedAttachment($file); $this->assertSame($cid, $cid2); $this->assertContains('@' . env('HTTP_HOST'), $cid); $res = $this->Email->getProtected('attachments'); $this->assertSame(1, count($res)); $image = array_shift($res); $expected = [ 'file' => $file, 'mimetype' => 'image/png', 'contentId' => $cid ]; $this->assertSame($expected, $image); } /** * Html email * * @return void */ public function testAddEmbeddedAttachmentSend() { $file = Plugin::path('Tools') . 'tests' . DS . 'test_files' . DS . 'img' . DS . 'hotel.png'; Configure::write('debug', 0); $this->Email = new TestEmail(); $this->Email->emailFormat('both'); $this->Email->to(Configure::read('Config.adminEmail')); $cid = $this->Email->addEmbeddedAttachment($file); $cid2 = $this->Email->addEmbeddedAttachment($file); $this->assertContains('@' . env('HTTP_HOST'), $cid); $html = '