Example #1
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     batch_test_stack(NULL, TRUE);
     $function = '_batch_test_' . $form_state->getValue('batch');
     batch_set($function());
     $form_state->setRedirect('batch_test.redirect');
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, array &$form_state)
 {
     batch_test_stack(NULL, TRUE);
     $function = '_batch_test_' . $form_state['values']['batch'];
     batch_set($function());
     $form_state['redirect_route'] = new Url('batch_test.redirect');
 }
 /**
  * Form submission handler #4 for batch_test_chained_form
  */
 public static function batchTestChainedFormSubmit4($form, FormStateInterface $form_state)
 {
     batch_test_stack('submit handler 4');
     batch_test_stack('value = ' . $form_state['values']['value']);
     $form_state['values']['value']++;
     batch_set(_batch_test_batch_3());
     $form_state->setRedirect('batch_test.redirect');
 }
 /**
  * Form submission handler #4 for batch_test_chained_form
  */
 public static function batchTestChainedFormSubmit4($form, &$form_state)
 {
     batch_test_stack('submit handler 4');
     batch_test_stack('value = ' . $form_state['values']['value']);
     $form_state['values']['value']++;
     batch_set(_batch_test_batch_3());
     $form_state['redirect_route'] = new Url('batch_test.redirect');
 }
Example #5
0
 /**
  * Tests that the batch API progress page shows the title correctly.
  */
 function testBatchProgressPageTitle()
 {
     // Visit an administrative page that runs a test batch, and check that the
     // title shown during batch execution (which the batch callback function
     // saved as a variable) matches the theme used on the administrative page.
     $this->drupalGet('batch-test/test-title');
     // The stack should contain the title shown on the progress page.
     $this->assertEqual(batch_test_stack(), ['Batch Test'], 'The batch title is shown on the batch page.');
     $this->assertText('Redirection successful.', 'Redirection after batch execution is correct.');
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     batch_test_stack(NULL, TRUE);
     switch ($form_state['storage']['step']) {
         case 1:
             batch_set(_batch_test_batch_1());
             break;
         case 2:
             batch_set(_batch_test_batch_2());
             break;
     }
     if ($form_state['storage']['step'] < 2) {
         $form_state['storage']['step']++;
         $form_state['rebuild'] = TRUE;
     }
     $form_state->setRedirect('batch_test.redirect');
 }
 /**
  * Tests that the batch API progress page uses the correct theme.
  */
 function testBatchProgressPageTheme()
 {
     // Make sure that the page which starts the batch (an administrative page)
     // is using a different theme than would normally be used by the batch API.
     $this->container->get('theme_handler')->install(array('seven', 'bartik'));
     $this->container->get('config.factory')->get('system.theme')->set('default', 'bartik')->set('admin', 'seven')->save();
     // Log in as an administrator who can see the administrative theme.
     $admin_user = $this->drupalCreateUser(array('view the administration theme'));
     $this->drupalLogin($admin_user);
     // Visit an administrative page that runs a test batch, and check that the
     // theme that was used during batch execution (which the batch callback
     // function saved as a variable) matches the theme used on the
     // administrative page.
     $this->drupalGet('admin/batch-test/test-theme');
     // The stack should contain the name of the theme used on the progress
     // page.
     $this->assertEqual(batch_test_stack(), array('seven'), 'A progressive batch correctly uses the theme of the page that started the batch.');
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     batch_test_stack(NULL, TRUE);
     $step = $form_state->get('step');
     switch ($step) {
         case 1:
             batch_set(_batch_test_batch_1());
             break;
         case 2:
             batch_set(_batch_test_batch_2());
             break;
     }
     if ($step < 2) {
         $form_state->set('step', ++$step);
         $form_state->setRebuild();
     }
     $form_state->setRedirect('batch_test.redirect');
 }
Example #9
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, array &$form_state)
 {
     batch_test_stack('mock form submitted with value = ' . $form_state['values']['test_value']);
 }
Example #10
0
 /**
  * Tests batches that return $context['finished'] > 1 do in fact complete.
  *
  * @see https://www.drupal.org/node/600836
  */
 function testBatchLargePercentage()
 {
     // Displaying the page triggers batch 5.
     $this->drupalGet('batch-test/large-percentage');
     $this->assertBatchMessages($this->_resultMessages('batch_5'), 'Batch for step 2 performed successfully.');
     $this->assertEqual(batch_test_stack(), $this->_resultStack('batch_5'), 'Execution order was correct.');
     $this->assertText('Redirection successful.', 'Redirection after batch execution is correct.');
 }
Example #11
0
 /**
  * Runs a batch for testing the title shown on the progress page.
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|null
  *   A redirect response if the batch is progressive. No return value otherwise.
  */
 public function testTitleBatch()
 {
     batch_test_stack(NULL, TRUE);
     $batch = ['title' => 'Batch Test', 'operations' => [['_batch_test_title_callback', []]]];
     batch_set($batch);
     return batch_process('batch-test/redirect');
 }
Example #12
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     batch_test_stack('mock form submitted with value = ' . $form_state->getValue('test_value'));
 }
 /**
  * Runs a batch for testing theme used on the progress page.
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|null
  *   A redirect response if the batch is progressive. No return value otherwise.
  */
 public function testThemeBatch()
 {
     batch_test_stack(NULL, TRUE);
     $batch = array('operations' => array(array('_batch_test_theme_callback', array())));
     batch_set($batch);
     return batch_process('batch-test/redirect');
 }