getNodeByTitle example



  /** * Tests creating and deleting content. */
  public function testCreatingContent() {
    $this->drupalGet('node/add/moderated_content');
    $this->submitForm([
      'title[0][value]' => 'moderated content',
      'moderation_state[0][state]' => 'draft',
    ], 'Save');
    $node = $this->getNodeByTitle('moderated content');
    if (!$node) {
      $this->fail('Test node was not saved correctly.');
    }
    $this->assertEquals('draft', $node->moderation_state->value);

    $path = 'node/' . $node->id() . '/edit';
    // Set up published revision.     $this->drupalGet($path);
    $this->submitForm(['moderation_state[0][state]' => 'published'], 'Save');
    \Drupal::entityTypeManager()->getStorage('node')->resetCache([$node->id()]);
    /** @var \Drupal\node\NodeInterface $node */
    

  public function testNodePathAlias() {
    // Create some moderated content with a path alias.     $this->drupalGet('node/add/moderated');
    $this->assertSession()->fieldValueEquals('path[0][alias]', '');
    $this->submitForm([
      'title[0][value]' => 'moderated content',
      'path[0][alias]' => '/moderated-content',
      'moderation_state[0][state]' => 'published',
    ], 'Save');
    $node = $this->getNodeByTitle('moderated content');

    // Add a pending revision with the same alias.     $this->drupalGet('node/' . $node->id() . '/edit');
    $this->assertSession()->fieldValueEquals('path[0][alias]', '/moderated-content');
    $this->submitForm([
      'title[0][value]' => 'pending revision',
      'path[0][alias]' => '/moderated-content',
      'moderation_state[0][state]' => 'draft',
    ], 'Save');
    $this->assertSession()->statusMessageNotContains('You can only change the URL alias for the published version of this content.');

    
public function testPublishedDefaultState() {
    // Set the default moderation state to be "published".     $this->drupalGet('admin/config/workflow/workflows/manage/' . $this->workflow->id());
    $this->submitForm(['type_settings[workflow_settings][default_moderation_state]' => 'published'], 'Save');

    $this->drupalGet('node/add/moderated_content');
    $this->assertEquals('published', $this->assertSession()->selectExists('moderation_state[0][state]')->getValue());
    $this->submitForm([
      'title[0][value]' => 'moderated content',
    ], 'Save');

    $node = $this->getNodeByTitle('moderated content');
    $this->assertEquals('published', $node->moderation_state->value);
  }

  /** * Tests access to deleting the default state. */
  public function testDeleteDefaultStateAccess() {
    $this->drupalGet('admin/config/workflow/workflows/manage/editorial/state/archived/delete');
    $this->assertSession()->statusCodeEquals(200);

    $this->drupalGet('admin/config/workflow/workflows/manage/' . $this->workflow->id());
    
    $this->enableModerationThroughUi('moderated_content', 'editorial');

    // Access that the status field is no longer visible.     $this->drupalGet('node/add/moderated_content');
    $this->assertSession()->fieldNotExists('Published');

    // Create a node to test with.     $this->submitForm([
      'title[0][value]' => 'moderated content',
      'moderation_state[0][state]' => 'draft',
    ], 'Save');
    $node = $this->getNodeByTitle('moderated content');
    if (!$node) {
      $this->fail('Test node was not saved correctly.');
    }

    $view_path = 'node/' . $node->id();
    $edit_path = 'node/' . $node->id() . '/edit';
    $latest_path = 'node/' . $node->id() . '/latest';

    // Now make a new user and verify that the new user's access is correct.     $user = $this->createUser([
      'use editorial transition create_new_draft',
      
    $this->clickLink('Edit', 1);
    // Upload and image after changing the node language.     $images = $this->drupalGetTestFiles('image')[1];
    $edit = [
      'langcode[0][value]' => 'de',
      'files[field_image_field_0]' => $images->uri,
    ];
    $this->submitForm($edit, 'Upload');
    $this->submitForm(['field_image_field[0][alt]' => 'alternative_text'], 'Save (this translation)');

    // Check that the translation languages are correct.     $node = $this->getNodeByTitle('english_title');
    $translation_languages = $node->getTranslationLanguages();
    $this->assertArrayHasKey('fr', $translation_languages);
    $this->assertArrayHasKey('de', $translation_languages);
  }

  /** * Tests that title does not change on ajax call with new language value. */
  public function testTitleDoesNotChangesOnChangingLanguageWidgetAndTriggeringAjaxCall() {
    // Create a node in English.     $this->drupalGet('node/add/article', ['query' => ['test_field_only_en_fr' => 1]]);
    
Home | Imprint | This part of the site doesn't use cookies.