3 namespace Friendica\Test\src\Model\Storage;
5 use Friendica\Model\Storage\IStorage;
6 use Friendica\Test\MockedTest;
8 abstract class StorageTest extends MockedTest
10 /** @return IStorage */
11 abstract protected function getInstance();
13 abstract protected function assertOption(IStorage $storage);
16 * Test if the instance is "really" implementing the interface
18 public function testInstance()
20 $instance = $this->getInstance();
21 $this->assertInstanceOf(IStorage::class, $instance);
25 * Test if the "getOption" is asserted
27 public function testGetOptions()
29 $instance = $this->getInstance();
31 $this->assertOption($instance);
35 * Test basic put, get and delete operations
37 public function testPutGetDelete()
39 $instance = $this->getInstance();
41 $ref = $instance->put('data12345');
42 $this->assertNotEmpty($ref);
44 $this->assertEquals('data12345', $instance->get($ref));
46 $this->assertTrue($instance->delete($ref));
50 * Test a delete with an invalid reference
52 public function testInvalidDelete()
54 $instance = $this->getInstance();
56 // Even deleting not existing references should return "true"
57 $this->assertTrue($instance->delete(-1234456));
61 * Test a get with an invalid reference
63 public function testInvalidGet()
65 $instance = $this->getInstance();
67 // Invalid references return an empty string
68 $this->assertEmpty($instance->get(-123456));
72 * Test an update with a given reference
74 public function testUpdateReference()
76 $instance = $this->getInstance();
78 $ref = $instance->put('data12345');
79 $this->assertNotEmpty($ref);
81 $this->assertEquals('data12345', $instance->get($ref));
83 $this->assertEquals($ref, $instance->put('data5432', $ref));
84 $this->assertEquals('data5432', $instance->get($ref));
88 * Test that an invalid update results in an insert
90 public function testInvalidUpdate()
92 $instance = $this->getInstance();
94 $this->assertEquals(-123, $instance->put('data12345', -123));