ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
TileTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Badge\test;
22 
23 use Exception;
34 use ILIAS\UI\Component\Card\Standard as StandardCard;
42 use ILIAS\UI\Factory as UI;
44 use ilBadge;
46 use ilCtrl;
47 use ilLanguage;
51 
52 class TileTest extends TestCase
53 {
54  public function testConstruct(): void
55  {
56  $container = $this->getMockBuilder(Container::class)->disableOriginalConstructor()->getMock();
57  $parent = $this->getMockBuilder(BadgeParent::class)->disableOriginalConstructor()->getMock();
58  $modal = $this->getMockBuilder(Modal::class)->disableOriginalConstructor()->getMock();
59  $sign_file = static fn(string $x): string => '';
60  $format_date = static fn(int $x): string => '';
61 
62  $this->assertInstanceOf(Tile::class, new Tile($container, $parent, $modal, $sign_file, $format_date));
63  }
64 
68  public function testAs(string $method, array $expected_components): void
69  {
70  $signed_file = '/some-signed-file';
71  $badge_image_path = '/file-path';
72  $badge_image_name = 'Dummy image';
73  $badge_image_rid_name = '43242-324234-324234-234233';
74  $badge = $this->getMockBuilder(ilBadge::class)->disableOriginalConstructor()->getMock();
75  $modal_content = $this->getMockBuilder(ModalContent::class)->disableOriginalConstructor()->getMock();
76  $container = $this->getMockBuilder(Container::class)->disableOriginalConstructor()->getMock();
77  $parent = $this->getMockBuilder(BadgeParent::class)->disableOriginalConstructor()->getMock();
78  $modal = $this->getMockBuilder(Modal::class)->disableOriginalConstructor()->getMock();
79  $ui = $this->getMockBuilder(UIServices::class)->disableOriginalConstructor()->getMock();
80  $ctrl = $this->getMockBuilder(ilCtrl::class)->disableOriginalConstructor()->getMock();
81  $language = $this->getMockBuilder(ilLanguage::class)->disableOriginalConstructor()->getMock();
82  $resource_storage = $this->getMockBuilder(Services::class)->disableOriginalConstructor()->getMock();
83  $language->method('txt')->willReturnCallback(
84  static fn(string $lang_key) => 'Translated: ' . $lang_key
85  );
86  $container->method('ui')->willReturn($ui);
87  $container->method('ctrl')->willReturn($ctrl);
88  $container->method('language')->willReturn($language);
89  $container->method('resourceStorage')->willReturn($resource_storage);
90  $format_date = function (int $x): void {
91  throw new Exception('Should not be called.');
92  };
93  $sign_file = function (string $path) use ($signed_file, $badge_image_path): string {
94  return $signed_file;
95  };
96 
97  $badge->method('getImagePath')->willReturn($badge_image_path);
98  $badge->method('getImage')->willReturn($badge_image_name);
99  $badge->method('getImageRid')->willReturn($badge_image_rid_name);
100  $modal_content->method('badge')->willReturn($badge);
101 
102  $tile = new Tile($container, $parent, $modal, $sign_file, $format_date);
103 
104  $components = $tile->$method($modal_content);
105 
106  $this->assertSame(count($expected_components), count($components));
107  array_map($this->assertInstanceOf(...), $expected_components, $components);
108  }
109 
110  public static function provideAsVariants(): array
111  {
112  return [
113  'Test asImage' => ['asImage', [ModalComponent::class, ImageComponent::class]],
114  'Test asTitle' => ['asTitle', [ModalComponent::class, ButtonComponent::class]],
115  'Test asTitleWithLeadingImage' => [
116  'asTitleWithLeadingImage',
117  [ModalComponent::class, ImageComponent::class, ButtonComponent::class]
118  ],
119  ];
120  }
121 }
This is how the factory for UI elements looks.
Definition: Factory.php:29
This describes a standard Card.
Definition: Standard.php:26
testAs(string $method, array $expected_components)
provideAsVariants
Definition: TileTest.php:68
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$path
Definition: ltiservices.php:29
$components
$container
Definition: wac.php:36
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This is how the factory for UI elements looks.
Definition: Factory.php:27
This is how a factory for buttons looks like.
Definition: Factory.php:29