mailgun-php/tests/Lists/OptInHandlerTest.php

56 lines
1.9 KiB
PHP
Raw Normal View History

<?php
2016-07-24 14:42:47 +03:00
/*
* Copyright (C) 2013 Mailgun
*
* This software may be modified and distributed under the terms
2016-12-06 21:12:52 +03:00
* of the MIT license. See the LICENSE file for details.
*/
2013-08-16 22:20:01 +04:00
namespace Mailgun\Tests\Lists;
use Mailgun\Tests\Mock\Mailgun;
2013-08-16 22:20:01 +04:00
2016-07-24 14:42:47 +03:00
class OptInHandlerTest extends \Mailgun\Tests\MailgunTestCase
2014-05-14 17:06:05 +04:00
{
private $client;
2017-12-19 20:36:55 +03:00
2014-05-14 17:06:05 +04:00
private $optInHandler;
public function setUp()
{
2016-07-24 14:42:47 +03:00
$this->client = new Mailgun('My-Super-Awesome-API-Key');
2014-05-14 17:06:05 +04:00
$this->optInHandler = $this->client->OptInHandler();
}
public function testReturnOfGenerateHash()
{
$generatedHash = $this->optInHandler->generateHash(
'mytestlist@example.com',
'mysupersecretappid',
'testrecipient@example.com'
);
2016-07-24 14:42:47 +03:00
$knownHash = 'eyJoIjoiMTllODc2YWNkMWRmNzk4NTc0ZTU0YzhjMzIzOTNiYTNjNzdhNGMxOCIsInAiOiJleUp5SWpvaWRHVnpkSEpsWTJsd2FXVnVkRUJsZUdGdGNHeGxMbU52YlNJc0ltd2lPaUp0ZVhSbGMzUnNhWE4wUUdWNFlXMXdiR1V1WTI5dEluMD0ifQ%3D%3D';
2014-05-14 17:06:05 +04:00
$this->assertEquals($generatedHash, $knownHash);
}
public function testGoodHash()
{
$validation = $this->optInHandler->validateHash(
'mysupersecretappid',
'eyJoIjoiMTllODc2YWNkMWRmNzk4NTc0ZTU0YzhjMzIzOTNiYTNjNzdhNGMxOCIsInAiOiJleUp5SWpvaWRHVnpkSEpsWTJsd2FXVnVkRUJsZUdGdGNHeGxMbU52YlNJc0ltd2lPaUp0ZVhSbGMzUnNhWE4wUUdWNFlXMXdiR1V1WTI5dEluMD0ifQ%3D%3D'
);
$this->assertArrayHasKey('recipientAddress', $validation);
$this->assertArrayHasKey('mailingList', $validation);
}
public function testBadHash()
{
$validation = $this->optInHandler->validateHash(
'mybadsecretappid',
'eyJoIjoiMTllODc2YWNkMWRmNzk4NTc0ZTU0YzhjMzIzOTNiYTNjNzdhNGMxOCIsInAiOiJleUp5SWpvaWRHVnpkSEpsWTJsd2FXVnVkRUJsZUdGdGNHeGxMbU52YlNJc0ltd2lPaUp0ZVhSbGMzUnNhWE4wUUdWNFlXMXdiR1V1WTI5dEluMD0ifQ%3D%3D'
);
$this->assertFalse($validation);
}
2013-08-16 22:20:01 +04:00
}