Skip to content

Commit

Permalink
Work on unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicksagona committed Oct 24, 2023
1 parent 1b56999 commit f33de87
Show file tree
Hide file tree
Showing 3 changed files with 355 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/Client/ClientTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Pop\Mail\Test\Transport;
namespace Pop\Mail\Test\Client;

use Pop\Http;
use Pop\Mail\Client;
Expand Down
162 changes: 162 additions & 0 deletions tests/Client/GoogleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
<?php

namespace Pop\Mail\Test\Client;

use Pop\Http;
use Pop\Mail\Client;
use PHPUnit\Framework\TestCase;

class GoogleTest extends TestCase
{

public function testGetMessages1()
{
$google = new Client\Google();
$google->createClient(__DIR__ . '/../tmp/my-google-app.json', '[email protected]');
$google->setToken('AUTH_TOKEN');
$google->setTokenExpires(time() + 1000);

$this->expectException('DomainException');
$messages = $google->getMessages();
}

public function testGetMessages2()
{
$google = new Client\Google();
$google->createClient(__DIR__ . '/../tmp/my-google-app.json', '[email protected]');
$google->setToken('AUTH_TOKEN');
$google->setTokenExpires(time() + 1000);

$search = [
'subject%' => 'Test',
'%to' => '@outlook.com',
'from' => '[email protected]',
'sent>=' => '2023-10-01'
];

$this->expectException('DomainException');
$messages = $google->getMessages('Inbox', $search, 25);
}

public function testGetMessages3()
{
$google = new Client\Google();
$google->createClient(__DIR__ . '/../tmp/my-google-app.json', '[email protected]');
$google->setToken('AUTH_TOKEN');
$google->setTokenExpires(time() + 1000);

$search = [
'subject' => 'Test',
'to!=' => '[email protected]',
'sent>' => '2023-10-01',
'received<' => '2023-10-01',
'date<=' => '2023-10-01',
'unread' => true
];

$this->expectException('DomainException');
$messages = $google->getMessages('Inbox', $search, 25);
}

public function testGetMessage()
{
$google = new Client\Google();
$google->createClient(__DIR__ . '/../tmp/my-google-app.json', '[email protected]');
$google->setToken('AUTH_TOKEN');
$google->setTokenExpires(time() + 1000);

$this->expectException('DomainException');
$message = $google->getMessage('123456789');
}

public function testGetMessageRaw()
{
$google = new Client\Google();
$google->createClient(__DIR__ . '/../tmp/my-google-app.json', '[email protected]');
$google->setToken('AUTH_TOKEN');
$google->setTokenExpires(time() + 1000);

$this->expectException('DomainException');
$message = $google->getMessage('123456789', true);
}

public function testGetAttachments()
{
$google = new Client\Google();
$google->createClient(__DIR__ . '/../tmp/my-google-app.json', '[email protected]');
$google->setToken('AUTH_TOKEN');
$google->setTokenExpires(time() + 1000);

$this->expectException('DomainException');
$attachments = $google->getAttachments('123456789');
}

public function testGetAttachment()
{
$google = new Client\Google();
$google->createClient(__DIR__ . '/../tmp/my-google-app.json', '[email protected]');
$google->setToken('AUTH_TOKEN');
$google->setTokenExpires(time() + 1000);

$this->expectException('DomainException');
$attachment = $google->getAttachment('123456789', '123456789');
}

public function testMarkAsRead()
{
$google = new Client\Google();
$google->createClient(__DIR__ . '/../tmp/my-google-app.json', '[email protected]');
$google->setToken('AUTH_TOKEN');
$google->setTokenExpires(time() + 1000);

$this->expectException('DomainException');
$google->markAsRead('123456789');
}

public function testMarkAsUnread()
{
$google = new Client\Google();
$google->createClient(__DIR__ . '/../tmp/my-google-app.json', '[email protected]');
$google->setToken('AUTH_TOKEN');
$google->setTokenExpires(time() + 1000);

$this->expectException('DomainException');
$google->markAsUnread('123456789');
}

public function testGetMessagesException()
{
$this->expectException('Pop\Mail\Client\Exception');
$google = new Client\Google();
$messages = $google->getMessages();
}

public function testGetMessageException()
{
$this->expectException('Pop\Mail\Client\Exception');
$google = new Client\Google();
$message = $google->getMessage('123456789');
}

public function testGetAttachmentsException()
{
$this->expectException('Pop\Mail\Client\Exception');
$google = new Client\Google();
$message = $google->getAttachments('123456789');
}

public function testGetAttachmentException()
{
$this->expectException('Pop\Mail\Client\Exception');
$google = new Client\Google();
$message = $google->getAttachment('123456789', '123456798');
}

public function testMarkAsReadException()
{
$this->expectException('Pop\Mail\Client\Exception');
$google = new Client\Google();
$google->markAsRead('123456789');
}

}
192 changes: 192 additions & 0 deletions tests/Client/Office365Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
<?php

namespace Pop\Mail\Test\Client;

use Pop\Http;
use Pop\Mail\Client;
use PHPUnit\Framework\TestCase;

