You are here

function OGMTBasicTest::testNodeOverrideDefaultImage in Open Graph meta tags 7

Same name and namespace in other branches
  1. 6 tests/Basic.test \OGMTBasicTest::testNodeOverrideDefaultImage()

File

tests/Basic.test, line 211

Class

OGMTBasicTest
Tests for Open Graph meta tags.

Code

function testNodeOverrideDefaultImage() {

  /*
   * Ensure that node image is used instead of global fallback image when no row is present for the node in
   * the OG meta tags table.
   */

  // empty node values
  // Important: there is no row in the data store!
  $node = $this
    ->_build_test_node(1);
  $this->ogm_settings
    ->set(OPENGRAPH_META_VAR_CONTENT_TYPE_ . 'type1', '');
  $this->ogm_settings
    ->set(OPENGRAPH_META_VAR_FALLBACK_IMG, 'default.jpg');

  // Check if the default image is returned when the node does not contain an image
  $this->ogm
    ->render_data($node, $this->ogm
    ->load_node_data($node));
  $this
    ->_check_rendered_meta_tags(array(
    'og:' . OpenGraphMeta::TITLE => $node->title,
    'og:' . OpenGraphMeta::DESCRIPTION => drupal_substr(strip_tags(OpenGraphMetaDrupalLayer::get_node_body($node)), 0, 200),
    'og:' . OpenGraphMeta::SITE_NAME => 'Drupal',
    'og:' . OpenGraphMeta::IMAGE => url('default.jpg', array(
      'absolute' => TRUE,
    )),
    'og:' . OpenGraphMeta::URL => url('node/1', array(
      'absolute' => TRUE,
    )),
  ), __FUNCTION__ . ' default image is returned');

  // Add an image to the node
  $this
    ->_reset_rendered_tags();
  $node->field_image = $this
    ->_create_img_field('image/jpeg', 'node.jpg');
  $this->ogm
    ->render_data($node, $this->ogm
    ->load_node_data($node));
  $imgpath = 'node.jpg';
  $url = image_style_url('thumbnail', $imgpath);
  $this
    ->_check_rendered_meta_tags(array(
    'og:' . OpenGraphMeta::TITLE => $node->title,
    'og:' . OpenGraphMeta::DESCRIPTION => drupal_substr(strip_tags(OpenGraphMetaDrupalLayer::get_node_body($node)), 0, 200),
    'og:' . OpenGraphMeta::SITE_NAME => 'Drupal',
    'og:' . OpenGraphMeta::IMAGE => url($url, array(
      'absolute' => TRUE,
    )),
    'og:' . OpenGraphMeta::URL => url('node/1', array(
      'absolute' => TRUE,
    )),
  ), __FUNCTION__ . ' default image is overridden');
}