View source
<?php
namespace Drupal\Tests\sms\Kernel;
use Drupal\Core\Url;
use Drupal\sms\Entity\SmsGateway;
use Drupal\sms\Direction;
use Drupal\sms\Entity\SmsGatewayInterface;
class SmsFrameworkGatewayEntityTest extends SmsFrameworkKernelBase {
public static $modules = [
'sms',
'sms_test_gateway',
'telephone',
'dynamic_entity_reference',
];
public function testSkipQueue() {
$gateway = $this
->createGateway();
$this
->assertFalse($gateway
->getSkipQueue(), 'Default value does not skip queue.');
$gateway
->setSkipQueue(TRUE);
$this
->assertTrue($gateway
->getSkipQueue());
}
public function testIncomingRetentionDuration() {
$gateway = $this
->createGateway();
$this
->assertEquals(0, $gateway
->getRetentionDuration(Direction::INCOMING));
$gateway
->setRetentionDuration(Direction::INCOMING, 444);
$this
->assertEquals(444, $gateway
->getRetentionDuration(Direction::INCOMING));
}
public function testOutgoingRetentionDuration() {
$gateway = $this
->createGateway();
$this
->assertEquals(0, $gateway
->getRetentionDuration(Direction::INCOMING));
$gateway
->setRetentionDuration(Direction::OUTGOING, 999);
$this
->assertEquals(999, $gateway
->getRetentionDuration(Direction::OUTGOING));
}
public function testGetRetentionDurationInvalidDirection() {
$gateway = $this
->createGateway();
$this
->setExpectedException(\InvalidArgumentException::class, '0 is not a valid direction.');
$gateway
->getRetentionDuration(0);
}
public function testPushIncomingPath() {
$gateway = $this
->createGateway([
'plugin' => 'incoming',
]);
$path = $gateway
->getPushIncomingPath();
$this
->assertTrue(strpos($path, '/sms/incoming/receive/') === 0);
$new_path = '/' . $this
->randomMachineName();
$return = $gateway
->setPushIncomingPath($new_path);
$this
->assertTrue($return instanceof SmsGatewayInterface);
$this
->assertEquals($new_path, $gateway
->getPushIncomingPath());
}
public function testSupportsIncoming() {
$gateway = $this
->createGateway([
'plugin' => 'incoming',
]);
$this
->assertTrue($gateway
->supportsIncoming());
}
public function testNotSupportsIncoming() {
$gateway = $this
->createGateway([
'plugin' => 'capabilities_default',
]);
$this
->assertFalse($gateway
->supportsIncoming());
}
public function testAutoCreateIncomingRoute() {
$gateway = $this
->createGateway([
'plugin' => 'incoming',
]);
$this
->assertTrue($gateway
->autoCreateIncomingRoute());
}
public function testNoAutoCreateIncomingRoute() {
$gateway = $this
->createGateway([
'plugin' => 'capabilities_default',
]);
$this
->assertFalse($gateway
->autoCreateIncomingRoute());
}
public function testPushReportPath() {
$gateway = $this
->createGateway();
$path = $gateway
->getPushReportPath();
$this
->assertTrue(strpos($path, '/sms/delivery-report/receive/') === 0);
$new_path = '/' . $this
->randomMachineName();
$return = $gateway
->setPushReportPath($new_path);
$this
->assertTrue($return instanceof SmsGatewayInterface);
$this
->assertEquals($new_path, $gateway
->getPushReportPath());
}
public function testPushReportUrl() {
$gateway = $this
->createGateway();
$this
->assertTrue($gateway
->getPushReportUrl() instanceof Url);
}
public function testSupportsReportsPushCustom() {
$gateway = $this
->createGateway([
'plugin' => 'memory',
]);
$this
->assertTrue($gateway
->supportsReportsPush());
}
public function testSupportsReportsPushDefault() {
$gateway = $this
->createGateway([
'plugin' => 'capabilities_default',
]);
$this
->assertFalse($gateway
->supportsReportsPush());
}
public function testSupportsReportsPullCustom() {
$gateway = $this
->createGateway([
'plugin' => 'memory',
]);
$this
->assertTrue($gateway
->supportsReportsPull());
}
public function testSupportsReportsPullDefault() {
$gateway = $this
->createGateway([
'plugin' => 'capabilities_default',
]);
$this
->assertFalse($gateway
->supportsReportsPull());
}
public function testGetMaxRecipientsOutgoingCustom() {
$gateway = $this
->createGateway([
'plugin' => 'memory',
]);
$this
->assertEquals(-1, $gateway
->getMaxRecipientsOutgoing());
}
public function testGetMaxRecipientsOutgoingDefault() {
$gateway = $this
->createGateway([
'plugin' => 'capabilities_default',
]);
$this
->assertEquals(1, $gateway
->getMaxRecipientsOutgoing());
}
public function testSupportsIncomingCustom() {
$gateway = $this
->createGateway([
'plugin' => 'memory',
]);
$this
->assertEquals(TRUE, $gateway
->supportsIncoming());
}
public function testSupportsIncomingDefault() {
$gateway = $this
->createGateway([
'plugin' => 'capabilities_default',
]);
$this
->assertEquals(FALSE, $gateway
->supportsIncoming());
}
public function testIsScheduleAwareCustom() {
$gateway = $this
->createGateway([
'plugin' => 'memory_schedule_aware',
]);
$this
->assertTrue($gateway
->isScheduleAware());
}
public function testIsScheduleAwareDefault() {
$gateway = $this
->createGateway([
'plugin' => 'capabilities_default',
]);
$this
->assertFalse($gateway
->isScheduleAware());
}
public function testSupportsCreditBalanceQueryCustom() {
$gateway = $this
->createGateway([
'plugin' => 'memory',
]);
$this
->assertTrue($gateway
->supportsCreditBalanceQuery());
}
public function testSupportsCreditBalanceQueryDefault() {
$gateway = $this
->createGateway([
'plugin' => 'capabilities_default',
]);
$this
->assertFalse($gateway
->supportsCreditBalanceQuery());
}
protected function createGateway(array $values = []) {
return SmsGateway::create($values + [
'plugin' => 'memory',
]);
}
}