You are here

function MediaEntityTest::testQueryMedia in D7 Media 7

Test the ability to create and query media items.

File

test/media.entity.test, line 31
Tests for media entity controllers.

Class

MediaEntityTest
Test media type creation and management.

Code

function testQueryMedia() {
  $text_files = $this
    ->drupalGetTestFiles('text');
  $images = $this
    ->drupalGetTestFiles('image');

  // Moves serveral images to public://
  foreach (array_merge($text_files, $images) as $file) {
    $file = file_uri_to_object($file->uri);
    file_save($file);
  }
  $query = new EntityFieldQuery();
  $query
    ->entityCondition('entity_type', 'file');
  $query
    ->propertyCondition('uri', 'public://%', 'LIKE');
  $result = $query
    ->execute();
  $this
    ->assertEqual(count($result['file']), count($images) + count($text_files), "Returned results as expected for like % condition");
  $query = new EntityFieldQuery();
  $query
    ->entityCondition('entity_type', 'file');
  $query
    ->propertyCondition('uri', '%.jpg', 'LIKE');
  $result = $query
    ->execute();
  $this
    ->assertEqual(count($result['file']), 2, "Returned 2 results as expected for jpgs");
  $query = new EntityFieldQuery();
  $query
    ->entityCondition('entity_type', 'file');
  $query
    ->propertyCondition('type', 'image');
  $result = $query
    ->execute();
  $this
    ->assertEqual(count($result['file']), count($images), "Returned expected results for type query");
  $query = new EntityFieldQuery();
  $query
    ->entityCondition('entity_type', 'file');
  $query
    ->propertyCondition('uri', 'http://%', 'LIKE');
  $result = $query
    ->execute();
  $this
    ->assertEqual(count($result), 0, "Got no results for http scheme uris");
}