/** * @covers Email::send */ public function test_send_returns_true_when_we_pass_valid_parameters() { $to = get_option('admin_email'); $res = Email::to($to)->subject('My Subject')->text('My Message')->HTML('<p>Some HTML</p>')->send(); $this->assertTrue($res); $res = Email::to($to)->subject('My Subject')->text('My Message')->HTML(null)->send(); $this->assertTrue($res); // invalid email $res = Email::to('example.com')->subject('My Subject')->text('My Message')->HTML('<p>Some HTML</p>')->send(); $this->assertFalse($res); // no subject $res = Email::to($to)->subject(null)->text('My Message')->HTML('<p>Some HTML</p>')->send(); $this->assertFalse($res); // no message text $res = Email::to($to)->subject('My Subject')->text(null)->HTML('<p>Some HTML</p>')->send(); $this->assertFalse($res); // no message text or HTML $res = Email::to($to)->subject('My Subject')->text(null)->HTML(null)->send(); $this->assertFalse($res); }
/** * Method called by wp_con event * * Here we build up the email contents and pass it to our Email class. * @todo: return a call to an event rather than boolean * * @param bool $test Weather we are testing the callback or not * @return bool|void If no draft posts are found returns false */ public function cron_callback($test = false) { try { $posts = $this->get_posts(); } catch (\Exception $e) { // we have no posts if (false === $test) { return false; } $posts = null; } if ($test || $posts) { $to = self::$options['email_address']; $subject = __('You have drafts waiting to be published', 'drafty-in-here'); $text = $this->build_message($posts, $test); $html = '<html><body>' . nl2br($text) . '</body></html>'; Email::to($to)->subject($subject)->text($text)->HTML($html)->send(); return true; } return false; }