ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
EntityListingTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 use ILIAS\UI\Component as I;
26 
28 {
29  public function getEntityMapping(): I\Listing\Entity\RecordToEntity
30  {
31  return new class () implements I\Listing\Entity\RecordToEntity {
32  public function map(
33  UIFactory $ui_factory,
34  mixed $record
35  ): Entity\Entity {
36  return $ui_factory->entity()->standard('primary', 'secondary');
37  }
38  };
39  }
40  public function getUIFactory(): NoUIFactory
41  {
42  return new class () extends NoUIFactory {
43  public function listing(): Listing\Factory
44  {
45  return new Listing\Factory(
46  new Listing\Workflow\Factory(),
47  new Listing\CharacteristicValue\Factory(),
48  new Listing\Entity\Factory(),
49  );
50  }
51  public function entity(): Entity\Factory
52  {
53  return new Entity\Factory();
54  }
55  };
56  }
57 
58  public function testEntityListingFactory(): void
59  {
60  $this->assertInstanceOf(
61  I\Listing\Entity\EntityListing::class,
62  $this->getUIFactory()->listing()->entity()->standard($this->getEntityMapping())
63  );
64  }
65 
66  public function testEntityListingYieldingEntities(): void
67  {
68  $data = new class () implements I\Listing\Entity\DataRetrieval {
69  protected $data = [1,2,3];
70 
71  public function getEntities(
72  I\Listing\Entity\Mapping $mapping,
73  ?Range $range,
74  ?array $additional_parameters
75  ): \Generator {
76  foreach ($this->data as $entry) {
77  yield $mapping->map($entry);
78  }
79  }
80  };
81 
82  $listing = $this->getUIFactory()->listing()->entity()
83  ->standard($this->getEntityMapping())
84  ->withData($data);
85 
86  $entities = iterator_to_array($listing->getEntities($this->getUIFactory()));
87 
88  $this->assertCount(3, $entities);
89 
90  $this->assertInstanceOf(I\Entity\Entity::class, array_pop($entities));
91  }
92 }
This describes an Entity.
Definition: Entity.php:36
standard()
description: > This is an example, of how the Notification Slate is generated by assigning Notificat...
Definition: standard.php:38
This is the factory for Entities.
Definition: Factory.php:31
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:28