diff --git a/src/Tests/LingotekIntelligenceMetadataTranslationTest.php b/src/Tests/LingotekIntelligenceMetadataTranslationTest.php index f628eb7..7132c68 100644 --- a/src/Tests/LingotekIntelligenceMetadataTranslationTest.php +++ b/src/Tests/LingotekIntelligenceMetadataTranslationTest.php @@ -233,6 +233,65 @@ class LingotekIntelligenceMetadataTranslationTest extends LingotekTestBase { $this->assertIdentical($data['_lingotek_metadata']['_api_data_region'], 'region2'); } + public function testUploadNodeWithContactEmailAsAuthorSetting() { + $domain = \Drupal::request()->getSchemeAndHttpHost(); + + $this->setupGeneralIntelligenceSettings(); + $this->setupContactEmailForAuthorIntelligenceSettings(); + + // Create a node. + $edit = []; + $edit['title[0][value]'] = 'Llamas are cool'; + $edit['body[0][value]'] = 'Llamas are very cool'; + $edit['langcode[0][value]'] = 'en'; + + $this->saveAndPublishNodeForm($edit); + + $this->node = Node::load(1); + + // Check that the translate tab is in the node. + $this->drupalGet('node/1'); + $this->clickLink('Translate'); + + // Check that only the configured fields have been uploaded. + $data = json_decode(\Drupal::state() + ->get('lingotek.uploaded_content', '[]'), TRUE); + $this->assertUploadedDataFieldCount($data, 2); + $this->assertTrue(isset($data['title'][0]['value'])); + $this->assertEqual(1, count($data['body'][0])); + $this->assertTrue(isset($data['body'][0]['value'])); + $this->assertIdentical('en_US', \Drupal::state() + ->get('lingotek.uploaded_locale')); + + // Check that the profile used was the right one. + $used_profile = \Drupal::state()->get('lingotek.used_profile'); + $this->assertIdentical('automatic', $used_profile, 'The automatic profile was used.'); + + $this->assertEqual(20, count($data['_lingotek_metadata'])); + $this->assertIdentical($data['_lingotek_metadata']['_entity_id'], '1'); + $this->assertIdentical($data['_lingotek_metadata']['_entity_revision'], '1'); + $this->assertIdentical($data['_lingotek_metadata']['_entity_type_id'], 'node'); + + $this->assertIdentical($data['_lingotek_metadata']['_api_data_external_document_id'], '1'); + $this->assertIdentical($data['_lingotek_metadata']['_api_data_content_type'], 'node'); + $this->assertIdentical($data['_lingotek_metadata']['_api_data_domain'], $domain); + $this->assertIdentical($data['_lingotek_metadata']['_api_data_reference_url'], $this->node->toUrl()->setAbsolute(TRUE)->toString()); + $this->assertIdentical($data['_lingotek_metadata']['_api_data_author_name'], 'admin'); + $this->assertIdentical($data['_lingotek_metadata']['_api_data_author_email'], 'general@example.com'); + $this->assertIdentical($data['_lingotek_metadata']['_api_data_business_unit'], 'General Business Unit'); + $this->assertIdentical($data['_lingotek_metadata']['_api_data_business_division'], 'General Business Division'); + $this->assertIdentical($data['_lingotek_metadata']['_api_data_campaign_id'], 'General Campaign ID'); + $this->assertIdentical($data['_lingotek_metadata']['_api_data_campaign_rating'], 3); + $this->assertIdentical($data['_lingotek_metadata']['_api_data_channel'], 'General Channel Test'); + $this->assertIdentical($data['_lingotek_metadata']['_api_data_contact_name'], 'General Test Contact Name'); + $this->assertIdentical($data['_lingotek_metadata']['_api_data_contact_email'], 'general@example.com'); + $this->assertIdentical($data['_lingotek_metadata']['_api_data_content_description'], 'General Content description'); + $this->assertIdentical($data['_lingotek_metadata']['_api_data_external_style_id'], 'general-my-style-id'); + $this->assertIdentical($data['_lingotek_metadata']['_api_data_purchase_order'], 'General PO32'); + $this->assertIdentical($data['_lingotek_metadata']['_api_data_region'], 'region2'); + } + + public function testUploadNodeWithProfileOverride() { $domain = \Drupal::request()->getSchemeAndHttpHost(); @@ -359,7 +418,6 @@ class LingotekIntelligenceMetadataTranslationTest extends LingotekTestBase { } protected function setupGeneralIntelligenceSettings() { - // Check we can store the values. $edit = [ 'intelligence_metadata[use_author]' => 1, 'intelligence_metadata[use_author_email]' => 1, @@ -393,4 +451,11 @@ class LingotekIntelligenceMetadataTranslationTest extends LingotekTestBase { $this->drupalPostForm(NULL, $edit, 'Save Lingotek Intelligence Metadata', [], [], 'lingotekintelligence-metadata-form'); } + protected function setupContactEmailForAuthorIntelligenceSettings() { + $edit = [ + 'intelligence_metadata[use_contact_email_for_author]' => TRUE, + ]; + $this->drupalPostForm(NULL, $edit, 'Save Lingotek Intelligence Metadata', [], [], 'lingotekintelligence-metadata-form'); + } + }