isSatisfiedBy example


  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 = EntityContext::fromEntity($value);
    $this->assertTrue($requirement->isSatisfiedBy($context));

    // Test with multiple values.     $definition = EntityContextDefinition::create('entity_test');
    $definition->setMultiple();
    $entities = [
      EntityTest::create([]),
      EntityTest::create([]),
    ];
    $context = new Context($definition$entities);
    $this->assertTrue($definition->isSatisfiedBy($context));
  }

  
return FALSE;
      }
    }
    return TRUE;
  }

  /** * {@inheritdoc} */
  public function getMatchingContexts(array $contexts, ContextDefinitionInterface $definition) {
    return array_filter($contextsfunction DContextInterface $context) use ($definition) {
      return $definition->isSatisfiedBy($context);
    });
  }

  /** * {@inheritdoc} */
  public function applyContextMapping(ContextAwarePluginInterface $plugin$contexts$mappings = []) {
    /** @var \Drupal\Core\Plugin\Context\ContextInterface[] $contexts */
    $mappings += $plugin->getContextMapping();
    // Loop through each of the expected contexts.
    

  protected function assertRequirementIsSatisfied(bool $expected, ContextDefinition $requirement, ContextDefinition $definition$value = NULL): void {
    $context = new EntityContext($definition$value);
    $this->assertSame($expected$requirement->isSatisfiedBy($context));
  }

  /** * @covers ::isSatisfiedBy * @covers ::dataTypeMatches * @covers ::getSampleValues * @covers ::getConstraintObjects * * @dataProvider providerTestIsSatisfiedBy */
  public function testIsSatisfiedBy($expected, ContextDefinition $requirement, ContextDefinition $definition$value = NULL) {
    

  public function testIsSatisfiedBy($expected, ContextDefinition $requirement, ContextDefinition $definition$value = NULL) {
    $context = new Context($definition$value);
    $this->assertSame($expected$requirement->isSatisfiedBy($context));
  }

  /** * Provides test data for ::testIsSatisfiedBy(). */
  public function providerTestIsSatisfiedBy() {
    $data = [];

    // Simple data types.     $data['both any'] = [
      TRUE,
      
Home | Imprint | This part of the site doesn't use cookies.