ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilTermsOfServiceAcceptanceHistoryProviderTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
26 {
28  {
30  $factory->setDatabaseAdapter($this->getMockBuilder(ilDBInterface::class)->getMock());
31 
33 
34  $this->assertInstanceOf(ilTermsOfServiceAcceptanceHistoryProvider::class, $provider);
35  $this->assertInstanceOf(ilTermsOfServiceTableDatabaseDataProvider::class, $provider);
36  $this->assertInstanceOf(ilTermsOfServiceTableDataProvider::class, $provider);
37  }
38 
39  public function testListCanBeRetrieved(): void
40  {
41  $database = $this->getMockBuilder(ilDBInterface::class)->getMock();
42  $result = $this->getMockBuilder(ilDBStatement::class)->getMock();
43 
45  $factory->setDatabaseAdapter($database);
46 
48 
49  $database
50  ->expects($this->exactly(2))
51  ->method('query')
52  ->with($this->stringContains('SELECT'))
53  ->willReturn($result);
54 
55  $database
56  ->expects($this->exactly(4))
57  ->method('fetchAssoc')
58  ->will($this->onConsecutiveCalls(['phpunit'], ['phpunit'], [], ['cnt' => 2]));
59 
60  $database
61  ->method('like')
62  ->with(
63  $this->isType('string'),
64  $this->isType('string'),
65  $this->isType('string')
66  )->will($this->returnArgument(2));
67 
68  $database
69  ->method('quote')
70  ->with($this->anything(), $this->isType('string'))
71  ->willReturnCallback(static function ($arg1): string {
72  return (string) $arg1;
73  });
74 
75  $data = $provider->getList(
76  [
77  'limit' => 5,
78  'order_field' => 'ts'
79  ],
80  [
81  'query' => 'phpunit',
82  'period' => [
83  'start' => time(),
84  'end' => time()
85  ]
86  ]
87  );
88 
89  $this->assertArrayHasKey('items', $data);
90  $this->assertArrayHasKey('cnt', $data);
91  $this->assertCount(2, $data['items']);
92  $this->assertSame(2, $data['cnt']);
93  }
94 
99  {
100  $database = $this->getMockBuilder(ilDBInterface::class)->getMock();
101 
103  $factory->setDatabaseAdapter($database);
104 
106 
107  try {
108  $provider->getList(['limit' => 'phpunit'], []);
109  $this->fail('An expected exception has not been raised.');
110  } catch (InvalidArgumentException $e) {
111  }
112 
113  try {
114  $provider->getList(['limit' => 5, 'offset' => 'phpunit'], []);
115  $this->fail('An expected exception has not been raised.');
116  } catch (InvalidArgumentException $e) {
117  }
118 
119  try {
120  $provider->getList(['order_field' => 'phpunit'], []);
121  $this->fail('An expected exception has not been raised.');
122  } catch (InvalidArgumentException $e) {
123  }
124 
125  try {
126  $provider->getList(['order_field' => 5], []);
127  $this->fail('An expected exception has not been raised.');
128  } catch (InvalidArgumentException $e) {
129  }
130 
131  try {
132  $provider->getList(['order_field' => 'ts', 'order_direction' => 'phpunit'], []);
133  $this->fail('An expected exception has not been raised.');
134  } catch (InvalidArgumentException $e) {
135  }
136  }
137 }
Class ilTermsOfServiceAcceptanceHistoryProviderTest.
$provider
Definition: ltitoken.php:83
Class ilTermsOfServiceBaseTest.
$factory
Definition: metadata.php:75