class Office365Test extends TestCase
{

public function testGetMessages1()
{
$office365 = new Client\Office365();
$office365->createClient(json_encode([
'client_id' => 'CLIENT_ID',
'client_secret' => 'CLIENT_SECRET',
'scope' => 'https://graph.microsoft.com/.default',
'tenant_id' => 'TENANT_ID',
'account_id' => 'ACCOUNT_ID',
]));
$office365->setToken('AUTH_TOKEN');
$office365->setTokenExpires(time() + 1000);

$this->assertTrue(is_array($office365->getMessages()));
}

public function testGetMessages2()
{
$office365 = new Client\Office365();
$office365->createClient(json_encode([
'client_id' => 'CLIENT_ID',
'client_secret' => 'CLIENT_SECRET',
'scope' => 'https://graph.microsoft.com/.default',
'tenant_id' => 'TENANT_ID',
'account_id' => 'ACCOUNT_ID',
]));
$office365->setToken('AUTH_TOKEN');
$office365->setTokenExpires(time() + 1000);

$search = [
'subject%' => 'Test',
'%to' => '@outlook.com',
'from' => '[email protected]',
'sent>=' => '2023-10-01'
];

$this->assertTrue(is_array($office365->getMessages('Inbox', $search, 25)));
}

public function testGetMessages3()
{
$office365 = new Client\Office365();
$office365->createClient(json_encode([
'client_id' => 'CLIENT_ID',
'client_secret' => 'CLIENT_SECRET',
'scope' => 'https://graph.microsoft.com/.default',
'tenant_id' => 'TENANT_ID',
'account_id' => 'ACCOUNT_ID',
]));
$office365->setToken('AUTH_TOKEN');
$office365->setTokenExpires(time() + 1000);

$search = [
'subject' => 'Test',
'to!=' => '[email protected]',
'sent>' => '2023-10-01',
'received<' => '2023-10-01',
'date<=' => '2023-10-01',
'unread' => true
];

$this->assertTrue(is_array($office365->getMessages('Inbox', $search, 25)));
}

public function testGetMessage()
{
$office365 = new Client\Office365();
$office365->createClient(json_encode([
'client_id' => 'CLIENT_ID',
'client_secret' => 'CLIENT_SECRET',
'scope' => 'https://graph.microsoft.com/.default',
'tenant_id' => 'TENANT_ID',
'account_id' => 'ACCOUNT_ID',
]));
$office365->setToken('AUTH_TOKEN');
$office365->setTokenExpires(time() + 1000);

$this->assertTrue(is_array($office365->getMessage('123456789')));
}

public function testGetMessageRaw()
{
$office365 = new Client\Office365();
$office365->createClient(json_encode([
'client_id' => 'CLIENT_ID',
'client_secret' => 'CLIENT_SECRET',
'scope' => 'https://graph.microsoft.com/.default',
'tenant_id' => 'TENANT_ID',
'account_id' => 'ACCOUNT_ID',
]));
$office365->setToken('AUTH_TOKEN');
$office365->setTokenExpires(time() + 1000);

$this->assertTrue(is_array($office365->getMessage('123456789', true)));
}

public function testGetAttachments()
{
$office365 = new Client\Office365();
$office365->createClient(json_encode([
'client_id' => 'CLIENT_ID',
'client_secret' => 'CLIENT_SECRET',
'scope' => 'https://graph.microsoft.com/.default',
'tenant_id' => 'TENANT_ID',
'account_id' => 'ACCOUNT_ID',
]));
$office365->setToken('AUTH_TOKEN');
$office365->setTokenExpires(time() + 1000);

$this->assertTrue(is_array($office365->getAttachments('123456789')));
}

public function testGetAttachment()
{
$office365 = new Client\Office365();
$office365->createClient(json_encode([
'client_id' => 'CLIENT_ID',
'client_secret' => 'CLIENT_SECRET',
'scope' => 'https://graph.microsoft.com/.default',
'tenant_id' => 'TENANT_ID',
'account_id' => 'ACCOUNT_ID',
]));
$office365->setToken('AUTH_TOKEN');
$office365->setTokenExpires(time() + 1000);

$this->assertTrue(is_array($office365->getAttachment('123456789', '123456789')));
}

public function testMarkAsRead()
{
$office365 = new Client\Office365();
$office365->createClient(json_encode([
'client_id' => 'CLIENT_ID',
'client_secret' => 'CLIENT_SECRET',
'scope' => 'https://graph.microsoft.com/.default',
'tenant_id' => 'TENANT_ID',
'account_id' => 'ACCOUNT_ID',
]));
$office365->setToken('AUTH_TOKEN');
$office365->setTokenExpires(time() + 1000);

$this->assertInstanceOf('Pop\Mail\Client\Office365', $office365->markAsRead('123456789'));
$this->assertInstanceOf('Pop\Mail\Client\Office365', $office365->markAsUnread('123456789'));
}

public function testGetMessagesException()
{
$this->expectException('Pop\Mail\Client\Exception');
$office365 = new Client\Office365();
$messages = $office365->getMessages();
}

public function testGetMessageException()
{
$this->expectException('Pop\Mail\Client\Exception');
$office365 = new Client\Office365();
$message = $office365->getMessage('123456789');
}

public function testGetAttachmentsException()
{
$this->expectException('Pop\Mail\Client\Exception');
$office365 = new Client\Office365();
$message = $office365->getAttachments('123456789');
}

public function testGetAttachmentException()
{
$this->expectException('Pop\Mail\Client\Exception');
$office365 = new Client\Office365();
$message = $office365->getAttachment('123456789', '123456798');
}

public function testMarkAsReadException()
{
$this->expectException('Pop\Mail\Client\Exception');
$office365 = new Client\Office365();
$office365->markAsRead('123456789');
}

}

0 comments on commit f33de87

Please sign in to comment.