Commit dee7c121 authored by Dave Reid's avatar Dave Reid

Cleaned up and fixed tests.

parent 235b0126
......@@ -5,6 +5,7 @@ core = 7.x
dependencies[] = file_entity
dependencies[] = image
files[] = includes/MediaReadOnlyStreamWrapper.inc
files[] = test/media.types.test
files[] = test/media.entity.test
files[] = tests/media.test
files[] = tests/media.types.test
files[] = tests/media.entity.test
testing_api = 2.x
<?php
//$ Id;
<?php
/**
* @file
......@@ -9,7 +8,7 @@
/**
* Test media type creation and management.
*/
class MediaEntityTest extends DrupalWebTestCase {
class MediaEntityTest extends MediaTestHelper {
public static function getInfo() {
return array(
......@@ -19,12 +18,6 @@ class MediaEntityTest extends DrupalWebTestCase {
);
}
function setUp() {
parent::setUp('media');
// Nice, TDD FTW. #totalsarcasm
variable_set('simpletest_verbose', TRUE);
}
/**
* Test the ability to create and query media items.
*/
......@@ -35,32 +28,30 @@ class MediaEntityTest extends DrupalWebTestCase {
foreach (array_merge($text_files, $images) as $file) {
file_save($file);
}
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'media');
$query->entityCondition('entity_type', 'file');
$query->propertyCondition('uri', 'public://%', 'LIKE');
$result = $query->execute();
$this->verbose(dpr($result, 1));
$this->assertEqual(count($result['media']), count($images) + count($text_files), "Returned results as expected for like % condition");
$this->assertEqual(count($result['file']), count($images) + count($text_files), "Returned results as expected for like % condition");
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'media');
$query->entityCondition('entity_type', 'file');
$query->propertyCondition('uri', '%.jpg', 'LIKE');
$result = $query->execute();
$this->assertEqual(count($result['media']), 2, "Returned 2 results as expected for jpgs");
$this->assertEqual(count($result['file']), 2, "Returned 2 results as expected for jpgs");
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'media');
$query->entityCondition('entity_type', 'file');
$query->propertyCondition('type', 'image');
$result = $query->execute();
$this->assertEqual(count($result['media']), count($images), "Returned expected results for type query");
$this->assertEqual(count($result['file']), count($images), "Returned expected results for type query");
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'media');
$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");
}
}
?>
<?php
/**
* @file
* Test integration for the media module.
*/
class MediaTestHelper extends DrupalWebTestCase {
function setUp() {
parent::setUp(array('media'));
// Nice, TDD FTW. #totalsarcasm
variable_set('simpletest_verbose', TRUE);
}
protected function createType($overrides) {
$type = new StdClass();
$type->name = 'test';
$type->label = "Test";
$type->base = TRUE;
// $type->view_mode_defaults = array(
// 'media_preview' => 'styles_file_square_thumbnail',
// 'media_original' => 'file_default',
// );
$type->type_callback_args =
array(
'match_type' => 'all',
'mimetypes' => array('/^test/'),
'extensions' => array('jpg', 'jpeg', 'gif', 'png', 'tiff'),
'streams' => array('public', 'private'),
);
foreach ($overrides as $k => $v) {
$type->$k = $v;
}
media_type_save($type);
return $type;
}
}
......@@ -8,7 +8,7 @@
/**
* Test media type creation and management.
*/
class MediaTypeTest extends DrupalWebTestCase {
class MediaTypeTest extends MediaTestHelper {
public static function getInfo() {
return array(
......@@ -18,38 +18,6 @@ class MediaTypeTest extends DrupalWebTestCase {
);
}
function setUp() {
parent::setUp('media');
// Nice, TDD FTW. #totalsarcasm
variable_set('simpletest_verbose', TRUE);
}
private function createType($overrides) {
$type = new StdClass();
$type->name = 'test';
$type->label = "Test";
$type->base = TRUE;
// $type->view_mode_defaults = array(
// 'media_preview' => 'styles_file_square_thumbnail',
// 'media_original' => 'file_default',
// );
$type->type_callback_args =
array(
'match_type' => 'all',
'mimetypes' => array('/^test/'),
'extensions' => array('jpg', 'jpeg', 'gif', 'png', 'tiff'),
'streams' => array('public', 'private'),
);
foreach ($overrides as $k => $v) {
$type->$k = $v;
}
media_type_save($type);
return $type;
}
/**
* Test creating a new type. Basic CRUD.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment