Mercurial > hg > isophonics-drupal-site
annotate core/modules/migrate/tests/src/Kernel/NodeCommentCombinationTrait.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 4c8ae668cc8c |
children | af1871eacc83 |
rev | line source |
---|---|
Chris@0 | 1 <?php |
Chris@0 | 2 |
Chris@0 | 3 namespace Drupal\Tests\migrate\Kernel; |
Chris@0 | 4 |
Chris@0 | 5 use Drupal\comment\Entity\CommentType; |
Chris@0 | 6 use Drupal\node\Entity\NodeType; |
Chris@0 | 7 |
Chris@0 | 8 /** |
Chris@0 | 9 * Provides methods for testing node and comment combinations. |
Chris@0 | 10 */ |
Chris@0 | 11 trait NodeCommentCombinationTrait { |
Chris@0 | 12 |
Chris@0 | 13 /** |
Chris@0 | 14 * Creates a node type with a corresponding comment type. |
Chris@0 | 15 * |
Chris@0 | 16 * @param string $node_type |
Chris@0 | 17 * The node type ID. |
Chris@0 | 18 * @param string $comment_type |
Chris@0 | 19 * (optional) The comment type ID, if not provided defaults to |
Chris@0 | 20 * comment_node_{type}. |
Chris@0 | 21 */ |
Chris@0 | 22 protected function createNodeCommentCombination($node_type, $comment_type = NULL) { |
Chris@0 | 23 if (!$comment_type) { |
Chris@0 | 24 $comment_type = "comment_node_$node_type"; |
Chris@0 | 25 } |
Chris@0 | 26 NodeType::create([ |
Chris@0 | 27 'type' => $node_type, |
Chris@0 | 28 'label' => $this->randomString(), |
Chris@0 | 29 ])->save(); |
Chris@0 | 30 |
Chris@0 | 31 CommentType::create([ |
Chris@0 | 32 'id' => $comment_type, |
Chris@0 | 33 'label' => $this->randomString(), |
Chris@0 | 34 'target_entity_type_id' => 'node', |
Chris@0 | 35 ])->save(); |
Chris@0 | 36 } |
Chris@0 | 37 |
Chris@0 | 38 } |