ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilTermsOfServiceAcceptanceHistoryProviderTest.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3
9{
14 {
15 $factory = new \ilTermsOfServiceTableDataProviderFactory();
16 $factory->setDatabaseAdapter($this->getMockBuilder(\ilDBInterface::class)->getMock());
17
19
20 $this->assertInstanceOf(\ilTermsOfServiceAcceptanceHistoryProvider::class, $provider);
21 $this->assertInstanceOf(\ilTermsOfServiceTableDatabaseDataProvider::class, $provider);
22 $this->assertInstanceOf(\ilTermsOfServiceTableDataProvider::class, $provider);
23 }
24
28 public function testListCanBeRetrieved()
29 {
30 $database = $this->getMockBuilder(\ilDBInterface::class)->getMock();
31 $result = $this->getMockBuilder(\ilDBStatement::class)->getMock();
32
33 $factory = new \ilTermsOfServiceTableDataProviderFactory();
34 $factory->setDatabaseAdapter($database);
35
37
38 $database
39 ->expects($this->exactly(2))
40 ->method('query')
41 ->with($this->stringContains('SELECT'))
42 ->will($this->returnValue($result));
43
44 $database
45 ->expects($this->exactly(4))
46 ->method('fetchAssoc')
47 ->will($this->onConsecutiveCalls(['phpunit'], ['phpunit'], [], ['cnt' => 2]));
48
49 $database
50 ->expects($this->any())
51 ->method('like')
52 ->with(
53 $this->isType('string'),
54 $this->isType('string'),
55 $this->isType('string')
56 )->will($this->returnArgument(2));
57
58 $database
59 ->expects($this->any())
60 ->method('quote')
61 ->with($this->anything(), $this->isType('string'))
62 ->will($this->returnArgument(0));
63
64 $data = $provider->getList(
65 [
66 'limit' => 5,
67 'order_field' => 'ts'
68 ],
69 [
70 'query' => 'phpunit',
71 'period' => [
72 'start' => time(),
73 'end' => time()
74 ]
75 ]
76 );
77
78 $this->assertArrayHasKey('items', $data);
79 $this->assertArrayHasKey('cnt', $data);
80 $this->assertCount(2, $data['items']);
81 $this->assertEquals(2, $data['cnt']);
82 }
83
88 {
89 $database = $this->getMockBuilder(\ilDBInterface::class)->getMock();
90
91 $factory = new \ilTermsOfServiceTableDataProviderFactory();
92 $factory->setDatabaseAdapter($database);
93
95
96 try {
97 $provider->getList(array('limit' => 'phpunit'), array());
98 $this->fail('An expected exception has not been raised.');
99 } catch (\InvalidArgumentException $e) {
100 }
101
102 try {
103 $provider->getList(array('limit' => 5, 'offset' => 'phpunit'), array());
104 $this->fail('An expected exception has not been raised.');
105 } catch (\InvalidArgumentException $e) {
106 }
107
108 try {
109 $provider->getList(array('order_field' => 'phpunit'), array());
110 $this->fail('An expected exception has not been raised.');
111 } catch (\InvalidArgumentException $e) {
112 }
113
114 try {
115 $provider->getList(array('order_field' => 5), array());
116 $this->fail('An expected exception has not been raised.');
117 } catch (\InvalidArgumentException $e) {
118 }
119
120 try {
121 $provider->getList(array('order_field' => 'ts', 'order_direction' => 'phpunit'), array());
122 $this->fail('An expected exception has not been raised.');
123 } catch (\InvalidArgumentException $e) {
124 }
125 }
126}
$result
$factory
Definition: metadata.php:43
An exception for terminatinating execution or to throw for unit testing.
Class ilTermsOfServiceAcceptanceHistoryProviderTest.
Class ilTermsOfServiceBaseTest.
$data
Definition: bench.php:6