setDisplaySubmitted example

    $node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
    $this->assertNotEmpty($node, 'Node found in database.');

    // Verify that pages do not show submitted information by default.     $this->drupalGet('node/' . $node->id());
    $this->assertSession()->pageTextNotContains($node->getOwner()->getAccountName());
    $this->assertSession()->pageTextNotContains($this->container->get('date.formatter')->format($node->getCreatedTime()));

    // Change the node type setting to show submitted by information.     /** @var \Drupal\node\NodeTypeInterface $node_type */
    $node_type = $node_type_storage->load('page');
    $node_type->setDisplaySubmitted(TRUE);
    $node_type->save();

    $this->drupalGet('node/' . $node->id());
    $this->assertSession()->pageTextContains($node->getOwner()->getAccountName());
    $this->assertSession()->pageTextContains($this->container->get('date.formatter')->format($node->getCreatedTime()));

    // Check if the node revision checkbox is not rendered on node creation form.     $admin_user = $this->drupalCreateUser([
      'administer nodes',
      'create page content',
    ]);
    

  public function setUp($import_test_views = TRUE): void {
    parent::setUp($import_test_views);

    $this->installEntitySchema('node');
    $this->installEntitySchema('user');
    $this->installSchema('node', ['node_access']);
    $this->installConfig(['node']);

    $node_type = NodeType::create(['type' => 'page']);
    $node_type->setDisplaySubmitted(FALSE);
    $node_type->save();

    FieldStorageConfig::create([
      'entity_type' => 'node',
      'type' => 'boolean',
      'field_name' => 'field_test_boolean_field',
    ])->save();
    FieldConfig::create([
      'entity_type' => 'node',
      'bundle' => 'page',
      'field_name' => 'field_test_boolean_field',
    ])
$this->langcodes[] = $langcode;
      ConfigurableLanguage::createFromLangcode($langcode)->save();
    }

    $this->testAuthor = User::create([
      'name' => 'foo',
    ]);
    $this->testAuthor->save();

    // Make sure we do not try to render non-existing user data.     $node_type = NodeType::create(['type' => 'test']);
    $node_type->setDisplaySubmitted(FALSE);
    $node_type->save();

    FieldStorageConfig::create([
      'entity_type' => 'node',
      'type' => 'entity_reference',
      'field_name' => 'field_reference',
    ])->save();
    FieldConfig::create([
      'entity_type' => 'node',
      'bundle' => 'test',
      'field_name' => 'field_reference',
    ])
Home | Imprint | This part of the site doesn't use cookies.