Location: PHPKode > projects > UseBB > usebb-UseBB-f3b53f8/Utils/Mail/Tests/MailTest.php
<?php

namespace UseBB\Utils\Mail\Tests;

use UseBB\Utils\Mail\Sender;
use UseBB\System\ServiceRegistry;
use UseBB\Utils\SchemaManagement\SystemSchema;

class MailTest extends \PHPUnit_Framework_TestCase {
	private $services;
	private $sSchema;
	private $mail;
	
	protected function setUp() {
		$this->services = new ServiceRegistry($GLOBALS["dbConfig"]);
		$this->sSchema = new SystemSchema($this->services);
		$this->sSchema->install();
		$this->mail = $this->services->get("mail");
	}
	
	protected function tearDown() {
		$this->sSchema->uninstall();
	}
	
	public function testMail() {
		$params = $this->mail->send("ik", "hide@address.com", 
			array("hide@address.com" => "jij"), "test", "foobar", array(), 
			TRUE);
		
		$this->assertEquals("=?utf-8?B?amlq?= <hide@address.com>", $params[0]);
		$this->assertEquals("=?utf-8?B?dGVzdA==?=", $params[1]);
		$this->assertEquals("foobar", $params[2]);
		
		$headers = explode("\n", $params[3]);
		$this->assertContains("MIME-Version: 1.0", $headers);
		$this->assertContains("Content-Type: text/plain; charset=UTF-8", 
			$headers);
		$this->assertContains("Content-Transfer-Encoding: 8bit", $headers);
		$this->assertContains("From: =?utf-8?B?aWs=?= <hide@address.com>", $headers);
	}
	
	public function testEmptyFromName() {
		$params = $this->mail->send(NULL, "hide@address.com", 
			array("hide@address.com" => "jij"), "test", "foobar", array(), 
			TRUE);
		
		$this->assertEquals("=?utf-8?B?amlq?= <hide@address.com>", $params[0]);
		$this->assertEquals("=?utf-8?B?dGVzdA==?=", $params[1]);
		$this->assertEquals("foobar", $params[2]);
		
		$headers = explode("\n", $params[3]);
		$this->assertContains("From: hide@address.com", $headers);
	}
	
	public function testMultiTo() {
		$params = $this->mail->send("ik", "hide@address.com", array(
			"hide@address.com" => "jij",
			"hide@address.com" => "baz"
		), "test", "foobar", array(), TRUE);
		
		$this->assertEquals("=?utf-8?B?amlq?= <hide@address.com>, "
			. "=?utf-8?B?YmF6?= <hide@address.com>", $params[0]);
		$this->assertEquals("=?utf-8?B?dGVzdA==?=", $params[1]);
		$this->assertEquals("foobar", $params[2]);
		
		$headers = explode("\n", $params[3]);
		$this->assertContains("From: =?utf-8?B?aWs=?= <hide@address.com>", $headers);
	}
	
	public function testCC() {
		$params = $this->mail->send("ik", "hide@address.com", 
			array("hide@address.com" => "jij"), "test", "foobar", array(
				"cc" => array(
					"hide@address.com" => "baz",
					"hide@address.com" => "some thing"
				)
			), TRUE);
		
		$this->assertEquals("=?utf-8?B?amlq?= <hide@address.com>", $params[0]);
		$this->assertEquals("=?utf-8?B?dGVzdA==?=", $params[1]);
		$this->assertEquals("foobar", $params[2]);
		
		$headers = explode("\n", $params[3]);
		$this->assertContains("From: =?utf-8?B?aWs=?= <hide@address.com>", $headers);
		$this->assertContains("Cc: =?utf-8?B?YmF6?= <hide@address.com>, "
			."=?utf-8?B?c29tZSB0aGluZw==?= <hide@address.com>", $headers);
	}
	
	public function testBCC() {
		$params = $this->mail->send("ik", "hide@address.com", 
			array("hide@address.com" => "jij"), "test", "foobar", array(
				"bcc" => array(
					"hide@address.com" => "baz",
					"hide@address.com" => "some thing"
				)
			), TRUE);
		
		$this->assertEquals("=?utf-8?B?amlq?= <hide@address.com>", $params[0]);
		$this->assertEquals("=?utf-8?B?dGVzdA==?=", $params[1]);
		$this->assertEquals("foobar", $params[2]);
		
		$headers = explode("\n", $params[3]);
		$this->assertContains("From: =?utf-8?B?aWs=?= <hide@address.com>", $headers);
		$this->assertContains("Bcc: =?utf-8?B?YmF6?= <hide@address.com>, "
			."=?utf-8?B?c29tZSB0aGluZw==?= <hide@address.com>", $headers);
	}
	
	public function testSenderParameter() {
		$this->services->get("config")
			->set("system", "mailEnableSenderParameter", TRUE);
		
		$params = $this->mail->send("ik", "hide@address.com", 
			array("hide@address.com" => "jij"), "test", "foobar", array(), 
			TRUE);
		
		$this->assertEquals("=?utf-8?B?amlq?= <hide@address.com>", $params[0]);
		$this->assertEquals("=?utf-8?B?dGVzdA==?=", $params[1]);
		$this->assertEquals("foobar", $params[2]);
		
		$headers = explode("\n", $params[3]);
		$this->assertContains("From: =?utf-8?B?aWs=?= <hide@address.com>", $headers);
		
		$opts = explode(" ", $params[4]);
		$this->assertContains("-hide@address.com", $opts);
	}
}
Return current item: UseBB