BaseFlowTest.php in TMGMT Translator Smartling 8.4
File
tests/src/Kernel/BaseFlowTest.php
View source
<?php
namespace Drupal\Tests\tmgmt_smartling\Kernel;
use Smartling\AuditLog\Params\CreateRecordParameters;
class BaseFlowTest extends SmartlingTestBase {
public function setUp() : void {
parent::setUp();
$api_factory_mock = $this
->getMockBuilder('\\Drupal\\tmgmt_smartling\\Smartling\\SmartlingApiFactory')
->setMethods(NULL)
->getMock();
$logger_mock = $this
->getMockBuilder('\\Drupal\\Core\\Logger\\LoggerChannel')
->setMethods(NULL)
->disableOriginalConstructor()
->getMock();
$this->apiWrapperMock = $this
->getMockBuilder('\\Drupal\\tmgmt_smartling\\Smartling\\SmartlingApiWrapper')
->setMethods([
'deleteFile',
'createAuditLogRecord',
])
->setConstructorArgs([
$api_factory_mock,
$logger_mock,
])
->getMock();
\Drupal::getContainer()
->set('tmgmt_smartling.smartling_api_wrapper', $this->apiWrapperMock);
}
function testJobFileDeletionInDashboardSuccess() {
$translate_job = $this
->createJobWithItems([]);
$this->apiWrapperMock
->expects($this
->once())
->method('createAuditLogRecord')
->with($translate_job, NULL, \Drupal::currentUser(), CreateRecordParameters::ACTION_TYPE_DELETE);
$this->apiWrapperMock
->expects($this
->once())
->method('deleteFile')
->with('JobID1_en_de.xml');
$translate_job
->delete();
}
function testJobFileDeletionInDashboardNoTranslatorAssigned() {
$this->apiWrapperMock
->expects($this
->never())
->method('createAuditLogRecord');
$this->apiWrapperMock
->expects($this
->never())
->method('deleteFile');
$translate_job = $this
->createJobWithItems([], NULL);
$translate_job
->delete();
}
function testJobFileDeletionInDashboardNotSmartlingTranslatorAssigned() {
$this->apiWrapperMock
->expects($this
->never())
->method('createAuditLogRecord');
$this->apiWrapperMock
->expects($this
->never())
->method('deleteFile');
$translate_job = $this
->createJobWithItems([], $this->default_translator
->id());
$translate_job
->delete();
}
function testJobCancelingLeadsToAuditLogRecordCreation() {
$translate_job = $this
->createJobWithItems([]);
$this->apiWrapperMock
->expects($this
->once())
->method('createAuditLogRecord')
->with($translate_job, NULL, \Drupal::currentUser(), CreateRecordParameters::ACTION_TYPE_CANCEL);
$translate_job
->getTranslatorPlugin()
->abortTranslation($translate_job);
}
function testTranslatorSettingsUpdateLeadsToAuditLogRecordCreation() {
$translate_job = $this
->createJobWithItems([]);
$translator = $translate_job
->getTranslator();
$this->apiWrapperMock
->expects($this
->once())
->method('createAuditLogRecord')
->with(NULL, $translator, \Drupal::currentUser(), CreateRecordParameters::ACTION_TYPE_UPDATE_SETTINGS);
$translator
->save();
}
}