19 declare(strict_types=1);
51 protected function setUp(): void
53 if (!defined(
'ILIAS_HTTP_PATH')) {
54 define(
'ILIAS_HTTP_PATH',
'https://ilias.unit.test');
57 $this->file_info_repository = $this->createMock(\ilObjFileInfoRepository::class);
58 $this->
access = $this->createMock(\ilAccessHandler::class);
59 $this->
ctrl = $this->createMock(\ilCtrlInterface::class);
60 $this->action_repository = $this->createMock(ActionRepository::class);
61 $this->
http = $this->createMock(Services::class);
62 $this->static_url = $this->createMock(URIBuilder::class);
63 $this->type_resolver = $this->createMock(TypeResolver::class);
64 $this->workspace_access_handler = $this->createMock(ilWorkspaceAccessHandler::class);
66 $this->type_resolver->method(
'resolveTypeByObjectId')
71 $this->file_info_repository,
74 $this->action_repository,
78 $this->workspace_access_handler
88 if (!self::$update_readme) {
100 'infopage_first' =>
true,
101 'user_permissions' => [
104 Permissions::VISIBLE,
105 Permissions::EDIT_CONTENT,
106 Permissions::VIEW_CONTENT
108 'expected_best' => Capabilities::FORCED_INFO_PAGE
113 'infopage_first' =>
false,
114 'user_permissions' => [
117 Permissions::VISIBLE,
118 Permissions::EDIT_CONTENT,
119 Permissions::VIEW_CONTENT
121 'expected_best' => Capabilities::VIEW_EXTERNAL
126 'infopage_first' =>
false,
127 'user_permissions' => [
128 Permissions::EDIT_CONTENT,
129 Permissions::VIEW_CONTENT
131 'expected_best' => Capabilities::VIEW_EXTERNAL
134 'wopi_view' =>
false,
135 'wopi_edit' =>
false,
136 'infopage_first' =>
true,
137 'user_permissions' => [
141 'expected_best' => Capabilities::FORCED_INFO_PAGE
146 'infopage_first' =>
false,
147 'user_permissions' => [
148 Permissions::EDIT_CONTENT,
150 'expected_best' => Capabilities::EDIT_EXTERNAL
155 'infopage_first' =>
false,
156 'user_permissions' => [
159 'expected_best' => Capabilities::DOWNLOAD
164 'infopage_first' =>
false,
165 'user_permissions' => [
169 'expected_best' => Capabilities::DOWNLOAD
174 'infopage_first' =>
false,
175 'user_permissions' => [
178 'expected_best' => Capabilities::MANAGE_VERSIONS
183 'infopage_first' =>
false,
184 'user_permissions' => [
185 Permissions::VISIBLE,
187 'expected_best' => Capabilities::INFO_PAGE
192 'infopage_first' =>
true,
193 'user_permissions' => [
197 'expected_best' => Capabilities::FORCED_INFO_PAGE
202 'infopage_first' =>
false,
203 'user_permissions' => [
206 'expected_best' => Capabilities::NONE
211 'infopage_first' =>
true,
212 'user_permissions' => [
214 Permissions::VISIBLE,
216 'expected_best' => Capabilities::FORCED_INFO_PAGE
221 #[DataProvider('environmentProvider')] 225 bool $infopage_first,
226 array $user_permissions,
230 $permissions = $user_permissions;
237 Context::CONTEXT_REPO
240 $this->
access->method(
'checkAccess')
241 ->willReturnCallback(
242 function (
string $permission) use ($permissions):
bool {
243 $checked_permissions = explode(
',', $permission);
244 $common_permissions = array_intersect(
248 return $common_permissions !== [];
252 $file_info = $this->createMock(\ilObjFileInfo::class);
253 $file_info->method(
'shouldDownloadDirectly')
254 ->willReturn(!$infopage_first);
256 $this->file_info_repository->method(
'getByObjectId')
258 ->willReturn($file_info);
260 $this->action_repository->method(
'hasEditActionForSuffix')
261 ->willReturn($wopi_edit);
263 $this->action_repository->method(
'hasViewActionForSuffix')
264 ->willReturn($wopi_view);
266 $capabilities = $this->capability_builder->get(
$context);
267 $best = $capabilities->getBest();
269 $this->assertEquals($expected_best, $best->getCapability());
271 self::$readme_infos[] = [
273 ($wopi_view ?
'Yes' :
'No'),
274 ($wopi_edit ?
'Yes' :
'No'),
275 ($infopage_first ?
'Info-Page' :
'Open'),
276 $best->getCapability()->name
283 $readme_file = __DIR__ .
'/../../docs/README.md';
284 $readme_content = file_get_contents($readme_file);
288 'User\'s Permissions',
289 'WOPI View Action av.',
290 'WOPI Edit Action av.',
292 'Expected Capability' 295 $readme_infos = self::$readme_infos;
297 usort($readme_infos,
static function (
$a,
$b):
int {
298 $a_string = implode(
'', array_reverse(
$a));
299 $b_string = implode(
'', array_reverse(
$b));
301 return strcmp((
string) $a_string, (
string) $b_string);
304 $table = array_merge($table, $readme_infos);
307 $start_marker =
"<!-- START CAPABILITY_TABLE -->";
308 $end_marker =
"<!-- END CAPABILITY_TABLE -->";
311 $new_block = $start_marker .
"\n\n" . self::arrayToMarkdownTable($table) .
"\n\n" . $end_marker;
314 $pattern =
'/' . preg_quote($start_marker,
'/') .
'.*?' . preg_quote($end_marker,
'/') .
'/s';
315 $readme_content = preg_replace($pattern, $new_block, $readme_content);
317 file_put_contents($readme_file, $readme_content);
323 if (empty($data) || !is_array($data[0])) {
329 static fn($col_index):
int => max(
331 static fn($row):
int => isset($row[$col_index]) ? mb_strlen((
string) $row[$col_index]) : 0,
339 $pad_row =
static fn($row): array =>
array_map(
static function ($value, $index) use ($col_widths):
string {
341 return str_pad($value, $col_widths[$index],
" ", STR_PAD_RIGHT);
342 }, $row, array_keys($col_widths));
345 $header = $pad_row($data[0]);
346 $rows =
array_map($pad_row, array_slice($data, 1));
350 . implode(
" | ", $header)
353 . implode(
" | ",
array_map(
static fn($width):
string => str_repeat(
"-", $width), $col_widths))
355 $data_rows =
array_map(
static fn($row):
string =>
"| " . implode(
" | ", $row) .
" |", $rows);
358 return implode(
"\n", array_merge([$header_row, $sep_row], $data_rows));
ActionRepository MockObject $action_repository
CapabilityBuilder $capability_builder
ilObjFileInfoRepository MockObject $file_info_repository
ilAccessHandler MockObject $access
static array $readme_infos
PHPUnit Framework MockObject MockObject $workspace_access_handler
static environmentProvider()
static bool $update_readme
static http()
Fetches the global http state from ILIAS.
testCapabilityPriority(bool $wopi_view, bool $wopi_edit, bool $infopage_first, array $user_permissions, Capabilities $expected_best)
static arrayToMarkdownTable(array $data)
Services MockObject $http
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
URIBuilder MockObject $static_url
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
PHPUnit Framework MockObject MockObject TypeResolver $type_resolver
ilCtrlInterface MockObject $ctrl
static tearDownAfterClass()