Commit 5d5af494 authored by alexpott's avatar alexpott

Issue #2952962 by tim.plunkett, sureshcj, JordiK, Madis, cilefen: Block...

Issue #2952962 by tim.plunkett, sureshcj, JordiK, Madis, cilefen: Block visibility setting tab for Roles not showing
parent bc07d425
......@@ -282,7 +282,14 @@ public function isSatisfiedBy(ContextInterface $context) {
$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;
......
<?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));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment