/** * {@inheritdoc} */ public function viewElements(FieldItemListInterface $items, $langcode) { $elements = []; $thumb_image_style = $this->getSetting('thumbnail_image_style'); $popup_image_style = $this->getSetting('popup_image_style'); $gallery_type = $this->getSetting('gallery_type'); $files = $this->getEntitiesToView($items, $langcode); foreach ($files as $delta => $file) { $image_uri = $file->getFileUri(); $popup_image_path = !empty($popup_image_style) ? ImageStyle::load($popup_image_style)->buildUrl($image_uri) : $image_uri; // Depending on the outcome of https://www.drupal.org/node/2622586, // Either a class will need to be added to the $url object, // Or a custom theme function might be needed to do so. // For the time being, 'a' is used as the delegate in magnific-popup.js. $url = Url::fromUri(file_create_url($popup_image_path)); $item = $file->_referringItem; $item_attributes = $file->_attributes; unset($file->_attributes); $item_attributes['class'][] = 'mfp-thumbnail'; if ($gallery_type === 'first_item' && $delta > 0) { $elements[$delta] = ['#theme' => 'image_formatter', '#url' => $url, '#attached' => ['library' => ['magnific_popup/magnific_popup']]]; } else { $elements[$delta] = ['#theme' => 'image_formatter', '#item' => $item, '#item_attributes' => $item_attributes, '#image_style' => $thumb_image_style, '#url' => $url, '#attached' => ['library' => ['magnific_popup/magnific_popup']]]; } } return $elements; }
/** * {@inheritdoc} */ public function transformDimensions(array &$dimensions, $uri) { if (!isset($dimensions['width']) || !isset($dimensions['height'])) { // We cannot know which preset would be executed and thus cannot know the // resulting dimensions, unless both styles return the same dimensions: $landscape_dimensions = $portrait_dimensions = $dimensions; /* @var ImageStyle $landscape_style */ $landscape_style = ImageStyle::load($this->configuration['landscape']); $landscape_style->transformDimensions($landscape_dimensions, $uri); /* @var ImageStyle $portrait_style */ $portrait_style = ImageStyle::load($this->configuration['portrait']); $portrait_style->transformDimensions($portrait_dimensions, $uri); if ($landscape_dimensions == $portrait_dimensions) { $dimensions = $landscape_dimensions; } else { $dimensions['width'] = $dimensions['height'] = NULL; } } else { $ratio_adjustment = isset($this->configuration['ratio_adjustment']) ? floatval($this->configuration['ratio_adjustment']) : 1; $aspect = $dimensions['width'] / $dimensions['height']; $style_name = $aspect * $ratio_adjustment > 1 ? $this->configuration['landscape'] : $this->configuration['portrait']; /* @var ImageStyle $style */ $style = ImageStyle::load($style_name); $style->transformDimensions($dimensions, $uri); } }
/** * Auto Orientation operations test. */ public function doTestAutoOrientOperations() { $image_factory = $this->container->get('image.factory'); $test_data = [['test_file' => drupal_get_path('module', 'image_effects') . '/misc/portrait-painting.jpg', 'original_width' => 640, 'original_height' => 480, 'derivative_width' => 200, 'derivative_height' => 267], ['test_file' => drupal_get_path('module', 'simpletest') . '/files/image-test.jpg', 'original_width' => 40, 'original_height' => 20, 'derivative_width' => 200, 'derivative_height' => 100], ['test_file' => drupal_get_path('module', 'simpletest') . '/files/image-1.png', 'original_width' => 360, 'original_height' => 240, 'derivative_width' => 200, 'derivative_height' => 133]]; foreach ($test_data as $data) { // Get expected URIs. $original_uri = file_unmanaged_copy($data['test_file'], 'public://', FILE_EXISTS_RENAME); $generated_uri = 'public://styles/image_effects_test/public/' . \Drupal::service('file_system')->basename($original_uri); // Test source image dimensions. $image = $image_factory->get($original_uri); $this->assertEqual($data['original_width'], $image->getWidth()); $this->assertEqual($data['original_height'], $image->getHeight()); // Load Image Style and get expected derivative URL. $image_style = ImageStyle::load('image_effects_test'); $url = file_url_transform_relative($image_style->buildUrl($original_uri)); // Check that ::transformDimensions returns expected dimensions. $variables = array('#theme' => 'image_style', '#style_name' => 'image_effects_test', '#uri' => $original_uri, '#width' => $image->getWidth(), '#height' => $image->getHeight()); $this->assertEqual('<img src="' . $url . '" width="' . $data['derivative_width'] . '" height="' . $data['derivative_height'] . '" alt="" class="image-style-image-effects-test" />', $this->getImageTag($variables)); // Check that ::applyEffect generates image with expected dimensions. $image_style->createDerivative($original_uri, $image_style->buildUri($original_uri)); $image = $image_factory->get($generated_uri); $this->assertEqual($data['derivative_width'], $image->getWidth()); $this->assertEqual($data['derivative_height'], $image->getHeight()); } }
/** * {@inheritdoc} */ public function viewElements(FieldItemListInterface $items, $langcode) { $elements = array(); $files = $this->getEntitiesToView($items, $langcode); // Early opt-out if the field is empty. if (empty($files)) { return $elements; } $image_style_setting = $this->getSetting('image_style'); // Determine if Image style is required. $image_style = NULL; if (!empty($image_style_setting)) { $image_style = entity_load('image_style', $image_style_setting); } foreach ($files as $delta => $file) { $image_uri = $file->getFileUri(); // Get image style URL if ($image_style) { $image_uri = ImageStyle::load($image_style->getName())->buildUrl($image_uri); } else { // Get absolute path for original image $image_uri = $file->url(); } $elements[$delta] = array('#markup' => $image_uri); } return $elements; }
/** * Color Shift operations test. */ public function doTestColorshiftOperations() { $image_factory = $this->container->get('image.factory'); // Test on the PNG test image. $test_file = drupal_get_path('module', 'simpletest') . '/files/image-test.png'; $original_uri = file_unmanaged_copy($test_file, 'public://', FILE_EXISTS_RENAME); $generated_uri = 'public://styles/image_effects_test/public/' . \Drupal::service('file_system')->basename($original_uri); // Test data. $test_data = ['#FF0000' => [$this->red, $this->yellow, $this->transparent, $this->fuchsia], '#00FF00' => [$this->yellow, $this->green, $this->transparent, $this->cyan], '#0000FF' => [$this->fuchsia, $this->cyan, $this->transparent, $this->blue], '#929BEF' => [[255, 155, 239, 0], [146, 255, 239, 0], $this->transparent, [146, 155, 255, 0]]]; foreach ($test_data as $key => $colors) { // Add Color Shift effect to the test image style. $effect = ['id' => 'image_effects_color_shift', 'data' => ['RGB][hex' => $key]]; $uuid = $this->addEffectToTestStyle($effect); // Load Image Style. $image_style = ImageStyle::load('image_effects_test'); // Check that ::applyEffect generates image with expected color shift. $image_style->createDerivative($original_uri, $image_style->buildUri($original_uri)); $image = $image_factory->get($generated_uri, 'gd'); $this->assertTrue($this->colorsAreEqual($colors[0], $this->getPixelColor($image, 0, 0))); $this->assertTrue($this->colorsAreEqual($colors[1], $this->getPixelColor($image, 39, 0))); $this->assertTrue($this->colorsAreEqual($colors[2], $this->getPixelColor($image, 0, 19))); $this->assertTrue($this->colorsAreEqual($colors[3], $this->getPixelColor($image, 39, 19))); // Remove effect. $uuid = $this->removeEffectFromTestStyle($uuid); } }
/** * Tests embedded users on node pages. */ function testPictureOnNodeComment() { $this->drupalLogin($this->webUser); // Save a new picture. $image = current($this->drupalGetTestFiles('image')); $file = $this->saveUserPicture($image); $node = $this->drupalCreateNode(array('type' => 'article')); // Enable user pictures on nodes. $this->config('system.theme.global')->set('features.node_user_picture', TRUE)->save(); $image_style_id = $this->config('core.entity_view_display.user.user.compact')->get('content.user_picture.settings.image_style'); $style = ImageStyle::load($image_style_id); $image_url = $style->buildUrl($file->getfileUri()); $alt_text = 'Profile picture for user ' . $this->webUser->getUsername(); // Verify that the image is displayed on the node page. $this->drupalGet('node/' . $node->id()); $elements = $this->cssSelect('.node__meta .field--name-user-picture img[alt="' . $alt_text . '"][src="' . $image_url . '"]'); $this->assertEqual(count($elements), 1, 'User picture with alt text found on node page.'); // Enable user pictures on comments, instead of nodes. $this->config('system.theme.global')->set('features.node_user_picture', FALSE)->set('features.comment_user_picture', TRUE)->save(); $edit = array('comment_body[0][value]' => $this->randomString()); $this->drupalPostForm('comment/reply/node/' . $node->id() . '/comment', $edit, t('Save')); $elements = $this->cssSelect('.comment__meta .field--name-user-picture img[alt="' . $alt_text . '"][src="' . $image_url . '"]'); $this->assertEqual(count($elements), 1, 'User picture with alt text found on the comment.'); // Disable user pictures on comments and nodes. $this->config('system.theme.global')->set('features.node_user_picture', FALSE)->set('features.comment_user_picture', FALSE)->save(); $this->drupalGet('node/' . $node->id()); $this->assertNoRaw(file_uri_target($file->getFileUri()), 'User picture not found on node and comment.'); }
/** * {@inheritdoc} */ public function build() { $query = \Drupal::entityQuery('node')->condition('status', 1)->condition('type', 'team_member')->sort('field_order', 'ASC'); $nids = $query->execute(); $nodes = node_load_multiple($nids); //$nodes = entity_load_multiple('node', $nids); $ind = 1; $output = '<div class="tabbable tabs-left tabcordion"> <ul class="nav nav-tabs">'; foreach ($nodes as $node) { $class = $ind == 1 ? 'active' : ''; $output .= '<li class="' . $class . '"><a data-target="#team_member_tab' . $ind . '" data-toggle="tab">' . $node->title->value . '<span>' . $node->get('field_designation')->value . '</span></a></li>'; $ind++; } $ind = 1; $output .= '</ul> <div class="tab-content">'; foreach ($nodes as $node) { $class = $ind == 1 ? 'active' : ''; if (is_object($node->field_image->entity)) { $path = $node->field_image->entity->getFileUri(); $url = ImageStyle::load('person_picture')->buildUrl($path); $tab_content_html = '<div class="row"><div class="col-md-3"><img src="' . $url . '" alt=""></div><div class="col-md-9">' . $node->get('body')->value . '</div> </div>'; } else { $tab_content_html = '<div>' . $node->get('body')->value . '</div>'; } $output .= '<div class="tab-pane ' . $class . '" id="team_member_tab' . $ind . '"> ' . $tab_content_html . ' </div>'; $ind++; } $output .= '</div> </div>'; return array('#type' => 'markup', '#markup' => $output, '#attached' => array('library' => array('barney_river_utilities/tabcordion', 'barney_river_utilities/tabcordion_hook'))); }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state, $grouping = NULL) { // Load logo image. $rendered_image = NULL; if (!empty($grouping->logo_fid)) { $file = File::load($grouping->logo_fid); if ($file) { $logo_url = ImageStyle::load('ea_groupings_200x200')->buildUrl($file->getFileUri()); $image_array = array('#theme' => 'image', '#uri' => $logo_url, '#alt' => $this->t('Logo for @grouping', array('@grouping' => $grouping->title)), '#title' => $this->t('@grouping', array('@grouping' => $grouping->title))); $rendered_image = \Drupal::service('renderer')->render($image_array); } } // Construct form. $form = array(); $form['gid'] = array('#type' => 'value', '#value' => $grouping->gid); $form['add'] = array('#type' => 'fieldset', '#description' => $this->t('Update grouping'), '#title' => $this->t('Edit grouping')); $form['add']['title'] = array('#type' => 'textfield', '#title' => $this->t('Title'), '#description' => $this->t('Title of grouping'), '#size' => 20, '#maxlength' => 20, '#required' => FALSE, '#default_value' => $grouping->title); $form['add']['description'] = array('#type' => 'textarea', '#title' => $this->t('Description'), '#description' => $this->t('A short description of the grouping'), '#required' => FALSE, '#default_value' => $grouping->description); $form['add']['logo'] = array('#type' => 'markup', '#markup' => $rendered_image); $form['add']['logo_fid'] = array('#title' => $this->t('Update logo'), '#type' => 'managed_file', '#description' => $this->t('Upload a logo for the grouping'), '#default_value' => NULL, '#upload_location' => 'public://logos/'); $form['add']['time_zone'] = array('#title' => $this->t('Timezone'), '#type' => 'select', '#description' => $this->t('Select a time zone for the grouping'), '#options' => _ea_groupings_get_time_zones(), '#default_value' => $grouping->time_zone); $form['add']['parent_gid'] = array('#type' => 'select', '#description' => $this->t('Select a parent grouping'), '#options' => _ea_groupings_get_groupings_list(FALSE, $grouping->gid), '#disabled' => _ea_groupings_is_parent($grouping->gid), '#default_value' => $grouping->parent_gid); $form['add']['submit'] = array('#type' => 'submit', '#name' => 'add_group', '#value' => $this->t('Update grouping'), '#weight' => 100); $form['add']['old_title'] = array('#type' => 'value', '#value' => $grouping->title); $form['add']['old_logo_fid'] = array('#type' => 'value', '#value' => $grouping->logo_fid); $form['add']['old_parent_gid'] = array('#type' => 'value', '#value' => $grouping->parent_gid); return $form; }
/** * Watermark operations test. */ public function doTestWatermarkOperations() { $image_factory = $this->container->get('image.factory'); $test_file = drupal_get_path('module', 'simpletest') . '/files/image-1.png'; $original_uri = file_unmanaged_copy($test_file, 'public://', FILE_EXISTS_RENAME); $generated_uri = 'public://styles/image_effects_test/public/' . \Drupal::service('file_system')->basename($original_uri); $watermark_file = drupal_get_path('module', 'simpletest') . '/files/image-test.png'; $watermark_uri = file_unmanaged_copy($watermark_file, 'public://', FILE_EXISTS_RENAME); $effect = ['id' => 'image_effects_watermark', 'data' => ['placement' => 'left-top', 'x_offset' => 1, 'y_offset' => 1, 'opacity' => 100, 'watermark_image' => $watermark_uri]]; $uuid = $this->addEffectToTestStyle($effect); // Load Image Style. $image_style = ImageStyle::load('image_effects_test'); // Check that ::applyEffect generates image with expected watermark. $image_style->createDerivative($original_uri, $image_style->buildUri($original_uri)); $image = $image_factory->get($generated_uri, 'gd'); $watermark = $image_factory->get($watermark_uri, 'gd'); $this->assertFalse($this->colorsAreEqual($this->getPixelColor($watermark, 0, 0), $this->getPixelColor($image, 0, 0))); $this->assertTrue($this->colorsAreEqual($this->getPixelColor($watermark, 0, 0), $this->getPixelColor($image, 1, 1))); $this->assertTrue($this->colorsAreEqual($this->getPixelColor($watermark, 0, 1), $this->getPixelColor($image, 1, 2))); $this->assertTrue($this->colorsAreEqual($this->getPixelColor($watermark, 0, 3), $this->getPixelColor($image, 1, 4))); // Remove effect. $this->removeEffectFromTestStyle($uuid); // Test for watermark PNG image with full transparency set, 100% opacity // watermark. $test_file = drupal_get_path('module', 'image_effects') . '/tests/images/fuchsia.png'; $original_uri = file_unmanaged_copy($test_file, 'public://', FILE_EXISTS_RENAME); $generated_uri = 'public://styles/image_effects_test/public/' . \Drupal::service('file_system')->basename($original_uri); $watermark_file = drupal_get_path('module', 'simpletest') . '/files/image-test.png'; $watermark_uri = file_unmanaged_copy($watermark_file, 'public://', FILE_EXISTS_RENAME); $effect = ['id' => 'image_effects_watermark', 'data' => ['placement' => 'left-top', 'x_offset' => 0, 'y_offset' => 0, 'opacity' => 100, 'watermark_image' => $watermark_uri]]; $uuid = $this->addEffectToTestStyle($effect); // Load Image Style. $image_style = ImageStyle::load('image_effects_test'); // Check that ::applyEffect generates image with expected transparency. $image_style->createDerivative($original_uri, $image_style->buildUri($original_uri)); $image = $image_factory->get($generated_uri, 'gd'); $this->assertTrue($this->colorsAreEqual($this->getPixelColor($image, 0, 19), $this->fuchsia)); // Remove effect. $this->removeEffectFromTestStyle($uuid); // Test for watermark PNG image with full transparency set, 50% opacity // watermark. $test_file = drupal_get_path('module', 'image_effects') . '/tests/images/fuchsia.png'; $original_uri = file_unmanaged_copy($test_file, 'public://', FILE_EXISTS_RENAME); $generated_uri = 'public://styles/image_effects_test/public/' . \Drupal::service('file_system')->basename($original_uri); $watermark_file = drupal_get_path('module', 'simpletest') . '/files/image-test.png'; $watermark_uri = file_unmanaged_copy($watermark_file, 'public://', FILE_EXISTS_RENAME); $effect = ['id' => 'image_effects_watermark', 'data' => ['placement' => 'left-top', 'x_offset' => 0, 'y_offset' => 0, 'opacity' => 50, 'watermark_image' => $watermark_uri]]; $uuid = $this->addEffectToTestStyle($effect); // Load Image Style. $image_style = ImageStyle::load('image_effects_test'); // Check that ::applyEffect generates image with expected alpha. $image_style->createDerivative($original_uri, $image_style->buildUri($original_uri)); $image = $image_factory->get($generated_uri, 'gd'); $this->assertTrue($this->colorsAreEqual($this->getPixelColor($image, 0, 19), $this->fuchsia)); // GD and ImageMagick return slightly different colors, use the // ::colorsAreClose method. $this->assertTrue($this->colorsAreClose($this->getPixelColor($image, 39, 0), [127, 127, 127, 0])); // Remove effect. $this->removeEffectFromTestStyle($uuid); }
/** * Contrast operations test. */ public function doTestContrastOperations() { $image_factory = $this->container->get('image.factory'); $image_toolkit_id = $image_factory->getToolkitId(); // Test on the PNG test image. $test_file = drupal_get_path('module', 'simpletest') . '/files/image-test.png'; $original_uri = file_unmanaged_copy($test_file, 'public://', FILE_EXISTS_RENAME); $generated_uri = 'public://styles/image_effects_test/public/' . \Drupal::service('file_system')->basename($original_uri); // Test data. $test_data = ['0' => [$this->red, $this->green, $this->transparent, $this->blue], '-50' => [$image_toolkit_id === 'imagemagick' ? array(180, 75, 75, 0) : array(159, 95, 95, 0), $image_toolkit_id === 'imagemagick' ? array(75, 180, 75, 0) : array(95, 159, 95, 0), $this->transparent, $image_toolkit_id === 'imagemagick' ? array(75, 75, 180, 0) : array(95, 95, 159, 0)], '-100' => [$image_toolkit_id === 'imagemagick' ? array(128, 128, 128, 0) : array(127, 127, 127, 0), $image_toolkit_id === 'imagemagick' ? array(128, 128, 128, 0) : array(127, 127, 127, 0), $this->transparent, $image_toolkit_id === 'imagemagick' ? array(128, 128, 128, 0) : array(127, 127, 127, 0)], '50' => [array(255, 0, 0, 0), array(0, 255, 0, 0), $this->transparent, array(0, 0, 255, 0)], '100' => [array(255, 0, 0, 0), array(0, 255, 0, 0), $this->transparent, array(0, 0, 255, 0)]]; foreach ($test_data as $key => $colors) { // Add contrast effect to the test image style. $effect = ['id' => 'image_effects_contrast', 'data' => ['level' => $key]]; $uuid = $this->addEffectToTestStyle($effect); // Load Image Style. $image_style = ImageStyle::load('image_effects_test'); // Check that ::applyEffect generates image with expected contrast. $image_style->createDerivative($original_uri, $image_style->buildUri($original_uri)); $image = $image_factory->get($generated_uri, 'gd'); $this->assertTrue($this->colorsAreEqual($colors[0], $this->getPixelColor($image, 0, 0))); $this->assertTrue($this->colorsAreEqual($colors[1], $this->getPixelColor($image, 39, 0))); $this->assertTrue($this->colorsAreEqual($colors[2], $this->getPixelColor($image, 0, 19))); $this->assertTrue($this->colorsAreEqual($colors[3], $this->getPixelColor($image, 39, 19))); // Remove effect. $uuid = $this->removeEffectFromTestStyle($uuid); } }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->fileSystem = $this->container->get('file_system'); $this->config('system.file')->set('default_scheme', 'public')->save(); $this->imageStyle = ImageStyle::create(['name' => 'test']); $this->imageStyle->save(); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->style = ImageStyle::create(['name' => 'style_foo', 'label' => $this->randomString()]); $this->style->save(); $this->replacementStyle = ImageStyle::create(['name' => 'style_bar', 'label' => $this->randomString()]); $this->replacementStyle->save(); $this->entityTypeManager = \Drupal::entityTypeManager(); }
/** * {@inheritdoc} */ public function renderThumbnail($image_style, $link_url) { $this->downloadThumbnail(); $output = ['#theme' => 'image', '#uri' => !empty($image_style) ? ImageStyle::load($image_style)->buildUrl($this->getLocalThumbnailUri()) : $this->getLocalThumbnailUri()]; if ($link_url) { $output = ['#type' => 'link', '#title' => $output, '#url' => $link_url]; } return $output; }
/** * Tests the dependency between ImageStyle and entity display components. */ public function testEntityDisplayDependency() { // Create two image styles. /** @var \Drupal\image\ImageStyleInterface $style */ $style = ImageStyle::create(['name' => 'main_style']); $style->save(); /** @var \Drupal\image\ImageStyleInterface $replacement */ $replacement = ImageStyle::create(['name' => 'replacement_style']); $replacement->save(); // Create a node-type, named 'note'. $node_type = NodeType::create(['type' => 'note']); $node_type->save(); // Create an image field and attach it to the 'note' node-type. FieldStorageConfig::create(['entity_type' => 'node', 'field_name' => 'sticker', 'type' => 'image'])->save(); FieldConfig::create(['entity_type' => 'node', 'field_name' => 'sticker', 'bundle' => 'note'])->save(); // Create the default entity view display and set the 'sticker' field to use // the 'main_style' images style in formatter. /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $view_display */ $view_display = EntityViewDisplay::create(['targetEntityType' => 'node', 'bundle' => 'note', 'mode' => 'default', 'status' => TRUE])->setComponent('sticker', ['settings' => ['image_style' => 'main_style']]); $view_display->save(); // Create the default entity form display and set the 'sticker' field to use // the 'main_style' images style in the widget. /** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display */ $form_display = EntityFormDisplay::create(['targetEntityType' => 'node', 'bundle' => 'note', 'mode' => 'default', 'status' => TRUE])->setComponent('sticker', ['settings' => ['preview_image_style' => 'main_style']]); $form_display->save(); // Check that the entity displays exists before dependency removal. $this->assertNotNull(EntityViewDisplay::load($view_display->id())); $this->assertNotNull(EntityFormDisplay::load($form_display->id())); // Delete the 'main_style' image style. Before that, emulate the UI process // of selecting a replacement style by setting the replacement image style // ID in the image style storage. /** @var \Drupal\image\ImageStyleStorageInterface $storage */ $storage = $this->container->get('entity.manager')->getStorage($style->getEntityTypeId()); $storage->setReplacementId('main_style', 'replacement_style'); $style->delete(); // Check that the entity displays exists after dependency removal. $this->assertNotNull($view_display = EntityViewDisplay::load($view_display->id())); $this->assertNotNull($form_display = EntityFormDisplay::load($form_display->id())); // Check that the 'sticker' formatter component exists in both displays. $this->assertNotNull($formatter = $view_display->getComponent('sticker')); $this->assertNotNull($widget = $form_display->getComponent('sticker')); // Check that both displays are using now 'replacement_style' for images. $this->assertSame('replacement_style', $formatter['settings']['image_style']); $this->assertSame('replacement_style', $widget['settings']['preview_image_style']); // Delete the 'replacement_style' without setting a replacement image style. $replacement->delete(); // The entity view and form displays exists after dependency removal. $this->assertNotNull($view_display = EntityViewDisplay::load($view_display->id())); $this->assertNotNull($form_display = EntityFormDisplay::load($form_display->id())); // The 'sticker' formatter component should be hidden in view display. $this->assertNull($view_display->getComponent('sticker')); $this->assertTrue($view_display->get('hidden')['sticker']); // The 'sticker' widget component should be active in form displays, but the // image preview should be disabled. $this->assertNotNull($widget = $form_display->getComponent('sticker')); $this->assertSame('', $widget['settings']['preview_image_style']); }
/** * Set canvas operations test. */ public function doTestSetCanvasOperations() { $image_factory = $this->container->get('image.factory'); $test_file = drupal_get_path('module', 'simpletest') . '/files/image-test.png'; $original_uri = file_unmanaged_copy($test_file, 'public://', FILE_EXISTS_RENAME); $generated_uri = 'public://styles/image_effects_test/public/' . \Drupal::service('file_system')->basename($original_uri); // Test EXACT size canvas. $effect = ['id' => 'image_effects_set_canvas', 'data' => ['canvas_size' => 'exact', 'canvas_color][container][transparent' => FALSE, 'canvas_color][container][hex' => '#FF00FF', 'canvas_color][container][opacity' => 100, 'exact][width' => '200%', 'exact][height' => '200%']]; $uuid = $this->addEffectToTestStyle($effect); // Load Image Style. $image_style = ImageStyle::load('image_effects_test'); // Check that ::transformDimensions returns expected dimensions. $image = $image_factory->get($original_uri); $this->assertEqual(40, $image->getWidth()); $this->assertEqual(20, $image->getHeight()); $url = file_url_transform_relative($image_style->buildUrl($original_uri)); $variables = array('#theme' => 'image_style', '#style_name' => 'image_effects_test', '#uri' => $original_uri, '#width' => $image->getWidth(), '#height' => $image->getHeight()); $this->assertEqual('<img src="' . $url . '" width="80" height="40" alt="" class="image-style-image-effects-test" />', $this->getImageTag($variables)); // Check that ::applyEffect generates image with expected canvas. $image_style->createDerivative($original_uri, $image_style->buildUri($original_uri)); $image = $image_factory->get($generated_uri, 'gd'); $this->assertEqual(80, $image->getWidth()); $this->assertEqual(40, $image->getHeight()); $this->assertTrue($this->colorsAreEqual($this->fuchsia, $this->getPixelColor($image, 0, 0))); $this->assertTrue($this->colorsAreEqual($this->fuchsia, $this->getPixelColor($image, 79, 0))); $this->assertTrue($this->colorsAreEqual($this->fuchsia, $this->getPixelColor($image, 0, 39))); $this->assertTrue($this->colorsAreEqual($this->fuchsia, $this->getPixelColor($image, 79, 39))); // Remove effect. $this->removeEffectFromTestStyle($uuid); // Test RELATIVE size canvas. $effect = ['id' => 'image_effects_set_canvas', 'data' => ['canvas_size' => 'relative', 'canvas_color][container][transparent' => FALSE, 'canvas_color][container][hex' => '#FFFF00', 'canvas_color][container][opacity' => 100, 'relative][right' => 10, 'relative][left' => 20, 'relative][top' => 30, 'relative][bottom' => 40]]; $uuid = $this->addEffectToTestStyle($effect); // Load Image Style. $image_style = ImageStyle::load('image_effects_test'); // Check that ::transformDimensions returns expected dimensions. $image = $image_factory->get($original_uri); $this->assertEqual(40, $image->getWidth()); $this->assertEqual(20, $image->getHeight()); $url = file_url_transform_relative($image_style->buildUrl($original_uri)); $variables = array('#theme' => 'image_style', '#style_name' => 'image_effects_test', '#uri' => $original_uri, '#width' => $image->getWidth(), '#height' => $image->getHeight()); $this->assertEqual('<img src="' . $url . '" width="70" height="90" alt="" class="image-style-image-effects-test" />', $this->getImageTag($variables)); // Check that ::applyEffect generates image with expected canvas. $image_style->createDerivative($original_uri, $image_style->buildUri($original_uri)); $image = $image_factory->get($generated_uri, 'gd'); $this->assertEqual(70, $image->getWidth()); $this->assertEqual(90, $image->getHeight()); $this->assertTrue($this->colorsAreEqual($this->yellow, $this->getPixelColor($image, 0, 0))); $this->assertTrue($this->colorsAreEqual($this->yellow, $this->getPixelColor($image, 69, 0))); $this->assertTrue($this->colorsAreEqual($this->yellow, $this->getPixelColor($image, 0, 89))); $this->assertTrue($this->colorsAreEqual($this->yellow, $this->getPixelColor($image, 69, 89))); // Remove effect. $this->removeEffectFromTestStyle($uuid); }
/** * Tests importing image styles. */ public function testImport() { $style = ImageStyle::create(['name' => 'test']); $style->addImageEffect(['id' => 'image_module_test_null']); $style->addImageEffect(['id' => 'image_module_test_null']); $style->save(); $this->assertEqual(count($style->getEffects()), 2); $uuid = \Drupal::service('uuid')->generate(); $style->set('effects', [$uuid => ['id' => 'image_module_test_null']]); $style->save(); $style = ImageStyle::load('test'); $this->assertEqual(count($style->getEffects()), 1); }
/** * Test basic passing migrations. */ public function testPassingMigration() { $this->executeMigration('d6_imagecache_presets'); /** @var \Drupal\image\Entity\ImageStyle $style */ $style = ImageStyle::load('big_blue_cheese'); // Check basic Style info. $this->assertIdentical('big_blue_cheese', $style->get('name'), 'ImageStyle name set correctly'); $this->assertIdentical('big_blue_cheese', $style->get('label'), 'ImageStyle label set correctly'); // Test effects. $effects = $style->getEffects(); // Check crop effect. $this->assertImageEffect($effects, 'image_crop', ['width' => 555, 'height' => 5555, 'anchor' => 'center-center']); // Check resize effect. $this->assertImageEffect($effects, 'image_resize', ['width' => 55, 'height' => 55]); // Check rotate effect. $this->assertImageEffect($effects, 'image_rotate', ['degrees' => 55, 'random' => FALSE, 'bgcolor' => '']); }
/** * General test to flush a style. */ function testFlush() { // Setup a style to be created and effects to add to it. $style_name = strtolower($this->randomMachineName(10)); $style_label = $this->randomString(); $style_path = 'admin/config/media/image-styles/manage/' . $style_name; $effect_edits = array('image_resize' => array('data[width]' => 100, 'data[height]' => 101), 'image_scale' => array('data[width]' => 110, 'data[height]' => 111, 'data[upscale]' => 1)); // Add style form. $edit = array('name' => $style_name, 'label' => $style_label); $this->drupalPostForm('admin/config/media/image-styles/add', $edit, t('Create new style')); // Add each sample effect to the style. foreach ($effect_edits as $effect => $edit) { // Add the effect. $this->drupalPostForm($style_path, array('new' => $effect), t('Add')); if (!empty($edit)) { $this->drupalPostForm(NULL, $edit, t('Add effect')); } } // Load the saved image style. $style = ImageStyle::load($style_name); // Create an image for the 'public' wrapper. $image_path = $this->createSampleImage($style, 'public'); // Expecting to find 2 images, one is the sample.png image shown in // image style preview. $this->assertEqual($this->getImageCount($style, 'public'), 2, format_string('Image style %style image %file successfully generated.', array('%style' => $style->label(), '%file' => $image_path))); // Create an image for the 'private' wrapper. $image_path = $this->createSampleImage($style, 'private'); $this->assertEqual($this->getImageCount($style, 'private'), 1, format_string('Image style %style image %file successfully generated.', array('%style' => $style->label(), '%file' => $image_path))); // Remove the 'image_scale' effect and updates the style, which in turn // forces an image style flush. $style_path = 'admin/config/media/image-styles/manage/' . $style->id(); $uuids = array(); foreach ($style->getEffects() as $uuid => $effect) { $uuids[$effect->getPluginId()] = $uuid; } $this->drupalPostForm($style_path . '/effects/' . $uuids['image_scale'] . '/delete', array(), t('Delete')); $this->assertResponse(200); $this->drupalPostForm($style_path, array(), t('Update style')); $this->assertResponse(200); // Post flush, expected 1 image in the 'public' wrapper (sample.png). $this->assertEqual($this->getImageCount($style, 'public'), 1, format_string('Image style %style flushed correctly for %wrapper wrapper.', array('%style' => $style->label(), '%wrapper' => 'public'))); // Post flush, expected no image in the 'private' wrapper. $this->assertEqual($this->getImageCount($style, 'private'), 0, format_string('Image style %style flushed correctly for %wrapper wrapper.', array('%style' => $style->label(), '%wrapper' => 'private'))); }
/** * Asserts various aspects of an ImageStyle entity. * * @param string $id * The expected image style ID. * @param string $label * The expected image style label. * @param array $expected_effect_plugins * An array of expected plugins attached to the image style entity * @param array $expected_effect_config * An array of expected configuration for each effect in the image style */ protected function assertEntity($id, $label, array $expected_effect_plugins, array $expected_effect_config) { $style = ImageStyle::load($id); $this->assertTrue($style instanceof ImageStyleInterface); /** @var \Drupal\image\ImageStyleInterface $style */ $this->assertIdentical($id, $style->id()); $this->assertIdentical($label, $style->label()); // Check the number of effects associated with the style. $effects = $style->getEffects(); $this->assertIdentical(count($effects), count($expected_effect_plugins)); $index = 0; foreach ($effects as $effect) { $this->assertTrue($effect instanceof ImageEffectBase); $this->assertIdentical($expected_effect_plugins[$index], $effect->getPluginId()); $config = $effect->getConfiguration(); $this->assertIdentical($expected_effect_config[$index], $config['data']); $index++; } }
/** * Strip metadata operations test. */ public function doTestStripMetadataOperations() { $image_factory = $this->container->get('image.factory'); $test_data = [['test_file' => drupal_get_path('module', 'image_effects') . '/misc/portrait-painting.jpg', 'original_orientation' => 8], ['test_file' => drupal_get_path('module', 'simpletest') . '/files/image-test.jpg', 'original_orientation' => NULL], ['test_file' => drupal_get_path('module', 'simpletest') . '/files/image-1.png', 'original_orientation' => NULL]]; foreach ($test_data as $data) { // Get expected URIs. $test_file = drupal_get_path('module', 'image_effects') . '/misc/portrait-painting.jpg'; $original_uri = file_unmanaged_copy($data['test_file'], 'public://', FILE_EXISTS_RENAME); $generated_uri = 'public://styles/image_effects_test/public/' . \Drupal::service('file_system')->basename($original_uri); // Test source image EXIF data. $exif = @exif_read_data(\Drupal::service('file_system')->realpath($original_uri)); $this->assertEqual($data['original_orientation'], isset($exif['Orientation']) ? $exif['Orientation'] : NULL); // Load Image Style and process source image. $image_style = ImageStyle::load('image_effects_test'); $image_style->createDerivative($original_uri, $image_style->buildUri($original_uri)); // Check that ::applyEffect strips EXIF metadata. $exif = @exif_read_data(\Drupal::service('file_system')->realpath($generated_uri)); $this->assertEqual(NULL, isset($exif['Orientation']) ? $exif['Orientation'] : NULL); } }
/** * Tests moving a randomly generated image. */ function testNormal() { // Pick a file for testing. $file = File::create((array) current($this->drupalGetTestFiles('image'))); // Create derivative image. $styles = ImageStyle::loadMultiple(); $style = reset($styles); $original_uri = $file->getFileUri(); $derivative_uri = $style->buildUri($original_uri); $style->createDerivative($original_uri, $derivative_uri); // Check if derivative image exists. $this->assertTrue(file_exists($derivative_uri), 'Make sure derivative image is generated successfully.'); // Clone the object so we don't have to worry about the function changing // our reference copy. $desired_filepath = 'public://' . $this->randomMachineName(); $result = file_move(clone $file, $desired_filepath, FILE_EXISTS_ERROR); // Check if image has been moved. $this->assertTrue(file_exists($result->getFileUri()), 'Make sure image is moved successfully.'); // Check if derivative image has been flushed. $this->assertFalse(file_exists($derivative_uri), 'Make sure derivative image has been flushed.'); }
/** * Tests devel silent. */ public function testDevelSilent() { // TODO Quickfix for dynamic_page_cache, enabled by default in the testing // profile. $this->container->get('module_installer')->uninstall(['dynamic_page_cache']); $web_user = $this->drupalCreateUser(['administer site configuration', 'access devel information', 'administer software updates']); $this->drupalLogin($web_user); // Ensure that devel is disabled if response come from routes that are // declared with '_devel_silent' requirement. $this->drupalGet('devel-silent/route-requirement'); $this->assertText(t('"_devel_silent" route requirement forces devel to be inactive.')); // Ensure that devel doesn't interfere with non html response (e.g JsonResponse). $response = $this->drupalGet('devel-silent/json'); $this->assertResponse(200); $expected = ['data' => 'Devel is active only on HtmlResponse.']; $this->assertIdentical(Json::decode($response), $expected); // Ensure that devel doesn't interfere with private image style creation // and with BinaryFileResponse response. $style = ImageStyle::create(['name' => 'zyx', 'label' => $this->randomString()]); $style->save(); $image = current($this->drupalGetTestFiles('image')); $image_uri = file_unmanaged_copy($image->uri, 'private://'); // Let the devel_test module know about this file, so it can claim // ownership in hook_file_download(). \Drupal::state()->set('devel.test_file_download', $image_uri); $this->drupalGet($style->buildUrl($image_uri)); $this->assertResponse(200); $this->assertRaw(file_get_contents($style->buildUri($image_uri)), 'URL returns expected file.'); // Ensure that devel doesn't interfere with private files and with // BinaryFileResponse response. $file = File::create(['uid' => $web_user->id(), 'filename' => 'drupal.txt', 'uri' => 'private://devel.txt', 'filemime' => 'text/plain', 'status' => FILE_STATUS_PERMANENT]); file_put_contents($file->getFileUri(), 'Hello world!'); $file->save(); // Let the image_module_test module know about this file, so it can claim // ownership in hook_file_download(). \Drupal::state()->set('devel.test_file_download', $file->getFileUri()); $this->drupalGet($file->url()); $this->assertResponse(200); $this->assertRaw(file_get_contents($file->getFileUri()), 'URL returns expected file.'); }
/** * Tests integration with image module. */ public function testImage() { /** @var \Drupal\image\ImageStyleInterface $style */ $style = ImageStyle::create(['name' => 'foo']); $style->save(); // Create a new image field 'bar' to be used in 'entity_test_fields' view. FieldStorageConfig::create(['entity_type' => 'entity_test', 'field_name' => 'bar', 'type' => 'image'])->save(); FieldConfig::create(['entity_type' => 'entity_test', 'bundle' => 'entity_test', 'field_name' => 'bar'])->save(); /** @var \Drupal\views\ViewEntityInterface $view */ $view = View::load('entity_test_fields'); $display =& $view->getDisplay('default'); // Add the 'bar' image field to 'entity_test_fields' view. $display['display_options']['fields']['bar'] = ['id' => 'bar', 'field' => 'bar', 'plugin_id' => 'field', 'table' => 'entity_test__bar', 'entity_type' => 'entity_test', 'entity_field' => 'bar', 'type' => 'image', 'settings' => ['image_style' => 'foo', 'image_link' => '']]; $view->save(); $dependencies = $view->getDependencies() + ['config' => []]; // Checks that style 'foo' is a dependency of view 'entity_test_fields'. $this->assertTrue(in_array('image.style.foo', $dependencies['config'])); // Delete the 'foo' image style. $style->delete(); // Checks that the view has been deleted too. $this->assertNull(View::load('entity_test_fields')); }
/** * {@inheritdoc} */ public function blockForm($form, FormStateInterface $form_state) { $form['featured'] = array('#type' => 'details', '#title' => t('Homepage Featured content'), '#open' => TRUE); for ($c = 1; $c <= 3; $c++) { $form['featured']['item' . $c] = array('#type' => 'details', '#title' => t('Item #' . $c), '#open' => TRUE); $file = $fid = NULL; $file_uuid = $this->configuration['featured_image' . $c]; if (!empty($file_uuid)) { $fid = db_query("SELECT fid FROM {file_managed}\n WHERE uuid = :uuid", array(':uuid' => $file_uuid))->fetchColumn(); } $link = $this->configuration['featured_link' . $c]; // Add preview image. if (!empty($fid)) { $file = !empty($fid) ? file_load($fid) : NULL; $url = ImageStyle::load('thumbnail')->buildUrl($file->getFileUri()); $image = '<img src="' . $url . '" title="' . $file->name . '" width="100" />'; } $form['featured']['item' . $c]['image' . $c] = array('#type' => 'managed_file', '#title' => t('Current Image'), '#required' => TRUE, '#field_prefix' => !empty($file) ? $image : NULL, '#description' => t('Image to be shown if no image is uploaded.'), '#default_value' => !empty($fid) ? array($fid) : NULL, '#upload_location' => 'public://oc_homepage/'); $form['featured']['item' . $c]['link' . $c] = array('#type' => 'textfield', '#title' => t('Link'), '#required' => FALSE, '#default_value' => !empty($link) ? array($link) : NULL); } return $form; }
/** * {@inheritdoc} */ public function getSummary() { $summery = parent::getSummary(); $summery[] = $this->t('Show image dimensions: @show_image_dimensions', [ '@show_image_dimensions' => $this->configuration['images']['show_dimensions'] ? $this->t('Yes') : $this->t('No'), ]); $summery[] = $this->t('Show image thumbnail: @show_image_thumbnail', [ '@show_image_thumbnail' => $this->configuration['images']['show_thumbnail'] ? $this->t('Yes') : $this->t('No'), ]); if ($this->moduleHandler->moduleExists('image') && $this->configuration['images']['show_thumbnail']) { $image_style = ImageStyle::load($this->configuration['images']['thumbnail_image_style']); if (!is_null($image_style)) { $summery[] = $this->t('Thumbnail style: @thumbnail_style', [ '@thumbnail_style' => $image_style->label(), ]); } } return $summery; }
/** * Test Focal Point change. */ public function testFocalPointChange() { // Media ID used for testing. $mediaId = 9; $page = $this->getSession()->getPage(); $this->drupalGet("media/{$mediaId}/edit"); $this->createScreenshot($this->getScreenshotFolder() . '/MediaImageModifyTest_BeforeFocalPointChange_' . date('Ymd_His') . '.png'); $this->getSession()->getDriver()->executeScript('var e = new jQuery.Event("click"); e.offsetX = 48; e.offsetY = 15; jQuery(".focal-point-wrapper img").trigger(e);'); $this->createScreenshot($this->getScreenshotFolder() . '/MediaImageModifyTest_AfterFocalPointChange_' . date('Ymd_His') . '.png'); $page->pressButton('Save and keep publish'); $media = Media::load($mediaId); $img = $media->get('field_image')->target_id; $file = File::load($img); $path = $file->getFileUri(); $derivativeUri = ImageStyle::load('teaser')->buildUri($path); ImageStyle::load('teaser')->createDerivative($path, $derivativeUri); $image1 = new Imagick($derivativeUri); $image2 = new Imagick(dirname(__FILE__) . '/../../fixtures/reference.jpg'); $result = $image1->compareImages($image2, \Imagick::METRIC_MEANSQUAREERROR); $this->assertTrue($result[1] < 0.01, 'Images are identical'); $image1->clear(); $image2->clear(); }
/** * {@inheritdoc} */ public function viewElements(FieldItemListInterface $items) { $elements = array(); $image_style_setting = $this->getSetting('image_style'); // Determine if Image style is required. $image_style = NULL; if (!empty($image_style_setting)) { $image_style = entity_load('image_style', $image_style_setting); } foreach ($items as $delta => $item) { if ($item->entity) { $image_uri = $item->entity->getFileUri(); // Get image style URL if ($image_style) { $image_uri = ImageStyle::load($image_style->getName())->buildUrl($image_uri); } else { // Get absolute path for original image $image_uri = $item->entity->url(); } $elements[$delta] = array('#markup' => $image_uri); } } return $elements; }
/** * Tests that image fields in teasers have correct resources. */ function testNodeTeaser() { // Set the display options for the teaser. $display_options = array('type' => 'image', 'settings' => array('image_style' => 'medium', 'image_link' => 'content')); $display = entity_get_display('node', 'article', 'teaser'); $display->setComponent($this->fieldName, $display_options)->save(); // Render the teaser. $node_render_array = node_view($this->node, 'teaser'); $html = \Drupal::service('renderer')->renderRoot($node_render_array); // Parse the teaser. $parser = new \EasyRdf_Parser_Rdfa(); $graph = new \EasyRdf_Graph(); $base_uri = \Drupal::url('<front>', [], ['absolute' => TRUE]); $parser->parse($graph, $html, 'rdfa', $base_uri); // Construct the node and image URIs for testing. $node_uri = $this->node->url('canonical', ['absolute' => TRUE]); $image_uri = ImageStyle::load('medium')->buildUrl($this->file->getFileUri()); // Test relations from node to image. $expected_value = array('type' => 'uri', 'value' => $image_uri); $this->assertTrue($graph->hasProperty($node_uri, 'http://ogp.me/ns#image', $expected_value), 'Node to file relation found in RDF output (og:image).'); // Test image type. $expected_value = array('type' => 'uri', 'value' => 'http://xmlns.com/foaf/0.1/Image'); $this->assertTrue($graph->hasProperty($image_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'Image type found in RDF output (foaf:Image).'); }
/** * Tests image style configuration import that does a delete. */ function testConfigImport() { // Create a new style. $style_name = strtolower($this->randomMachineName(10)); $style_label = $this->randomString(); $style = entity_create('image_style', array('name' => $style_name, 'label' => $style_label)); $style->save(); // Create an image field that uses the new style. $field_name = strtolower($this->randomMachineName(10)); $this->createImageField($field_name, 'article'); entity_get_display('node', 'article', 'default')->setComponent($field_name, array('type' => 'image', 'settings' => array('image_style' => $style_name)))->save(); // Create a new node with an image attached. $test_image = current($this->drupalGetTestFiles('image')); $nid = $this->uploadNodeImage($test_image, $field_name, 'article', $this->randomMachineName()); $node = Node::load($nid); // Get node field original image URI. $fid = $node->get($field_name)->target_id; $original_uri = File::load($fid)->getFileUri(); // Test that image is displayed using newly created style. $this->drupalGet('node/' . $nid); $this->assertRaw($style->buildUrl($original_uri), format_string('Image displayed using style @style.', array('@style' => $style_name))); // Copy config to sync, and delete the image style. $sync = $this->container->get('config.storage.sync'); $active = $this->container->get('config.storage'); $this->copyConfig($active, $sync); $sync->delete('image.style.' . $style_name); $this->configImporter()->import(); $this->assertFalse(ImageStyle::load($style_name), 'Style deleted after config import.'); $this->assertEqual($this->getImageCount($style), 0, 'Image style was flushed after being deleted by config import.'); }
/** * Tests responsive image formatters linked to the file or node. * * @param string $link_type * The link type to test. Either 'file' or 'content'. */ private function assertResponsiveImageFieldFormattersLink($link_type) { $field_name = Unicode::strtolower($this->randomMachineName()); $field_settings = array('alt_field_required' => 0); $this->createImageField($field_name, 'article', array('uri_scheme' => 'public'), $field_settings); // Create a new node with an image attached. $test_image = current($this->drupalGetTestFiles('image')); // Test the image linked to file formatter. $display_options = array('type' => 'responsive_image', 'settings' => array('image_link' => $link_type, 'responsive_image_style' => 'style_one')); entity_get_display('node', 'article', 'default')->setComponent($field_name, $display_options)->save(); // Ensure that preview works. $this->previewNodeImage($test_image, $field_name, 'article'); // Look for a picture tag in the preview output $this->assertPattern('/picture/'); $nid = $this->uploadNodeImage($test_image, $field_name, 'article'); $this->container->get('entity.manager')->getStorage('node')->resetCache(array($nid)); $node = Node::load($nid); // Use the responsive image formatter linked to file formatter. $display_options = array('type' => 'responsive_image', 'settings' => array('image_link' => $link_type, 'responsive_image_style' => 'style_one')); entity_get_display('node', 'article', 'default')->setComponent($field_name, $display_options)->save(); // Create a derivative so at least one MIME type will be known. $large_style = ImageStyle::load('large'); $image_uri = File::load($node->{$field_name}->target_id)->getFileUri(); $large_style->createDerivative($image_uri, $large_style->buildUri($image_uri)); // Output should contain all image styles and all breakpoints. $this->drupalGet('node/' . $nid); $this->removeWhiteSpace(); switch ($link_type) { case 'file': // Make sure the link to the file is present. $this->assertPattern('/<a(.*?)href="' . preg_quote(file_url_transform_relative(file_create_url($image_uri)), '/') . '"(.*?)><picture/'); break; case 'content': // Make sure the link to the node is present. $this->assertPattern('/<a(.*?)href="' . preg_quote($node->url(), '/') . '"(.*?)><picture/'); break; } }