media.entity.test 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * @file
  4. * Tests for media entity controllers.
  5. */
  6. /**
  7. * Test media type creation and management.
  8. */
  9. class MediaEntityTest extends DrupalWebTestCase {
  10. public static function getInfo() {
  11. return array(
  12. 'name' => 'Media entity',
  13. 'description' => 'Tests media entity handling',
  14. 'group' => 'Media',
  15. 'dependencies' => array('ctools'),
  16. );
  17. }
  18. function setUp() {
  19. parent::setUp('media');
  20. // Nice, TDD FTW. #totalsarcasm
  21. variable_set('simpletest_verbose', TRUE);
  22. }
  23. /**
  24. * Test the ability to create and query media items.
  25. */
  26. function testQueryMedia() {
  27. $text_files = $this->drupalGetTestFiles('text');
  28. $images = $this->drupalGetTestFiles('image');
  29. // Moves serveral images to public://
  30. foreach (array_merge($text_files, $images) as $file) {
  31. $file = file_uri_to_object($file->uri);
  32. file_save($file);
  33. }
  34. $query = new EntityFieldQuery();
  35. $query->entityCondition('entity_type', 'file');
  36. $query->propertyCondition('uri', 'public://%', 'LIKE');
  37. $result = $query->execute();
  38. $this->assertEqual(count($result['file']), count($images) + count($text_files), "Returned results as expected for like % condition");
  39. $query = new EntityFieldQuery();
  40. $query->entityCondition('entity_type', 'file');
  41. $query->propertyCondition('uri', '%.jpg', 'LIKE');
  42. $result = $query->execute();
  43. $this->assertEqual(count($result['file']), 2, "Returned 2 results as expected for jpgs");
  44. $query = new EntityFieldQuery();
  45. $query->entityCondition('entity_type', 'file');
  46. $query->propertyCondition('type', 'image');
  47. $result = $query->execute();
  48. $this->assertEqual(count($result['file']), count($images), "Returned expected results for type query");
  49. $query = new EntityFieldQuery();
  50. $query->entityCondition('entity_type', 'file');
  51. $query->propertyCondition('uri', 'http://%', 'LIKE');
  52. $result = $query->execute();
  53. $this->assertEqual(count($result), 0, "Got no results for http scheme uris");
  54. }
  55. }