/** * Tests of the job item review process. */ public function testProgress() { // Test that there are no jobs at the beginning. $this->drupalGet('admin/tmgmt/jobs'); $this->assertText('No jobs available.'); // Create Jobs. $job1 = $this->createJob(); $job1->save(); $job1->setState(Job::STATE_UNPROCESSED); $job2 = $this->createJob(); $job2->save(); $job2->setState(Job::STATE_ACTIVE); $job3 = $this->createJob(); $job3->save(); $job3->setState(Job::STATE_REJECTED); $job4 = $this->createJob(); $job4->save(); $job4->setState(Job::STATE_ABORTED); $job5 = $this->createJob(); $job5->save(); $job5->setState(Job::STATE_FINISHED); // Test their icons. $this->drupalGet('admin/tmgmt/jobs', array('query' => array('state' => 'All'))); $this->assertEqual(count($this->xpath('//tbody/tr')), 5); $this->assertJobStateIcon(1, 'Unprocessed'); $this->assertJobStateIcon(2, 'In progress'); $this->assertJobStateIcon(3, 'Rejected'); $this->assertJobStateIcon(4, 'Aborted'); $this->assertJobStateIcon(5, 'Finished'); // Test the row amount for each state selected. $this->drupalGet('admin/tmgmt/jobs', array('query' => array('state' => 'open_jobs'))); $this->assertEqual(count($this->xpath('//tbody/tr')), 3); $this->drupalGet('admin/tmgmt/jobs', array('query' => array('state' => '0'))); $this->assertEqual(count($this->xpath('//tbody/tr')), 1); $this->drupalGet('admin/tmgmt/jobs', array('query' => array('state' => 'in_progress'))); $this->assertEqual(count($this->xpath('//tbody/tr')), 1); $this->drupalGet('admin/tmgmt/jobs', array('query' => array('state' => '2'))); $this->assertEqual(count($this->xpath('//tbody/tr')), 1); $this->drupalGet('admin/tmgmt/jobs', array('query' => array('state' => '4'))); $this->assertEqual(count($this->xpath('//tbody/tr')), 1); $this->drupalGet('admin/tmgmt/jobs', array('query' => array('state' => '5'))); $this->assertEqual(count($this->xpath('//tbody/tr')), 1); \Drupal::state()->set('tmgmt.test_source_data', array('title' => array('deep_nesting' => array('#text' => '<p><em><strong>Six dummy HTML tags in the title.</strong></em></p>', '#label' => 'Title')), 'body' => array('deep_nesting' => array('#text' => '<p>Two dummy HTML tags in the body.</p>', '#label' => 'Body')))); // Add 2 items to job1 and submit it to provider. $item1 = $job1->addItem('test_source', 'test', 1); $job1->addItem('test_source', 'test', 2); $redirects = tmgmt_job_checkout_multiple(array($job1)); $this->drupalGet(reset($redirects)); $this->drupalGet('admin/tmgmt/job_items', array('query' => array('state' => '2'))); $this->assertEqual(count($this->xpath('//tbody/tr')), 2); $this->assertJobItemOverviewStateIcon(1, 'Inactive'); $this->assertLink($job1->label()); $this->drupalGet('admin/tmgmt/jobs/1'); $edit = array('target_language' => 'de', 'settings[action]' => 'submit'); $this->drupalPostForm(NULL, $edit, t('Submit to provider')); // Translate body of one item. $this->drupalGet('admin/tmgmt/items/' . $item1->id()); $this->drupalPostForm(NULL, array('body|deep_nesting[translation]' => 'translation'), t('Save')); // Check job item state is still in progress. $this->assertJobItemStateIcon(1, 'In progress'); $this->drupalGet('admin/tmgmt/job_items', array('query' => array('state' => '3'))); $this->assertEqual(count($this->xpath('//tbody/tr')), 2); $this->assertJobItemOverviewStateIcon(1, 'In progress'); $this->drupalGet('admin/tmgmt/jobs', array('query' => array('state' => 'in_progress'))); // Check progress bar and icon. $this->assertJobProgress(1, 3, 1, 0, 0); $this->assertJobStateIcon(1, 'In progress'); // Translate title of one item. $this->drupalGet('admin/tmgmt/items/' . $item1->id()); $this->drupalPostForm(NULL, array('title|deep_nesting[translation]' => 'translation'), t('Save')); // Check job item state changed to needs review. $this->assertJobItemStateIcon(1, 'Needs review'); $this->drupalGet('admin/tmgmt/job_items', array('query' => array('state' => '4'))); $this->assertEqual(count($this->xpath('//tbody/tr')), 1); $this->assertJobItemOverviewStateIcon(1, 'Needs review'); // Check exposed filter for needs review. $this->drupalGet('admin/tmgmt/jobs', array('query' => array('state' => 'needs_review'))); $this->assertEqual(count($this->xpath('//tbody/tr')), 1); // Check progress bar and icon. $this->assertJobProgress(1, 2, 2, 0, 0); $this->assertJobStateIcon(1, 'Needs review'); // Review the translation one by one. $this->drupalPostAjaxForm('admin/tmgmt/items/' . $item1->id(), NULL, 'reviewed-body|deep_nesting'); $this->drupalGet('admin/tmgmt/jobs/' . $job1->id()); // Check the icon of the job item. $this->assertJobItemStateIcon(1, 'Needs review'); $this->drupalPostAjaxForm('admin/tmgmt/items/' . $item1->id(), NULL, 'reviewed-title|deep_nesting'); $this->drupalGet('admin/tmgmt/jobs/' . $job1->id()); // Check the icon of the job item. $this->assertJobItemStateIcon(1, 'Needs review'); $this->drupalGet('admin/tmgmt/jobs', array('query' => array('state' => 'open_jobs'))); // Check progress bar and icon. $this->assertJobProgress(1, 2, 0, 2, 0); $this->assertJobStateIcon(1, 'Needs review'); // Save one job item as completed. $this->drupalPostForm('admin/tmgmt/items/' . $item1->id(), NULL, t('Save as completed')); // Check job item state changed to accepted. $this->assertJobItemStateIcon(1, 'Accepted'); $this->drupalGet('admin/tmgmt/job_items', array('query' => array('state' => '5'))); $this->assertEqual(count($this->xpath('//tbody/tr')), 1); $this->assertJobItemOverviewStateIcon(1, 'Accepted'); $this->drupalGet('admin/tmgmt/jobs', array('query' => array('state' => 'open_jobs'))); // Check progress bar and icon. $this->assertJobProgress(1, 2, 0, 0, 2); $this->assertJobStateIcon(1, 'In progress'); // Assert the legend. $this->drupalGet('admin/tmgmt/items/' . $item1->id()); $this->assertRaw('class="tmgmt-color-legend'); }
/** * {@inheritdoc} */ public function overviewFormSubmit(array $form, FormStateInterface $form_state, $type) { // Handle search redirect. if ($this->overviewSearchFormRedirect($form, $form_state, $type)) { return; } $jobs = array(); $items = array(); if ($type == ConfigSource::SIMPLE_CONFIG) { foreach (array_filter($form_state->getValue('items')) as $item) { $definition = \Drupal::service('plugin.manager.config_translation.mapper')->getDefinition($item); $item_id = $definition['id']; $items[$item_id]['label'] = $definition['title']; $items[$item_id]['langcode'] = \Drupal::config($definition['names'][0])->get('langcode') ?: 'en'; $items[$item_id]['type'] = $type; } } else { $entity_type = \Drupal::entityManager()->getDefinition($type); $entity_ids = str_replace($entity_type->getConfigPrefix() . '.', '', array_filter($form_state->getValue('items'))); $entities = entity_load_multiple($type, $entity_ids); foreach ($entities as $entity) { /* @var $entity \Drupal\Core\Entity\EntityInterface */ $item_id = $entity->getConfigDependencyName(); $items[$item_id]['label'] = $entity->label(); $items[$item_id]['langcode'] = $entity->language()->getId(); // The type cannot be field_config, should be the id of the // fieldable entity type. if ($type == 'field_config') { $items[$item_id]['type'] = $entity->get('entity_type') . '_fields'; } else { $items[$item_id]['type'] = $type; } } } $source_lang_registry = array(); // Loop through entities and create individual jobs for each source language. foreach ($items as $id => $extra) { $source_lang = $extra['langcode']; try { // For given source lang no job exists yet. if (!isset($source_lang_registry[$source_lang])) { // Create new job. $job = tmgmt_job_create($source_lang, LanguageInterface::LANGCODE_NOT_SPECIFIED, \Drupal::currentUser()->id()); // Add initial job item. $job->addItem('config', $extra['type'], $id); // Add job identifier into registry $source_lang_registry[$source_lang] = $job->id(); // Add newly created job into jobs queue. $jobs[$job->id()] = $job; } else { $jobs[$source_lang_registry[$source_lang]]->addItem('config', $extra['type'], $id); } } catch (TMGMTException $e) { watchdog_exception('tmgmt', $e); drupal_set_message($this->t('Unable to add job item for entity %name: %error.', array('%name' => $extra['label'], '%error' => $e->getMessage())), 'error'); } } // If necessary, do a redirect. $redirects = tmgmt_job_checkout_multiple($jobs); if ($redirects) { tmgmt_redirect_queue_set($redirects, Url::fromRoute('<current>')->getInternalPath()); $form_state->setRedirectUrl(Url::fromUri('base:' . tmgmt_redirect_queue_dequeue())); drupal_set_message(\Drupal::translation()->formatPlural(count($redirects), $this->t('One job needs to be checked out.'), $this->t('@count jobs need to be checked out.'))); } }
/** * {@inheritdoc} */ public function overviewFormSubmit(array $form, FormStateInterface $form_state, $type) { // Handle search redirect. if ($this->overviewSearchFormRedirect($form, $form_state, $type)) { return; } $jobs = array(); $entities = entity_load_multiple($type, $form_state->getValue('items')); $source_lang_registry = array(); // Loop through entities and create individual jobs for each source language. foreach ($entities as $entity) { /* @var $entity \Drupal\Core\Entity\EntityInterface */ $source_lang = $entity->language()->getId(); try { // For given source lang no job exists yet. if (!isset($source_lang_registry[$source_lang])) { // Create new job. $job = tmgmt_job_create($source_lang, LanguageInterface::LANGCODE_NOT_SPECIFIED, \Drupal::currentUser()->id()); // Add initial job item. $job->addItem('content', $type, $entity->id()); // Add job identifier into registry $source_lang_registry[$source_lang] = $job->id(); // Add newly created job into jobs queue. $jobs[$job->id()] = $job; } else { $jobs[$source_lang_registry[$source_lang]]->addItem('content', $type, $entity->id()); } } catch (TMGMTException $e) { watchdog_exception('tmgmt', $e); drupal_set_message($this->t('Unable to add job item for entity %name: %error.', array('%name' => $entity->label(), '%error' => $e->getMessage())), 'error'); } } // If necessary, do a redirect. $redirects = tmgmt_job_checkout_multiple($jobs); if ($redirects) { tmgmt_redirect_queue_set($redirects, Url::fromRoute('<current>')->getInternalPath()); $form_state->setRedirectUrl(Url::fromUri('base:' . tmgmt_redirect_queue_dequeue())); drupal_set_message(\Drupal::translation()->formatPlural(count($redirects), $this->t('One job needs to be checked out.'), $this->t('@count jobs need to be checked out.'))); } }