Skip to content

Commit 13b4209

Browse files
AdrienClairembaultcedric-anne
authored andcommitted
Fix multiple twig errors in itil side panel
1 parent 2ff6f60 commit 13b4209

File tree

4 files changed

+42
-6
lines changed

4 files changed

+42
-6
lines changed

phpunit/functional/ChangeTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
namespace tests\units;
3636

37+
use Change;
3738
use DbTestCase;
3839

3940
/* Test for inc/change.class.php */
@@ -464,4 +465,20 @@ public function testCentralChangeValidationList()
464465
$output = ob_get_clean();
465466
$this->assertStringNotContainsString("Your changes to validate", $output);
466467
}
468+
469+
public function testShowFormNewItem(): void
470+
{
471+
// Arrange: prepare an empty change
472+
$change = new Change();
473+
$change->getEmpty();
474+
475+
// Act: render form for a new change
476+
$this->login();
477+
ob_start();
478+
$change->showForm($change->getID());
479+
$html = ob_get_clean();
480+
481+
// Assert: make sure some html was generated
482+
$this->assertNotEmpty($html);
483+
}
467484
}

phpunit/functional/ProblemTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
namespace tests\units;
3636

3737
use DbTestCase;
38+
use Problem;
3839

3940
/* Test for inc/problem.class.php */
4041

@@ -306,4 +307,20 @@ public function testSearchOptions()
306307
$this->assertTrue(array_key_exists('ITEM_Problem_74', $problem_with_so));
307308
$this->assertEquals($last_solution_date, $problem_with_so['ITEM_Problem_74']);
308309
}
310+
311+
public function testShowFormNewItem(): void
312+
{
313+
// Arrange: prepare an empty problem
314+
$problem = new Problem();
315+
$problem->getEmpty();
316+
317+
// Act: render form for a new problem
318+
$this->login();
319+
ob_start();
320+
$problem->showForm($problem->getID());
321+
$html = ob_get_clean();
322+
323+
// Assert: make sure some html was generated
324+
$this->assertNotEmpty($html);
325+
}
309326
}

templates/components/itilobject/actors/main.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
'itiltemplate': itiltemplate,
6767
'params': params,
6868
'canupdate': canupdate,
69-
'cancreateuser': cancreateuser,
69+
'cancreateuser': cancreateuser|default(false),
7070
'canassigntome': canassigntome ?? false,
7171
'main_rand': main_rand,
7272
'allow_auto_submit': allow_auto_submit,
@@ -99,7 +99,7 @@
9999
'itiltemplate': itiltemplate,
100100
'params': params,
101101
'canupdate': canupdate,
102-
'cancreateuser': cancreateuser,
102+
'cancreateuser': cancreateuser|default(false),
103103
'canassigntome': canassigntome ?? false,
104104
'main_rand': main_rand,
105105
'allow_auto_submit': allow_auto_submit,

templates/components/itilobject/fields_panel.html.twig

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@
7070
item.fields['entities_id'],
7171
_n('Entity', 'Entities', 1),
7272
field_options|merge({
73-
'entity': userentities,
73+
'entity': userentities|default(
74+
session('glpiactive_entity')
75+
),
7476
'on_change': 'this.form.submit()',
7577
})
7678
) }}
@@ -196,7 +198,7 @@
196198
{{ include('components/itilobject/fields/status.html.twig') }}
197199

198200
{# validation #}
199-
{% if item.fields['global_validation'] != 1 %}
201+
{% if item.fields['global_validation']|default(1) != 1 %}
200202
{{ include('components/itilobject/fields/global_validation.html.twig') }}
201203
{% endif %}
202204

@@ -275,7 +277,7 @@
275277
<span class="badge bg-secondary text-secondary-fg ms-2">
276278
{{ item.countActors() }}
277279
</span>
278-
{% if not (params['template_preview'] ?? false) and cancreateuser and canupdate %}
280+
{% if not (params['template_preview'] ?? false) and cancreateuser|default(false) and canupdate %}
279281
{{ include('components/user/create_user.html.twig') }}
280282
{% endif %}
281283
</button>
@@ -287,7 +289,7 @@
287289
</div>
288290
</section>
289291

290-
{% if canreadnote %}
292+
{% if canreadnote|default(false) %}
291293
{% set notes = call('Notepad::getAllForItem', [get_item('Entity', item.fields['entities_id']), 'Ticket']) %}
292294
{% set notes_show = headers_states['notes'] is not defined or headers_states['notes'] == "true" ? true : (notes|length > 0) %}
293295
{% if notes|length != 0 %}

0 commit comments

Comments
 (0)