You are here

function OGMTBasicTest::testExtractImagesFromNode in Open Graph meta tags 6

Same name and namespace in other branches
  1. 7.2 tests/Basic.test \OGMTBasicTest::testExtractImagesFromNode()
  2. 7 tests/Basic.test \OGMTBasicTest::testExtractImagesFromNode()

File

tests/Basic.test, line 19

Class

OGMTBasicTest
Tests for Open Graph meta tags.

Code

function testExtractImagesFromNode() {

  /*
   * Check that logic to extract image URLs from the node body works as expected.
   */
  $node = new stdClass();
  $this
    ->_set_node_body($node, 'bla bla bla <a href="this is">...<img src="body.jpg">...<img> <img src=""></p>');
  $node->type = 'page';
  $node->field_image = $this
    ->_create_img_field('image', 'field1.jpg');
  $node->field_no_image = $this
    ->_create_img_field('pdf', 'field2.jpg');
  $node->sub_field_image = array(
    'child' => $this
      ->_create_img_field('image', 'subfield.jpg'),
  );
  $ret = $this->ogm
    ->harvest_images_from_node($node);
  $expected = array();
  foreach (array(
    'field1.jpg',
    'subfield.jpg',
    'body.jpg',
  ) as $imgpath) {
    if (7 <= OPENGRAPH_META_DRUPAL_VERSION && 'body.jpg' != $imgpath) {
      $imgpath = image_style_url('thumbnail', $imgpath);
    }
    array_push($expected, array(
      'title' => $imgpath,
      'alt' => $imgpath,
      'url' => $imgpath,
    ));
  }
  $this
    ->assertEqual(serialize($expected), serialize($ret), t('Extract images from node fields and body content'));
}