Issue #2952962 by tim.plunkett, sureshcj, JordiK, Madis, cilefen: Block visibility setting tab for Roles not showing

merge-requests/1654/head
Alex Pott 2018-04-02 15:56:56 +02:00
parent bc07d425c8
commit 5d5af494fb
No known key found for this signature in database
GPG Key ID: 31905460D4A69276
2 changed files with 45 additions and 1 deletions

View File

@ -282,7 +282,14 @@ class ContextDefinition implements ContextDefinitionInterface {
$validator = $this->getTypedDataManager()->getValidator();
foreach ($values as $value) {
$violations = $validator->validate($value, array_values($this->getConstraintObjects()));
$constraints = array_values($this->getConstraintObjects());
$violations = $validator->validate($value, $constraints);
foreach ($violations as $delta => $violation) {
// Remove any violation that does not correspond to the constraints.
if (!in_array($violation->getConstraint(), $constraints)) {
$violations->remove($delta);
}
}
// If a value has no violations then the requirement is satisfied.
if (!$violations->count()) {
return TRUE;

View File

@ -0,0 +1,37 @@
<?php
namespace Drupal\KernelTests\Core\Plugin;
use Drupal\Core\Plugin\Context\Context;
use Drupal\Core\Plugin\Context\ContextDefinition;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\KernelTests\KernelTestBase;
/**
* @coversDefaultClass \Drupal\Core\Plugin\Context\ContextDefinition
* @group Plugin
*/
class ContextDefinitionTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['entity_test', 'user'];
/**
* @covers ::isSatisfiedBy
*/
public function testIsSatisfiedBy() {
$this->installEntitySchema('user');
$value = EntityTest::create([]);
// Assert that the entity has at least one violation.
$this->assertNotEmpty($value->validate());
// Assert that these violations do not prevent it from satisfying the
// requirements of another object.
$requirement = new ContextDefinition('any');
$context = new Context(new ContextDefinition('entity:entity_test'), $value);
$this->assertTrue($requirement->isSatisfiedBy($context));
}
}