ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
HasHelpTopicsTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 
26 require_once("vendor/composer/vendor/autoload.php");
27 
32 {
33  protected IHasHelpTopics $mock;
34 
35  public function setUp(): void
36  {
37  $this->mock = new class () implements IHasHelpTopics {
38  use HasHelpTopics;
39  };
40  }
41 
42  public function testEmptyAtCreation()
43  {
44  $this->assertEquals([], $this->mock->getHelpTopics());
45  }
46 
47  public function testWithHelpTopics()
48  {
49  $topics = [new Topic("a"), new Topic("b"), new Topic("c")];
50  $mock = $this->mock->withHelpTopics(...$topics);
51  $this->assertEquals([], $this->mock->getHelpTopics());
52  $this->assertEquals($topics, $mock->getHelpTopics());
53  }
54 
55  public function testAdditionalHelpTopics()
56  {
57  $a = new Topic("a");
58  $topics = [new Topic("b"), new Topic("c")];
59  $mock = $this->mock->withHelpTopics($a);
60  $mock2 = $mock->withAdditionalHelpTopics(...$topics);
61  $this->assertEquals([$a], $mock->getHelpTopics());
62  $all_topics = [new Topic("a"), new Topic("b"), new Topic("c")];
63  $this->assertEquals($all_topics, $mock2->getHelpTopics());
64  }
65 
66  public function testWithHelpTopicsOverwrites()
67  {
68  $topics1 = [new Topic("a"), new Topic("b"), new Topic("c")];
69  $topics2 = [new Topic("d"), new Topic("e")];
70  $mock = $this->mock->withHelpTopics(...$topics1)->withHelpTopics(...$topics2);
71  $this->assertEquals($topics2, $mock->getHelpTopics());
72  }
73 
75  {
76  $dup_topics = [new Topic("a"), new Topic("b"), new Topic("c"), new Topic("a"), new Topic("a"), new Topic("b")];
77  $topics = [new Topic("a"), new Topic("b"), new Topic("c")];
78  $mock = $this->mock->withHelpTopics(...$dup_topics);
79  $this->assertEquals($topics, $mock->getHelpTopics());
80  }
81 
83  {
84  $dup_topics = [new Topic("a"), new Topic("b"), new Topic("c"), new Topic("a"), new Topic("a"), new Topic("b")];
85  $topics = [new Topic("a"), new Topic("b"), new Topic("c")];
86  $mock = $this->mock->withHelpTopics(new Topic("c"))->withAdditionalHelpTopics(...$dup_topics);
87  $this->assertEquals($topics, $mock->getHelpTopics());
88  }
89 }
This is just a class that marks a string as a help topic.
Definition: Topic.php:26
IHasHelpTopics $mock
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples