/** * Load the given view and data * * @param string $view View name. * @param string $data Data to be used to render the view. * @return Mailman Current object instance, allows for method chaining. */ public function make($view, $data = []) { $message = new Message(new Swift_Message(), $this->viewFactory, $this->filesystem, $this->translator); $message->setView($view); $message->with($data); $message->setCss($this->config->get('mailman.cssFile')); $fromAddress = $this->config->get('mail.from.address'); $fromName = $this->config->get('mail.from.name'); if ($fromAddress) { $message->from($fromAddress, $fromName); } $mailer = new Mailer($this->swiftMailer, $message); $mailer->setQueueManager($this->queueManager); return $mailer; }
/** * Queue a new e-mail message for sending after (n) seconds. * * @param int $delay * @param string $queue * @return void */ public function later($delay, $queue = null) { if ($this->queueManager) { $swiftMessage = $this->message->getSwiftMessage(); $this->queueManager->later($delay, new SendEmailJob($swiftMessage), $queue); } }
/** * @test */ public function it_sets_locale() { $viewFactory = Mockery::mock(ViewFactory::class); $filesystem = Mockery::mock(Filesystem::class); $translator = Mockery::mock(Translator::class); $message = new Message(new Swift_Message(), $viewFactory, $filesystem, $translator); $message->setView('view'); $message->setCss('cssPath'); $message->setLocale('es'); $translator->shouldReceive('getLocale')->andReturn('en'); $translator->shouldReceive('setLocale')->once()->with('es'); $translator->shouldReceive('setLocale')->once()->with('en'); $viewFactory->shouldReceive('make')->with('view', [])->andReturn($viewFactory); $viewFactory->shouldReceive('render')->andReturn('<h1>Hola</h1>'); $filesystem->shouldReceive('get')->with(base_path('cssPath'))->andReturn('h1 { color: blue; }'); $html = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html><body><h1 style="color: blue;">Hola</h1></body></html> '; $this->assertEquals($html, $message->getBody()); }