Update to Drupal 8.0-dev-2015-11-17. Commits through da81cd220, Tue Nov 17 15:53:49 2015 +0000, Issue #2617224 by Wim Leers: Move around/fix some documentation.
This commit is contained in:
parent
4afb23bbd3
commit
7784f4c23d
929 changed files with 19798 additions and 5304 deletions
|
@ -40,7 +40,7 @@ class FieldInstance extends DrupalSqlBase {
|
|||
public function fields() {
|
||||
return array(
|
||||
'field_name' => $this->t('The machine name of field.'),
|
||||
'type_name' => $this->t('Content type where is used this field.'),
|
||||
'type_name' => $this->t('Content type where this field is in use.'),
|
||||
'weight' => $this->t('Weight.'),
|
||||
'label' => $this->t('A name to show.'),
|
||||
'widget_type' => $this->t('Widget type.'),
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
namespace Drupal\field\Tests\EntityReference;
|
||||
|
||||
use Drupal\comment\Entity\Comment;
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Field\FieldItemListInterface;
|
||||
use Drupal\Core\Field\FieldItemInterface;
|
||||
|
@ -17,8 +19,11 @@ use Drupal\entity_test\Entity\EntityTestStringId;
|
|||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\field\Tests\FieldUnitTestBase;
|
||||
use Drupal\file\Entity\File;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\taxonomy\Entity\Term;
|
||||
use Drupal\taxonomy\Entity\Vocabulary;
|
||||
use Drupal\user\Entity\User;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -35,7 +40,7 @@ class EntityReferenceItemTest extends FieldUnitTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['taxonomy', 'text', 'filter', 'views', 'field'];
|
||||
public static $modules = ['node', 'comment', 'file', 'taxonomy', 'text', 'filter', 'views', 'field'];
|
||||
|
||||
/**
|
||||
* The taxonomy vocabulary to test with.
|
||||
|
@ -66,6 +71,11 @@ class EntityReferenceItemTest extends FieldUnitTestBase {
|
|||
|
||||
$this->installEntitySchema('entity_test_string_id');
|
||||
$this->installEntitySchema('taxonomy_term');
|
||||
$this->installEntitySchema('node');
|
||||
$this->installEntitySchema('comment');
|
||||
$this->installEntitySchema('file');
|
||||
|
||||
$this->installSchema('comment', ['comment_entity_statistics']);
|
||||
|
||||
$this->vocabulary = entity_create('taxonomy_vocabulary', array(
|
||||
'name' => $this->randomMachineName(),
|
||||
|
@ -90,6 +100,10 @@ class EntityReferenceItemTest extends FieldUnitTestBase {
|
|||
$this->createEntityReferenceField('entity_test', 'entity_test', 'field_test_taxonomy_term', 'Test content entity reference', 'taxonomy_term');
|
||||
$this->createEntityReferenceField('entity_test', 'entity_test', 'field_test_entity_test_string_id', 'Test content entity reference with string ID', 'entity_test_string_id');
|
||||
$this->createEntityReferenceField('entity_test', 'entity_test', 'field_test_taxonomy_vocabulary', 'Test config entity reference', 'taxonomy_vocabulary');
|
||||
$this->createEntityReferenceField('entity_test', 'entity_test', 'field_test_node', 'Test node entity reference', 'node');
|
||||
$this->createEntityReferenceField('entity_test', 'entity_test', 'field_test_user', 'Test user entity reference', 'user');
|
||||
$this->createEntityReferenceField('entity_test', 'entity_test', 'field_test_comment', 'Test comment entity reference', 'comment');
|
||||
$this->createEntityReferenceField('entity_test', 'entity_test', 'field_test_file', 'Test file entity reference', 'file');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -333,9 +347,9 @@ class EntityReferenceItemTest extends FieldUnitTestBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Tests validation constraint.
|
||||
* Tests ValidReferenceConstraint with newly created and unsaved entities.
|
||||
*/
|
||||
public function testValidation() {
|
||||
public function testAutocreateValidation() {
|
||||
// The term entity is unsaved here.
|
||||
$term = Term::create(array(
|
||||
'name' => $this->randomMachineName(),
|
||||
|
@ -367,6 +381,100 @@ class EntityReferenceItemTest extends FieldUnitTestBase {
|
|||
$entity->save();
|
||||
$errors = $entity->validate();
|
||||
$this->assertEqual(0, count($errors));
|
||||
|
||||
// Test with an unpublished and unsaved node.
|
||||
$title = $this->randomString();
|
||||
$node = Node::create([
|
||||
'title' => $title,
|
||||
'type' => 'node',
|
||||
'status' => NODE_NOT_PUBLISHED,
|
||||
]);
|
||||
|
||||
$entity = EntityTest::create([
|
||||
'field_test_node' => [
|
||||
'entity' => $node,
|
||||
],
|
||||
]);
|
||||
|
||||
$errors = $entity->validate();
|
||||
$this->assertEqual(1, count($errors));
|
||||
$this->assertEqual($errors[0]->getMessage(), new FormattableMarkup('This entity (%type: %label) cannot be referenced.', ['%type' => 'node', '%label' => $title]));
|
||||
$this->assertEqual($errors[0]->getPropertyPath(), 'field_test_node.0.entity');
|
||||
|
||||
// Publish the node and try again.
|
||||
$node->setPublished(TRUE);
|
||||
$errors = $entity->validate();
|
||||
$this->assertEqual(0, count($errors));
|
||||
|
||||
// Test with an unpublished and unsaved comment.
|
||||
$title = $this->randomString();
|
||||
$comment = Comment::create([
|
||||
'subject' => $title,
|
||||
'comment_type' => 'comment',
|
||||
'status' => 0,
|
||||
]);
|
||||
|
||||
$entity = EntityTest::create([
|
||||
'field_test_comment' => [
|
||||
'entity' => $comment,
|
||||
],
|
||||
]);
|
||||
|
||||
$errors = $entity->validate();
|
||||
$this->assertEqual(1, count($errors));
|
||||
$this->assertEqual($errors[0]->getMessage(), new FormattableMarkup('This entity (%type: %label) cannot be referenced.', ['%type' => 'comment', '%label' => $title]));
|
||||
$this->assertEqual($errors[0]->getPropertyPath(), 'field_test_comment.0.entity');
|
||||
|
||||
// Publish the comment and try again.
|
||||
$comment->setPublished(TRUE);
|
||||
$errors = $entity->validate();
|
||||
$this->assertEqual(0, count($errors));
|
||||
|
||||
// Test with an inactive and unsaved user.
|
||||
$name = $this->randomString();
|
||||
$user = User::create([
|
||||
'name' => $name,
|
||||
'status' => 0,
|
||||
]);
|
||||
|
||||
$entity = EntityTest::create([
|
||||
'field_test_user' => [
|
||||
'entity' => $user,
|
||||
],
|
||||
]);
|
||||
|
||||
$errors = $entity->validate();
|
||||
$this->assertEqual(1, count($errors));
|
||||
$this->assertEqual($errors[0]->getMessage(), new FormattableMarkup('This entity (%type: %label) cannot be referenced.', ['%type' => 'user', '%label' => $name]));
|
||||
$this->assertEqual($errors[0]->getPropertyPath(), 'field_test_user.0.entity');
|
||||
|
||||
// Activate the user and try again.
|
||||
$user->activate();
|
||||
$errors = $entity->validate();
|
||||
$this->assertEqual(0, count($errors));
|
||||
|
||||
// Test with a temporary and unsaved file.
|
||||
$filename = $this->randomMachineName() . '.txt';
|
||||
$file = File::create([
|
||||
'filename' => $filename,
|
||||
'status' => 0,
|
||||
]);
|
||||
|
||||
$entity = EntityTest::create([
|
||||
'field_test_file' => [
|
||||
'entity' => $file,
|
||||
],
|
||||
]);
|
||||
|
||||
$errors = $entity->validate();
|
||||
$this->assertEqual(1, count($errors));
|
||||
$this->assertEqual($errors[0]->getMessage(), new FormattableMarkup('This entity (%type: %label) cannot be referenced.', ['%type' => 'file', '%label' => $filename]));
|
||||
$this->assertEqual($errors[0]->getPropertyPath(), 'field_test_file.0.entity');
|
||||
|
||||
// Set the file as permanent and try again.
|
||||
$file->setPermanent();
|
||||
$errors = $entity->validate();
|
||||
$this->assertEqual(0, count($errors));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -68,6 +68,11 @@ class UriItemTest extends FieldUnitTestBase {
|
|||
'type' => 'uri',
|
||||
])
|
||||
->save();
|
||||
|
||||
// Test the generateSampleValue() method.
|
||||
$entity = entity_create('entity_test');
|
||||
$entity->$field_name->generateSampleItems();
|
||||
$this->entityValidateAndSave($entity);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Reference in a new issue