diff --git a/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php b/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php index 2af89b5..b020891 100644 --- a/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php +++ b/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php @@ -13,7 +13,6 @@ use Drupal\Core\Entity\Display\EntityFormDisplayInterface; use Drupal\Core\Entity\EntityDisplayBase; use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\StringTranslation\StringTranslationTrait; use Symfony\Component\Validator\ConstraintViolation; use Symfony\Component\Validator\ConstraintViolationList; use Symfony\Component\Validator\ConstraintViolationListInterface; @@ -41,8 +40,6 @@ */ class EntityFormDisplay extends EntityDisplayBase implements EntityFormDisplayInterface { - use StringTranslationTrait; - /** * {@inheritdoc} */ diff --git a/core/modules/node/node.module b/core/modules/node/node.module index aa26ce4..a448b6c 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -738,28 +738,6 @@ function node_page_title(NodeInterface $node) { } /** - * Finds the last time a node was changed. - * - * @param $nid - * The ID of a node. - * @param string $langcode - * (optional) The language to get the last changed time for. If omitted, the - * last changed time across all translations will be returned. - * - * @return string - * A unix timestamp indicating the last time the node was changed. - * - * @todo Remove once https://www.drupal.org/node/2002180 is resolved. It's only - * used for validation, which will be done by - * EntityChangedConstraintValidator. - */ -function node_last_changed($nid, $langcode = NULL) { - $node = \Drupal::entityManager()->getStorage('node')->loadUnchanged($nid); - $changed = $langcode ? $node->getTranslation($langcode)->getChangedTime() : $node->getChangedTimeAcrossTranslations(); - return $changed ?: FALSE; -} - -/** * Finds the most recently changed nodes that are available to the current user. * * @param $number diff --git a/core/modules/node/src/Tests/NodeLastChangedTest.php b/core/modules/node/src/Tests/NodeLastChangedTest.php deleted file mode 100644 index 23fa4b4..0000000 --- a/core/modules/node/src/Tests/NodeLastChangedTest.php +++ /dev/null @@ -1,46 +0,0 @@ -installEntitySchema('node'); - $this->installEntitySchema('user'); - } - - /** - * Runs basic tests for node_last_changed function. - */ - function testNodeLastChanged() { - $node = entity_create('node', array('type' => 'article', 'title' => $this->randomMachineName())); - $node->save(); - - // Test node last changed timestamp. - $changed_timestamp = node_last_changed($node->id()); - $this->assertEqual($changed_timestamp, $node->getChangedTimeAcrossTranslations(), 'Expected last changed timestamp returned.'); - - $changed_timestamp = node_last_changed($node->id(), $node->language()->getId()); - $this->assertEqual($changed_timestamp, $node->getChangedTime(), 'Expected last changed timestamp returned.'); - } -} diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityConstraintViolationListTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityConstraintViolationListTest.php new file mode 100644 index 0000000..a9a48f4 --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Entity/EntityConstraintViolationListTest.php @@ -0,0 +1,165 @@ +prophesize('\Drupal\Core\Session\AccountInterface')->reveal(); + $entity = $this->setupEntity($account); + + $constraint_list = $this->setupConstraintListWithoutCompositeConstraint($entity); + $violations = iterator_to_array($constraint_list); + + $this->assertSame($constraint_list->filterByFields(['name']), $constraint_list); + $this->assertCount(4, $constraint_list); + $this->assertArrayEquals(array_values(iterator_to_array($constraint_list)), [$violations[2], $violations[3], $violations[4], $violations[5]]); + } + + /** + * @covers ::filterByFields + */ + public function testFilterByFieldsWithCompositeConstraints() { + $account = $this->prophesize('\Drupal\Core\Session\AccountInterface')->reveal(); + $entity = $this->setupEntity($account); + + $constraint_list = $this->setupConstraintListWithCompositeConstraint($entity); + $violations = iterator_to_array($constraint_list); + + $this->assertSame($constraint_list->filterByFields(['name']), $constraint_list); + $this->assertCount(4, $constraint_list); + $this->assertArrayEquals(array_values(iterator_to_array($constraint_list)), [$violations[2], $violations[3], $violations[4], $violations[5]]); + } + + /** + * @covers ::filterByFieldAccess + */ + public function testFilterByFieldAccess() { + $account = $this->prophesize('\Drupal\Core\Session\AccountInterface')->reveal(); + $entity = $this->setupEntity($account); + + $constraint_list = $this->setupConstraintListWithoutCompositeConstraint($entity); + $violations = iterator_to_array($constraint_list); + + $this->assertSame($constraint_list->filterByFieldAccess($account), $constraint_list); + $this->assertCount(4, $constraint_list); + $this->assertArrayEquals(array_values(iterator_to_array($constraint_list)), [$violations[2], $violations[3], $violations[4], $violations[5]]); + } + + /** + * @covers ::filterByFieldAccess + */ + public function testFilterByFieldAccessWithCompositeConstraint() { + $account = $this->prophesize('\Drupal\Core\Session\AccountInterface')->reveal(); + $entity = $this->setupEntity($account); + + $constraint_list = $this->setupConstraintListWithCompositeConstraint($entity); + $violations = iterator_to_array($constraint_list); + + $this->assertSame($constraint_list->filterByFieldAccess($account), $constraint_list); + $this->assertCount(4, $constraint_list); + $this->assertArrayEquals(array_values(iterator_to_array($constraint_list)), [$violations[2], $violations[3], $violations[4], $violations[5]]); + } + + /** + * Builds the entity. + * + * @param \Drupal\Core\Session\AccountInterface $account + * An account. + * + * @return \Drupal\Core\Field\FieldItemListInterface + * A fieldable entity. + */ + protected function setupEntity(AccountInterface $account) { + $prophecy = $this->prophesize('\Drupal\Core\Field\FieldItemListInterface'); + $prophecy->access('edit', $account) + ->willReturn(FALSE); + $name_field_item_list = $prophecy->reveal(); + + $prophecy = $this->prophesize('\Drupal\Core\Field\FieldItemListInterface'); + $prophecy->access('edit', $account) + ->willReturn(TRUE); + $type_field_item_list = $prophecy->reveal(); + + $prophecy = $this->prophesize('\Drupal\Core\Entity\FieldableEntityInterface'); + $prophecy->hasField('name') + ->willReturn(TRUE); + $prophecy->hasField('type') + ->willReturn(TRUE); + $prophecy->get('name') + ->willReturn($name_field_item_list); + $prophecy->get('type') + ->willReturn($type_field_item_list); + + return $prophecy->reveal(); + } + + /** + * Builds a entity constraint violation list without composite constraints. + * + * @param \Drupal\Core\Entity\FieldableEntityInterface $entity + * A fieldable entity. + * + * @return \Drupal\Core\Entity\EntityConstraintViolationList + */ + protected function setupConstraintListWithoutCompositeConstraint(FieldableEntityInterface $entity) { + $violations = []; + + // Add two violations to two specific fields. + $violations[] = new ConstraintViolation('test name violation', '', [], '', 'name', 'invalid'); + $violations[] = new ConstraintViolation('test name violation2', '', [], '', 'name', 'invalid'); + + $violations[] = new ConstraintViolation('test type violation', '', [], '', 'type', 'invalid'); + $violations[] = new ConstraintViolation('test type violation2', '', [], '', 'type', 'invalid'); + // Add two entity level specific violations. + $violations[] = new ConstraintViolation('test entity violation', '', [], '', '', 'invalid'); + $violations[] = new ConstraintViolation('test entity violation2', '', [], '', '', 'invalid'); + + return new EntityConstraintViolationList($entity, $violations); + } + + /** + * Builds a entity constraint violation list with composite constraints. + * + * @param \Drupal\Core\Entity\FieldableEntityInterface $entity + * A fieldable entity. + * + * @return \Drupal\Core\Entity\EntityConstraintViolationList + */ + protected function setupConstraintListWithCompositeConstraint(FieldableEntityInterface $entity) { + $violations = []; + + // Add two violations to two specific fields. + $violations[] = new ConstraintViolation('test name violation', '', [], '', 'name', 'invalid'); + $violations[] = new ConstraintViolation('test name violation2', '', [], '', 'name', 'invalid'); + + $violations[] = new ConstraintViolation('test type violation', '', [], '', 'type', 'invalid'); + $violations[] = new ConstraintViolation('test type violation2', '', [], '', 'type', 'invalid'); + + // Add two entity level specific violations with a combound constraint. + $composite_constraint = new EntityTestCompositeConstraint(); + $violations[] = new ConstraintViolation('test composite violation', '', [], '', '', 'invalid', NULL, NULL, $composite_constraint); + $violations[] = new ConstraintViolation('test composite violation2', '', [], '', '', 'invalid', NULL, NULL, $composite_constraint); + return new EntityConstraintViolationList($entity, $violations); + } + +}