Fetch/tests/Fetch/Test/ServerTest.php

128 lines
4.4 KiB
PHP
Raw Normal View History

<?php
/*
* This file is part of the Fetch library.
*
* (c) Robert Hafner <tedivm@tedivm.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Fetch\Test;
use Fetch\Server;
/**
* @package Fetch
* @author Robert Hafner <tedivm@tedivm.com>
*/
class ServerTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider flagsDataProvider
* @param string $expected server string with %host% placeholder
* @param integer $port to use (needed to test behavior on port 143 and 993 from constructor)
* @param array $flags to set/unset ($flag => $value)
*/
public function testFlags($expected, $port, $flags)
{
$server = new Server(TESTING_SERVER_HOST, $port);
foreach ($flags as $flag => $value) {
$server->setFlag($flag, $value);
}
$this->assertEquals(str_replace('%host%', TESTING_SERVER_HOST, $expected), $server->getServerString());
}
public function flagsDataProvider() {
return array(
array('{%host%:143/novalidate-cert}', 143, array()),
array('{%host%:143/validate-cert}', 143, array('validate-cert' => true)),
array('{%host%:143}', 143, array('novalidate-cert' => false)),
array('{%host%:993/ssl}', 993, array()),
array('{%host%:993}', 993, array('ssl' => false)),
array('{%host%:100/tls}', 100, array('tls' => true)),
array('{%host%:100/tls}', 100, array('tls' => true, 'tls' => true)),
array('{%host%:100/notls}', 100, array('tls' => true, 'notls' => true)),
array('{%host%:100}', 100, array('ssl' => true, 'ssl' => false)),
array('{%host%:100/user=foo}', 100, array('user' => 'foo')),
array('{%host%:100/user=foo}', 100, array('user' => 'foo', 'user' => 'foo')),
array('{%host%:100/user=bar}', 100, array('user' => 'foo', 'user' => 'bar')),
array('{%host%:100}', 100, array('user' => 'foo', 'user' => false)),
);
}
/**
* @dataProvider connectionDataProvider
* @param integer $port to use (needed to test behavior on port 143 and 993 from constructor)
* @param array $flags to set/unset ($flag => $value)
* @param string $message Assertion message
*/
public function testConnection($port, $flags, $message)
{
$server = new Server(TESTING_SERVER_HOST, $port);
$server->setAuthentication(TEST_USER, TEST_PASSWORD);
foreach ($flags as $flag => $value) {
$server->setFlag($flag, $value);
}
$imapSteam = $server->getImapStream();
$this->assertInternalType('resource', $imapSteam, $message);
}
public function connectionDataProvider() {
return array(
array(143, array(), 'Connects with default settings.'),
array(993, array('novalidate-cert' => true), 'Connects over SSL (self signed).'),
);
}
public function testNumMessages()
{
$server = $this->getServer();
$numMessages = $server->numMessages();
$this->assertEquals(21, $numMessages);
}
public function testGetMessages()
{
$server = $this->getServer();
$messages = $server->getMessages(5);
$this->assertCount(5, $messages, 'Five messages returned');
foreach($messages as $message) {
$this->assertInstanceOf('\Fetch\Message', $message, 'Returned values are Messages');
}
}
public function testHasMailBox()
{
$server = $this->getServer();
$this->assertTrue($server->hasMailBox('Sent'), 'Has mailbox "Sent"');
$this->assertTrue($server->hasMailBox('Flagged Emails'), 'Has mailbox "Flagged Email"');
$this->assertFalse($server->hasMailBox('Cheese'), 'Does not have mailbox "Cheese"');
}
public function testCreateMailbox()
{
$server = $this->getServer();
$this->assertFalse($server->hasMailBox('Cheese'), 'Does not have mailbox "Cheese"');
$this->assertTrue($server->createMailBox('Cheese'), 'createMailbox returns true.');
$this->assertTrue($server->hasMailBox('Cheese'), 'Mailbox "Cheese" was created');
}
2013-12-05 23:04:25 -08:00
public function getServer()
{
$server = new Server(TESTING_SERVER_HOST, 143);
$server->setAuthentication(TEST_USER, TEST_PASSWORD);
return $server;
}
}