createNode example


  protected $defaultTheme = 'claro';

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    // Create a Content type and two test nodes.     $this->createContentType(['type' => 'page']);
    $this->createNode(['title' => 'Page One']);
    $this->createNode(['title' => 'Page Two']);

    // Create a user privileged enough to use exposed filters and view content.     $user = $this->drupalCreateUser([
      'administer site configuration',
      'access content',
      'access content overview',
      'edit any page content',
    ]);
    $this->drupalLogin($user);
  }

  
    // Local 1:     // - Test article 2 - stage     // - Test article 3 - dev     // - Test article 4 - local_1     //     // Local 2:     // - Test article 2 - stage     // - Test article 3 - dev     //     // Note that the contents of each workspace are inherited automatically in     // each of its descendants.     $this->createNode(['title' => 'Test article 1 - live', 'type' => 'article']);

    // This creates revisions 2 and 3. Revision 2 is an unpublished default     // revision (which is also available in Live), and revision 3 is a published     // pending revision that is available in Stage and all its descendants.     $this->switchToWorkspace('stage');
    $this->createNode(['title' => 'Test article 2 - stage', 'type' => 'article']);

    $expected_workspace_association = [
      'stage' => [3],
      'dev' => [3],
      'local_1' => [3],
      

  protected function setUp(): void {
    parent::setUp();

    $this->createContentType(['type' => 'bundle_with_section_field']);
    LayoutBuilderEntityViewDisplay::load('node.bundle_with_section_field.default')
      ->enableLayoutBuilder()
      ->setOverridable()
      ->save();

    $this->createNode([
      'type' => 'bundle_with_section_field',
    ]);
    $this->drupalLogin($this->drupalCreateUser([
      'configure any layout',
    ]));
  }

  /** * Tests changing the columns widths of a multi-width section. */
  public function testWidthChange() {
    
/** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $this->createContentType(['type' => 'bundle_with_section_field']);
    LayoutBuilderEntityViewDisplay::load('node.bundle_with_section_field.default')
      ->enableLayoutBuilder()
      ->setOverridable()
      ->save();
    $this->createNode(['type' => 'bundle_with_section_field']);
  }

  /** * Tests that validation messages are shown on the block form. */
  public function testValidationMessage() {
    // @todo Work out why this fixes random fails in this test.     // https://www.drupal.org/project/drupal/issues/3055982     $this->getSession()->resizeWindow(800, 1000);
    $assert_session = $this->assertSession();
    $page = $this->getSession()->getPage();

    
'info' => 'My content block',
      'type' => 'basic',
      'body' => [
        [
          'value' => 'This is the block content',
          'format' => filter_default_format(),
        ],
      ],
    ])->save();

    $this->createContentType(['type' => 'bundle_with_section_field']);
    $this->node = $this->createNode([
      'type' => 'bundle_with_section_field',
      'title' => 'The node title',
      'body' => [
        [
          'value' => 'The node body',
        ],
      ],
    ]);

    $this->drupalLogin($this->drupalCreateUser([
      'access contextual links',
      
/** * Tests contextual links on Views page displays. */
  public function testPageContextualLinks() {
    $view = View::load('test_display');
    $view->enable()->save();
    $this->container->get('router.builder')->rebuildIfNeeded();

    // Create node so the view has content and the contextual area is higher     // than 0 pixels.     $this->drupalCreateContentType(['type' => 'page']);
    $this->createNode();

    // When no "main content" block is placed, we find a contextual link     // placeholder for editing just the view.     $this->drupalGet('test-display');
    $page = $this->getSession()->getPage();
    $this->assertSession()->assertWaitOnAjaxRequest();

    $selector = '.views-element-container';
    $this->toggleContextualTriggerVisibility($selector);

    $element = $this->getSession()->getPage()->find('css', $selector);
    

  protected function setUp(): void {
    parent::setUp();

    $this->installConfig(['entity_reference_test', 'filter']);
    $this->installEntitySchema('user');
    $this->installEntitySchema('node');

    // Create test nodes.     $type = strtolower($this->randomMachineName());
    NodeType::create(['type' => $type])->save();
    $node1 = $this->createNode(['type' => $type]);
    $node2 = $this->createNode(['type' => $type]);
    $node3 = $this->createNode();

    foreach ([$node1$node2$node3] as $node) {
      $this->nodes[$node->id()] = $node;
    }

    // Create an entity reference field.     $handler_settings = [
      'view' => [
        'view_name' => 'test_entity_reference',
        
->set('display.default.display_options.use_ajax', TRUE)
      ->save();

    // Import user_test_views and set it to use ajax.     ViewTestData::createTestViews(get_class($this)['user_test_views']);
    \Drupal::configFactory()->getEditable('views.view.test_user_name')
      ->set('display.default.display_options.use_ajax', TRUE)
      ->save();

    // Create a Content type and two test nodes.     $this->createContentType(['type' => 'page']);
    $this->createNode(['title' => 'Page One']);
    $this->createNode(['title' => 'Page Two']);

    // Create a user privileged enough to use exposed filters and view content.     $user = $this->drupalCreateUser([
      'administer site configuration',
      'access content',
      'access content overview',
      'edit any page content',
    ]);
    $this->drupalLogin($user);
  }

  

  protected $defaultTheme = 'stark';

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    ViewTestData::createTestViews(self::class['views_test_config']);
    $this->createContentType(['type' => 'page']);
    $this->createContentType(['type' => 'article']);
    $this->createNode(['title' => 'Page A']);
    $this->createNode(['title' => 'Page B']);
    $this->createNode(['title' => 'Article A', 'type' => 'article']);

    $this->drupalLogin($this->drupalCreateUser([
      'access content',
    ]));
  }

  /** * Tests if exposed filtering and reset works with a views block and ajax. */
  

  protected function setUp(): void {
    parent::setUp();

    $this->createContentType(['type' => 'bundle_with_section_field']);
    LayoutBuilderEntityViewDisplay::load('node.bundle_with_section_field.default')
      ->enableLayoutBuilder()
      ->setOverridable()
      ->save();

    $this->createNode([
      'type' => 'bundle_with_section_field',
      'title' => 'The first node title',
      'body' => [
        [
          'value' => 'The first node body',
        ],
      ],
    ]);
    $this->createNode([
      'type' => 'bundle_with_section_field',
      'title' => 'The second node title',
      
'bypass node access',
      'administer views',
    ]);
    $user->save();
    $this->drupalLogin($user);
    $this->createContentType(['type' => 'bundle_with_section_field']);
    LayoutBuilderEntityViewDisplay::load('node.bundle_with_section_field.default')
      ->enableLayoutBuilder()
      ->setOverridable()
      ->save();

    $this->createNode([
      'type' => 'bundle_with_section_field',
      'body' => [
        [
          'value' => 'The node body',
        ],
      ],
    ]);
  }

  /** * Tests that the contextual links inside Layout Builder are removed. */
// Check that the 'workspace' cache context is present when the module is     // installed.     $this->drupalGet('<front>');
    $this->assertCacheContext('workspace');

    $cache_context = new WorkspaceCacheContext(\Drupal::service('workspaces.manager'));
    $this->assertSame('live', $cache_context->getContext());

    // Create a node and check that its render array contains the proper cache     // context.     $this->drupalCreateContentType(['type' => 'page']);
    $node = $this->createNode();

    // Get a fully built entity view render array.     $build = \Drupal::entityTypeManager()->getViewBuilder('node')->view($node, 'full');

    // Render it so the default cache contexts are applied.     $renderer->renderRoot($build);
    $this->assertContains('workspace', $build['#cache']['contexts']);

    $cid_parts = array_merge($build['#cache']['keys']$cache_contexts_manager->convertTokensToKeys($build['#cache']['contexts'])->getKeys());
    $this->assertContains('[workspace]=live', $cid_parts);

    

  protected function setUp(): void {
    parent::setUp();

    $this->drupalPlaceBlock('local_tasks_block');

    // Create two nodes.     $this->createContentType([
      'type' => 'bundle_with_section_field',
      'name' => 'Bundle with section field',
    ]);
    $this->createNode([
      'type' => 'bundle_with_section_field',
      'title' => 'The first node title',
      'body' => [
        [
          'value' => 'The first node body',
        ],
      ],
    ]);
    $this->createNode([
      'type' => 'bundle_with_section_field',
      'title' => 'The second node title',
      
protected $defaultTheme = 'stark';

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->createContentType([
      'type' => 'article',
    ]);
    $this->createNode([
      'type' => 'article',
      'title' => 'The node title',
      'body' => [
        ['value' => 'The node body'],
      ],
    ]);
    $this->drupalLogin($this->drupalCreateUser([
      'access administration pages',
      'administer content types',
      'administer nodes',
      'administer node fields',
      
$timestamp_2 = '6000000';
    $timestamp_3 = '7000000';
    // Expected: node 1.     $timestamp_smaller_than_value = $timestamp_2;
    // Expected: node 1 and node 2.     $timestamp_smaller_than_or_equal_value = $timestamp_2;
    // Expected: node 3.     $timestamp_greater_than_value = $timestamp_2;
    // Expected: node 2 and node 3.     $timestamp_greater_than_or_equal_value = $timestamp_2;

    $node_1 = $this->createNode([
      'type' => 'article',
      'uuid' => 'es_test_1',
      'status' => NodeInterface::PUBLISHED,
      'field_datetime' => $date_formatter->format($timestamp_1, 'custom', DateTimeItemInterface::DATETIME_STORAGE_FORMAT),
    ]);
    $node_2 = $this->createNode([
      'type' => 'article',
      'uuid' => 'es_test_2',
      'status' => NodeInterface::PUBLISHED,
      'field_datetime' => $date_formatter->format($timestamp_2, 'custom', DateTimeItemInterface::DATETIME_STORAGE_FORMAT),
    ]);
    
Home | Imprint | This part of the site doesn't use cookies.