View source
<?php
namespace Drupal\Tests\lingotek\Functional;
trait LingotekManagementTestTrait {
protected function assertLingotekUploadLink($entity_id = 1, $entity_type_id = 'node', $prefix = NULL, $destination_entity_type_id = NULL, $destination_entity_id = NULL) {
$basepath = \Drupal::request()
->getBasePath();
$languagePrefix = $prefix === NULL ? '' : '/' . $prefix;
$destination_entity_type_id = $destination_entity_type_id ?: $entity_type_id;
$href = $basepath . $languagePrefix . '/admin/lingotek/entity/upload/' . $entity_type_id . '/' . $entity_id;
if ($destination = $this
->getDestination($destination_entity_type_id, $prefix)) {
$href .= $destination;
}
$this
->assertLinkByHref($href);
}
protected function assertNoLingotekUploadLink($entity_id = 1, $entity_type_id = 'node', $prefix = NULL, $destination_entity_type_id = NULL, $destination_entity_id = NULL) {
$basepath = \Drupal::request()
->getBasePath();
$languagePrefix = $prefix === NULL ? '' : '/' . $prefix;
$destination_entity_type_id = $destination_entity_type_id ?: $entity_type_id;
$href = $basepath . $languagePrefix . '/admin/lingotek/entity/upload/' . $entity_type_id . '/' . $entity_id;
if ($destination = $this
->getDestination($destination_entity_type_id, $prefix)) {
$href .= $destination;
}
$this
->assertNoLinkByHref($href);
}
protected function assertLingotekUpdateLink($document_id = 'dummy-document-hash-id', $entity_type_id = 'node', $prefix = NULL, $destination_entity_type_id = NULL, $destination_entity_id = NULL) {
$basepath = \Drupal::request()
->getBasePath();
$languagePrefix = $prefix === NULL ? '' : '/' . $prefix;
$destination_entity_type_id = $destination_entity_type_id ?: $entity_type_id;
$href = $basepath . $languagePrefix . '/admin/lingotek/entity/update/' . $document_id;
if ($destination = $this
->getDestination($destination_entity_type_id, $prefix)) {
$href .= $destination;
}
$this
->assertLinkByHref($href);
}
protected function assertLingotekCheckSourceStatusLink($document_id = 'dummy-document-hash-id', $entity_type_id = 'node', $prefix = NULL, $destination_entity_type_id = NULL, $destination_entity_id = NULL) {
$basepath = \Drupal::request()
->getBasePath();
$languagePrefix = $prefix === NULL ? '' : '/' . $prefix;
$destination_entity_type_id = $destination_entity_type_id ?: $entity_type_id;
$href = $basepath . $languagePrefix . '/admin/lingotek/entity/check_upload/' . $document_id;
if ($destination = $this
->getDestination($destination_entity_type_id, $prefix)) {
$href .= $destination;
}
$this
->assertLinkByHref($href);
}
protected function assertNoLingotekCheckSourceStatusLink($document_id = 'dummy-document-hash-id', $entity_type_id = 'node', $prefix = NULL, $destination_entity_type_id = NULL, $destination_entity_id = NULL) {
$basepath = \Drupal::request()
->getBasePath();
$languagePrefix = $prefix === NULL ? '' : '/' . $prefix;
$destination_entity_type_id = $destination_entity_type_id ?: $entity_type_id;
$href = $basepath . $languagePrefix . '/admin/lingotek/entity/check_upload/' . $document_id;
if ($destination = $this
->getDestination($destination_entity_type_id, $prefix)) {
$href .= $destination;
}
$this
->assertNoLinkByHref($href);
}
protected function assertLingotekRequestTranslationLink($locale, $document_id = 'dummy-document-hash-id', $entity_type_id = 'node', $prefix = NULL, $destination_entity_type_id = NULL, $destination_entity_id = NULL) {
$basepath = \Drupal::request()
->getBasePath();
$languagePrefix = $prefix === NULL ? '' : '/' . $prefix;
$destination_entity_type_id = $destination_entity_type_id ?: $entity_type_id;
$href = $basepath . $languagePrefix . '/admin/lingotek/entity/add_target/' . $document_id . '/' . $locale;
if ($destination = $this
->getDestination($destination_entity_type_id, $prefix)) {
$href .= $destination;
}
$this
->assertLinkByHref($href);
}
protected function assertNoLingotekRequestTranslationLink($locale, $document_id = 'dummy-document-hash-id', $entity_type_id = 'node', $prefix = NULL, $destination_entity_type_id = NULL, $destination_entity_id = NULL) {
$basepath = \Drupal::request()
->getBasePath();
$languagePrefix = $prefix === NULL ? '' : '/' . $prefix;
$destination_entity_type_id = $destination_entity_type_id ?: $entity_type_id;
$href = $basepath . $languagePrefix . '/admin/lingotek/entity/add_target/' . $document_id . '/' . $locale;
if ($destination = $this
->getDestination($destination_entity_type_id, $prefix)) {
$href .= $destination;
}
$this
->assertNoLinkByHref($href);
}
protected function assertLingotekCheckTargetStatusLink($locale, $document_id = 'dummy-document-hash-id', $entity_type_id = 'node', $prefix = NULL, $destination_entity_type_id = NULL, $destination_entity_id = NULL) {
$basepath = \Drupal::request()
->getBasePath();
$languagePrefix = $prefix === NULL ? '' : '/' . $prefix;
$destination_entity_type_id = $destination_entity_type_id ?: $entity_type_id;
$href = $basepath . $languagePrefix . '/admin/lingotek/entity/check_target/' . $document_id . '/' . $locale;
if ($destination = $this
->getDestination($destination_entity_type_id, $prefix)) {
$href .= $destination;
}
$this
->assertLinkByHref($href);
}
protected function assertNoLingotekCheckTargetStatusLink($locale, $document_id = 'dummy-document-hash-id', $entity_type_id = 'node', $prefix = NULL, $destination_entity_type_id = NULL, $destination_entity_id = NULL) {
$basepath = \Drupal::request()
->getBasePath();
$languagePrefix = $prefix === NULL ? '' : '/' . $prefix;
$destination_entity_type_id = $destination_entity_type_id ?: $entity_type_id;
$href = $basepath . $languagePrefix . '/admin/lingotek/entity/check_target/' . $document_id . '/' . $locale;
if ($destination = $this
->getDestination($destination_entity_type_id, $prefix)) {
$href .= $destination;
}
$this
->assertNoLinkByHref($href);
}
protected function assertLingotekDownloadTargetLink($locale, $document_id = 'dummy-document-hash-id', $entity_type_id = 'node', $prefix = NULL, $destination_entity_type_id = NULL, $destination_entity_id = NULL) {
$basepath = \Drupal::request()
->getBasePath();
$languagePrefix = $prefix === NULL ? '' : '/' . $prefix;
$destination_entity_type_id = $destination_entity_type_id ?: $entity_type_id;
$href = $basepath . $languagePrefix . '/admin/lingotek/entity/download/' . $document_id . '/' . $locale;
if ($destination = $this
->getDestination($destination_entity_type_id, $prefix)) {
$href .= $destination;
}
$this
->assertLinkByHref($href);
}
protected function assertNoLingotekDownloadTargetLink($locale, $document_id = 'dummy-document-hash-id', $entity_type_id = 'node', $prefix = NULL, $destination_entity_type_id = NULL, $destination_entity_id = NULL) {
$basepath = \Drupal::request()
->getBasePath();
$languagePrefix = $prefix === NULL ? '' : '/' . $prefix;
$destination_entity_type_id = $destination_entity_type_id ?: $entity_type_id;
$href = $basepath . $languagePrefix . '/admin/lingotek/entity/download/' . $document_id . '/' . $locale;
if ($destination = $this
->getDestination($destination_entity_type_id, $prefix)) {
$href .= $destination;
}
$this
->assertNoLinkByHref($href);
}
protected function assertLingotekWorkbenchLink($locale, $document_id = 'dummy-document-hash-id') {
$basepath = \Drupal::request()
->getBasePath();
$this
->assertLinkByHref($basepath . '/admin/lingotek/workbench/' . $document_id . '/' . $locale);
$workbench_link = $this
->xpath("//a[@href='{$basepath}/admin/lingotek/workbench/{$document_id}/{$locale}' and @target='_blank']");
$this
->assertEqual(count($workbench_link), 1, 'Workbench links open in a new tab.');
}
protected function getBulkSelectionKey($langcode, $revision_id, $entity_type_id = 'node') {
return 'table[' . $revision_id . ']';
}
protected function getBulkOperationFormName() {
return 'operation';
}
protected function getBulkOperationNameForUpload($entity_type_id) {
return 'upload';
}
protected function getBulkOperationNameForCheckUpload($entity_type_id) {
return 'check_upload';
}
protected function getBulkOperationNameForRequestTranslations($entity_type_id) {
return 'request_translations';
}
protected function getBulkOperationNameForRequestTranslation($langcode, $entity_type_id) {
return 'request_translation:' . $langcode;
}
protected function getBulkOperationNameForCheckTranslations($entity_type_id) {
return 'check_translations';
}
protected function getBulkOperationNameForCheckTranslation($langcode, $entity_type_id) {
return 'check_translation:' . $langcode;
}
protected function getBulkOperationNameForDownloadTranslations($entity_type_id) {
return 'download';
}
protected function getBulkOperationNameForDownloadTranslation($langcode, $entity_type_id) {
return 'download:' . $langcode;
}
protected function getBulkOperationNameForCancel($entity_type_id) {
return 'cancel';
}
protected function getBulkOperationNameForCancelTarget($langcode, $entity_type_id) {
return 'cancel:' . $langcode;
}
protected function getBulkOperationNameForDeleteTranslation($langcode, $entity_type_id) {
return 'delete_translation:' . $langcode;
}
protected function getBulkOperationNameForDeleteTranslations($entity_type_id) {
return 'delete_translations';
}
protected function getBulkOperationNameForAssignJobId($entity_type_id) {
return 'assign_job';
}
protected function getBulkOperationNameForClearJobId($entity_type_id) {
return 'clear_job';
}
protected function getApplyActionsButtonLabel() {
return t('Execute');
}
}