composer-update-patch

This commit is contained in:
Manish Verma
2016-11-03 05:44:29 +05:30
parent 2dca47f5a4
commit 5d49d384a0
5118 changed files with 51603 additions and 122575 deletions

View File

@@ -1,118 +0,0 @@
<?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;
/**
* @package Fetch
* @author Robert Hafner <tedivm@tedivm.com>
*/
class AttachmentTest extends \PHPUnit_Framework_TestCase
{
public static function getAttachments($MessageId)
{
$server = ServerTest::getServer();
$message = new \Fetch\Message($MessageId, $server);
$attachments = $message->getAttachments();
$returnAttachments = array();
foreach($attachments as $attachment)
$returnAttachments[$attachment->getFileName()] = $attachment;
return $returnAttachments;
}
public function testGetData()
{
$attachments = static::getAttachments('6');
$attachment_RCA = $attachments['RCA_Indian_Head_test_pattern.JPG.zip'];
$md5_RCA = '3e9b6f02551590a7bcfff5d50b5b7b20';
$this->assertEquals($md5_RCA, md5($attachment_RCA->getData()));
$attachment_TestCard = $attachments['Test_card.png.zip'];
$md5_TestCard = '94c40bd83fbfa03b29bf1811f9aaccea';
$this->assertEquals($md5_TestCard, md5($attachment_TestCard->getData()));
}
public function testGetMimeType()
{
$attachments = static::getAttachments('6');
$attachment_RCA = $attachments['RCA_Indian_Head_test_pattern.JPG.zip'];
$mimetype_RCA = 'application/zip';
$this->assertEquals($mimetype_RCA, $attachment_RCA->getMimeType());
$attachment_TestCard = $attachments['Test_card.png.zip'];
$mimetype_TestCard = 'application/zip';
$this->assertEquals($mimetype_TestCard, $attachment_TestCard->getMimeType());
}
public function testGetSize()
{
$attachments = static::getAttachments('6');
$attachment_RCA = $attachments['RCA_Indian_Head_test_pattern.JPG.zip'];
$size_RCA = 378338;
$this->assertEquals($size_RCA, $attachment_RCA->getSize());
$attachment_TestCard = $attachments['Test_card.png.zip'];
$size_TestCard = 32510;
$this->assertEquals($size_TestCard, $attachment_TestCard->getSize());
}
public function testGetStructure()
{
$attachments = static::getAttachments('6');
$attachment_RCA = $attachments['RCA_Indian_Head_test_pattern.JPG.zip'];
$structure_RCA = $attachment_RCA->getStructure();
$this->assertObjectHasAttribute('type', $structure_RCA);
$this->assertEquals(3, $structure_RCA->type);
$this->assertObjectHasAttribute('subtype', $structure_RCA);
$this->assertEquals('ZIP', $structure_RCA->subtype);
$this->assertObjectHasAttribute('bytes', $structure_RCA);
$this->assertEquals(378338, $structure_RCA->bytes);
}
public function testSaveToDirectory()
{
$attachments = static::getAttachments('6');
$attachment_RCA = $attachments['RCA_Indian_Head_test_pattern.JPG.zip'];
$tmpdir = rtrim(sys_get_temp_dir(), '/') . '/';
$filepath = $tmpdir . 'RCA_Indian_Head_test_pattern.JPG.zip';
$this->assertTrue($attachment_RCA->saveToDirectory($tmpdir));
$this->assertFileExists($filepath);
$this->assertEquals(md5(file_get_contents($filepath)), md5($attachment_RCA->getData()));
$attachments = static::getAttachments('6');
$attachment_RCA = $attachments['RCA_Indian_Head_test_pattern.JPG.zip'];
$this->assertFalse($attachment_RCA->saveToDirectory('/'), 'Returns false when attempting to save without filesystem permission.');
$attachments = static::getAttachments('6');
$attachment_RCA = $attachments['RCA_Indian_Head_test_pattern.JPG.zip'];
$this->assertFalse($attachment_RCA->saveToDirectory($filepath), 'Returns false when attempting to save over a file.');
}
public static function tearDownAfterClass()
{
$tmpdir = rtrim(sys_get_temp_dir(), '/') . '/';
$filepath = $tmpdir . 'RCA_Indian_Head_test_pattern.JPG.zip';
unlink($filepath);
}
}

