3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
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.
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.
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/>.
22 namespace Friendica\Test\src\Model\Storage;
24 use Friendica\Model\Storage\IStorage;
25 use Friendica\Test\MockedTest;
27 abstract class StorageTest extends MockedTest
29 /** @return IStorage */
30 abstract protected function getInstance();
32 abstract protected function assertOption(IStorage $storage);
35 * Test if the instance is "really" implementing the interface
37 public function testInstance()
39 $instance = $this->getInstance();
40 $this->assertInstanceOf(IStorage::class, $instance);
44 * Test if the "getOption" is asserted
46 public function testGetOptions()
48 $instance = $this->getInstance();
50 $this->assertOption($instance);
54 * Test basic put, get and delete operations
56 public function testPutGetDelete()
58 $instance = $this->getInstance();
60 $ref = $instance->put('data12345');
61 $this->assertNotEmpty($ref);
63 $this->assertEquals('data12345', $instance->get($ref));
65 $this->assertTrue($instance->delete($ref));
69 * Test a delete with an invalid reference
71 public function testInvalidDelete()
73 $instance = $this->getInstance();
75 // Even deleting not existing references should return "true"
76 $this->assertTrue($instance->delete(-1234456));
80 * Test a get with an invalid reference
82 public function testInvalidGet()
84 $instance = $this->getInstance();
86 // Invalid references return an empty string
87 $this->assertEmpty($instance->get(-123456));
91 * Test an update with a given reference
93 public function testUpdateReference()
95 $instance = $this->getInstance();
97 $ref = $instance->put('data12345');
98 $this->assertNotEmpty($ref);
100 $this->assertEquals('data12345', $instance->get($ref));
102 $this->assertEquals($ref, $instance->put('data5432', $ref));
103 $this->assertEquals('data5432', $instance->get($ref));
107 * Test that an invalid update results in an insert
109 public function testInvalidUpdate()
111 $instance = $this->getInstance();
113 $this->assertEquals(-123, $instance->put('data12345', -123));