コード例 #1
0
 /**
  * @test
  */
 public function it_creates_an_ImapMessageCollection_object()
 {
     $imap = m::mock('Humps\\MailManager\\Contracts\\Imap');
     $imap->shouldReceive('getMessageHeaders')->andReturn(ImapMailManagerTestHelper::getMessageHeaders());
     $imap->shouldReceive('fetchStructure')->andReturn(ImapMailManagerTestHelper::fetchStructure());
     $imap->shouldReceive('fetchBody')->andReturn(ImapMailManagerTestHelper::fetchBody());
     $messages = ImapMessageCollectionFactory::create([1, 2], $imap);
     $this->assertInstanceOf('Humps\\MailManager\\Collections\\ImapMessageCollection', $messages);
     $this->assertEquals(2, count($messages));
 }
コード例 #2
0
 /**
  * @test
  */
 public function it_downloads_the_embedded_images()
 {
     $connection = $this->getImapConnectionMock();
     /**
      * @var Imap $imap
      */
     $imap = m::mock('Humps\\MailManager\\Contracts\\Imap');
     $imap->shouldReceive('getMessageHeaders')->andReturn(ImapMailManagerTestHelper::getMessageHeaders());
     $imap->shouldReceive('fetchBody')->andReturn(ImapMailManagerEmbeddedImageHelper::fetchBody());
     $imap->shouldReceive('fetchStructure')->andReturn(ImapMailManagerEmbeddedImageHelper::fetchStructure());
     $imap->shouldReceive('getFolderName')->andReturn('INBOX');
     $imap->shouldReceive('getConnection')->andReturn($connection);
     /**
      * @var Message $message
      */
     $message = m::mock('Humps\\MailManager\\Components\\Contracts\\Message');
     $message->shouldReceive('getBodyParts')->andReturn(ImapMailManagerEmbeddedImageHelper::getBody());
     $message->shouldReceive('getHtmlBody')->andReturn(ImapMailManagerEmbeddedImageHelper::fetchBody());
     $message->shouldReceive('getMessageNum')->andReturn(2);
     $message->shouldReceive('setHtmlBody')->with(m::on(function ($result) {
         // It has replaced the img src with the saved image path.
         if (preg_match("/images\\/INBOX\\/2\\/wrench\\.png/", $result) && preg_match("/images\\/INBOX\\/2\\/google_logo\\.png/", $result) && !preg_match("/cid/", $result)) {
             return true;
         }
         return false;
     }));
     $messageService = new ImapMessageService($message, $imap);
     $messageService->downloadEmbeddedImages('images');
     // It's saved the images to the correct location
     $this->assertFileExists('images/INBOX/2/google_logo.png');
     $this->assertFileExists('images/INBOX/2/wrench.png');
     //Cleanup
     unlink('images/INBOX/2/wrench.png');
     unlink('images/INBOX/2/google_logo.png');
     rmdir('images/INBOX/2');
     rmdir('images/INBOX');
     rmdir('images');
 }
コード例 #3
0
 /**
  * @test
  */
 public function it_excludes_the_body_from_the_message()
 {
     /**
      * @var Imap $imap
      */
     $imap = m::mock('Humps\\MailManager\\Contracts\\Imap');
     $imap->shouldReceive('getMessageHeaders')->andReturn(ImapMailManagerTestHelper::getMessageHeaders());
     $imap->shouldReceive('fetchStructure')->andReturn(ImapMailManagerTestHelper::fetchStructure());
     $message = ImapMessageFactory::create(1, $imap, true);
     $imap->shouldNotHaveReceived('fetchBody');
     $this->assertNull($message->getTextBody());
     $this->assertNull($message->getHtmlBody());
 }