public function ClassyParagraphsTestBase::createNodeWithParagraph in Classy paragraphs 7
Helper method used to create node with paragraphs.
Parameters
array $css_classes: Classes that should be added to the class field.
string $node_type: A type of a node that should be created.
Return value
array An array containing newly created node and entity, in this order.
2 calls to ClassyParagraphsTestBase::createNodeWithParagraph()
- ClassyParagraphsTestClassCase::testClassyParagraphsCheckMarkup in tests/
classy_paragraphs.test - Check markup class.
- ClassyParagraphsTestClassCase::testClassyParagraphsCheckMarkupOfMultipleClasses in tests/
classy_paragraphs.test - Check markup of multiple class.
File
- tests/
classy_paragraphs.test, line 25 - Contains tests for Classy Paragraphs.
Class
- ClassyParagraphsTestBase
- Class ClassyParagraphsTestBase
Code
public function createNodeWithParagraph($css_classes, $node_type = 'cp_test_landing_page') {
// Make an array if necessary.
if (!is_array($css_classes)) {
$css_classes = array(
$css_classes,
);
}
// Decide whether paragraph item with one class or multiple classes should be created.
$field_name = count($css_classes) == 1 ? 'field_cp_test_class' : 'field_cp_multiple_classes';
$bundle = count($css_classes) == 1 ? 'cp_test_content' : 'cp_test_content_multiple_classes';
$node = $this
->drupalCreateNode(array(
'type' => $node_type,
));
$entity = entity_create('paragraphs_item', array(
'bundle' => $bundle,
'field_name' => 'field_cp_test_paragraphs',
));
// Add all css classes.
$index = 0;
foreach ($css_classes as $css_class) {
$entity->{$field_name}[LANGUAGE_NONE][$index]['value'] = $css_class;
++$index;
}
$entity->field_cp_test_body[LANGUAGE_NONE][0]['value'] = $this
->randomString();
$entity
->setHostEntity('node', $node);
$entity
->save();
return array(
$node,
$entity,
);
}