2023-05-13 16:04:51 -04:00
|
|
|
<?php
|
2023-05-13 16:35:32 -04:00
|
|
|
/**
|
|
|
|
* @copyright Copyright (C) 2010-2023, the Friendica project
|
|
|
|
*
|
|
|
|
* @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/>.
|
|
|
|
*
|
|
|
|
*/
|
2023-05-13 16:04:51 -04:00
|
|
|
|
|
|
|
namespace Friendica\Test\src\Database;
|
|
|
|
|
|
|
|
use Friendica\Core\Config\Util\ConfigFileManager;
|
|
|
|
use Friendica\Core\Config\ValueObject\Cache;
|
|
|
|
use Friendica\Test\FixtureTest;
|
|
|
|
use Friendica\Test\Util\CreateDatabaseTrait;
|
|
|
|
|
|
|
|
class DatabaseTest extends FixtureTest
|
|
|
|
{
|
|
|
|
use CreateDatabaseTrait;
|
|
|
|
|
|
|
|
protected function setUp(): void
|
|
|
|
{
|
|
|
|
$this->setUpVfsDir();
|
|
|
|
|
|
|
|
parent::setUp();
|
|
|
|
|
2023-05-13 16:36:18 -04:00
|
|
|
$this->configCache = new Cache();
|
2023-05-13 16:04:51 -04:00
|
|
|
$this->configFileManager = new ConfigFileManager($this->root->url(), $this->root->url() . '/config/', $this->root->url() . '/static/');
|
|
|
|
}
|
|
|
|
|
2023-05-13 16:18:00 -04:00
|
|
|
/**
|
|
|
|
* Test, if directly updating a field is possible
|
|
|
|
*/
|
2023-05-13 16:04:51 -04:00
|
|
|
public function testUpdateIncrease()
|
|
|
|
{
|
|
|
|
$db = $this->getDbInstance();
|
|
|
|
|
|
|
|
self::assertTrue($db->insert('config', ['cat' => 'test', 'k' => 'inc', 'v' => 0]));
|
|
|
|
self::assertTrue($db->update('config', ["`v` = `v` + 1"], ['cat' => 'test', 'k' => 'inc']));
|
|
|
|
self::assertEquals(1, $db->selectFirst('config', ['v'], ['cat' => 'test', 'k' => 'inc'])['v']);
|
|
|
|
}
|
|
|
|
|
2023-05-13 16:18:00 -04:00
|
|
|
/**
|
|
|
|
* Test if combining directly field updates with normal updates is working
|
|
|
|
*/
|
2023-05-13 16:04:51 -04:00
|
|
|
public function testUpdateWithField()
|
|
|
|
{
|
|
|
|
$db = $this->getDbInstance();
|
|
|
|
|
|
|
|
self::assertEquals('https://friendica.local', $db->selectFirst('gserver', ['url'], ['nurl' => 'http://friendica.local'])['url']);
|
2023-05-13 16:18:00 -04:00
|
|
|
self::assertTrue($db->update('gserver', ['active-week-users' => 0], ['nurl' => 'http://friendica.local']));
|
2023-05-13 16:42:56 -04:00
|
|
|
self::assertTrue($db->update('gserver', [
|
|
|
|
'site_name' => 'test', "`registered-users` = `registered-users` + 1",
|
|
|
|
'info' => 'another test',
|
|
|
|
"`active-week-users` = `active-week-users` + 2"
|
|
|
|
], [
|
|
|
|
'nurl' => 'http://friendica.local'
|
|
|
|
]));
|
2023-05-13 16:04:51 -04:00
|
|
|
self::assertEquals(1, $db->selectFirst('gserver', ['registered-users'], ['nurl' => 'http://friendica.local'])['registered-users']);
|
2023-05-13 16:18:00 -04:00
|
|
|
self::assertEquals(2, $db->selectFirst('gserver', ['active-week-users'], ['nurl' => 'http://friendica.local'])['active-week-users']);
|
2023-05-13 16:42:56 -04:00
|
|
|
self::assertTrue($db->update('gserver', [
|
|
|
|
'site_name' => 'test', "`registered-users` = `registered-users` + 1",
|
|
|
|
'info' => 'another test'], ['nurl' => 'http://friendica.local'
|
|
|
|
]));
|
2023-05-13 16:04:51 -04:00
|
|
|
self::assertEquals(2, $db->selectFirst('gserver', ['registered-users'], ['nurl' => 'http://friendica.local'])['registered-users']);
|
2023-05-13 16:42:56 -04:00
|
|
|
self::assertTrue($db->update('gserver', [
|
|
|
|
'site_name' => 'test', "`registered-users` = `registered-users` - 1",
|
|
|
|
'info' => 'another test'], ['nurl' => 'http://friendica.local'
|
|
|
|
]));
|
2023-05-13 16:04:51 -04:00
|
|
|
self::assertEquals(1, $db->selectFirst('gserver', ['registered-users'], ['nurl' => 'http://friendica.local'])['registered-users']);
|
|
|
|
}
|
|
|
|
}
|