]> git.mxchange.org Git - friendica.git/blob - tests/src/Model/Storage/StorageTest.php
Merge pull request #8099 from annando/statistics
[friendica.git] / tests / src / Model / Storage / StorageTest.php
1 <?php
2
3 namespace Friendica\Test\src\Model\Storage;
4
5 use Friendica\Model\Storage\IStorage;
6 use Friendica\Test\MockedTest;
7
8 abstract class StorageTest extends MockedTest
9 {
10         /** @return IStorage */
11         abstract protected function getInstance();
12
13         abstract protected function assertOption(IStorage $storage);
14
15         /**
16          * Test if the instance is "really" implementing the interface
17          */
18         public function testInstance()
19         {
20                 $instance = $this->getInstance();
21                 $this->assertInstanceOf(IStorage::class, $instance);
22         }
23
24         /**
25          * Test if the "getOption" is asserted
26          */
27         public function testGetOptions()
28         {
29                 $instance = $this->getInstance();
30
31                 $this->assertOption($instance);
32         }
33
34         /**
35          * Test basic put, get and delete operations
36          */
37         public function testPutGetDelete()
38         {
39                 $instance = $this->getInstance();
40
41                 $ref = $instance->put('data12345');
42                 $this->assertNotEmpty($ref);
43
44                 $this->assertEquals('data12345', $instance->get($ref));
45
46                 $this->assertTrue($instance->delete($ref));
47         }
48
49         /**
50          * Test a delete with an invalid reference
51          */
52         public function testInvalidDelete()
53         {
54                 $instance = $this->getInstance();
55
56                 // Even deleting not existing references should return "true"
57                 $this->assertTrue($instance->delete(-1234456));
58         }
59
60         /**
61          * Test a get with an invalid reference
62          */
63         public function testInvalidGet()
64         {
65                 $instance = $this->getInstance();
66
67                 // Invalid references return an empty string
68                 $this->assertEmpty($instance->get(-123456));
69         }
70
71         /**
72          * Test an update with a given reference
73          */
74         public function testUpdateReference()
75         {
76                 $instance = $this->getInstance();
77
78                 $ref = $instance->put('data12345');
79                 $this->assertNotEmpty($ref);
80
81                 $this->assertEquals('data12345', $instance->get($ref));
82
83                 $this->assertEquals($ref, $instance->put('data5432', $ref));
84                 $this->assertEquals('data5432', $instance->get($ref));
85         }
86
87         /**
88          * Test that an invalid update results in an insert
89          */
90         public function testInvalidUpdate()
91         {
92                 $instance = $this->getInstance();
93
94                 $this->assertEquals(-123, $instance->put('data12345', -123));
95         }
96 }