View File

@@ -1,252 +0,0 @@
<?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\Message;
/**
* @package Fetch
* @author Robert Hafner <tedivm@tedivm.com>
*/
class MessageTest extends \PHPUnit_Framework_TestCase
{
public static function getMessage($id)
{
$server = ServerTest::getServer();
return new \Fetch\Message($id, $server);
}
public function testConstructMessage()
{
$message = static::getMessage(3);
$this->assertInstanceOf('\Fetch\Message', $message);
}
public function testGetOverview()
{
$message = static::getMessage(3);
$overview = $message->getOverview();
$this->assertEquals('Welcome', $overview->subject, 'Subject available from overview');
$this->assertEquals('tedivm@tedivm.com', $overview->from, 'From available from overview');
$this->assertEquals('testuser@tedivm.com', $overview->to, 'To available from overview');
$this->assertEquals(1465, $overview->size, 'Size available from overview');
$this->assertEquals(0, $overview->flagged, 'Flagged available from overview');
$this->assertEquals(1, $overview->seen, 'Seen available from overview');
}
public function testGetHeaders()
{
$message = static::getMessage(3);
$headers = $message->getHeaders();
$this->assertEquals('Sun, 1 Dec 2013 21:14:03 -0800 (PST)', $headers->date, 'Headers contain the right date.');
$this->assertEquals('testuser@tedivm.com', $headers->toaddress, 'Headers contain toaddress.');
$this->assertEquals('tedivm@tedivm.com', $headers->fromaddress, 'Headers contain fromaddress');
}
public function testGetStructure()
{
}
public function testGetMessageBody()
{
// easiest way to deal with php encoding issues is simply not to.
$plaintextTest = 'f9377a89c9c935463a2b35c92dd61042';
$convertedHtmlTest = '11498bcf191900d634ff8772a64ca523';
$pureHtmlTest = '6a366ddecf080199284146d991d52169';
$message = static::getMessage(3);
$messageNonHTML = $message->getMessageBody();
$this->assertEquals($plaintextTest, md5($messageNonHTML), 'Message returns as plaintext.');
$messageHTML = $message->getMessageBody(true);
$this->assertEquals($convertedHtmlTest, md5($messageHTML), 'Message converts from plaintext to HTML when requested.');
$message = static::getMessage(4);
$messageHTML = $message->getMessageBody(true);
$this->assertEquals($pureHtmlTest, md5($messageHTML), 'Message returns as HTML.');
}
public function testGetAddresses()
{
$message = static::getMessage(3);
$addresses = $message->getAddresses('to');
$this->assertEquals('testuser@tedivm.com', $addresses[0]['address'], 'Retrieving to user from address array.');
$addressString = $message->getAddresses('to', true);
$this->assertEquals('testuser@tedivm.com', $addressString, 'Returning To address as string.');
$addresses = $message->getAddresses('from');
$this->assertEquals('tedivm@tedivm.com', $addresses['address'], 'Returning From address as an address array.');
$addressString = $message->getAddresses('from', true);
$this->assertEquals('tedivm@tedivm.com', $addressString, 'Returning From address as string.');
}
public function testGetDate()
{
$message = static::getMessage(3);
$this->assertEquals(1385961243, $message->getDate(), 'Returns date as timestamp.');
}
public function testGetSubject()
{
$message = static::getMessage(3);
$this->assertEquals('Welcome', $message->getSubject(), 'Returns Subject.');
}
public function testDelete()
{
}
public function testGetImapBox()
{
$server = ServerTest::getServer();
$message = new \Fetch\Message('3', $server);
$this->assertEquals($server, $message->getImapBox(), 'getImapBox returns Server used to create Message.');
}
public function testGetUid()
{
$message = static::getMessage('3');
$this->assertEquals(3, $message->getUid(), 'Message returns UID');
}
public function testGetAttachments()
{
$messageWithoutAttachments = static::getMessage('3');
$this->assertFalse($messageWithoutAttachments->getAttachments(), 'getAttachments returns false when no attachments present.');
$messageWithAttachments = static::getMessage('6');
$attachments = $messageWithAttachments->getAttachments();
$this->assertCount(2, $attachments);
foreach($attachments as $attachment)
$this->assertInstanceOf('\Fetch\Attachment', $attachment, 'getAttachments returns Fetch\Attachment objects.');
$attachment = $messageWithAttachments->getAttachments('Test_card.png.zip');
$this->assertInstanceOf('\Fetch\Attachment', $attachment, 'getAttachment returns specified Fetch\Attachment object.');
}
public function testCheckFlag()
{
$message = static::getMessage('3');
$this->assertFalse($message->checkFlag('flagged'));
$this->assertTrue($message->checkFlag('seen'));
}
public function testSetFlag()
{
$message = static::getMessage('3');
$this->assertFalse($message->checkFlag('answered'), 'Message is not answered.');
$this->assertTrue($message->setFlag('answered'), 'setFlag returned true.');
$this->assertTrue($message->checkFlag('answered'), 'Message was successfully answered.');
$this->assertTrue($message->setFlag('answered', false), 'setFlag returned true.');
$this->assertFalse($message->checkFlag('answered'), 'Message was successfully unanswered.');
$message = static::getMessage('2');
$this->assertFalse($message->checkFlag('flagged'), 'Message is not flagged.');
$this->assertTrue($message->setFlag('flagged'), 'setFlag returned true.');
$this->assertTrue($message->checkFlag('flagged'), 'Message was successfully flagged.');
$message = static::getMessage('2');
$this->assertTrue($message->setFlag('flagged', false), 'setFlag returned true.');
$this->assertFalse($message->checkFlag('flagged'), 'Message was successfully unflagged.');
}
public function testMoveToMailbox()
{
$server = ServerTest::getServer();
// Testing by moving message from "Test Folder" to "Sent"
// Count Test Folder
$server->setMailBox('Test Folder');
$testFolderNumStart = $server->numMessages();
// Get message from Test Folder
$message = $server->getMessageByUid(1);
$this->assertInstanceOf('\Fetch\Message', $message, 'Server returned Message.');
// Switch to Sent folder, count messages
$server->setMailBox('Sent');
$sentFolderNumStart = $server->numMessages();
// Switch to "Flagged" folder in order to test that function properly returns to it
$this->assertTrue($server->setMailBox('Flagged Email'));
// Move the message!
$this->assertTrue($message->moveToMailBox('Sent'));
// Make sure we're still in the same folder
$this->assertEquals('Flagged Email', $server->getMailBox(), 'Returned Server back to right mailbox.');
$this->assertAttributeEquals('Sent', 'mailbox', $message, 'Message mailbox changed to new location.');
// Make sure Test Folder lost a message
$this->assertTrue($server->setMailBox('Test Folder'));
$this->assertEquals($testFolderNumStart - 1, $server->numMessages(), 'Message moved out of Test Folder.');
// Make sure Sent folder gains one
$this->assertTrue($server->setMailBox('Sent'));
$this->assertEquals($sentFolderNumStart + 1, $server->numMessages(), 'Message moved into Sent Folder.');
}
public function testDecode()
{
$quotedPrintableDecoded = "Now's the time for all folk to come to the aid of their country.";
$quotedPrintable = <<<'ENCODE'
Now's the time =
for all folk to come=
to the aid of their country.
ENCODE;
$this->assertEquals($quotedPrintableDecoded, Message::decode($quotedPrintable, 'quoted-printable'), 'Decodes quoted printable');
$this->assertEquals($quotedPrintableDecoded, Message::decode($quotedPrintable, 4), 'Decodes quoted printable');
$testString = 'This is a test string';
$base64 = base64_encode($testString);
$this->assertEquals($testString, Message::decode($base64, 'base64'), 'Decodes quoted base64');
$this->assertEquals($testString, Message::decode($base64, 3), 'Decodes quoted base64');
$notEncoded = '> w - www.somesite.com.au<http://example.com/track/click.php?u=30204369&id=af4110cab28e464cb0702723bc84b3f3>';
$this->assertEquals($notEncoded, Message::decode($notEncoded, 0), 'Nothing to decode');
}
public function testTypeIdToString()
{
$types = array();
$types[0] = 'text';
$types[1] = 'multipart';
$types[2] = 'message';
$types[3] = 'application';
$types[4] = 'audio';
$types[5] = 'image';
$types[6] = 'video';
$types[7] = 'other';
$types[8] = 'other';
$types[32] = 'other';
foreach($types as $id => $type)
$this->assertEquals($type, Message::typeIdToString($id));
}
public function testGetParametersFromStructure()
{
}
}

