Issue #1938228 by corvus_ch, Xano: Convert TypedDataTest to make use of DrupalUnitTestBase.
parent
0d3968eee2
commit
e5e22caa5c
|
@ -2149,25 +2149,6 @@ abstract class WebTestBase extends TestBase {
|
||||||
$this->drupalSettings = $settings;
|
$this->drupalSettings = $settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a typed data object and executes some basic assertions.
|
|
||||||
*
|
|
||||||
* @see Drupal\Core\TypedData\TypedDataManager::create().
|
|
||||||
*/
|
|
||||||
protected function createTypedData($definition, $value = NULL, $context = array()) {
|
|
||||||
// Save the type that was passed in so we can compare with it later.
|
|
||||||
$type = $definition['type'];
|
|
||||||
// Construct the object.
|
|
||||||
$data = typed_data()->create($definition, $value, $context);
|
|
||||||
// Assert the definition of the wrapper.
|
|
||||||
$this->assertTrue($data instanceof \Drupal\Core\TypedData\TypedDataInterface, 'Typed data object is an instance of the typed data interface.');
|
|
||||||
$definition = $data->getDefinition();
|
|
||||||
$this->assertTrue(!empty($definition['type']), format_string('!type data definition was returned.', array('!type' => $definition['type'])));
|
|
||||||
// Assert that the correct type was constructed.
|
|
||||||
$this->assertEqual($data->getType(), $type, format_string('!type object returned type.', array('!type' => $definition['type'])));
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pass if the internal browser's URL matches the given path.
|
* Pass if the internal browser's URL matches the given path.
|
||||||
*
|
*
|
||||||
|
|
|
@ -7,14 +7,14 @@
|
||||||
|
|
||||||
namespace Drupal\system\Tests\TypedData;
|
namespace Drupal\system\Tests\TypedData;
|
||||||
|
|
||||||
use Drupal\simpletest\WebTestBase;
|
use Drupal\simpletest\DrupalUnitTestBase;
|
||||||
use Drupal\Core\Datetime\DrupalDateTime;
|
use Drupal\Core\Datetime\DrupalDateTime;
|
||||||
use DateInterval;
|
use DateInterval;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests primitive data types.
|
* Tests primitive data types.
|
||||||
*/
|
*/
|
||||||
class TypedDataTest extends WebTestBase {
|
class TypedDataTest extends DrupalUnitTestBase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The typed data manager to use.
|
* The typed data manager to use.
|
||||||
|
@ -23,6 +23,13 @@ class TypedDataTest extends WebTestBase {
|
||||||
*/
|
*/
|
||||||
protected $typedData;
|
protected $typedData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modules to enable.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public static $modules = array('system', 'file');
|
||||||
|
|
||||||
public static function getInfo() {
|
public static function getInfo() {
|
||||||
return array(
|
return array(
|
||||||
'name' => 'Test typed data objects',
|
'name' => 'Test typed data objects',
|
||||||
|
@ -33,9 +40,30 @@ class TypedDataTest extends WebTestBase {
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
parent::setup();
|
parent::setup();
|
||||||
|
|
||||||
|
$this->installSchema('file', array('file_managed', "file_usage"));
|
||||||
$this->typedData = typed_data();
|
$this->typedData = typed_data();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a typed data object and executes some basic assertions.
|
||||||
|
*
|
||||||
|
* @see Drupal\Core\TypedData\TypedDataManager::create().
|
||||||
|
*/
|
||||||
|
protected function createTypedData($definition, $value = NULL, $name = NULL) {
|
||||||
|
// Save the type that was passed in so we can compare with it later.
|
||||||
|
$type = $definition['type'];
|
||||||
|
// Construct the object.
|
||||||
|
$data = typed_data()->create($definition, $value, $name);
|
||||||
|
// Assert the definition of the wrapper.
|
||||||
|
$this->assertTrue($data instanceof \Drupal\Core\TypedData\TypedDataInterface, 'Typed data object is an instance of the typed data interface.');
|
||||||
|
$definition = $data->getDefinition();
|
||||||
|
$this->assertTrue(!empty($definition['type']), format_string('!type data definition was returned.', array('!type' => $definition['type'])));
|
||||||
|
// Assert that the correct type was constructed.
|
||||||
|
$this->assertEqual($data->getType(), $type, format_string('!type object returned type.', array('!type' => $definition['type'])));
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the basics around constructing and working with typed data objects.
|
* Tests the basics around constructing and working with typed data objects.
|
||||||
*/
|
*/
|
||||||
|
@ -160,8 +188,16 @@ class TypedDataTest extends WebTestBase {
|
||||||
$typed_data->setValue('invalid');
|
$typed_data->setValue('invalid');
|
||||||
$this->assertEqual($typed_data->validate()->count(), 1, 'Validation detected invalid value.');
|
$this->assertEqual($typed_data->validate()->count(), 1, 'Validation detected invalid value.');
|
||||||
|
|
||||||
|
|
||||||
// Generate some files that will be used to test the binary data type.
|
// Generate some files that will be used to test the binary data type.
|
||||||
$files = $this->drupalGetTestFiles('image');
|
$files = array();
|
||||||
|
for ($i = 0; $i < 3; $i++){
|
||||||
|
$path = "public://example_$i.png";
|
||||||
|
file_unmanaged_copy(DRUPAL_ROOT . '/core/misc/druplicon.png', $path);
|
||||||
|
$image = entity_create('file', array('uri' => $path));
|
||||||
|
$image->save();
|
||||||
|
$files[] = $image;
|
||||||
|
}
|
||||||
|
|
||||||
// Email type.
|
// Email type.
|
||||||
$value = $this->randomString();
|
$value = $this->randomString();
|
||||||
|
|
Loading…
Reference in New Issue