]> git.mxchange.org Git - friendica.git/blob - tests/src/Model/Storage/StorageTest.php
remove test logging
[friendica.git] / tests / src / Model / Storage / StorageTest.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Test\src\Model\Storage;
23
24 use Friendica\Model\Storage\IStorage;
25 use Friendica\Test\MockedTest;
26
27 abstract class StorageTest extends MockedTest
28 {
29         /** @return IStorage */
30         abstract protected function getInstance();
31
32         abstract protected function assertOption(IStorage $storage);
33
34         /**
35          * Test if the instance is "really" implementing the interface
36          */
37         public function testInstance()
38         {
39                 $instance = $this->getInstance();
40                 self::assertInstanceOf(IStorage::class, $instance);
41         }
42
43         /**
44          * Test if the "getOption" is asserted
45          */
46         public function testGetOptions()
47         {
48                 $instance = $this->getInstance();
49
50                 $this->assertOption($instance);
51         }
52
53         /**
54          * Test basic put, get and delete operations
55          */
56         public function testPutGetDelete()
57         {
58                 $instance = $this->getInstance();
59
60                 $ref = $instance->put('data12345');
61                 self::assertNotEmpty($ref);
62
63                 self::assertEquals('data12345', $instance->get($ref));
64
65                 self::assertTrue($instance->delete($ref));
66         }
67
68         /**
69          * Test a delete with an invalid reference
70          */
71         public function testInvalidDelete()
72         {
73                 $instance = $this->getInstance();
74
75                 // Even deleting not existing references should return "true"
76                 self::assertTrue($instance->delete(-1234456));
77         }
78
79         /**
80          * Test a get with an invalid reference
81          */
82         public function testInvalidGet()
83         {
84                 $instance = $this->getInstance();
85
86                 // Invalid references return an empty string
87                 self::assertEmpty($instance->get(-123456));
88         }
89
90         /**
91          * Test an update with a given reference
92          */
93         public function testUpdateReference()
94         {
95                 $instance = $this->getInstance();
96
97                 $ref = $instance->put('data12345');
98                 self::assertNotEmpty($ref);
99
100                 self::assertEquals('data12345', $instance->get($ref));
101
102                 self::assertEquals($ref, $instance->put('data5432', $ref));
103                 self::assertEquals('data5432', $instance->get($ref));
104         }
105
106         /**
107          * Test that an invalid update results in an insert
108          */
109         public function testInvalidUpdate()
110         {
111                 $instance = $this->getInstance();
112
113                 self::assertEquals(-123, $instance->put('data12345', -123));
114         }
115 }