ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
EntityListingTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
24use ILIAS\UI\Factory as UIFactory;
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(),
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,
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}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:29
Provides common functionality for UI tests.
Definition: Base.php:337
This describes an Entity.
Definition: Entity.php:37
This is the factory for Entities.
Definition: Factory.php:32