PMC-1346 Changes in the email server creation

This commit is contained in:
Roly Rudy Gutierrez Pinto
2019-11-21 15:07:44 -04:00
parent ab30241886
commit 70b71985a3
12 changed files with 1097 additions and 263 deletions

View File

@@ -0,0 +1,265 @@
<?php
namespace Tests\unit\workflow\engine\src\ProcessMaker\GmailOAuth;
use Exception;
use Faker\Factory;
use Google_Client;
use Google_Service_Gmail_Message;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use PHPMailerOAuth;
use ProcessMaker\GmailOAuth\GmailOAuth;
use RBAC;
use Tests\TestCase;
class GmailOAuthTest extends TestCase
{
use DatabaseTransactions;
private $faker;
/**
* Init properties
*/
public function setUp()
{
parent::setUp();
$this->faker = Factory::create();
global $RBAC;
$RBAC = RBAC::getSingleton();
$RBAC->initRBAC();
}
/**
* This ensures that the properties of the GmailOAuth object have consistency.
* @test
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::setEmailServerUid()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::setEmailEngine()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::setClientID()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::setClientSecret()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::setRedirectURI()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::setEmailEngine()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::setFromAccount()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::setSenderEmail()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::setSenderName()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::setSendTestMail()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::setMailTo()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::setSetDefaultConfiguration()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::setRefreshToken()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::getEmailServerUid()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::getClientID()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::getClientSecret()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::getRedirectURI()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::getEmailEngine()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::getFromAccount()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::getSenderEmail()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::getSenderName()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::getSendTestMail()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::getMailTo()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::getSetDefaultConfiguration()
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::getRefreshToken()
*/
public function it_should_set_and_get_properties()
{
$faker = $this->faker;
$expected = $faker->word;
$digit = $faker->randomDigitNotNull;
$gmailOAuth = new GmailOAuth();
$gmailOAuth->setEmailServerUid($expected);
$actual = $gmailOAuth->getEmailServerUid();
$this->assertEquals($expected, $actual);
$gmailOAuth->setClientID($expected);
$actual = $gmailOAuth->getClientID();
$this->assertEquals($expected, $actual);
$gmailOAuth->setClientSecret($expected);
$actual = $gmailOAuth->getClientSecret();
$this->assertEquals($expected, $actual);
$gmailOAuth->setRedirectURI($expected);
$actual = $gmailOAuth->getRedirectURI();
$this->assertEquals($expected, $actual);
$gmailOAuth->setEmailEngine($expected);
$actual = $gmailOAuth->getEmailEngine();
$this->assertEquals($expected, $actual);
$gmailOAuth->setFromAccount($expected);
$actual = $gmailOAuth->getFromAccount();
$this->assertEquals($expected, $actual);
$gmailOAuth->setSenderEmail($expected);
$actual = $gmailOAuth->getSenderEmail();
$this->assertEquals($expected, $actual);
$gmailOAuth->setSenderName($expected);
$actual = $gmailOAuth->getSenderName();
$this->assertEquals($expected, $actual);
$gmailOAuth->setSendTestMail($expected);
$actual = $gmailOAuth->getSendTestMail();
$this->assertEquals($expected, $actual);
$gmailOAuth->setMailTo($expected);
$actual = $gmailOAuth->getMailTo();
$this->assertEquals($expected, $actual);
$gmailOAuth->setSetDefaultConfiguration($expected);
$actual = $gmailOAuth->getSetDefaultConfiguration();
$this->assertEquals($expected, $actual);
$gmailOAuth->setRefreshToken($expected);
$actual = $gmailOAuth->getRefreshToken();
$this->assertEquals($expected, $actual);
}
/**
* Obtenga una instancia de Google_Client.
* @test
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::getGoogleClient()
*/
public function it_should_()
{
$gmailOAuth = new GmailOAuth();
$gmailOAuth->setClientID("");
$gmailOAuth->setClientSecret("");
$gmailOAuth->setRedirectURI("");
$googleClient = $gmailOAuth->getGoogleClient();
$this->assertTrue($googleClient instanceof Google_Client);
}
/**
* Create Email Server data.
* @test
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::saveEmailServer()
*/
public function it_should_create_email_server()
{
$this->markTestIncomplete("It required valid workspace");
$faker = $this->faker;
$gmailOAuth = new GmailOAuth();
$gmailOAuth->setEmailEngine("GMAILAPI");
$gmailOAuth->setClientID($faker->uuid);
$gmailOAuth->setClientSecret($faker->uuid);
$gmailOAuth->setRefreshToken($faker->uuid);
$gmailOAuth->setFromAccount($faker->email);
$gmailOAuth->setSenderEmail(1);
$gmailOAuth->setSenderName($faker->word);
$gmailOAuth->setSendTestMail(1);
$gmailOAuth->setMailTo($faker->email);
$gmailOAuth->setSetDefaultConfiguration(0);
$this->expectException(Exception::class);
$result = $gmailOAuth->saveEmailServer();
}
/**
* Update Email Server data.
* @test
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::saveEmailServer()
*/
public function it_should_udpate_email_server()
{
$this->markTestIncomplete("It required valid workspace");
$faker = $this->faker;
$gmailOAuth = new GmailOAuth();
$gmailOAuth->setEmailServerUid($faker->uuid);
$gmailOAuth->setEmailEngine("GMAILAPI");
$gmailOAuth->setClientID($faker->uuid);
$gmailOAuth->setClientSecret($faker->uuid);
$gmailOAuth->setRefreshToken($faker->uuid);
$gmailOAuth->setFromAccount($faker->email);
$gmailOAuth->setSenderEmail(1);
$gmailOAuth->setSenderName($faker->word);
$gmailOAuth->setSendTestMail(1);
$gmailOAuth->setMailTo($faker->email);
$gmailOAuth->setSetDefaultConfiguration(0);
$this->expectException(Exception::class);
$result = $gmailOAuth->saveEmailServer();
}
/**
* This ensures proof of email delivery with Google_Service_Gmail.
* @test
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::sendTestEmailWithGoogleServiceGmail()
*/
public function it_should_send_an_email_test_with_google_service_gmail()
{
$faker = $this->faker;
$gmailOauth = new GmailOAuth();
$result = $gmailOauth->sendTestEmailWithGoogleServiceGmail();
$this->assertTrue($result instanceof Google_Service_Gmail_Message);
$gmailOauth->setFromAccount($faker->email);
$result = $gmailOauth->sendTestEmailWithGoogleServiceGmail();
$this->assertTrue($result instanceof Google_Service_Gmail_Message);
$gmailOauth->setSenderEmail($faker->email);
$result = $gmailOauth->sendTestEmailWithGoogleServiceGmail();
$this->assertTrue($result instanceof Google_Service_Gmail_Message);
$gmailOauth->setMailTo($faker->email);
$gmailOauth->setSendTestMail(0);
$result = $gmailOauth->sendTestEmailWithGoogleServiceGmail();
$this->assertTrue($result instanceof Google_Service_Gmail_Message);
}
/**
* This test ensures that the message body for the email test.
* @test
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::getRawMessage()
*/
public function it_should_get_raw_message_for_test_email()
{
$gmailOAuth = new GmailOAuth();
$result = $gmailOAuth->getRawMessage();
$this->assertTrue(is_string($result));
}
/**
* This ensures proof of email delivery with PHPMailerOAuth.
* @test
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::sendTestMailWithPHPMailerOAuth()
*/
public function it_should_send_an_email_test_with_PHPMailerOAuth()
{
$faker = $this->faker;
$gmailOauth = new GmailOAuth();
$result = $gmailOauth->sendTestMailWithPHPMailerOAuth();
$this->assertTrue($result instanceof PHPMailerOAuth);
$gmailOauth->setFromAccount($faker->email);
$result = $gmailOauth->sendTestMailWithPHPMailerOAuth();
$this->assertTrue($result instanceof PHPMailerOAuth);
$gmailOauth->setSenderEmail($faker->email);
$result = $gmailOauth->sendTestMailWithPHPMailerOAuth();
$this->assertTrue($result instanceof PHPMailerOAuth);
$gmailOauth->setMailTo($faker->email);
$gmailOauth->setSendTestMail(0);
$result = $gmailOauth->sendTestMailWithPHPMailerOAuth();
$this->assertTrue($result instanceof PHPMailerOAuth);
}
/**
* This ensures proof of get message body.
* @test
* @covers \ProcessMaker\GmailOAuth\GmailOAuth::getMessageBody()
*/
public function it_should_get_message_body()
{
$gmailOauth = new GmailOAuth();
$result = $gmailOauth->getMessageBody();
$this->assertTrue(is_string($result));
}
}