annotate core/modules/node/tests/src/Kernel/NodeLegacyTest.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents af1871eacc83
children
rev   line source
Chris@18 1 <?php
Chris@18 2
Chris@18 3 namespace Drupal\Tests\node\Kernel;
Chris@18 4
Chris@18 5 use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
Chris@18 6 use Drupal\node\Entity\Node;
Chris@18 7 use Drupal\node\Entity\NodeType;
Chris@18 8 use Drupal\node\NodeInterface;
Chris@18 9 use Drupal\node\NodeTypeInterface;
Chris@18 10
Chris@18 11 /**
Chris@18 12 * Tests legacy user functionality.
Chris@18 13 *
Chris@18 14 * @group user
Chris@18 15 * @group legacy
Chris@18 16 */
Chris@18 17 class NodeLegacyTest extends EntityKernelTestBase {
Chris@18 18
Chris@18 19 /**
Chris@18 20 * Modules to enable.
Chris@18 21 *
Chris@18 22 * @var array
Chris@18 23 */
Chris@18 24 public static $modules = ['node'];
Chris@18 25
Chris@18 26 /**
Chris@18 27 * {@inheritdoc}
Chris@18 28 */
Chris@18 29 protected function setUp() {
Chris@18 30 parent::setUp();
Chris@18 31
Chris@18 32 // Create the node bundles required for testing.
Chris@18 33 $type = NodeType::create([
Chris@18 34 'type' => 'page',
Chris@18 35 'name' => 'page',
Chris@18 36 ]);
Chris@18 37 $type->save();
Chris@18 38
Chris@18 39 $this->installSchema('node', 'node_access');
Chris@18 40 }
Chris@18 41
Chris@18 42 /**
Chris@18 43 * @expectedDeprecation node_load_multiple() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\node\Entity\Node::loadMultiple(). See https://www.drupal.org/node/2266845
Chris@18 44 * @expectedDeprecation node_load() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\node\Entity\Node::load(). See https://www.drupal.org/node/2266845
Chris@18 45 * @expectedDeprecation node_type_load() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\node\Entity\NodeType::load(). See https://www.drupal.org/node/2266845
Chris@18 46 */
Chris@18 47 public function testEntityLegacyCode() {
Chris@18 48 $this->assertCount(0, node_load_multiple());
Chris@18 49 Node::create([
Chris@18 50 'type' => 'page',
Chris@18 51 'title' => $this->randomMachineName(),
Chris@18 52 ])->save();
Chris@18 53 $this->assertCount(1, node_load_multiple());
Chris@18 54 Node::create([
Chris@18 55 'type' => 'page',
Chris@18 56 'title' => $this->randomMachineName(),
Chris@18 57 ])->save();
Chris@18 58 $this->assertCount(2, node_load_multiple());
Chris@18 59
Chris@18 60 $this->assertNull(node_load(30));
Chris@18 61 $this->assertInstanceOf(NodeInterface::class, node_load(1));
Chris@18 62 $this->assertNull(node_type_load('a_node_type_does_not_exist'));
Chris@18 63 $this->assertInstanceOf(NodeTypeInterface::class, node_type_load('page'));
Chris@18 64 }
Chris@18 65
Chris@18 66 }