diff --git a/tests/Client/ClientTest.php b/tests/Client/ClientTest.php index 3d08f6f..4f854c3 100644 --- a/tests/Client/ClientTest.php +++ b/tests/Client/ClientTest.php @@ -1,6 +1,6 @@ createClient(__DIR__ . '/../tmp/my-google-app.json', 'test@gmail.com'); + $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', 'test@gmail.com'); + $google->setToken('AUTH_TOKEN'); + $google->setTokenExpires(time() + 1000); + + $search = [ + 'subject%' => 'Test', + '%to' => '@outlook.com', + 'from' => 'me@outlook.com', + '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', 'test@gmail.com'); + $google->setToken('AUTH_TOKEN'); + $google->setTokenExpires(time() + 1000); + + $search = [ + 'subject' => 'Test', + 'to!=' => 'me@outlook.com', + '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', 'test@gmail.com'); + $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', 'test@gmail.com'); + $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', 'test@gmail.com'); + $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', 'test@gmail.com'); + $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', 'test@gmail.com'); + $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', 'test@gmail.com'); + $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'); + } + +} \ No newline at end of file diff --git a/tests/Client/Office365Test.php b/tests/Client/Office365Test.php new file mode 100644 index 0000000..a6cef6f --- /dev/null +++ b/tests/Client/Office365Test.php @@ -0,0 +1,192 @@ +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' => 'me@outlook.com', + '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!=' => 'me@outlook.com', + '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'); + } + +} \ No newline at end of file