ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
ilObjDataCollectionTest.php
Go to the documentation of this file.
1 <?php
2 
4 
5 include_once("./Services/Exceptions/classes/class.ilException.php");
6 
14 {
18  protected $root_object;
19 
20  protected $backupGlobals = false;
21 
22  protected function setUp() : void
23  {
24  parent::setUp();
25 
26  require_once("./Modules/DataCollection/classes/class.ilObjDataCollection.php");
27 
28  include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
29  ilUnitUtil::performInitialisation();
30  $this->root_object = new ilObjDataCollection();
31  $this->root_object->setTitle('DataCollection');
32 
33  $this->root_object->create();
34  $this->root_object->createReference();
35  $this->root_object_obj_id = $this->root_object->getId();
36  $this->root_object_ref_id = $this->root_object->getRefId();
37  $this->root_object->putInTree(ROOT_FOLDER_ID);
38 
39  //
40 
41  global $DIC;
42  $tree = $DIC['tree'];
43  $this->tree = $tree;
44 
45  global $DIC;
46  $objDefinition = $DIC['objDefinition'];
47  $this->obj_definition = $objDefinition;
48  }
49 
50  protected function tearDown() : void
51  {
52  if ($this->root_object) {
53  $this->root_object->delete();
54  }
55  }
56 
60  public function testCreation()
61  {
62  $this->assertNotEmpty($this->root_object_obj_id);
63  $this->assertGreaterThan(0, $this->root_object_obj_id);
64 
65  $this->assertNotEmpty($this->root_object_ref_id);
66  $this->assertGreaterThan(0, $this->root_object_ref_id);
67 
68  $this->assertTrue($this->tree->isInTree($this->root_object_ref_id));
69  }
70 
71  public function testDefaultTableCreated()
72  {
73  $tables = $this->root_object->getTables();
74  $this->assertEquals(count($tables), 1);
75 
76  $table = array_shift($tables);
77  $this->assertTrue($table instanceof ilDclTable);
78  return $table;
79  }
80 
84  public function testDefaultTable(ilDclTable $table)
85  {
86 // $this->assertEquals($table->getId(), $this->root_object->getMainTableId());
87  $this->assertEquals($table->getTitle(), $this->root_object->getTitle());
88 // $this->assertEquals($table->getObjId(), $this->root_object_obj_id);
89  $this->assertFalse((bool) $table->getPublicCommentsEnabled());
90  $this->assertEmpty($table->getRecords());
91  $this->assertEmpty($table->getRecordFields());
92  $this->assertEquals(count($table->getFields()), count($table->getStandardFields()));
93 
94  $this->assertTrue($this->root_object->_hasTableByTitle($this->root_object->getTitle(), $this->root_object_obj_id));
95  }
96 
100  public function testDefaultTableViewCreated(ilDclTable $table)
101  {
102  $tableviews = $table->getTableViews();
103  $this->assertEquals(count($tableviews), 1);
104 
105  $tableview = array_shift($tableviews);
106  $this->assertTrue($tableview instanceof ilDclTableView);
107  return array('table' => $table, 'tableview' => $tableview);
108  }
109 
113  public function testDefaultTableView(array $array)
114  {
115  $this->assertEquals(count(ilDclTableView::getAllForTableId($array['table']->getId())), 1);
116  $this->assertEquals($array['tableview']->getTable(), $array['table']);
117 
118  $this->assertEquals($array['tableview']->getOrder(), 10);
119  }
120 
124  public function testDefaultTableViewFieldSettings(array $array)
125  {
126  $field_settings = $array['tableview']->getFieldSettings();
127 // $this->assertEquals(count($field_settings), count($array['table']->getFields()) - $array['table']->getPublicCommentsEnabled());
128 
129  foreach ($array['table']->getFields() as $field) {
130  $f_sets = $field->getFieldSettings();
131  $this->assertNotEmpty($f_sets);
132  }
133  }
134 
135  public function testPrepareMessageText() : void
136  {
137  $testData = [
138  "test\r\n message" => "test\r\n message",
139  "test<br />\r\n message" => "test\r\n message",
140  "test<br /><br>\r\n message" => "test\r\n\r\n message",
141  "test><br><br /><br>\r\n message" => "test\r\n\r\n\r\n message",
142  ];
143 
144  foreach ($testData as $testString => $expected) {
145  $this->assertEquals($expected, $testString);
146  }
147  }
148 }
testCreation()
Test creation of ilObjStudyProgramme.
testDefaultTableViewCreated(ilDclTable $table)
testDefaultTableCreated
Class ilObjDataCollectionTest needsInstalledILIAS.
const ROOT_FOLDER_ID
Definition: constants.php:30
testDefaultTableView(array $array)
testDefaultTableViewCreated
static getAllForTableId($table_id)
getFields()
Returns all fields of this table including the standard fields.
Class ilDclBaseFieldModel.
testDefaultTable(ilDclTable $table)
testDefaultTableCreated
global $DIC
Definition: goto.php:24
Class ilDclTableView.
getRecordFields()
Returns all fields of this table which are NOT standard fields.
testDefaultTableViewFieldSettings(array $array)
testDefaultTableViewCreated
Class ilObjDataCollection.