setupEntity example

/** * @coversDefaultClass \Drupal\Core\Entity\EntityConstraintViolationList * @group entity */
class EntityConstraintViolationListTest extends UnitTestCase {

  /** * @covers ::filterByFields */
  public function testFilterByFields() {
    $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->filterByFields(['name'])$constraint_list);
    $this->assertCount(4, $constraint_list);
    $this->assertEquals(array_values(iterator_to_array($constraint_list))[$violations[2]$violations[3]$violations[4]$violations[5]]);
  }

  /** * @covers ::filterByFields */
'label' => 'Reference',
      'translatable' => FALSE,
    ])->save();

    $this->container->get('entity_display.repository')
      ->getViewDisplay($this->entityTypeId, $this->entityTypeId, 'default')
      ->setComponent('field_reference', [
        'type' => 'entity_reference_entity_view',
      ])
      ->save();

    $this->setupEntity();

    // Create a second entity that references the first to test how the     // translation can be viewed through an entity reference field.     $this->referencingEntity = EntityTestMulRevPub::create([
      'name' => 'referencing',
      'field_reference' => $this->entity->id(),
    ]);
    $this->referencingEntity->addTranslation($this->langcodes[2]$this->referencingEntity->toArray());
    $this->referencingEntity->save();
  }

  
Home | Imprint | This part of the site doesn't use cookies.