ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
ilTermsOfServiceAcceptanceHistoryProviderTest.php
Go to the documentation of this file.
1 <?php declare(strict_types=1);
2 /* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
9 {
15  {
17  $factory->setDatabaseAdapter($this->getMockBuilder(ilDBInterface::class)->getMock());
18 
20 
21  $this->assertInstanceOf(ilTermsOfServiceAcceptanceHistoryProvider::class, $provider);
22  $this->assertInstanceOf(ilTermsOfServiceTableDatabaseDataProvider::class, $provider);
23  $this->assertInstanceOf(ilTermsOfServiceTableDataProvider::class, $provider);
24  }
25 
30  public function testListCanBeRetrieved() : void
31  {
32  $database = $this->getMockBuilder(ilDBInterface::class)->getMock();
33  $result = $this->getMockBuilder(ilDBStatement::class)->getMock();
34 
36  $factory->setDatabaseAdapter($database);
37 
39 
40  $database
41  ->expects($this->exactly(2))
42  ->method('query')
43  ->with($this->stringContains('SELECT'))
44  ->will($this->returnValue($result));
45 
46  $database
47  ->expects($this->exactly(4))
48  ->method('fetchAssoc')
49  ->will($this->onConsecutiveCalls(['phpunit'], ['phpunit'], [], ['cnt' => 2]));
50 
51  $database
52  ->expects($this->any())
53  ->method('like')
54  ->with(
55  $this->isType('string'),
56  $this->isType('string'),
57  $this->isType('string')
58  )->will($this->returnArgument(2));
59 
60  $database
61  ->expects($this->any())
62  ->method('quote')
63  ->with($this->anything(), $this->isType('string'))
64  ->will($this->returnArgument(0));
65 
66  $data = $provider->getList(
67  [
68  'limit' => 5,
69  'order_field' => 'ts'
70  ],
71  [
72  'query' => 'phpunit',
73  'period' => [
74  'start' => time(),
75  'end' => time()
76  ]
77  ]
78  );
79 
80  $this->assertArrayHasKey('items', $data);
81  $this->assertArrayHasKey('cnt', $data);
82  $this->assertCount(2, $data['items']);
83  $this->assertEquals(2, $data['cnt']);
84  }
85 
92  {
93  $database = $this->getMockBuilder(ilDBInterface::class)->getMock();
94 
96  $factory->setDatabaseAdapter($database);
97 
99 
100  try {
101  $provider->getList(array('limit' => 'phpunit'), array());
102  $this->fail('An expected exception has not been raised.');
103  } catch (InvalidArgumentException $e) {
104  }
105 
106  try {
107  $provider->getList(array('limit' => 5, 'offset' => 'phpunit'), array());
108  $this->fail('An expected exception has not been raised.');
109  } catch (InvalidArgumentException $e) {
110  }
111 
112  try {
113  $provider->getList(array('order_field' => 'phpunit'), array());
114  $this->fail('An expected exception has not been raised.');
115  } catch (InvalidArgumentException $e) {
116  }
117 
118  try {
119  $provider->getList(array('order_field' => 5), array());
120  $this->fail('An expected exception has not been raised.');
121  } catch (InvalidArgumentException $e) {
122  }
123 
124  try {
125  $provider->getList(array('order_field' => 'ts', 'order_direction' => 'phpunit'), array());
126  $this->fail('An expected exception has not been raised.');
127  } catch (InvalidArgumentException $e) {
128  }
129  }
130 }
$data
Definition: storeScorm.php:23
$result
Class ilTermsOfServiceAcceptanceHistoryProviderTest.
Class ilTermsOfServiceBaseTest.
$factory
Definition: metadata.php:58