public function ImageLinkFormatterTestCase::createNodeWithLinkImage in Image Link Formatter 7
Create a node with a link and an image attached.
The creation process of a node with an image attached is easier to code when it goes through submission of the creation form, rather than programmatically. Which is why this function uses the interface: node/add. However, it requires to grant test user the permissions to create and edit page content.
Return value
bool|int The nid of the created node if successful, otherwise FALSE.
1 call to ImageLinkFormatterTestCase::createNodeWithLinkImage()
- ImageLinkFormatterFieldUITestCase::testFormatterManageDisplaySettings in ./
image_link_formatter.test - Test Image Link formatter manage display settings.
File
- ./
image_link_formatter.test, line 152 - Test the Image Link Formatter module.
Class
- ImageLinkFormatterTestCase
- Provides common functionality for the Image Link Formatter test classes.
Code
public function createNodeWithLinkImage() {
// Get the first file returned as a test image.
$image = current($this
->drupalGetTestFiles('image'));
// Create a node with test link and image data.
$edit = array(
// Link field values: title and URL.
'title' => $this
->randomName(),
$this->fieldLinkName . '[' . LANGUAGE_NONE . '][0][title]' => 'Link ILF test',
$this->fieldLinkName . '[' . LANGUAGE_NONE . '][0][url]' => 'http://www.example.com/?example=query#example_fragment',
// Image field value.
'files[' . $this->fieldImageName . '_' . LANGUAGE_NONE . '_0]' => drupal_realpath($image->uri),
);
$this
->drupalPost('node/add/' . $this->bundle, $edit, t('Save'));
// Check the node was saved successfully.
$types = node_type_get_types();
$this
->assertText(t('@node_type @node_title has been created.', array(
'@node_type' => $types[$this->bundle]->name,
'@node_title' => $edit['title'],
)));
// Since the node is not created programmatically but by submitting a form,
// the newly created node's ID is not returned so it needs to be retrieved
// through the current page's URL.
$matches = array();
preg_match('/node\\/([0-9]+)/', $this
->getUrl(), $matches);
return isset($matches[1]) ? $matches[1] : FALSE;
}