From e5e22caa5cd448e1ce3645fc232fc15394fc0cb6 Mon Sep 17 00:00:00 2001 From: webchick Date: Sun, 17 Mar 2013 00:12:01 -0700 Subject: [PATCH] Issue #1938228 by corvus_ch, Xano: Convert TypedDataTest to make use of DrupalUnitTestBase. --- .../lib/Drupal/simpletest/WebTestBase.php | 19 --------- .../system/Tests/TypedData/TypedDataTest.php | 42 +++++++++++++++++-- 2 files changed, 39 insertions(+), 22 deletions(-) diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php index 9e8b0978165..95c82542a5d 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -2149,25 +2149,6 @@ abstract class WebTestBase extends TestBase { $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. * diff --git a/core/modules/system/lib/Drupal/system/Tests/TypedData/TypedDataTest.php b/core/modules/system/lib/Drupal/system/Tests/TypedData/TypedDataTest.php index 64366bc8458..880c720698e 100644 --- a/core/modules/system/lib/Drupal/system/Tests/TypedData/TypedDataTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/TypedData/TypedDataTest.php @@ -7,14 +7,14 @@ namespace Drupal\system\Tests\TypedData; -use Drupal\simpletest\WebTestBase; +use Drupal\simpletest\DrupalUnitTestBase; use Drupal\Core\Datetime\DrupalDateTime; use DateInterval; /** * Tests primitive data types. */ -class TypedDataTest extends WebTestBase { +class TypedDataTest extends DrupalUnitTestBase { /** * The typed data manager to use. @@ -23,6 +23,13 @@ class TypedDataTest extends WebTestBase { */ protected $typedData; + /** + * Modules to enable. + * + * @var array + */ + public static $modules = array('system', 'file'); + public static function getInfo() { return array( 'name' => 'Test typed data objects', @@ -33,9 +40,30 @@ class TypedDataTest extends WebTestBase { public function setUp() { parent::setup(); + + $this->installSchema('file', array('file_managed', "file_usage")); $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. */ @@ -160,8 +188,16 @@ class TypedDataTest extends WebTestBase { $typed_data->setValue('invalid'); $this->assertEqual($typed_data->validate()->count(), 1, 'Validation detected invalid value.'); + // 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. $value = $this->randomString();