ILIAS  trunk Revision v11.0_alpha-1851-ga8564da6fed
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
SearcherTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
24 use ILIAS\MetaData\Search\Clauses\NullFactory as NullClauseFactory;
25 use ILIAS\MetaData\Search\Filters\NullFactory as NullFilterFactory;
32 
33 class SearcherTest extends TestCase
34 {
35  public function getSearcher(): SearcherInterface
36  {
37  $clause_factory = new NullClauseFactory();
38  $filter_factory = new class () extends NullFilterFactory {
39  public function get(
40  int|Placeholder $obj_id = Placeholder::ANY,
41  int|Placeholder $sub_id = Placeholder::ANY,
42  string|Placeholder $type = Placeholder::ANY
43  ): FilterInterface {
44  return new class ($obj_id, $sub_id, $type) extends NullFilter {
45  public array $data = [];
46 
47  public function __construct(
48  int|Placeholder $obj_id,
49  int|Placeholder $sub_id,
50  string|Placeholder $type
51  ) {
52  $this->data = [
53  'obj_id' => $obj_id,
54  'sub_id' => $sub_id,
55  'type' => $type
56  ];
57  }
58  };
59  }
60  };
61  $repository = new class () extends NullRepository {
62  public function searchMD(
63  ClauseInterface $clause,
64  ?int $limit,
65  ?int $offset,
66  FilterInterface ...$filters
67  ): \Generator {
68  yield 'clause' => $clause;
69  yield 'limit' => $limit;
70  yield 'offset' => $offset;
71  yield 'filters' => $filters;
72  }
73  };
74 
75  return new Searcher($clause_factory, $filter_factory, $repository);
76  }
77 
78  public function testGetFilter(): void
79  {
80  $searcher = $this->getSearcher();
81 
82  $filter = $searcher->getFilter(56, 98, 'type');
83  $this->assertSame(
84  ['obj_id' => 56, 'sub_id' => 98, 'type' => 'type'],
85  $filter->data
86  );
87  }
88 
89  public function testGetFilterWithSubIDZero(): void
90  {
91  $searcher = $this->getSearcher();
92 
93  $filter = $searcher->getFilter(56, 0, 'type');
94  $this->assertSame(
95  ['obj_id' => 56, 'sub_id' => Placeholder::OBJ_ID, 'type' => 'type'],
96  $filter->data
97  );
98  }
99 
100  public function testGetFilterWithObjIDPlaceholder(): void
101  {
102  $searcher = $this->getSearcher();
103 
104  $filter = $searcher->getFilter(Placeholder::ANY, 98, 'type');
105  $this->assertSame(
106  ['obj_id' => Placeholder::ANY, 'sub_id' => 98, 'type' => 'type'],
107  $filter->data
108  );
109  }
110 
111  public function testGetFilterWithSubIDPlaceholder(): void
112  {
113  $searcher = $this->getSearcher();
114 
115  $filter = $searcher->getFilter(56, Placeholder::ANY, 'type');
116  $this->assertSame(
117  ['obj_id' => 56, 'sub_id' => Placeholder::ANY, 'type' => 'type'],
118  $filter->data
119  );
120  }
121 
122  public function testGetFilterWithTypePlaceholder(): void
123  {
124  $searcher = $this->getSearcher();
125 
126  $filter = $searcher->getFilter(56, 98, Placeholder::ANY);
127  $this->assertSame(
128  ['obj_id' => 56, 'sub_id' => 98, 'type' => Placeholder::ANY],
129  $filter->data
130  );
131  }
132 
133  public function testExecute(): void
134  {
135  $searcher = $this->getSearcher();
136  $clause = new NullClause();
137 
138  $results = iterator_to_array($searcher->execute($clause, null, null));
139  $this->assertSame(
140  ['clause' => $clause, 'limit' => null, 'offset' => null, 'filters' => []],
141  $results
142  );
143  }
144 
145  public function testExecuteWithLimit(): void
146  {
147  $searcher = $this->getSearcher();
148  $clause = new NullClause();
149 
150  $results = iterator_to_array($searcher->execute($clause, 999, null));
151  $this->assertSame(
152  ['clause' => $clause, 'limit' => 999, 'offset' => null, 'filters' => []],
153  $results
154  );
155  }
156 
157  public function testExecuteWithLimitAndOffset(): void
158  {
159  $searcher = $this->getSearcher();
160  $clause = new NullClause();
161 
162  $results = iterator_to_array($searcher->execute($clause, 999, 333));
163  $this->assertSame(
164  ['clause' => $clause, 'limit' => 999, 'offset' => 333, 'filters' => []],
165  $results
166  );
167  }
168 
169  public function testExecuteWithFilters(): void
170  {
171  $searcher = $this->getSearcher();
172  $clause = new NullClause();
173  $filter_1 = new NullFilter();
174  $filter_2 = new NullFilter();
175  $filter_3 = new NullFilter();
176 
177  $results = iterator_to_array($searcher->execute($clause, 999, 333, $filter_1, $filter_2, $filter_3));
178  $this->assertSame(
179  ['clause' => $clause, 'limit' => 999, 'offset' => 333, 'filters' => [$filter_1, $filter_2, $filter_3]],
180  $results
181  );
182  }
183 }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
__construct()
Constructor setup ILIAS global object public.
Definition: class.ilias.php:76
$results