X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fsimpletest%2Fsrc%2FNodeCreationTrait.php;h=d5b34d781c14e65498d88c8cc10b1ddfc13ee59d;hb=1c1cb0980bfa6caf0c24cce671b6bb541dc87583;hp=20dc3f8379d80ca13c7363292d291ababaacb41f;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/web/core/modules/simpletest/src/NodeCreationTrait.php b/web/core/modules/simpletest/src/NodeCreationTrait.php index 20dc3f837..d5b34d781 100644 --- a/web/core/modules/simpletest/src/NodeCreationTrait.php +++ b/web/core/modules/simpletest/src/NodeCreationTrait.php @@ -2,83 +2,20 @@ namespace Drupal\simpletest; -use Drupal\node\Entity\Node; +use Drupal\Tests\node\Traits\NodeCreationTrait as BaseNodeCreationTrait; /** * Provides methods to create node based on default settings. * * This trait is meant to be used only by test classes. + * + * @deprecated in Drupal 8.4.x. Will be removed before Drupal 9.0.0. Use + * \Drupal\Tests\node\Traits\NodeCreationTrait instead. + * + * @see https://www.drupal.org/node/2884454 */ trait NodeCreationTrait { - /** - * Get a node from the database based on its title. - * - * @param string|\Drupal\Component\Render\MarkupInterface $title - * A node title, usually generated by $this->randomMachineName(). - * @param $reset - * (optional) Whether to reset the entity cache. - * - * @return \Drupal\node\NodeInterface - * A node entity matching $title. - */ - public function getNodeByTitle($title, $reset = FALSE) { - if ($reset) { - \Drupal::entityTypeManager()->getStorage('node')->resetCache(); - } - // Cast MarkupInterface objects to string. - $title = (string) $title; - $nodes = \Drupal::entityTypeManager() - ->getStorage('node') - ->loadByProperties(['title' => $title]); - // Load the first node returned from the database. - $returned_node = reset($nodes); - return $returned_node; - } - - /** - * Creates a node based on default settings. - * - * @param array $settings - * (optional) An associative array of settings for the node, as used in - * entity_create(). Override the defaults by specifying the key and value - * in the array, for example: - * @code - * $this->drupalCreateNode(array( - * 'title' => t('Hello, world!'), - * 'type' => 'article', - * )); - * @endcode - * The following defaults are provided: - * - body: Random string using the default filter format: - * @code - * $settings['body'][0] = array( - * 'value' => $this->randomMachineName(32), - * 'format' => filter_default_format(), - * ); - * @endcode - * - title: Random string. - * - type: 'page'. - * - uid: The currently logged in user, or anonymous. - * - * @return \Drupal\node\NodeInterface - * The created node entity. - */ - protected function createNode(array $settings = []) { - // Populate defaults array. - $settings += [ - 'body' => [[ - 'value' => $this->randomMachineName(32), - 'format' => filter_default_format(), - ]], - 'title' => $this->randomMachineName(8), - 'type' => 'page', - 'uid' => \Drupal::currentUser()->id(), - ]; - $node = Node::create($settings); - $node->save(); - - return $node; - } + use BaseNodeCreationTrait; }