entity_background.test in Entity background 7
Test classes for Entity backgrounds.
File
tests/entity_background.testView source
<?php
/**
* @file
* Test classes for Entity backgrounds.
*/
/**
* Class EntityBackgroundTestBase
*
* Base test class used for all functional test.
*/
class EntityBackgroundTestBase extends DrupalWebTestCase {
/**
* Helper method used to create node with paragraphs.
*
* list ($node, $entity) = $this->createNodeWithParagraph();
* $this->drupalGet('node/' . $node->nid);
*
* @param string $node_type
* @return array
*/
public function createNodeWithParagraph($node_type = 'eb_test_landing_page') {
$node = $this
->drupalCreateNode(array(
'type' => $node_type,
));
$entity = entity_create('paragraphs_item', array(
'bundle' => 'eb_content_test',
'field_name' => 'field_eb_test_paragraphs',
));
$entity->field_eb_test_body[LANGUAGE_NONE][0]['value'] = $this
->randomString();
$entity
->setHostEntity('node', $node);
$entity
->save();
return array(
$node,
$entity,
);
}
}
/**
* Class EntityBackgroundEnableCheckboxTest
*
* Ensure that the bd_background field collection is created.
*/
class EntityBackgroundEnableCheckboxTest extends EntityBackgroundTestBase {
public static function getInfo() {
return array(
'name' => 'Test enable checkbox',
'description' => 'Ensure that the bd_background field collection is attached to bundle when enabling',
'group' => 'Entity background',
);
}
public function setUp() {
parent::setUp('entity_background_test');
// Log user in.
$web_user = $this
->drupalCreateUser(array(
'bypass node access',
'administer content types',
'administer paragraphs bundles',
));
$this
->drupalLogin($web_user);
}
/**
* Test enabling eb via the checkbox.
*/
public function testEntityBackgroundTestCheckbox() {
// Shouldn't see the checkbox on the create paragraph type.
$this
->drupalGet('admin/structure/paragraphs/add');
$this
->assertText(t('Please create paragraph bundle before configuring entity background.'));
// Get to paragraphs admin page.
$this
->drupalGet('admin/structure/paragraphs/eb-content-test/edit');
$this
->assertText(t('Enable entity background for EB Content (test)'));
// Enable BD.
$edit = array();
$edit['eb_enabled'] = TRUE;
$this
->drupalPost('admin/structure/paragraphs/eb-content-test/edit', $edit, t('Save Paragraph bundle'));
$this
->assertText(t('The paragraph bundle EB Content (test) has been updated.'));
$this
->drupalGet('admin/structure/paragraphs/eb-content-test/fields');
$this
->assertText('eb_background');
}
}
/**
* Class EntityBackgroundAPITest
*
* Ensure that the basic API in bd work.
*/
class EntityBackgroundAPITest extends EntityBackgroundTestBase {
public static function getInfo() {
return array(
'name' => 'Test EB API',
'description' => 'Ensure that the basic API in eb work.',
'group' => 'Entity background',
);
}
public function setUp() {
parent::setUp('entity_background_test', 'entity_background_image');
}
/**
* Test basic APIs.
*/
public function testEntityBackgroundTestAPI() {
// Assert returned array values.
$image_plugin = entity_background_get_background_plugin('image');
$this
->assertEqual($image_plugin['name'], 'image');
$this
->assertEqual($image_plugin['handler'], 'entity_background_image_decorator');
// Assert returned selector.
$selector = entity_background_get_selector('node');
$this
->assertEqual($selector, '.page-node-[entity-id]');
// Assert selectors and hook_entity_background_selectors_alter.
$selectors = entity_background_selectors();
$this
->assertEqual($selectors['custom_entity'], 'custom-entity-');
// Assert field groups
$groups = entity_background_selection_list();
$this
->assertEqual($groups['group_eb_image'], 'Image');
// Assert group name. Should be converted from group_eb_image to image.
$plugin_name = entity_background_get_plugin_from_group_name('group_eb_image');
$this
->assertEqual($plugin_name, 'image');
}
}
/**
* Class EntityBackgroundFeatureTestCase
*
* Ensure that the test features has been installed.
*/
class EntityBackgroundFeatureTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Test Entity background testing feature module',
'description' => 'Ensure that the Entity background testing feature installs.',
'group' => 'Entity background',
);
}
public function setUp() {
parent::setUp('entity_background_test');
// Log user in.
$web_user = $this
->drupalCreateUser(array(
'bypass node access',
'administer content types',
'administer paragraphs bundles',
));
$this
->drupalLogin($web_user);
}
/**
* Test content type stored in features.
*/
public function testEntityBackgroundNodeType() {
$node_types = node_type_get_types();
$this
->assertTrue(isset($node_types['eb_test_landing_page']), 'Node type landing page is available.');
// Go to test content type.
$this
->drupalGet('node/add/eb-test-landing-page');
$this
->assertText('Paragraphs', 'Found paragraphs field');
}
/**
* Test paragraphs stored in features.
*/
public function testEntityBackgroundTestParagraph() {
$paragraph = paragraphs_bundle_load('eb_content_test');
$this
->assertTrue(isset($paragraph), 'Found test paragraph.');
}
}
Classes
Name | Description |
---|---|
EntityBackgroundAPITest | Class EntityBackgroundAPITest |
EntityBackgroundEnableCheckboxTest | Class EntityBackgroundEnableCheckboxTest |
EntityBackgroundFeatureTestCase | Class EntityBackgroundFeatureTestCase |
EntityBackgroundTestBase | Class EntityBackgroundTestBase |