2020-01-05 01:58:49 +01:00
|
|
|
<?php
|
2020-02-09 15:45:36 +01:00
|
|
|
/**
|
2021-03-29 08:40:20 +02:00
|
|
|
* @copyright Copyright (C) 2010-2021, the Friendica project
|
2020-02-09 15:45:36 +01:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2020-01-05 01:58:49 +01:00
|
|
|
|
|
|
|
namespace Friendica\Test\src\Model\Storage;
|
|
|
|
|
|
|
|
use Friendica\Model\Storage\IStorage;
|
|
|
|
use Friendica\Test\MockedTest;
|
|
|
|
|
|
|
|
abstract class StorageTest extends MockedTest
|
|
|
|
{
|
|
|
|
/** @return IStorage */
|
|
|
|
abstract protected function getInstance();
|
|
|
|
|
|
|
|
abstract protected function assertOption(IStorage $storage);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test if the instance is "really" implementing the interface
|
|
|
|
*/
|
|
|
|
public function testInstance()
|
|
|
|
{
|
|
|
|
$instance = $this->getInstance();
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertInstanceOf(IStorage::class, $instance);
|
2020-01-05 01:58:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test if the "getOption" is asserted
|
|
|
|
*/
|
|
|
|
public function testGetOptions()
|
|
|
|
{
|
|
|
|
$instance = $this->getInstance();
|
|
|
|
|
|
|
|
$this->assertOption($instance);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test basic put, get and delete operations
|
|
|
|
*/
|
|
|
|
public function testPutGetDelete()
|
|
|
|
{
|
|
|
|
$instance = $this->getInstance();
|
|
|
|
|
|
|
|
$ref = $instance->put('data12345');
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertNotEmpty($ref);
|
2020-01-05 01:58:49 +01:00
|
|
|
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertEquals('data12345', $instance->get($ref));
|
2020-01-05 01:58:49 +01:00
|
|
|
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertTrue($instance->delete($ref));
|
2020-01-05 01:58:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test a delete with an invalid reference
|
|
|
|
*/
|
|
|
|
public function testInvalidDelete()
|
|
|
|
{
|
|
|
|
$instance = $this->getInstance();
|
|
|
|
|
|
|
|
// Even deleting not existing references should return "true"
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertTrue($instance->delete(-1234456));
|
2020-01-05 01:58:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test a get with an invalid reference
|
|
|
|
*/
|
|
|
|
public function testInvalidGet()
|
|
|
|
{
|
|
|
|
$instance = $this->getInstance();
|
|
|
|
|
|
|
|
// Invalid references return an empty string
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertEmpty($instance->get(-123456));
|
2020-01-05 01:58:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test an update with a given reference
|
|
|
|
*/
|
|
|
|
public function testUpdateReference()
|
|
|
|
{
|
|
|
|
$instance = $this->getInstance();
|
|
|
|
|
|
|
|
$ref = $instance->put('data12345');
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertNotEmpty($ref);
|
2020-01-05 01:58:49 +01:00
|
|
|
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertEquals('data12345', $instance->get($ref));
|
2020-01-05 01:58:49 +01:00
|
|
|
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertEquals($ref, $instance->put('data5432', $ref));
|
|
|
|
self::assertEquals('data5432', $instance->get($ref));
|
2020-01-05 01:58:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that an invalid update results in an insert
|
|
|
|
*/
|
|
|
|
public function testInvalidUpdate()
|
|
|
|
{
|
|
|
|
$instance = $this->getInstance();
|
|
|
|
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertEquals(-123, $instance->put('data12345', -123));
|
2020-01-05 01:58:49 +01:00
|
|
|
}
|
|
|
|
}
|