View File

@@ -1,225 +0,0 @@
<?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
{
public static $num_messages_inbox = 12;
/**
* @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 testFlagOverwrite()
{
$server = static::getServer();
$server->setFlag('TestFlag', 'true');
$this->assertAttributeContains('TestFlag=true', 'flags', $server);
$server->setFlag('TestFlag', 'false');
$this->assertAttributeContains('TestFlag=false', 'flags', $server);
}
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 = static::getServer();
$numMessages = $server->numMessages();
$this->assertEquals(self::$num_messages_inbox, $numMessages);
}
public function testGetMessages()
{
$server = static::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 testGetMessagesOrderedByDateAsc()
{
$server = static::getServer();
$messages = $server->getOrderedMessages(SORTDATE, false, 2);
$this->assertCount(2, $messages, 'Two messages returned');
$this->assertGreaterThan($messages[0]->getDate(), $messages[1]->getDate(), 'Messages in ascending order');
}
public function testGetMessagesOrderedByDateDesc()
{
$server = static::getServer();
$messages = $server->getOrderedMessages(SORTDATE, true, 2);
$this->assertCount(2, $messages, 'Two messages returned');
$this->assertLessThan($messages[0]->getDate(), $messages[1]->getDate(), 'Messages in descending order');
}
public function testGetMailBox()
{
$server = static::getServer();
$this->assertEquals('', $server->getMailBox());
$this->assertTrue($server->setMailBox('Sent'));
$this->assertEquals('Sent', $server->getMailBox());
}
public function testSetMailBox()
{
$server = static::getServer();
$this->assertTrue($server->setMailBox('Sent'));
$this->assertEquals('Sent', $server->getMailBox());
$this->assertTrue($server->setMailBox('Flagged Email'));
$this->assertEquals('Flagged Email', $server->getMailBox());
$this->assertFalse($server->setMailBox('Cheese'));
$this->assertTrue($server->setMailBox(''));
$this->assertEquals('', $server->getMailBox());
}
public function testHasMailBox()
{
$server = static::getServer();
$this->assertTrue($server->hasMailBox('Sent'), 'Has mailbox "Sent"');
$this->assertTrue($server->hasMailBox('Flagged Email'), 'Has mailbox "Flagged Email"');
$this->assertFalse($server->hasMailBox('Cheese'), 'Does not have mailbox "Cheese"');
}
public function testListMailBoxes()
{
$server = static::getServer();
$spec = sprintf('{%s:143/novalidate-cert}', TESTING_SERVER_HOST);
$list = $server->listMailboxes('*');
$this->assertContains($spec.'Sent', $list, 'Has mailbox "Sent"');
$this->assertNotContains($spec.'Cheese', $list, 'Does not have mailbox "Cheese"');
}
public function testCreateMailbox()
{
$server = static::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');
}
/**
* @expectedException \RuntimeException
*/
public function testSetOptionsException()
{
$server = static::getServer();
$server->setOptions('purple');
}
public function testSetOptions()
{
$server = static::getServer();
$server->setOptions(5);
$this->assertAttributeEquals(5, 'options', $server);
}
public function testExpunge()
{
$server = static::getServer();
$message = $server->getMessageByUid(12);
$this->assertInstanceOf('\Fetch\Message', $message, 'Message exists');
$message->delete();
$this->assertInstanceOf('\Fetch\Message', $server->getMessageByUid(12), 'Message still present after being deleted but before being expunged.');
$server->expunge();
$this->assertFalse($server->getMessageByUid(12), 'Message successfully expunged');
}
public static function getServer()
{
$server = new Server(TESTING_SERVER_HOST, 143);
$server->setAuthentication(TEST_USER, TEST_PASSWORD);
return $server;
}
}