EmailTemplatesTest.php in Auth0 Single Sign On 8.2
File
vendor/auth0/auth0-php/tests/API/Management/EmailTemplatesTest.php
View source
<?php
namespace Auth0\Tests\API\Management;
use Auth0\SDK\API\Management;
use Auth0\SDK\API\Management\EmailTemplates;
use Auth0\Tests\API\ApiTests;
use GuzzleHttp\Exception\ClientException;
class EmailTemplatesTest extends ApiTests {
const EMAIL_TEMPLATE_NAME = EmailTemplates::TEMPLATE_ENROLLMENT_EMAIL;
protected static $token;
protected static $domain;
protected static $api;
protected static $gotEmail = [];
protected static $setUpEmailError;
protected static $mustCreate = false;
public static function setUpBeforeClass() {
$env = self::getEnv();
self::$domain = $env['DOMAIN'];
self::$token = self::getToken($env, [
'email_templates' => [
'actions' => [
'create',
'read',
'update',
],
],
'email_provider' => [
'actions' => [
'read',
],
],
]);
self::$api = new Management(self::$token, self::$domain);
try {
self::$gotEmail = self::$api->emailTemplates
->get(self::EMAIL_TEMPLATE_NAME);
} catch (ClientException $e) {
self::$setUpEmailError = $e
->getCode();
if (404 === self::$setUpEmailError) {
self::$mustCreate = true;
}
}
}
protected function assertPreConditions() {
try {
self::$api->emails
->getEmailProvider();
} catch (\Exception $e) {
$this
->markTestSkipped('Need to specify an email provider in the dashboard > Emails > Provider');
}
if (!self::$mustCreate && empty(self::$gotEmail)) {
$this
->markTestSkipped('Email template ' . self::EMAIL_TEMPLATE_NAME . ' not found with error ' . self::$setUpEmailError);
}
}
public function testGotAnEmail() {
if (self::$mustCreate) {
$from_email = 'test@' . self::$domain;
self::$gotEmail = self::$api->emailTemplates
->create(self::EMAIL_TEMPLATE_NAME, $from_email);
$this
->assertEquals($from_email, self::$gotEmail['from']);
}
$this
->assertEquals(self::EMAIL_TEMPLATE_NAME, self::$gotEmail['template']);
}
public function testPatch() {
$new_subject = 'Email subject ' . time();
self::$gotEmail = self::$api->emailTemplates
->patch(self::EMAIL_TEMPLATE_NAME, [
'subject' => $new_subject,
]);
$this
->assertEquals($new_subject, self::$gotEmail['subject']);
}
}