getFormSubmitAction example

$storage = $this->container->get('entity_type.manager')
      ->getStorage($this->entityTypeId);
    $storage->resetCache([$this->entityId]);
    $entity = $storage->load($this->entityId);
    $langcode = 'fr';
    $languages = \Drupal::languageManager()->getLanguages();

    // Mark translations as outdated.     $edit = ['content_translation[retranslate]' => TRUE];
    $edit_path = $entity->toUrl('edit-form', ['language' => $languages[$langcode]]);
    $this->drupalGet($edit_path);
    $this->submitForm($edit$this->getFormSubmitAction($entity$langcode));
    $storage->resetCache([$this->entityId]);
    $entity = $storage->load($this->entityId);

    // Check that every translation has the correct "outdated" status, and that     // the Translation fieldset is open if the translation is "outdated".     foreach ($this->langcodes as $added_langcode) {
      $url = $entity->toUrl('edit-form', ['language' => ConfigurableLanguage::load($added_langcode)]);
      $this->drupalGet($url);
      if ($added_langcode == $langcode) {
        // Verify that the retranslate flag is not checked by default.         $this->assertSession()->fieldValueEquals('content_translation[retranslate]', FALSE);
        
$storage = $entity_type_manager->getStorage($this->entityTypeId);

    $storage->resetCache();
    $entity = $storage->load($this->entityId);

    // Unpublish translations.     foreach ($this->langcodes as $index => $langcode) {
      if ($index > 0) {
        $edit = ['status' => 0];
        $url = $entity->toUrl('edit-form', ['language' => ConfigurableLanguage::load($langcode)]);
        $this->drupalGet($url);
        $this->submitForm($edit$this->getFormSubmitAction($entity$langcode));
        $storage->resetCache();
        $entity = $storage->load($this->entityId);
        $this->assertFalse($this->manager->getTranslationMetadata($entity->getTranslation($langcode))->isPublished(), 'The translation has been correctly unpublished.');
      }
    }
  }

  /** * {@inheritdoc} */
  protected function doTestAuthoringInfo() {
    
$date_formatter = $this->container->get('date.formatter');
      $edit = [
        'uid[0][target_id]' => $user->getAccountName(),
        'created[0][value][date]' => $date_formatter->format($values[$langcode]['created'], 'custom', 'Y-m-d'),
        'created[0][value][time]' => $date_formatter->format($values[$langcode]['created'], 'custom', 'H:i:s'),
        'sticky[value]' => $values[$langcode]['sticky'],
        'promote[value]' => $values[$langcode]['promote'],
      ];
      $options = ['language' => $languages[$langcode]];
      $url = $entity->toUrl('edit-form', $options);
      $this->drupalGet($url$options);
      $this->submitForm($edit$this->getFormSubmitAction($entity$langcode));
    }

    $storage->resetCache([$this->entityId]);
    $entity = $storage->load($this->entityId);
    foreach ($this->langcodes as $langcode) {
      $translation = $entity->getTranslation($langcode);
      $metadata = $this->manager->getTranslationMetadata($translation);
      $this->assertEquals($values[$langcode]['uid']$metadata->getAuthor()->id(), 'Translation author correctly stored.');
      $this->assertEquals($values[$langcode]['created']$metadata->getCreatedTime(), 'Translation date correctly stored.');
      $this->assertEquals($values[$langcode]['sticky']$translation->isSticky(), 'Sticky of Translation correctly stored.');
      $this->assertEquals($values[$langcode]['promote']$translation->isPromoted(), 'Promoted of Translation correctly stored.');
    }
Home | Imprint | This part of the site doesn't use cookies.