class realistic_dummy_content_UnitTestCase in Realistic Dummy Content 7
The test case
Hierarchy
- class \DrupalTestCase
- class \DrupalUnitTestCase
Expanded class hierarchy of realistic_dummy_content_UnitTestCase
File
- api/
tests/ realistic_dummy_content_api.unit.test, line 37 - This file contains the testing code for this module
View source
class realistic_dummy_content_UnitTestCase extends DrupalUnitTestCase {
/**
* Info for this test case.
*/
public static function getInfo() {
return array(
'name' => t('Realistic dummy content unit test'),
'description' => t('Test pure functions for Realistic dummy content.'),
'group' => 'Realistic dummy content',
);
}
public function setUp() {
// specifically include files which contain functions to test.
module_load_include('module', 'realistic_dummy_content_api');
parent::setUp();
}
/*
* Test case for realistic_dummy_content_api.
*/
public function testModule() {
// only pure functions should be tested here. The database is not available.
$user = (object) array();
$user->mail = 'whatever@example.com.invalid';
$this
->assertTrue(realistic_dummy_content_api_realistic_dummy_content_api_dummy($user, 'user'), 'User with an email ending in .invalid is considered dummy content');
$user->mail = 'whatever@example.com';
$user->devel_generate = TRUE;
$this
->assertTrue(realistic_dummy_content_api_realistic_dummy_content_api_dummy($user, 'user'), 'User with the devel_generate property set is considered dummy content');
unset($user->devel_generate);
$this
->assertFalse(realistic_dummy_content_api_realistic_dummy_content_api_dummy($user, 'user'), 'User with neither an address ending in .invalid nor the devel_generate property set is considered non-dummy');
$node = (object) array();
$node->devel_generate = array();
$this
->assertTrue(realistic_dummy_content_api_realistic_dummy_content_api_dummy($node, 'node'), 'Node with the devel_generate property set to an empty array is considered dummy');
unset($node->devel_generate);
$this
->assertFALSE(realistic_dummy_content_api_realistic_dummy_content_api_dummy($node, 'node'), 'Node with the devel_generate not set is considered non-dummy');
$this
->assertSequential(0, 3, 'a', 0);
$this
->assertSequential(0, 3, 'a', 0);
$this
->assertSequential(0, 3, 'b', 1);
$this
->assertSequential(0, 3, 'b', 1);
$this
->assertSequential(0, 3, 'c', 2);
$this
->assertSequential(0, 3, 'c', 2);
$this
->assertSequential(0, 3, 'd', 3);
$this
->assertSequential(0, 2, 'd', 2);
$this
->assertSequential(10, 13, 'd', 10);
$this
->assertSequential(11, 12, 'd', 11);
}
/**
* Helper function to assert that the sequential number generator works.
*
* This calls realistic_dummy_content_api_sequential(), making sure that the result
* is as expected.
*
* @param $start
* Start number passed to realistic_dummy_content_api_sequential()
* @param $end
* End number passed to realistic_dummy_content_api_sequential()
* @param $hash
* Hash passed to realistic_dummy_content_api_sequential()
* @param $expected
* Expected result which realistic_dummy_content_api_sequential() is expected
* to return.
*/
function assertSequential($start, $end, $hash, $expected) {
$result = realistic_dummy_content_api_sequential($start, $end, $hash);
$this
->assertTrue($result == $expected, 'Sequential number is as expected for ' . $start . ', ' . $end . ' with hash ' . $hash . ': [expected] ' . $expected . ' = [result] ' . $result);
}
/**
* Test that file names are properly parsed and combined.
*/
function testFiles() {
module_load_include('inc', 'realistic_dummy_content_api', 'includes/RealisticDummyContentEnvironment');
$data = array(
'one.txt' => new stdClass(),
'reAdme.txt' => new stdClass(),
'README.md' => new stdClass(),
'readme.jpg' => new stdClass(),
'two.txt' => new stdClass(),
'two.notanattribute.txt' => new stdClass(),
'two.txt.attribute.txt' => new stdClass(),
'two.txt.attribute1.txt' => new stdClass(),
'three.png' => new stdClass(),
'three.png.alt.txt' => new stdClass(),
);
try {
$parsed = RealisticDummyContentEnvironment::SortCandidateFiles($data);
$parsed_images = RealisticDummyContentEnvironment::SortCandidateFiles($data, array(
'png',
));
} catch (Exception $e) {
$this
->assertFalse(TRUE, 'Got exception ' . $e
->getMessage());
}
$this
->assertTrue(count($parsed) == 4, '4 parsed files are returned, which excludes the readme riles (4 == ' . count($parsed) . ')');
$this
->assertTrue(is_object($parsed['one.txt']['file']));
$this
->assertTrue(is_object($parsed['two.txt']['file']));
$this
->assertTrue(is_object($parsed['two.txt']['attributes']['attribute']));
$this
->assertTrue(is_object($parsed['two.txt']['attributes']['attribute1']));
$this
->assertTrue(is_object($parsed['three.png']['file']));
$this
->assertTrue(is_object($parsed['three.png']['attributes']['alt']));
$this
->assertFalse(isset($parsed_images['two.txt']['attributes']['attribute1']));
$this
->assertTrue(is_object($parsed_images['three.png']['file']));
$this
->assertTrue(is_object($parsed_images['three.png']['attributes']['alt']));
$this
->assertTrue(is_object($parsed['two.notanattribute.txt']['file']));
}
/**
* Test that empty files and non-existing files are treated differently.
*/
function testEmpty() {
module_load_include('inc', 'realistic_dummy_content_api', 'includes/RealisticDummyContentAttribute');
module_load_include('inc', 'realistic_dummy_content_api', 'includes/RealisticDummyContentField');
module_load_include('inc', 'realistic_dummy_content_api', 'includes/RealisticDummyContentValueField');
$field = new RealisticDummyContentValueField('ignore entity', 'ignore name');
$null = new RealisticDummyContentUnitTestCaseDummyFile(NULL);
$empty = new RealisticDummyContentUnitTestCaseDummyFile('');
$this
->assertFalse(is_array($field
->ValueFromFile_($null)), 'No applicable field value is represented by NULL.');
$this
->assertTrue(is_array($field
->ValueFromFile_($empty)), 'An empty string is considered a valid value.');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DrupalTestCase:: |
protected | property | Assertions thrown in that test case. | |
DrupalTestCase:: |
protected | property | The database prefix of this test run. | |
DrupalTestCase:: |
protected | property | The original file directory, before it was changed for testing purposes. | |
DrupalTestCase:: |
public | property | Current results of this test case. | |
DrupalTestCase:: |
protected | property | Flag to indicate whether the test has been set up. | |
DrupalTestCase:: |
protected | property | ||
DrupalTestCase:: |
protected | property | ||
DrupalTestCase:: |
protected | property | This class is skipped when looking for the source of an assertion. | |
DrupalTestCase:: |
protected | property | The test run ID. | |
DrupalTestCase:: |
protected | property | Time limit for the test. | |
DrupalTestCase:: |
public | property | Whether to cache the installation part of the setUp() method. | |
DrupalTestCase:: |
public | property | Whether to cache the modules installation part of the setUp() method. | |
DrupalTestCase:: |
protected | property | URL to the verbose output file directory. | |
DrupalTestCase:: |
protected | function | Internal helper: stores the assert. | |
DrupalTestCase:: |
protected | function | Check to see if two values are equal. | |
DrupalTestCase:: |
protected | function | Check to see if a value is false (an empty string, 0, NULL, or FALSE). | |
DrupalTestCase:: |
protected | function | Check to see if two values are identical. | |
DrupalTestCase:: |
protected | function | Check to see if two values are not equal. | |
DrupalTestCase:: |
protected | function | Check to see if two values are not identical. | |
DrupalTestCase:: |
protected | function | Check to see if a value is not NULL. | |
DrupalTestCase:: |
protected | function | Check to see if a value is NULL. | |
DrupalTestCase:: |
protected | function | Check to see if a value is not false (not an empty string, 0, NULL, or FALSE). | |
DrupalTestCase:: |
public static | function | Delete an assertion record by message ID. | |
DrupalTestCase:: |
protected | function | Fire an error assertion. | 1 |
DrupalTestCase:: |
public | function | Handle errors during test runs. | 1 |
DrupalTestCase:: |
protected | function | Handle exceptions. | |
DrupalTestCase:: |
protected | function | Fire an assertion that is always negative. | |
DrupalTestCase:: |
public static | function | Converts a list of possible parameters into a stack of permutations. | |
DrupalTestCase:: |
protected | function | Cycles through backtrace until the first non-assertion method is found. | |
DrupalTestCase:: |
public static | function | Returns the database connection to the site running Simpletest. | |
DrupalTestCase:: |
public static | function | Store an assertion from outside the testing context. | |
DrupalTestCase:: |
protected | function | Fire an assertion that is always positive. | |
DrupalTestCase:: |
public static | function | Generates a random string containing letters and numbers. | |
DrupalTestCase:: |
public static | function | Generates a random string of ASCII characters of codes 32 to 126. | |
DrupalTestCase:: |
public | function | Run all tests in this class. | |
DrupalTestCase:: |
protected | function | Logs a verbose message in a text file. | |
DrupalUnitTestCase:: |
protected | function | 1 | |
DrupalUnitTestCase:: |
function |
Constructor for DrupalUnitTestCase. Overrides DrupalTestCase:: |
||
realistic_dummy_content_UnitTestCase:: |
function | Helper function to assert that the sequential number generator works. | ||
realistic_dummy_content_UnitTestCase:: |
public static | function | Info for this test case. | |
realistic_dummy_content_UnitTestCase:: |
public | function |
Sets up unit test environment. Overrides DrupalUnitTestCase:: |
|
realistic_dummy_content_UnitTestCase:: |
function | Test that empty files and non-existing files are treated differently. | ||
realistic_dummy_content_UnitTestCase:: |
function | Test that file names are properly parsed and combined. | ||
realistic_dummy_content_UnitTestCase:: |
public | function |