You are here

media.entity.test in D7 Media 7

Tests for media entity controllers.

File

test/media.entity.test
View source
<?php

/**
 * @file
 * Tests for media entity controllers.
 */

/**
 * Test media type creation and management.
 */
class MediaEntityTest extends DrupalWebTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Media entity',
      'description' => 'Tests media entity handling',
      'group' => 'Media',
      'dependencies' => array(
        'ctools',
      ),
    );
  }
  function setUp() {
    parent::setUp('media');

    // Nice, TDD FTW.  #totalsarcasm
    variable_set('simpletest_verbose', TRUE);
  }

  /**
   * Test the ability to create and query media items.
   */
  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");
  }

}

Classes

Namesort descending Description
MediaEntityTest Test media type creation and management.