protected function JuiceboxBaseCase::createNodeWithImage in Juicebox HTML5 Responsive Image Galleries 7.2
Helper to upload an image to a node.
Parameters
array $instance: The instance details, typically from field_info_instance(), that describe the field to upload an image to.
$image: A file object representing the image to upload.
4 calls to JuiceboxBaseCase::createNodeWithImage()
- JuiceboxBaseCase::prepArticle in tests/
JuiceboxBaseCase.test - Helper to turn the default instance of field_image on the article content type into a Juicebox display and create a test node that uses it.
- JuiceboxFileCase::testFile in tests/
JuiceboxFileCase.test - Test the field formatter with a file field and file upload widget.
- JuiceboxFileCase::testFileNonImage in tests/
JuiceboxFileCase.test - Test the non-image handling feature.
- JuiceboxFileEntityCase::testFileEntityText in tests/
JuiceboxFileEntityCase.test - Test using File Entity fields for gallery titles and captions.
File
- tests/
JuiceboxBaseCase.test, line 103 - Common helper methods for Juicebox module tests.
Class
- JuiceboxBaseCase
- Common helper class for Juicebox module tests.
Code
protected function createNodeWithImage($instance, $image) {
$edit = array(
'title' => 'Test Juicebox Gallery Node',
'files[' . $instance['field_name'] . '_' . LANGUAGE_NONE . '_0]' => drupal_realpath($image->uri),
);
$this
->drupalPost('node/add/' . $instance['bundle'], $edit, t('Save'));
// Get ID of the newly created node from the current URL.
$matches = array();
preg_match('/node\\/([0-9]+)/', $this
->getUrl(), $matches);
if (isset($matches[1])) {
$nid = $matches[1];
// Now re-edit the node to add title and caption values for the newly
// uploaded image. This could probably also be done above with
// DrupalWebTestCase::drupalPostAJAX(), but this works too.
$edit = array(
'body[' . LANGUAGE_NONE . '][0][value]' => 'Some body content on node ' . $nid . ' <strong>with formatting</strong>',
);
if ($instance['widget']['type'] == 'image_image') {
$edit[$instance['field_name'] . '[' . LANGUAGE_NONE . '][0][title]'] = 'Some title text for field ' . $instance['field_name'] . ' on node ' . $nid;
$edit[$instance['field_name'] . '[' . LANGUAGE_NONE . '][0][alt]'] = 'Some alt text for field ' . $instance['field_name'] . ' on node ' . $nid . ' <strong>with formatting</strong>';
}
if ($instance['widget']['type'] == 'file_generic') {
$edit[$instance['field_name'] . '[' . LANGUAGE_NONE . '][0][description]'] = 'Some description text for field ' . $instance['field_name'] . ' on node ' . $nid . ' <strong>with formatting</strong>';
}
$this
->drupalPost('node/' . $nid . '/edit', $edit, t('Save'));
$node = node_load($nid);
$items = field_get_items('node', $node, $instance['field_name']);
$this
->assertTrue(reset($items), 'Node with image content created');
return $node;
}
return FALSE;
}