ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilLSPostConditionDBTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
24 {
28  protected $db;
29 
30  protected function setUp(): void
31  {
32  $this->db = $this->createMock(ilDBInterface::class);
33  }
34 
35  public function testCreateObject(): void
36  {
37  $obj = new ilLSPostConditionDB($this->db);
38 
39  $this->assertInstanceOf(ilLSPostConditionDB::class, $obj);
40  }
41 
42  public function testSelectWithEmptyArray(): void
43  {
44  $obj = new ilLSPostConditionDB($this->db);
45 
46  $result = $obj->select([]);
47 
48  $this->assertIsArray($result);
49  $this->assertEmpty($result);
50  }
51 
52  public function testSelectWithNoDBResults(): void
53  {
54  $sql =
55  "SELECT ref_id, condition_operator, value" . PHP_EOL
56  . "FROM post_conditions" . PHP_EOL
57  . "WHERE ref_id IN (20,22)" . PHP_EOL
58  ;
59 
60  $return = $this->getMockBuilder(ilDBStatement::class)->getMock();
61  $this->db
62  ->expects($this->once())
63  ->method('query')
64  ->with($sql)
65  ->willReturn($return)
66  ;
67  $this->db
68  ->expects($this->once())
69  ->method('fetchAssoc')
70  ->with($return)
71  ->willReturn([])
72  ;
73 
74  $obj = new ilLSPostConditionDB($this->db);
75  $result = $obj->select([20,22]);
76 
77  $this->assertEquals(20, $result[0]->getRefId());
78  $this->assertEquals(ilLSPostConditionDB::STD_ALWAYS_OPERATOR, $result[0]->getConditionOperator());
79  $this->assertNull($result[0]->getValue());
80 
81  $this->assertEquals(22, $result[1]->getRefId());
82  $this->assertEquals(ilLSPostConditionDB::STD_ALWAYS_OPERATOR, $result[1]->getConditionOperator());
83  $this->assertNull($result[1]->getValue());
84  }
85 
86  public function testSelectWithDBResults(): void
87  {
88  $sql =
89  "SELECT ref_id, condition_operator, value" . PHP_EOL
90  . "FROM post_conditions" . PHP_EOL
91  . "WHERE ref_id IN (33,44)" . PHP_EOL
92  ;
93 
94  $rows = [
95  [
96  'ref_id' => 33,
97  'condition_operator' => 'failed',
98  'value' => "11"
99  ],
100  [
101  'ref_id' => 44,
102  'condition_operator' => 'finished',
103  'value' => "12"
104  ],
105  null
106  ];
107 
108  $return_statement = $this->getMockBuilder(ilDBStatement::class)->getMock();
109  $this->db
110  ->expects($this->once())
111  ->method('query')
112  ->with($sql)
113  ->willReturn($return_statement)
114  ;
115  $this->db
116  ->expects($this->any())
117  ->method('fetchAssoc')
118  ->with($return_statement)
119  ->willReturnOnConsecutiveCalls(...$rows)
120  ;
121 
122  $obj = new ilLSPostConditionDB($this->db);
123  $result = $obj->select([33,44]);
124 
125  $this->assertEquals(33, $result[0]->getRefId());
126  $this->assertEquals('failed', $result[0]->getConditionOperator());
127  $this->assertEquals("11", $result[0]->getValue());
128 
129  $this->assertEquals(44, $result[1]->getRefId());
130  $this->assertEquals('finished', $result[1]->getConditionOperator());
131  $this->assertEquals("12", $result[1]->getValue());
132  }
133 
134  public function testDelete(): void
135  {
136  $sql =
137  "DELETE FROM post_conditions" . PHP_EOL
138  . "WHERE ref_id IN (20,22)" . PHP_EOL
139  ;
140 
141  $this->db
142  ->expects($this->once())
143  ->method('manipulate')
144  ->with($sql)
145  ;
146 
147  $obj = new ilLSPostConditionDB($this->db);
148  $obj->delete([20,22]);
149  }
150 }
Storage for ilLSPostConditions.
getValue()
Get the value that is displayed in the input client side.
Definition: Group.php:49
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null