View source
<?php
namespace Drupal\Tests\lingotek\Functional\Form;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\lingotek\Entity\LingotekProfile;
use Drupal\Tests\lingotek\Functional\LingotekTestBase;
class LingotekProfileFormTest extends LingotekTestBase {
use IntelligenceMetadataFormTestTrait;
protected $defaultTheme = 'classy';
public static $modules = [
'node',
];
protected function setUp() : void {
parent::setUp();
$this
->setupResources();
}
public function testDefaultProfilesPresent() {
$assert_session = $this
->assertSession();
$this
->drupalGet('admin/lingotek/settings');
$this
->assertFieldChecked('edit-profile-automatic-auto-upload');
$this
->assertFieldChecked('edit-profile-automatic-auto-download');
$this
->assertNoFieldChecked('edit-profile-manual-auto-upload');
$this
->assertNoFieldChecked('edit-profile-manual-auto-download');
$this
->assertNoFieldChecked('edit-profile-disabled-auto-upload');
$this
->assertNoFieldChecked('edit-profile-disabled-auto-download');
$assert_session
->linkByHrefNotExists('/admin/lingotek/settings/profile/automatic/edit');
$assert_session
->linkByHrefNotExists('/admin/lingotek/settings/profile/manual/edit');
$assert_session
->linkByHrefNotExists('/admin/lingotek/settings/profile/disabled/edit');
$this
->assertFieldDisabled('edit-profile-automatic-auto-upload');
$this
->assertFieldDisabled('edit-profile-automatic-auto-download');
$this
->assertFieldDisabled('edit-profile-manual-auto-upload');
$this
->assertFieldDisabled('edit-profile-manual-auto-download');
$this
->assertFieldDisabled('edit-profile-disabled-auto-upload');
$this
->assertFieldDisabled('edit-profile-disabled-auto-download');
}
public function testAddingProfile() {
$assert_session = $this
->assertSession();
$this
->drupalGet('admin/lingotek/settings');
$this
->clickLink(t('Add new Translation Profile'));
$profile_id = strtolower($this
->randomMachineName());
$profile_name = $this
->randomString();
$edit = [
'id' => $profile_id,
'label' => $profile_name,
'auto_upload' => 1,
'auto_request' => 1,
'auto_download' => 1,
'append_type_to_title' => 'yes',
];
$this
->drupalPostForm(NULL, $edit, t('Save'));
$this
->assertText(t('The Lingotek profile has been successfully saved.'));
$assert_session
->linkByHrefExists("/admin/lingotek/settings/profile/{$profile_id}/edit");
$this
->assertFieldChecked("edit-profile-{$profile_id}-auto-upload");
$this
->assertFieldChecked("edit-profile-{$profile_id}-auto-request");
$this
->assertFieldChecked("edit-profile-{$profile_id}-auto-download");
$this
->assertFieldEnabled("edit-profile-{$profile_id}-auto-upload");
$this
->assertFieldEnabled("edit-profile-{$profile_id}-auto-request");
$this
->assertFieldEnabled("edit-profile-{$profile_id}-auto-download");
$profile = LingotekProfile::load($profile_id);
$this
->assertTrue($profile
->hasAutomaticUpload());
$this
->assertTrue($profile
->hasAutomaticRequest());
$this
->assertTrue($profile
->hasAutomaticDownload());
$this
->assertIdentical('yes', $profile
->getAppendContentTypeToTitle());
$this
->assertIdentical('default', $profile
->getProject());
$this
->assertIdentical('default', $profile
->getVault());
$this
->assertIdentical('default', $profile
->getWorkflow());
$this
->assertFalse($profile
->hasIntelligenceMetadataOverrides());
$this
->assertIdentical('drupal_default', $profile
->getFilter());
$this
->assertIdentical('drupal_default', $profile
->getSubfilter());
}
public function testWorkflows() {
$assert_session = $this
->assertSession();
$this
->drupalGet('admin/lingotek/settings');
$this
->clickLink(t('Add new Translation Profile'));
$this
->assertFieldByName('workflow');
$assert_session
->optionExists('edit-workflow', 'project_default');
$assert_session
->optionExists('edit-workflow', 'default');
}
public function testEditingProfile() {
$assert_session = $this
->assertSession();
$profile = LingotekProfile::create([
'id' => strtolower($this
->randomMachineName()),
'label' => $this
->randomString(),
]);
$profile
->save();
$profile_id = $profile
->id();
$this
->assertIdentical('global_setting', $profile
->getAppendContentTypeToTitle());
$this
->drupalGet("/admin/lingotek/settings/profile/{$profile_id}/edit");
$edit = [
'auto_upload' => FALSE,
'auto_download' => 1,
'project' => 'test_project',
'vault' => 'test_vault',
'workflow' => 'test_workflow',
'filter' => 'test_filter',
'subfilter' => 'test_filter2',
'append_type_to_title' => 'no',
];
$this
->drupalPostForm(NULL, $edit, t('Save'));
$profile = LingotekProfile::load($profile_id);
$this
->assertFalse($profile
->hasAutomaticUpload());
$this
->assertTrue($profile
->hasAutomaticDownload());
$this
->assertIdentical('no', $profile
->getAppendContentTypeToTitle());
$this
->assertIdentical('test_project', $profile
->getProject());
$this
->assertIdentical('test_vault', $profile
->getVault());
$this
->assertIdentical('test_workflow', $profile
->getWorkflow());
$this
->assertIdentical('test_filter', $profile
->getFilter());
$this
->assertIdentical('test_filter2', $profile
->getSubfilter());
$this
->drupalGet("/admin/lingotek/settings/profile/{$profile_id}/edit");
$this
->assertNoFieldChecked("edit-auto-upload");
$this
->assertFieldChecked("edit-auto-download");
$assert_session
->optionExists('edit-append-type-to-title', 'no');
$assert_session
->optionExists('edit-project', 'test_project');
$assert_session
->optionExists('edit-vault', 'test_vault');
$assert_session
->optionExists('edit-workflow', 'test_workflow');
$assert_session
->optionExists('edit-filter', 'test_filter');
$assert_session
->optionExists('edit-subfilter', 'test_filter2');
}
public function testEditingProfileInListing() {
$profile = LingotekProfile::create([
'id' => strtolower($this
->randomMachineName()),
'label' => $this
->randomString(),
]);
$profile
->save();
$profile_id = $profile
->id();
$this
->drupalGet("/admin/lingotek/settings");
$edit = [
"profile[{$profile_id}][auto_upload]" => 1,
"profile[{$profile_id}][auto_request]" => 0,
"profile[{$profile_id}][auto_download]" => 1,
];
$this
->drupalPostForm(NULL, $edit, 'Save configuration', [], 'lingotek-profile-admin-overview-form');
$profile = LingotekProfile::load($profile_id);
$this
->assertTrue($profile
->hasAutomaticUpload());
$this
->assertFalse($profile
->hasAutomaticRequest());
$this
->assertTrue($profile
->hasAutomaticDownload());
$this
->assertFieldChecked("profile[{$profile_id}][auto_upload]");
$this
->assertNoFieldChecked("profile[{$profile_id}][auto_request]");
$this
->assertFieldChecked("profile[{$profile_id}][auto_download]");
$edit = [
"profile[{$profile_id}][auto_upload]" => 1,
"profile[{$profile_id}][auto_request]" => 1,
"profile[{$profile_id}][auto_download]" => 0,
];
$this
->drupalPostForm(NULL, $edit, 'Save configuration', [], 'lingotek-profile-admin-overview-form');
$profile = LingotekProfile::load($profile_id);
$this
->assertTrue($profile
->hasAutomaticUpload());
$this
->assertTrue($profile
->hasAutomaticRequest());
$this
->assertFalse($profile
->hasAutomaticDownload());
$this
->assertFieldChecked("profile[{$profile_id}][auto_upload]");
$this
->assertFieldChecked("profile[{$profile_id}][auto_request]");
$this
->assertNoFieldChecked("profile[{$profile_id}][auto_download]");
$edit = [
"profile[{$profile_id}][auto_upload]" => 0,
"profile[{$profile_id}][auto_request]" => 1,
"profile[{$profile_id}][auto_download]" => 0,
];
$this
->drupalPostForm(NULL, $edit, 'Save configuration', [], 'lingotek-profile-admin-overview-form');
$profile = LingotekProfile::load($profile_id);
$this
->assertFalse($profile
->hasAutomaticUpload());
$this
->assertTrue($profile
->hasAutomaticRequest());
$this
->assertFalse($profile
->hasAutomaticDownload());
$this
->assertNoFieldChecked("profile[{$profile_id}][auto_upload]");
$this
->assertFieldChecked("profile[{$profile_id}][auto_request]");
$this
->assertNoFieldChecked("profile[{$profile_id}][auto_download]");
}
public function testDeletingProfile() {
$profile = LingotekProfile::create([
'id' => strtolower($this
->randomMachineName()),
'label' => $this
->randomString(),
]);
$profile
->save();
$profile_id = $profile
->id();
$this
->drupalGet("/admin/lingotek/settings/profile/{$profile_id}/delete");
$this
->assertText('This action cannot be undone.');
$this
->drupalPostForm(NULL, [], t('Delete'));
$this
->assertRaw(t('The lingotek profile %profile has been deleted.', [
'%profile' => $profile
->label(),
]));
$profile = LingotekProfile::load($profile_id);
$this
->assertNull($profile);
}
public function testDeletingProfileBeingUsedInContent() {
$profile = LingotekProfile::create([
'id' => strtolower($this
->randomMachineName()),
'label' => $this
->randomString(),
]);
$profile
->save();
$profile_id = $profile
->id();
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
ContentLanguageSettings::loadByEntityTypeBundle('node', 'article')
->setLanguageAlterable(TRUE)
->save();
\Drupal::service('content_translation.manager')
->setEnabled('node', 'article', TRUE);
$this
->saveLingotekContentTranslationSettingsForNodeTypes();
$edit = [];
$edit['title[0][value]'] = 'Llamas are cool';
$edit['body[0][value]'] = 'Llamas are very cool';
$edit['langcode[0][value]'] = 'en';
$edit['lingotek_translation_management[lingotek_translation_profile]'] = $profile_id;
$this
->saveAndPublishNodeForm($edit);
$this
->assertUrl('/node/1', [], 'Node has been created.');
$this
->drupalGet("/admin/lingotek/settings/profile/{$profile_id}/delete");
$this
->assertText(t('This action cannot be undone.'));
$this
->drupalPostForm(NULL, [], t('Delete'));
$this
->assertNoRaw(t('The lingotek profile %profile has been deleted.', [
'%profile' => $profile
->label(),
]));
$this
->assertRaw(t('The Lingotek profile %profile is being used so cannot be deleted.', [
'%profile' => $profile
->label(),
]));
$profile = LingotekProfile::load($profile_id);
$this
->assertNotNull($profile);
}
public function testDeletingProfileBeingUsedInConfigSettings() {
$profile = LingotekProfile::create([
'id' => strtolower($this
->randomMachineName()),
'label' => $this
->randomString(),
]);
$profile
->save();
$profile_id = $profile
->id();
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
$this
->goToConfigBulkManagementForm('node_type');
$edit = [
'table[article]' => TRUE,
$this
->getBulkOperationFormName() => 'change_profile:' . $profile_id,
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->drupalGet("/admin/lingotek/settings/profile/{$profile_id}/delete");
$this
->assertText(t('This action cannot be undone.'));
$this
->drupalPostForm(NULL, [], t('Delete'));
$this
->assertNoRaw(t('The lingotek profile %profile has been deleted.', [
'%profile' => $profile
->label(),
]));
$this
->assertRaw(t('The Lingotek profile %profile is being used so cannot be deleted.', [
'%profile' => $profile
->label(),
]));
$profile = LingotekProfile::load($profile_id);
$this
->assertNotNull($profile);
}
public function testDeletingProfileBeingUsedInContentSettings() {
$profile = LingotekProfile::create([
'id' => strtolower($this
->randomMachineName()),
'label' => $this
->randomString(),
]);
$profile
->save();
$profile_id = $profile
->id();
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
ContentLanguageSettings::loadByEntityTypeBundle('node', 'article')
->setLanguageAlterable(TRUE)
->save();
\Drupal::service('content_translation.manager')
->setEnabled('node', 'article', TRUE);
$this
->saveLingotekContentTranslationSettingsForNodeTypes([
'article',
], $profile_id);
$this
->drupalGet("/admin/lingotek/settings/profile/{$profile_id}/delete");
$this
->assertText(t('This action cannot be undone.'));
$this
->drupalPostForm(NULL, [], t('Delete'));
$this
->assertNoRaw(t('The lingotek profile %profile has been deleted.', [
'%profile' => $profile
->label(),
]));
$this
->assertRaw(t('The Lingotek profile %profile is being used so cannot be deleted.', [
'%profile' => $profile
->label(),
]));
$profile = LingotekProfile::load($profile_id);
$this
->assertNotNull($profile);
}
public function testProfileSettingsOverride() {
$assert_session = $this
->assertSession();
ConfigurableLanguage::createFromLangcode('es')
->setThirdPartySetting('lingotek', 'locale', 'es_MX')
->save();
ConfigurableLanguage::createFromLangcode('de')
->setThirdPartySetting('lingotek', 'locale', 'de_DE')
->save();
$profile = LingotekProfile::create([
'id' => strtolower($this
->randomMachineName()),
'label' => $this
->randomString(),
]);
$profile
->save();
$profile_id = $profile
->id();
$this
->drupalGet("/admin/lingotek/settings/profile/{$profile_id}/edit");
$assert_session
->optionExists('edit-language-overrides-es-overrides', 'default');
$assert_session
->optionExists('edit-language-overrides-en-overrides', 'default');
$edit = [
'auto_upload' => FALSE,
'auto_download' => 1,
'project' => 'default',
'vault' => 'default',
'workflow' => 'test_workflow2',
'language_overrides[es][overrides]' => 'custom',
'language_overrides[es][custom][auto_download]' => FALSE,
'language_overrides[es][custom][workflow]' => 'test_workflow',
'language_overrides[es][custom][vault]' => 'test_vault',
'language_overrides[de][overrides]' => 'custom',
'language_overrides[de][custom][auto_download]' => FALSE,
'language_overrides[de][custom][workflow]' => 'default',
'language_overrides[de][custom][vault]' => 'default',
];
$this
->drupalPostForm(NULL, $edit, t('Save'));
$profile = LingotekProfile::load($profile_id);
$this
->assertFalse($profile
->hasAutomaticUpload());
$this
->assertTrue($profile
->hasAutomaticDownload());
$this
->assertIdentical('default', $profile
->getProject());
$this
->assertIdentical('default', $profile
->getVault());
$this
->assertIdentical('test_workflow2', $profile
->getWorkflow());
$this
->assertIdentical('test_workflow', $profile
->getWorkflowForTarget('es'));
$this
->assertIdentical('default', $profile
->getWorkflowForTarget('de'));
$this
->assertIdentical('test_vault', $profile
->getVaultForTarget('es'));
$this
->assertIdentical('default', $profile
->getVaultForTarget('de'));
$this
->assertFalse($profile
->hasAutomaticDownloadForTarget('es'));
$this
->assertFalse($profile
->hasAutomaticDownloadForTarget('de'));
$this
->drupalGet("/admin/lingotek/settings/profile/{$profile_id}/edit");
$this
->assertNoFieldChecked("edit-auto-upload");
$this
->assertFieldChecked("edit-auto-download");
$assert_session
->optionExists('edit-project', 'default');
$assert_session
->optionExists('edit-vault', 'default');
$assert_session
->optionExists('edit-workflow', 'test_workflow2');
$assert_session
->optionExists('edit-language-overrides-es-overrides', 'custom');
$assert_session
->optionExists('edit-language-overrides-de-overrides', 'custom');
$assert_session
->optionExists('edit-language-overrides-en-overrides', 'default');
$this
->assertNoFieldChecked('edit-language-overrides-es-custom-auto-download');
$this
->assertNoFieldChecked('edit-language-overrides-de-custom-auto-download');
$this
->assertFieldChecked('edit-language-overrides-en-custom-auto-download');
$assert_session
->optionExists('edit-language-overrides-es-custom-workflow', 'test_workflow');
$assert_session
->optionExists('edit-language-overrides-de-custom-workflow', 'default');
$assert_session
->optionExists('edit-language-overrides-en-custom-workflow', 'default');
$selects = $this
->xpath('//details[@id="edit-language-overrides"]/*/*//select');
$this
->assertEqual(count($selects), 3 * 3, 'There are options for all the potential language overrides.');
$this
->assertEqual($selects[0]
->getAttribute('id'), 'edit-language-overrides-de-overrides', 'Languages are ordered alphabetically.');
}
public function testProfileTargetOverrideAsDisabled() {
$es = ConfigurableLanguage::createFromLangcode('es')
->setThirdPartySetting('lingotek', 'locale', 'es_MX');
$de = ConfigurableLanguage::createFromLangcode('de')
->setThirdPartySetting('lingotek', 'locale', 'de_DE');
$es
->save();
$de
->save();
$profile = LingotekProfile::create([
'id' => strtolower($this
->randomMachineName()),
'label' => $this
->randomString(),
]);
$profile
->save();
$profile_id = $profile
->id();
$this
->drupalGet("/admin/lingotek/settings/profile/{$profile_id}/edit");
$edit = [
'auto_upload' => FALSE,
'auto_download' => 1,
'project' => 'default',
'vault' => 'default',
'workflow' => 'test_workflow2',
'language_overrides[es][overrides]' => 'disabled',
'language_overrides[de][overrides]' => 'custom',
'language_overrides[de][custom][auto_request]' => TRUE,
'language_overrides[de][custom][auto_download]' => TRUE,
'language_overrides[de][custom][workflow]' => 'default',
'language_overrides[de][custom][vault]' => 'default',
];
$this
->drupalPostForm(NULL, $edit, t('Save'));
$profile = LingotekProfile::load($profile_id);
$this
->assertFalse($profile
->hasAutomaticUpload());
$this
->assertTrue($profile
->hasAutomaticDownload());
$this
->assertIdentical('default', $profile
->getProject());
$this
->assertIdentical('default', $profile
->getVault());
$this
->assertIdentical('test_workflow2', $profile
->getWorkflow());
$this
->assertIdentical(NULL, $profile
->getWorkflowForTarget('es'));
$this
->assertIdentical(NULL, $profile
->getVaultForTarget('es'));
$this
->assertTrue($profile
->hasDisabledTarget('es'));
$this
->assertFalse($profile
->hasAutomaticRequestForTarget('es'));
$this
->assertTrue($profile
->hasAutomaticRequestForTarget('de'));
$this
->assertFalse($profile
->hasAutomaticDownloadForTarget('es'));
$this
->assertTrue($profile
->hasAutomaticDownloadForTarget('de'));
}
public function testLanguageDisabled() {
$assert_session = $this
->assertSession();
$configLingotek = \Drupal::service('lingotek.configuration');
$es = ConfigurableLanguage::createFromLangcode('es')
->setThirdPartySetting('lingotek', 'locale', 'es_MX');
$de = ConfigurableLanguage::createFromLangcode('de')
->setThirdPartySetting('lingotek', 'locale', 'de_DE');
$es
->save();
$de
->save();
$profile = LingotekProfile::create([
'id' => strtolower($this
->randomMachineName()),
'label' => $this
->randomString(),
]);
$profile
->save();
$profile_id = $profile
->id();
$this
->drupalGet("/admin/lingotek/settings/profile/{$profile_id}/edit");
$this
->assertFieldByName('language_overrides[es][overrides]');
$assert_session
->optionExists('edit-language-overrides-de-overrides', 'default');
$assert_session
->optionExists('edit-language-overrides-de-overrides', 'default');
$configLingotek
->disableLanguage($es);
$this
->drupalGet("/admin/lingotek/settings/profile/{$profile_id}/edit");
$this
->assertNoFieldByName('language_overrides[es][overrides]');
$assert_session
->optionExists('edit-language-overrides-de-overrides', 'default');
$configLingotek
->enableLanguage($es);
$this
->drupalGet("/admin/lingotek/settings/profile/{$profile_id}/edit");
$this
->assertFieldByName('language_overrides[es][overrides]');
$assert_session
->optionExists('edit-language-overrides-es-overrides', 'default');
$assert_session
->optionExists('edit-language-overrides-de-overrides', 'default');
}
public function testIntelligenceOverrideDefaults() {
$this
->drupalGet('admin/lingotek/settings');
$this
->clickLink(t('Add new Translation Profile'));
$this
->assertNoFieldChecked('edit-intelligence-metadata-overrides-override');
$this
->assertIntelligenceFieldDefaults();
}
public function testEnableIntelligenceOverride() {
$assert_session = $this
->assertSession();
$this
->drupalGet('admin/lingotek/settings');
$this
->clickLink(t('Add new Translation Profile'));
$profile_id = strtolower($this
->randomMachineName());
$profile_name = $this
->randomString();
$edit = [
'id' => $profile_id,
'label' => $profile_name,
'auto_upload' => 1,
'auto_download' => 1,
'intelligence_metadata_overrides[override]' => 1,
'intelligence_metadata[use_author]' => 1,
'intelligence_metadata[use_author_email]' => 1,
'intelligence_metadata[use_contact_email_for_author]' => FALSE,
'intelligence_metadata[use_business_unit]' => 1,
'intelligence_metadata[use_business_division]' => 1,
'intelligence_metadata[use_campaign_id]' => 1,
'intelligence_metadata[use_campaign_rating]' => 1,
'intelligence_metadata[use_channel]' => 1,
'intelligence_metadata[use_contact_name]' => 1,
'intelligence_metadata[use_contact_email]' => 1,
'intelligence_metadata[use_content_description]' => 1,
'intelligence_metadata[use_external_style_id]' => 1,
'intelligence_metadata[use_purchase_order]' => 1,
'intelligence_metadata[use_region]' => 1,
'intelligence_metadata[use_base_domain]' => 1,
'intelligence_metadata[use_reference_url]' => 1,
'intelligence_metadata[default_author_email]' => 'test@example.com',
'intelligence_metadata[business_unit]' => 'Test Business Unit',
'intelligence_metadata[business_division]' => 'Test Business Division',
'intelligence_metadata[campaign_id]' => 'Campaign ID',
'intelligence_metadata[campaign_rating]' => 5,
'intelligence_metadata[channel]' => 'Channel Test',
'intelligence_metadata[contact_name]' => 'Test Contact Name',
'intelligence_metadata[contact_email]' => 'contact@example.com',
'intelligence_metadata[content_description]' => 'Content description',
'intelligence_metadata[external_style_id]' => 'my-style-id',
'intelligence_metadata[purchase_order]' => 'PO32',
'intelligence_metadata[region]' => 'region2',
];
$this
->drupalPostForm(NULL, $edit, t('Save'));
$this
->assertText(t('The Lingotek profile has been successfully saved.'));
$assert_session
->linkByHrefExists("/admin/lingotek/settings/profile/{$profile_id}/edit");
$this
->assertFieldChecked("edit-profile-{$profile_id}-auto-upload");
$this
->assertFieldChecked("edit-profile-{$profile_id}-auto-download");
$this
->assertFieldEnabled("edit-profile-{$profile_id}-auto-upload");
$this
->assertFieldEnabled("edit-profile-{$profile_id}-auto-download");
$this
->drupalGet("/admin/lingotek/settings/profile/{$profile_id}/edit");
$this
->assertFieldChecked('edit-intelligence-metadata-overrides-override');
$this
->assertNoFieldChecked('edit-intelligence-metadata-use-contact-email-for-author');
$this
->assertFieldByName('intelligence_metadata[default_author_email]', 'test@example.com');
$this
->assertFieldByName('intelligence_metadata[business_unit]', 'Test Business Unit');
$this
->assertFieldByName('intelligence_metadata[business_division]', 'Test Business Division');
$this
->assertFieldByName('intelligence_metadata[campaign_id]', 'Campaign ID');
$this
->assertFieldByName('intelligence_metadata[campaign_rating]', 5);
$this
->assertFieldByName('intelligence_metadata[channel]', 'Channel Test');
$this
->assertFieldByName('intelligence_metadata[contact_name]', 'Test Contact Name');
$this
->assertFieldByName('intelligence_metadata[contact_email]', 'contact@example.com');
$this
->assertFieldByName('intelligence_metadata[content_description]', 'Content description');
$this
->assertFieldByName('intelligence_metadata[external_style_id]', 'my-style-id');
$this
->assertFieldByName('intelligence_metadata[purchase_order]', 'PO32');
$this
->assertFieldByName('intelligence_metadata[region]', 'region2');
$profile = LingotekProfile::load($profile_id);
$this
->assertTrue($profile
->hasAutomaticUpload());
$this
->assertTrue($profile
->hasAutomaticDownload());
$this
->assertIdentical('default', $profile
->getProject());
$this
->assertIdentical('default', $profile
->getVault());
$this
->assertIdentical('default', $profile
->getWorkflow());
$this
->assertTrue($profile
->hasIntelligenceMetadataOverrides());
$this
->assertTrue($profile
->getAuthorPermission());
$this
->assertTrue($profile
->getAuthorEmailPermission());
$this
->assertEmpty($profile
->getContactEmailForAuthorPermission());
$this
->assertTrue($profile
->getBusinessUnitPermission());
$this
->assertTrue($profile
->getBusinessDivisionPermission());
$this
->assertTrue($profile
->getCampaignIdPermission());
$this
->assertTrue($profile
->getCampaignRatingPermission());
$this
->assertTrue($profile
->getChannelPermission());
$this
->assertTrue($profile
->getContactNamePermission());
$this
->assertTrue($profile
->getContactEmailPermission());
$this
->assertTrue($profile
->getContentDescriptionPermission());
$this
->assertTrue($profile
->getExternalStyleIdPermission());
$this
->assertTrue($profile
->getPurchaseOrderPermission());
$this
->assertTrue($profile
->getRegionPermission());
$this
->assertTrue($profile
->getBaseDomainPermission());
$this
->assertTrue($profile
->getReferenceUrlPermission());
$this
->assertIdentical($profile
->getDefaultAuthorEmail(), 'test@example.com');
$this
->assertIdentical($profile
->getBusinessUnit(), 'Test Business Unit');
$this
->assertIdentical($profile
->getBusinessDivision(), 'Test Business Division');
$this
->assertIdentical($profile
->getCampaignId(), 'Campaign ID');
$this
->assertIdentical($profile
->getCampaignRating(), 5);
$this
->assertIdentical($profile
->getChannel(), 'Channel Test');
$this
->assertIdentical($profile
->getContactName(), 'Test Contact Name');
$this
->assertIdentical($profile
->getContactEmail(), 'contact@example.com');
$this
->assertIdentical($profile
->getContentDescription(), 'Content description');
$this
->assertIdentical($profile
->getExternalStyleId(), 'my-style-id');
$this
->assertIdentical($profile
->getPurchaseOrder(), 'PO32');
$this
->assertIdentical($profile
->getRegion(), 'region2');
}
public function testFilters() {
$assert_session = $this
->assertSession();
$this
->drupalGet('admin/lingotek/settings');
$this
->clickLink(t('Add new Translation Profile'));
$this
->assertFieldByName('filter');
$this
->assertFieldByName('subfilter');
$assert_session
->optionExists('edit-filter', 'default');
$assert_session
->optionExists('edit-filter', 'project_default');
$assert_session
->optionExists('edit-filter', 'drupal_default');
$assert_session
->optionExists('edit-filter', 'test_filter');
$assert_session
->optionExists('edit-filter', 'test_filter2');
$assert_session
->optionExists('edit-filter', 'test_filter3');
$assert_session
->optionExists('edit-subfilter', 'default');
$assert_session
->optionExists('edit-subfilter', 'project_default');
$assert_session
->optionExists('edit-subfilter', 'drupal_default');
$assert_session
->optionExists('edit-subfilter', 'test_filter');
$assert_session
->optionExists('edit-subfilter', 'test_filter2');
$assert_session
->optionExists('edit-subfilter', 'test_filter3');
}
public function testNoFilters() {
$assert_session = $this
->assertSession();
\Drupal::configFactory()
->getEditable('lingotek.settings')
->set('account.resources.filter', [])
->save();
$this
->drupalGet('admin/lingotek/settings');
$this
->clickLink(t('Add new Translation Profile'));
$this
->assertFieldByName('filter');
$option_field = $assert_session
->optionExists('edit-filter', 'drupal_default');
$this
->assertTrue($option_field
->hasAttribute('selected'));
$assert_session
->optionExists('edit-filter', 'default');
$assert_session
->optionExists('edit-filter', 'project_default');
$assert_session
->optionNotExists('edit-filter', 'test_filter');
$assert_session
->optionNotExists('edit-filter', 'test_filter2');
$this
->assertFieldByName('subfilter');
$option_field = $assert_session
->optionExists('edit-subfilter', 'drupal_default');
$this
->assertTrue($option_field
->hasAttribute('selected'));
$assert_session
->optionExists('edit-subfilter', 'default');
$assert_session
->optionExists('edit-subfilter', 'project_default');
$assert_session
->optionNotExists('edit-subfilter', 'test_filter');
$assert_session
->optionNotExists('edit-subfilter', 'test_filter2');
}
protected function assertFieldDisabled($id, $message = '') {
$elements = $this
->xpath('//input[@id=:id]', [
':id' => $id,
]);
return $this
->assertTrue(isset($elements[0]) && !empty($elements[0]
->getAttribute('disabled')), $message ? $message : t('Field @id is disabled.', [
'@id' => $id,
]), t('Browser'));
}
protected function assertFieldEnabled($id, $message = '') {
$elements = $this
->xpath('//input[@id=:id]', [
':id' => $id,
]);
return $this
->assertTrue(isset($elements[0]) && empty($elements[0]
->getAttribute('disabled')), $message ? $message : t('Field @id is enabled.', [
'@id' => $id,
]), t('Browser'));
}
protected function setupResources() {
$config = \Drupal::configFactory()
->getEditable('lingotek.settings');
$config
->set('account.resources.community', [
'test_community' => 'Test community',
'test_community2' => 'Test community 2',
]);
$config
->set('account.resources.project', [
'test_project' => 'Test project',
'test_project2' => 'Test project 2',
]);
$config
->set('account.resources.vault', [
'test_vault' => 'Test vault',
'test_vault2' => 'Test vault 2',
]);
$config
->set('account.resources.workflow', [
'test_workflow' => 'Test workflow',
'test_workflow2' => 'Test workflow 2',
]);
$config
->set('account.resources.filter', [
'test_filter' => 'Test filter',
'test_filter2' => 'Test filter 2',
'test_filter3' => 'Test filter 3',
]);
$config
->save();
}
}