'Entity Source List tests', 'description' => 'Tests the user interface for entity translation lists.', 'group' => 'Translation Management', ); } function setUp() { parent::setUp(array('tmgmt_entity_ui', 'translation', 'comment', 'taxonomy')); $this->loginAsAdmin(array('administer entity translation')); $this->setEnvironment('de'); $this->setEnvironment('fr'); // Enable entity translations for nodes and comments. $edit = array(); $edit['entity_translation_entity_types[comment]'] = 1; $edit['entity_translation_entity_types[node]'] = 1; $edit['entity_translation_entity_types[taxonomy_term]'] = 1; $this->drupalPost('admin/config/regional/entity_translation', $edit, t('Save configuration')); $this->createNodeType('article', 'Article', ENTITY_TRANSLATION_ENABLED); $this->createNodeType('page', 'Page', TRANSLATION_ENABLED); // Create nodes that will be used during tests. // NOTE that the order matters as results are read by xpath based on // position in the list. $this->nodes['page']['en'][] = $this->createNode('page'); $this->nodes['article']['de'][0] = $this->createNode('article', 'de'); $this->nodes['article']['fr'][0] = $this->createNode('article', 'fr'); $this->nodes['article']['en'][3] = $this->createNode('article', 'en'); $this->nodes['article']['en'][2] = $this->createNode('article', 'en'); $this->nodes['article']['en'][1] = $this->createNode('article', 'en'); $this->nodes['article']['en'][0] = $this->createNode('article', 'en'); } /** * Tests that the term bundle filter works. */ function testTermBundleFilter() { $vocabulary1 = entity_create('taxonomy_vocabulary', array( 'machine_name' => 'vocab1', 'name' => $this->randomName(), )); taxonomy_vocabulary_save($vocabulary1); $term1 = entity_create('taxonomy_term', array( 'name' => $this->randomName(), 'vid' => $vocabulary1->vid, )); taxonomy_term_save($term1); $vocabulary2 = (object) array( 'machine_name' => 'vocab2', 'name' => $this->randomName(), ); taxonomy_vocabulary_save($vocabulary2); $term2 = entity_create('taxonomy_term', array( 'name' => $this->randomName(), 'vid' => $vocabulary2->vid, )); taxonomy_term_save($term2); $this->drupalGet('admin/tmgmt/sources/entity_taxonomy_term'); // Both terms should be displayed with their bundle. $this->assertText($term1->name); $this->assertText($term2->name); $this->assertTrue($this->xpath('//td[text()=@vocabulary]', array('@vocabulary' => $vocabulary1->name))); $this->assertTrue($this->xpath('//td[text()=@vocabulary]', array('@vocabulary' => $vocabulary2->name))); // Limit to the first vocabulary. $edit = array(); $edit['search[vocabulary_machine_name]'] = $vocabulary1->machine_name; $this->drupalPost(NULL, $edit, t('Search')); // Only term 1 should be displayed now. $this->assertText($term1->name); $this->assertNoText($term2->name); $this->assertTrue($this->xpath('//td[text()=@vocabulary]', array('@vocabulary' => $vocabulary1->name))); $this->assertFalse($this->xpath('//td[text()=@vocabulary]', array('@vocabulary' => $vocabulary2->name))); } function testAvailabilityOfEntityLists() { $this->drupalGet('admin/tmgmt/sources/entity_comment'); // Check if we are at comments page. $this->assertText(t('Comment overview (Entity)')); // No comments yet - empty message is expected. $this->assertText(t('No entities matching given criteria have been found.')); $this->drupalGet('admin/tmgmt/sources/entity_node'); // Check if we are at nodes page. $this->assertText(t('Node overview (Entity)')); // We expect article title as article node type is entity translatable. $this->assertText($this->nodes['article']['en'][0]->title); // Page node type should not be listed as it is not entity translatable. $this->assertNoText($this->nodes['page']['en'][0]->title); } function testTranslationStatuses() { // Test statuses: Source, Missing. $this->drupalGet('admin/tmgmt/sources/entity_node'); $langstatus_en = $this->xpath('//table[@id="tmgmt-entities-list"]/tbody/tr[1]/td[@class="langstatus-en"]'); $langstatus_de = $this->xpath('//table[@id="tmgmt-entities-list"]/tbody/tr[1]/td[@class="langstatus-de"]'); $this->assertEqual($langstatus_en[0]->div['title'], t('Source language')); $this->assertEqual($langstatus_de[0]->div['title'], t('Not translated')); // Test status: Active job item. $job = $this->createJob('en', 'de'); $job->translator = $this->default_translator->name; $job->settings = array(); $job->save(); $job->addItem('entity', 'node', $this->nodes['article']['en'][0]->nid); $job->requestTranslation(); $this->drupalGet('admin/tmgmt/sources/entity_node'); $langstatus_de = $this->xpath('//table[@id="tmgmt-entities-list"]/tbody/tr[1]/td[@class="langstatus-de"]/a'); $items = $job->getItems(); $wrapper = entity_metadata_wrapper('tmgmt_job_item', array_shift($items)); $label = t('Active job item: @state', array('@state' => $wrapper->state->label())); $this->assertEqual($langstatus_de[0]->div['title'], $label); // Test status: Current foreach ($job->getItems() as $job_item) { $job_item->acceptTranslation(); } $this->drupalGet('admin/tmgmt/sources/entity_node'); $langstatus_de = $this->xpath('//table[@id="tmgmt-entities-list"]/tbody/tr[1]/td[@class="langstatus-de"]'); $this->assertEqual($langstatus_de[0]->div['title'], t('Translation up to date')); } function testTranslationSubmissions() { // Simple submission. $nid = $this->nodes['article']['en'][0]->nid; $edit = array(); $edit["items[$nid]"] = 1; $this->drupalPost('admin/tmgmt/sources/entity_node', $edit, t('Request translation')); $this->assertText(t('One job needs to be checked out.')); // Submission of two entities of the same source language. $nid1 = $this->nodes['article']['en'][0]->nid; $nid2 = $this->nodes['article']['en'][1]->nid; $edit = array(); $edit["items[$nid1]"] = 1; $edit["items[$nid2]"] = 1; $this->drupalPost('admin/tmgmt/sources/entity_node', $edit, t('Request translation')); $this->assertText(t('One job needs to be checked out.')); // Submission of several entities of different source languages. $nid1 = $this->nodes['article']['en'][0]->nid; $nid2 = $this->nodes['article']['en'][1]->nid; $nid3 = $this->nodes['article']['en'][2]->nid; $nid4 = $this->nodes['article']['en'][3]->nid; $nid5 = $this->nodes['article']['de'][0]->nid; $nid6 = $this->nodes['article']['fr'][0]->nid; $edit = array(); $edit["items[$nid1]"] = 1; $edit["items[$nid2]"] = 1; $edit["items[$nid3]"] = 1; $edit["items[$nid4]"] = 1; $edit["items[$nid5]"] = 1; $edit["items[$nid6]"] = 1; $this->drupalPost('admin/tmgmt/sources/entity_node', $edit, t('Request translation')); $this->assertText(t('@count jobs need to be checked out.', array('@count' => '3'))); } function testNodeEntityListings() { // Turn off the entity translation. $edit = array(); $edit['language_content_type'] = TRANSLATION_ENABLED; $this->drupalPost('admin/structure/types/manage/article', $edit, t('Save content type')); // Check if we have appropriate message in case there are no entity // translatable content types. $this->drupalGet('admin/tmgmt/sources/entity_node'); $this->assertText(t('Entity translation is not enabled for any of existing content types. To use this functionality go to Content types administration and enable entity translation for desired content types.')); // Turn on the entity translation for both - article and page - to test // search form. $edit = array(); $edit['language_content_type'] = ENTITY_TRANSLATION_ENABLED; $this->drupalPost('admin/structure/types/manage/article', $edit, t('Save content type')); $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type')); // Create page node after entity translation is enabled. $page_node_translatable = $this->createNode('page'); $this->drupalGet('admin/tmgmt/sources/entity_node'); // We have both listed - one of articles and page. $this->assertText($this->nodes['article']['en'][0]->title); $this->assertText($page_node_translatable->title); // Try the search by content type. $edit = array(); $edit['search[type]'] = 'article'; $this->drupalPost('admin/tmgmt/sources/entity_node', $edit, t('Search')); // There should be article present. $this->assertText($this->nodes['article']['en'][0]->title); // The page node should not be listed. $this->assertNoText($page_node_translatable->title); // Try cancel button - despite we do post content type search value // we should get nodes of botch content types. $this->drupalPost('admin/tmgmt/sources/entity_node', $edit, t('Cancel')); $this->assertText($this->nodes['article']['en'][0]->title); $this->assertText($page_node_translatable->title); } function testEntitySourceListSearch() { // We need a node with title composed of several words to test // "any words" search. $title_part_1 = $this->randomName('4'); $title_part_2 = $this->randomName('4'); $title_part_3 = $this->randomName('4'); $this->nodes['article']['en'][0]->title = "$title_part_1 $title_part_2 $title_part_3"; node_save($this->nodes['article']['en'][0]); // Submit partial node title and see if we have a result. $edit = array(); $edit['search[title]'] = "$title_part_1 $title_part_3"; $this->drupalPost('admin/tmgmt/sources/entity_node', $edit, t('Search')); $this->assertText("$title_part_1 $title_part_2 $title_part_3", 'Searching on partial node title must return the result.'); // Check if there is only one result in the list. $search_result_rows = $this->xpath('//table[@id="tmgmt-entities-list"]/tbody/tr'); $this->assert(count($search_result_rows) == 1, 'The search result must return only one row.'); // To test if other entity types work go for simple comment search. $comment = new stdClass(); $comment->comment_body[LANGUAGE_NONE][0]['value'] = $this->randomName(); $comment->subject = $this->randomName(); // We need to associate the comment with entity translatable node object. $comment->nid = $this->nodes['article']['en'][0]->nid; // Set defaults - without these we will get Undefined property notices. $comment->is_anonymous = TRUE; $comment->cid = 0; $comment->pid = 0; $comment->uid = 0; // Will add further comment variables. $comment = comment_submit($comment); comment_save($comment); // Do search for the comment. $edit = array(); $edit['search[subject]'] = $comment->subject; $this->drupalPost('admin/tmgmt/sources/entity_comment', $edit, t('Search')); $this->assertText($comment->subject, 'Searching for a comment subject.'); } }