ILIAS  release_7 Revision v7.30-3-g800a261c036
SectionInputTest.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2020 Nils Haagen <nils.haagen@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
5require_once(__DIR__ . "/../../../../../libs/composer/vendor/autoload.php");
6require_once(__DIR__ . "/../../../Base.php");
7
9use \ILIAS\Data;
10
12{
13 public function getFieldFactory()
14 {
17 new Data\Factory(),
18 $this->getRefinery(),
19 $this->getLanguage()
20 );
21 return $factory;
22 }
23
24 public function testSectionRendering()
25 {
26 $f = $this->getFieldFactory();
27 $r = $this->getDefaultRenderer();
28 $inputs = [
29 $f->text("input1", "in 1"),
30 $f->text("input2", "in 2")
31 ];
32 $label = 'section label';
33 $byline = 'section byline';
34 $section = $f->section($inputs, $label, $byline);
35 $actual = $this->brutallyTrimHTML($r->render($section));
36 $expected = <<<EOT
37 <div class="il-section-input">
38 <div class="il-section-input-header">
39 <h2>section label</h2>
40 <div class="il-section-input-header-byline">section byline</div>
41 </div>
42 <div class="form-group row">
43 <label for="id_1" class="control-label col-sm-3">input1</label>
44 <div class="col-sm-9">
45 <input id="id_1" type="text" name="" class="form-control form-control-sm" />
46 <div class="help-block">in 1</div>
47 </div>
48 </div>
49 <div class="form-group row">
50 <label for="id_2" class="control-label col-sm-3">input2</label>
51 <div class="col-sm-9">
52 <input id="id_2" type="text" name="" class="form-control form-control-sm" />
53 <div class="help-block">in 2</div>
54 </div>
55 </div>
56 </div>
57EOT;
58 $expected = $this->brutallyTrimHTML($expected);
59 $this->assertEquals($expected, $actual);
60 }
61
63 {
64 $f = $this->getFieldFactory();
65 $r = $this->getDefaultRenderer();
66 $inputs = [
67 $f->text("input1", "in 1")
68 ];
69 $label = 'section label';
70 $byline = 'section byline';
71 $section = $f->section($inputs, $label, $byline);
72 $actual = $this->brutallyTrimHTML($r->render($section->withError("Some Error")));
73 $expected = <<<EOT
74 <div class="il-section-input">
75 <div class="il-section-input-header">
76 <h2>section label</h2>
77 <div class="il-section-input-header-byline">section byline</div>
78 </div>
79 <div class="help-block alert alert-danger" role="alert"> Some Error </div>
80 <div class="form-group row">
81 <label for="id_1" class="control-label col-sm-3">input1</label>
82 <div class="col-sm-9">
83 <input id="id_1" type="text" name="" class="form-control form-control-sm" />
84 <div class="help-block">in 1</div>
85 </div>
86 </div>
87 </div>
88EOT;
89 $expected = $this->brutallyTrimHTML($expected);
90 $this->assertEquals($expected, $actual);
91 }
92}
$section
Definition: Utf8Test.php:83
An exception for terminatinating execution or to throw for unit testing.
Builds data types.
Definition: Factory.php:20
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Error.php:14
Provides common functionality for UI tests.
Definition: Base.php:263
getDefaultRenderer(JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
Definition: Base.php:311
brutallyTrimHTML($html)
A more radical version of normalizeHTML.
Definition: Base.php:392
$factory
Definition: metadata.php:58