2018-08-05 12:00:43 +03:00
|
|
|
<?php
|
|
|
|
|
2019-01-09 22:32:09 +03:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2018-08-05 12:00:43 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 Mailgun
|
|
|
|
*
|
|
|
|
* This software may be modified and distributed under the terms
|
|
|
|
* of the MIT license. See the LICENSE file for details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Mailgun\Tests\Api;
|
|
|
|
|
|
|
|
use Mailgun\Api\Domain;
|
2020-10-12 20:31:10 +03:00
|
|
|
use Mailgun\Exception\InvalidArgumentException;
|
2018-08-05 12:00:43 +03:00
|
|
|
use Mailgun\Model\Domain\ConnectionResponse;
|
|
|
|
use Mailgun\Model\Domain\CreateCredentialResponse;
|
|
|
|
use Mailgun\Model\Domain\CreateResponse;
|
|
|
|
use Mailgun\Model\Domain\DeleteCredentialResponse;
|
|
|
|
use Mailgun\Model\Domain\DeleteResponse;
|
|
|
|
use Mailgun\Model\Domain\IndexResponse;
|
|
|
|
use Mailgun\Model\Domain\ShowResponse;
|
2020-10-10 00:43:27 +03:00
|
|
|
use Mailgun\Model\Domain\TrackingResponse;
|
|
|
|
use Mailgun\Model\Domain\UpdateClickTrackingResponse;
|
2018-08-05 12:00:43 +03:00
|
|
|
use Mailgun\Model\Domain\UpdateConnectionResponse;
|
|
|
|
use Mailgun\Model\Domain\UpdateCredentialResponse;
|
2020-10-10 00:43:27 +03:00
|
|
|
use Mailgun\Model\Domain\UpdateOpenTrackingResponse;
|
|
|
|
use Mailgun\Model\Domain\UpdateUnsubscribeTrackingResponse;
|
2018-08-05 12:00:43 +03:00
|
|
|
use Mailgun\Model\Domain\VerifyResponse;
|
2021-08-18 22:48:47 +03:00
|
|
|
use Nyholm\Psr7\Response;
|
2018-08-05 12:00:43 +03:00
|
|
|
|
|
|
|
class DomainTest extends TestCase
|
|
|
|
{
|
|
|
|
protected function getApiClass()
|
|
|
|
{
|
|
|
|
return Domain::class;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testIndex()
|
|
|
|
{
|
|
|
|
$this->setRequestMethod('GET');
|
|
|
|
$this->setRequestUri('/v3/domains?limit=100&skip=0');
|
|
|
|
$this->setHttpResponse(new Response(200, ['Content-Type' => 'application/json'], <<<'JSON'
|
|
|
|
{
|
|
|
|
"total_count": 1,
|
|
|
|
"items": [
|
|
|
|
{
|
|
|
|
"created_at": "Wed, 10 Jul 2013 19:26:52 GMT",
|
|
|
|
"smtp_login": "postmaster@samples.mailgun.org",
|
|
|
|
"name": "samples.mailgun.org",
|
|
|
|
"smtp_password": "4rtqo4p6rrx9",
|
|
|
|
"wildcard": true,
|
|
|
|
"spam_action": "disabled",
|
|
|
|
"state": "active"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
JSON
|
|
|
|
));
|
|
|
|
|
|
|
|
$api = $this->getApiInstance();
|
|
|
|
/** @var IndexResponse $response */
|
|
|
|
$response = $api->index();
|
|
|
|
$this->assertInstanceOf(IndexResponse::class, $response);
|
|
|
|
$this->assertEquals(1, $response->getTotalCount());
|
|
|
|
$this->assertEquals('samples.mailgun.org', $response->getDomains()[0]->getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testShow()
|
|
|
|
{
|
|
|
|
$this->setRequestMethod('GET');
|
|
|
|
$this->setRequestUri('/v3/domains/example.com');
|
|
|
|
$this->setHydrateClass(ShowResponse::class);
|
|
|
|
|
|
|
|
$api = $this->getApiInstance();
|
|
|
|
$api->show('example.com');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCreate()
|
|
|
|
{
|
|
|
|
$this->setRequestMethod('POST');
|
|
|
|
$this->setRequestUri('/v3/domains');
|
|
|
|
$this->setRequestBody([
|
2018-08-05 13:00:05 +03:00
|
|
|
'name' => 'example.com',
|
2018-08-05 12:00:43 +03:00
|
|
|
]);
|
|
|
|
$this->setHydrateClass(CreateResponse::class);
|
|
|
|
|
|
|
|
$api = $this->getApiInstance();
|
|
|
|
$api->create('example.com');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCreateWithPassword()
|
2019-08-28 07:59:58 +03:00
|
|
|
{
|
|
|
|
$this->setRequestMethod('POST');
|
|
|
|
$this->setRequestUri('/v3/domains');
|
|
|
|
$this->setRequestBody([
|
|
|
|
'name' => 'example.com',
|
|
|
|
'smtp_password' => 'foo',
|
|
|
|
]);
|
|
|
|
$this->setHydrateClass(CreateResponse::class);
|
|
|
|
|
|
|
|
$api = $this->getApiInstance();
|
|
|
|
$api->create('example.com', 'foo');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCreateWithPasswordSpamAction()
|
|
|
|
{
|
|
|
|
$this->setRequestMethod('POST');
|
|
|
|
$this->setRequestUri('/v3/domains');
|
|
|
|
$this->setRequestBody([
|
|
|
|
'name' => 'example.com',
|
|
|
|
'smtp_password' => 'foo',
|
|
|
|
'spam_action' => 'bar',
|
|
|
|
]);
|
|
|
|
$this->setHydrateClass(CreateResponse::class);
|
|
|
|
|
|
|
|
$api = $this->getApiInstance();
|
|
|
|
$api->create('example.com', 'foo', 'bar');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCreateWithPasswordSpamActionWildcard()
|
2018-08-05 12:00:43 +03:00
|
|
|
{
|
|
|
|
$this->setRequestMethod('POST');
|
|
|
|
$this->setRequestUri('/v3/domains');
|
|
|
|
$this->setRequestBody([
|
2018-08-05 13:00:05 +03:00
|
|
|
'name' => 'example.com',
|
|
|
|
'smtp_password' => 'foo',
|
|
|
|
'spam_action' => 'bar',
|
2019-08-28 07:59:58 +03:00
|
|
|
'wildcard' => 'true',
|
2018-08-05 12:00:43 +03:00
|
|
|
]);
|
|
|
|
$this->setHydrateClass(CreateResponse::class);
|
|
|
|
|
|
|
|
$api = $this->getApiInstance();
|
|
|
|
$api->create('example.com', 'foo', 'bar', true);
|
|
|
|
}
|
|
|
|
|
2020-06-12 09:55:34 +03:00
|
|
|
public function testCreateWithPasswordForceDkimAuthority()
|
|
|
|
{
|
|
|
|
$this->setRequestMethod('POST');
|
|
|
|
$this->setRequestUri('/v3/domains');
|
|
|
|
$this->setRequestBody([
|
|
|
|
'name' => 'example.com',
|
|
|
|
'smtp_password' => 'foo',
|
|
|
|
'force_dkim_authority' => 'true',
|
|
|
|
]);
|
|
|
|
$this->setHydrateClass(CreateResponse::class);
|
|
|
|
|
|
|
|
$api = $this->getApiInstance();
|
|
|
|
$api->create('example.com', 'foo', null, null, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCreateWithPasswordSpamActionWildcardForceDkimAuthority()
|
|
|
|
{
|
|
|
|
$this->setRequestMethod('POST');
|
|
|
|
$this->setRequestUri('/v3/domains');
|
|
|
|
$this->setRequestBody([
|
|
|
|
'name' => 'example.com',
|
|
|
|
'smtp_password' => 'foo',
|
|
|
|
'spam_action' => 'bar',
|
|
|
|
'wildcard' => 'true',
|
|
|
|
'force_dkim_authority' => 'true',
|
|
|
|
]);
|
|
|
|
$this->setHydrateClass(CreateResponse::class);
|
|
|
|
|
|
|
|
$api = $this->getApiInstance();
|
|
|
|
$api->create('example.com', 'foo', 'bar', true, true);
|
|
|
|
}
|
|
|
|
|
2018-08-05 12:00:43 +03:00
|
|
|
public function testDelete()
|
|
|
|
{
|
|
|
|
$this->setRequestMethod('DELETE');
|
|
|
|
$this->setRequestUri('/v3/domains/example.com');
|
|
|
|
$this->setHydrateClass(DeleteResponse::class);
|
|
|
|
|
|
|
|
$api = $this->getApiInstance();
|
|
|
|
$api->delete('example.com');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCreateCredential()
|
|
|
|
{
|
|
|
|
$this->setRequestMethod('POST');
|
|
|
|
$this->setRequestUri('/v3/domains/example.com/credentials');
|
|
|
|
$this->setRequestBody([
|
|
|
|
'login' => 'foo',
|
|
|
|
'password' => 'barbar',
|
|
|
|
]);
|
|
|
|
$this->setHydrateClass(CreateCredentialResponse::class);
|
|
|
|
|
|
|
|
$api = $this->getApiInstance();
|
|
|
|
$api->createCredential('example.com', 'foo', 'barbar');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateCredential()
|
|
|
|
{
|
|
|
|
$this->setRequestMethod('PUT');
|
|
|
|
$this->setRequestUri('/v3/domains/example.com/credentials/foo');
|
|
|
|
$this->setRequestBody([
|
|
|
|
'password' => 'barbar',
|
|
|
|
]);
|
|
|
|
$this->setHydrateClass(UpdateCredentialResponse::class);
|
|
|
|
|
|
|
|
$api = $this->getApiInstance();
|
|
|
|
$api->updateCredential('example.com', 'foo', 'barbar');
|
|
|
|
}
|
2018-08-05 13:00:05 +03:00
|
|
|
|
2018-08-05 12:00:43 +03:00
|
|
|
public function testDeleteCredential()
|
|
|
|
{
|
|
|
|
$this->setRequestMethod('DELETE');
|
|
|
|
$this->setRequestUri('/v3/domains/example.com/credentials/foo');
|
|
|
|
$this->setHydrateClass(DeleteCredentialResponse::class);
|
|
|
|
|
|
|
|
$api = $this->getApiInstance();
|
|
|
|
$api->deleteCredential('example.com', 'foo', 'barbar');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testConnection()
|
|
|
|
{
|
|
|
|
$this->setRequestMethod('GET');
|
|
|
|
$this->setRequestUri('/v3/domains/example.com/connection');
|
|
|
|
$this->setHydrateClass(ConnectionResponse::class);
|
|
|
|
|
|
|
|
$api = $this->getApiInstance();
|
|
|
|
$api->connection('example.com');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateConnection()
|
|
|
|
{
|
|
|
|
$this->setRequestMethod('PUT');
|
|
|
|
$this->setRequestUri('/v3/domains/example.com/connection');
|
|
|
|
$this->setRequestBody([
|
|
|
|
'require_tls' => 'true',
|
|
|
|
'skip_verification' => 'false',
|
|
|
|
]);
|
|
|
|
$this->setHydrateClass(UpdateConnectionResponse::class);
|
|
|
|
|
|
|
|
$api = $this->getApiInstance();
|
2018-08-05 13:00:05 +03:00
|
|
|
$api->updateConnection('example.com', true, false);
|
2018-08-05 12:00:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testVerify()
|
|
|
|
{
|
|
|
|
$this->setRequestMethod('PUT');
|
|
|
|
$this->setRequestUri('/v3/domains/example.com/verify');
|
|
|
|
$this->setHydrateClass(VerifyResponse::class);
|
|
|
|
|
|
|
|
$api = $this->getApiInstance();
|
|
|
|
$api->verify('example.com');
|
|
|
|
}
|
2020-10-05 17:50:47 +03:00
|
|
|
|
|
|
|
public function testCreateWithIps()
|
|
|
|
{
|
|
|
|
$this->setRequestMethod('POST');
|
|
|
|
$this->setRequestUri('/v3/domains');
|
|
|
|
$this->setRequestBody([
|
|
|
|
'name' => 'example.com',
|
|
|
|
'smtp_password' => 'foo',
|
2020-10-08 14:47:18 +03:00
|
|
|
'ips' => '127.0.0.1,127.0.0.2',
|
2020-10-05 17:50:47 +03:00
|
|
|
]);
|
|
|
|
$this->setHydrateClass(CreateResponse::class);
|
|
|
|
|
|
|
|
$api = $this->getApiInstance();
|
2020-10-08 14:47:18 +03:00
|
|
|
$api->create('example.com', 'foo', null, null, null, ['127.0.0.1', '127.0.0.2']);
|
2020-10-05 17:50:47 +03:00
|
|
|
}
|
2020-10-10 00:43:27 +03:00
|
|
|
|
|
|
|
public function testTracking()
|
|
|
|
{
|
|
|
|
$this->setRequestMethod('GET');
|
|
|
|
$this->setRequestUri('/v3/domains/example.com/tracking');
|
|
|
|
$this->setHydrateClass(TrackingResponse::class);
|
|
|
|
|
|
|
|
/**
|
2020-10-12 20:46:20 +03:00
|
|
|
* @var Domain
|
2020-10-10 00:43:27 +03:00
|
|
|
*/
|
|
|
|
$api = $this->getApiInstance();
|
|
|
|
$api->tracking('example.com');
|
|
|
|
}
|
|
|
|
|
2020-10-12 20:31:10 +03:00
|
|
|
public function updateClickTrackingDataProvider(): array
|
2020-10-10 00:43:27 +03:00
|
|
|
{
|
|
|
|
return [
|
2020-10-12 20:31:10 +03:00
|
|
|
['yes'],
|
|
|
|
['no'],
|
|
|
|
['htmlonly'],
|
2020-10-10 00:43:27 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-12 20:31:10 +03:00
|
|
|
* @dataProvider updateClickTrackingDataProvider
|
2020-10-10 00:43:27 +03:00
|
|
|
*/
|
2020-10-12 20:31:10 +03:00
|
|
|
public function testUpdateClickTracking(string $active)
|
2020-10-10 00:43:27 +03:00
|
|
|
{
|
|
|
|
$this->setRequestMethod('PUT');
|
|
|
|
$this->setRequestUri('/v3/domains/example.com/tracking/click');
|
|
|
|
$this->setRequestBody([
|
2020-10-12 20:31:10 +03:00
|
|
|
'active' => $active,
|
2020-10-10 00:43:27 +03:00
|
|
|
]);
|
|
|
|
$this->setHydrateClass(UpdateClickTrackingResponse::class);
|
|
|
|
|
|
|
|
/**
|
2020-10-12 20:46:20 +03:00
|
|
|
* @var Domain
|
2020-10-10 00:43:27 +03:00
|
|
|
*/
|
|
|
|
$api = $this->getApiInstance();
|
2020-10-12 20:31:10 +03:00
|
|
|
$api->updateClickTracking('example.com', $active);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateClickTrackingException()
|
|
|
|
{
|
|
|
|
$this->expectException(InvalidArgumentException::class);
|
|
|
|
|
|
|
|
/**
|
2020-10-12 20:46:20 +03:00
|
|
|
* @var Domain
|
2020-10-12 20:31:10 +03:00
|
|
|
*/
|
|
|
|
$api = $this->getApiInstance();
|
|
|
|
$api->updateClickTracking('example.com', 'non-valid-active-param');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function updateOpenTrackingDataProvider(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
['yes'],
|
|
|
|
['no'],
|
|
|
|
];
|
2020-10-10 00:43:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-12 20:31:10 +03:00
|
|
|
* @dataProvider updateOpenTrackingDataProvider
|
2020-10-10 00:43:27 +03:00
|
|
|
*/
|
2020-10-12 20:31:10 +03:00
|
|
|
public function testUpdateOpenTracking(string $active)
|
2020-10-10 00:43:27 +03:00
|
|
|
{
|
|
|
|
$this->setRequestMethod('PUT');
|
|
|
|
$this->setRequestUri('/v3/domains/example.com/tracking/open');
|
|
|
|
$this->setRequestBody([
|
2020-10-12 20:31:10 +03:00
|
|
|
'active' => $active,
|
2020-10-10 00:43:27 +03:00
|
|
|
]);
|
|
|
|
$this->setHydrateClass(UpdateOpenTrackingResponse::class);
|
|
|
|
|
|
|
|
/**
|
2020-10-12 20:46:20 +03:00
|
|
|
* @var Domain
|
2020-10-10 00:43:27 +03:00
|
|
|
*/
|
|
|
|
$api = $this->getApiInstance();
|
2020-10-12 20:31:10 +03:00
|
|
|
$api->updateOpenTracking('example.com', $active);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateOpenTrackingException()
|
|
|
|
{
|
|
|
|
$this->expectException(InvalidArgumentException::class);
|
|
|
|
|
|
|
|
/**
|
2020-10-12 20:46:20 +03:00
|
|
|
* @var Domain
|
2020-10-12 20:31:10 +03:00
|
|
|
*/
|
|
|
|
$api = $this->getApiInstance();
|
|
|
|
$api->updateOpenTracking('example.com', 'non-valid-active-param');
|
2020-10-10 00:43:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function unsubscribeDataProvider(): array
|
|
|
|
{
|
|
|
|
return [
|
2020-10-12 20:31:10 +03:00
|
|
|
['true', '<b>Test</b>', 'Test1'],
|
|
|
|
['false', '<s>Test</s>', 'Test2'],
|
2020-10-10 00:43:27 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider unsubscribeDataProvider
|
|
|
|
*/
|
2020-10-12 20:31:10 +03:00
|
|
|
public function testUpdateUnsubscribeTracking(string $active, string $htmlFooter, string $textFooter)
|
2020-10-10 00:43:27 +03:00
|
|
|
{
|
|
|
|
$this->setRequestMethod('PUT');
|
|
|
|
$this->setRequestUri('/v3/domains/example.com/tracking/unsubscribe');
|
|
|
|
$this->setRequestBody([
|
2020-10-12 20:31:10 +03:00
|
|
|
'active' => $active,
|
2020-10-10 00:43:27 +03:00
|
|
|
'html_footer' => $htmlFooter,
|
|
|
|
'text_footer' => $textFooter,
|
|
|
|
]);
|
|
|
|
$this->setHydrateClass(UpdateUnsubscribeTrackingResponse::class);
|
|
|
|
|
|
|
|
/**
|
2020-10-12 20:46:20 +03:00
|
|
|
* @var Domain
|
2020-10-10 00:43:27 +03:00
|
|
|
*/
|
|
|
|
$api = $this->getApiInstance();
|
2020-10-12 20:31:10 +03:00
|
|
|
$api->updateUnsubscribeTracking('example.com', $active, $htmlFooter, $textFooter);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateUnsubscribeTrackingException()
|
|
|
|
{
|
|
|
|
$this->expectException(InvalidArgumentException::class);
|
|
|
|
|
|
|
|
/**
|
2020-10-12 20:46:20 +03:00
|
|
|
* @var Domain
|
2020-10-12 20:31:10 +03:00
|
|
|
*/
|
|
|
|
$api = $this->getApiInstance();
|
|
|
|
$api->updateUnsubscribeTracking('example.com', 'non-valid-active-param', 'html-footer', 'text-footer');
|
2020-10-10 00:43:27 +03:00
|
|
|
}
|
2018-08-05 12:00:43 +03:00
|
|
|
}
|