ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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(): I\Listing\Factory
44  {
45  return new Listing\Factory();
46  }
47  public function entity(): I\Entity\Factory
48  {
49  return new Entity\Factory();
50  }
51  };
52  }
53 
54  public function testEntityListingFactory(): void
55  {
56  $this->assertInstanceOf(
57  I\Listing\Entity\EntityListing::class,
58  $this->getUIFactory()->listing()->entity()->standard($this->getEntityMapping())
59  );
60  }
61 
62  public function testEntityListingYieldingEntities(): void
63  {
64  $data = new class () implements I\Listing\Entity\DataRetrieval {
65  protected $data = [1,2,3];
66 
67  public function getEntities(
68  I\Listing\Entity\Mapping $mapping,
69  ?Range $range,
70  ?array $additional_parameters
71  ): \Generator {
72  foreach ($this->data as $entry) {
73  yield $mapping->map($entry);
74  }
75  }
76  };
77 
78  $listing = $this->getUIFactory()->listing()->entity()
79  ->standard($this->getEntityMapping())
80  ->withData($data);
81 
82  $entities = iterator_to_array($listing->getEntities($this->getUIFactory()));
83 
84  $this->assertCount(3, $entities);
85 
86  $this->assertInstanceOf(I\Entity\Entity::class, array_pop($entities));
87  }
88 }
This describes an Entity.
Definition: Entity.php:36
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
standard()
This is an example, of how the Notification Slate is generated by assigning Notification Items to it...
Definition: standard.php:16
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This is the factory for Entities.
Definition: Factory.php:31
Provides common functionality for UI tests.
Definition: Base.php:310
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
A simple class to express a range of whole positive numbers.
Definition: Range.php:30