Chris@0: drupalCreateUser(['create article content', 'create page content']); Chris@0: $this->drupalLogin($web_user); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Creates four nodes and ensures that they are loaded correctly. Chris@0: */ Chris@0: public function testNodeMultipleLoad() { Chris@0: $node1 = $this->drupalCreateNode(['type' => 'article', 'promote' => 1]); Chris@0: $node2 = $this->drupalCreateNode(['type' => 'article', 'promote' => 1]); Chris@0: $node3 = $this->drupalCreateNode(['type' => 'article', 'promote' => 0]); Chris@0: $node4 = $this->drupalCreateNode(['type' => 'page', 'promote' => 0]); Chris@0: Chris@0: // Confirm that promoted nodes appear in the default node listing. Chris@0: $this->drupalGet('node'); Chris@0: $this->assertText($node1->label(), 'Node title appears on the default listing.'); Chris@0: $this->assertText($node2->label(), 'Node title appears on the default listing.'); Chris@0: $this->assertNoText($node3->label(), 'Node title does not appear in the default listing.'); Chris@0: $this->assertNoText($node4->label(), 'Node title does not appear in the default listing.'); Chris@0: // Load nodes with only a condition. Nodes 3 and 4 will be loaded. Chris@0: $nodes = $this->container->get('entity_type.manager')->getStorage('node') Chris@0: ->loadByProperties(['promote' => 0]); Chris@0: $this->assertEqual($node3->label(), $nodes[$node3->id()]->label(), 'Node was loaded.'); Chris@0: $this->assertEqual($node4->label(), $nodes[$node4->id()]->label(), 'Node was loaded.'); Chris@0: $count = count($nodes); Chris@0: $this->assertTrue($count == 2, format_string('@count nodes loaded.', ['@count' => $count])); Chris@0: Chris@0: // Load nodes by nid. Nodes 1, 2 and 4 will be loaded. Chris@0: $nodes = Node::loadMultiple([1, 2, 4]); Chris@0: $count = count($nodes); Chris@0: $this->assertTrue(count($nodes) == 3, format_string('@count nodes loaded', ['@count' => $count])); Chris@0: $this->assertTrue(isset($nodes[$node1->id()]), 'Node is correctly keyed in the array'); Chris@0: $this->assertTrue(isset($nodes[$node2->id()]), 'Node is correctly keyed in the array'); Chris@0: $this->assertTrue(isset($nodes[$node4->id()]), 'Node is correctly keyed in the array'); Chris@0: foreach ($nodes as $node) { Chris@0: $this->assertTrue(is_object($node), 'Node is an object'); Chris@0: } Chris@0: } Chris@0: Chris@0: }