public function JuiceboxSubRequestCase::testSubRequestDependent in Juicebox HTML5 Responsive Image Galleries 7.2
Test a gallery embedded in a view row that is dependent on a sub-request when fetching the XML.
File
- tests/
JuiceboxSubRequestCase.test, line 42 - Test case for XML generation based on a sub-request.
Class
- JuiceboxSubRequestCase
- Class to define test case for XML generation based on a sub-request.
Code
public function testSubRequestDependent() {
$instance = $this->instance;
$node = $this->node;
$xml_path = 'juicebox/xml/field/node/' . $node->nid . '/' . $instance['field_name'] . '/unknown';
// Get the urls to the test image and thumb derivative used by default.
$items = field_get_items('node', $this->node, $this->instance['field_name']);
$item = reset($items);
$test_image_url = image_style_url('juicebox_medium', $item['uri']);
$test_thumb_url = image_style_url('juicebox_square_thumbnail', $item['uri']);
// Check for correct embed markup.
$content = $this
->drupalGet('juicebox-test-row-formatter');
$this
->assertRaw(trim(json_encode(array(
'configUrl' => url($xml_path),
)), '{}"'), 'Gallery setting found in Drupal.settings.');
$this
->assertRaw('id="field--node--' . $node->nid . '--field-image--unknown"', 'Embed code wrapper found.');
$this
->assertRaw(check_plain($test_image_url), 'Test image found in embed code');
// Extract the xml-source values from the XML.
$matches = array();
// In the pattern below we have to use four (yeah, FOUR) backslashes to
// match a SINGLE literal backslash. Our source will contain an encoded
// (JSON) "&" character as "\u0026", but we don't want the regex to confuse
// that with an actaul "&" char in the pattern itself.
preg_match('/xml-source-path=([a-z1-9-]+)\\\\u0026xml-source-id=([a-z1-9-]+)/', $content, $matches);
$this
->assertNotNull($matches[1], 'xml-source-path value found in Drupal.settings.');
$this
->assertNotNull($matches[2], 'xml-source-id value found in Drupal.settings.');
// Check for correct XML. This example is dependent on a sub-request XML
// lookup, so everything below would fail without that feature.
$this
->drupalGet($xml_path, array(
'query' => array(
'xml-source-path' => $matches[1],
'xml-source-id' => $matches[2],
),
));
$this
->assertRaw('<?xml version="1.0" encoding="UTF-8"?>', 'Valid XML detected.');
$this
->assertRaw('imageURL="' . check_plain($test_image_url), 'Test image found in XML.');
$this
->assertRaw('thumbURL="' . check_plain($test_thumb_url), 'Test thumbnail found in XML.');
$this
->assertRaw('backgroundcolor="green"', 'Custom background setting from pseudo field instance config found in XML.');
}