2020-01-05 00:58:49 +00:00
|
|
|
<?php
|
2024-08-24 12:31:41 +00:00
|
|
|
|
|
|
|
// Copyright (C) 2010-2024, the Friendica project
|
|
|
|
// SPDX-FileCopyrightText: 2010-2024 the Friendica project
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
2020-01-05 00:58:49 +00:00
|
|
|
|
2024-12-15 21:36:40 +00:00
|
|
|
namespace Friendica\Test;
|
2020-01-05 00:58:49 +00:00
|
|
|
|
2021-10-23 10:11:38 +00:00
|
|
|
use Friendica\Core\Storage\Capability\ICanReadFromStorage;
|
|
|
|
use Friendica\Core\Storage\Capability\ICanWriteToStorage;
|
|
|
|
use Friendica\Core\Storage\Exception\ReferenceStorageException;
|
2024-12-11 22:45:17 +00:00
|
|
|
use Friendica\Test\MockedTestCase;
|
2020-01-05 00:58:49 +00:00
|
|
|
|
2024-12-15 21:36:40 +00:00
|
|
|
abstract class StorageTestCase extends MockedTestCase
|
2020-01-05 00:58:49 +00:00
|
|
|
{
|
2021-10-23 10:11:38 +00:00
|
|
|
/** @return ICanWriteToStorage */
|
2020-01-05 00:58:49 +00:00
|
|
|
abstract protected function getInstance();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test if the instance is "really" implementing the interface
|
|
|
|
*/
|
|
|
|
public function testInstance()
|
|
|
|
{
|
|
|
|
$instance = $this->getInstance();
|
2021-10-23 10:11:38 +00:00
|
|
|
self::assertInstanceOf(ICanReadFromStorage::class, $instance);
|
2020-01-05 00:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test basic put, get and delete operations
|
|
|
|
*/
|
|
|
|
public function testPutGetDelete()
|
|
|
|
{
|
|
|
|
$instance = $this->getInstance();
|
|
|
|
|
|
|
|
$ref = $instance->put('data12345');
|
2020-10-17 12:19:57 +00:00
|
|
|
self::assertNotEmpty($ref);
|
2020-01-05 00:58:49 +00:00
|
|
|
|
2020-10-17 12:19:57 +00:00
|
|
|
self::assertEquals('data12345', $instance->get($ref));
|
2020-01-05 00:58:49 +00:00
|
|
|
|
2021-08-01 12:31:57 +00:00
|
|
|
$instance->delete($ref);
|
2020-01-05 00:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test a delete with an invalid reference
|
|
|
|
*/
|
|
|
|
public function testInvalidDelete()
|
|
|
|
{
|
2021-08-01 12:31:57 +00:00
|
|
|
self::expectException(ReferenceStorageException::class);
|
|
|
|
|
2020-01-05 00:58:49 +00:00
|
|
|
$instance = $this->getInstance();
|
|
|
|
|
2021-08-01 12:31:57 +00:00
|
|
|
$instance->delete(-1234456);
|
2020-01-05 00:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test a get with an invalid reference
|
|
|
|
*/
|
|
|
|
public function testInvalidGet()
|
|
|
|
{
|
2021-08-01 12:31:57 +00:00
|
|
|
self::expectException(ReferenceStorageException::class);
|
|
|
|
|
2020-01-05 00:58:49 +00:00
|
|
|
$instance = $this->getInstance();
|
|
|
|
|
2021-08-01 12:31:57 +00:00
|
|
|
$instance->get(-123456);
|
2020-01-05 00:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test an update with a given reference
|
|
|
|
*/
|
|
|
|
public function testUpdateReference()
|
|
|
|
{
|
|
|
|
$instance = $this->getInstance();
|
|
|
|
|
|
|
|
$ref = $instance->put('data12345');
|
2020-10-17 12:19:57 +00:00
|
|
|
self::assertNotEmpty($ref);
|
2020-01-05 00:58:49 +00:00
|
|
|
|
2020-10-17 12:19:57 +00:00
|
|
|
self::assertEquals('data12345', $instance->get($ref));
|
2020-01-05 00:58:49 +00:00
|
|
|
|
2020-10-17 12:19:57 +00:00
|
|
|
self::assertEquals($ref, $instance->put('data5432', $ref));
|
|
|
|
self::assertEquals('data5432', $instance->get($ref));
|
2020-01-05 00:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that an invalid update results in an insert
|
|
|
|
*/
|
|
|
|
public function testInvalidUpdate()
|
|
|
|
{
|
|
|
|
$instance = $this->getInstance();
|
|
|
|
|
2020-10-17 12:19:57 +00:00
|
|
|
self::assertEquals(-123, $instance->put('data12345', -123));
|
2020-01-05 00:58:49 +00:00
|
|
|
}
|
|
|
|
}
|