Browse Source

Style fixes

rpm
J. King 3 years ago
parent
commit
e16df90bae
  1. 21
      lib/Database.php
  2. 2
      lib/Db/PostgreSQL/PDOResult.php
  3. 2
      lib/Db/PostgreSQL/Result.php
  4. 5
      lib/REST/Miniflux/V1.php
  5. 1
      lib/User.php
  6. 26
      lib/User/Driver.php
  7. 4
      tests/cases/Database/SeriesCleanup.php
  8. 18
      tests/cases/Database/SeriesUser.php
  9. 5
      tests/cases/Db/BaseUpdate.php
  10. 8
      tests/cases/User/TestInternal.php
  11. 11
      tests/cases/User/TestUser.php
  12. 2
      tests/docroot/Icon/SVG1.php
  13. 2
      tests/docroot/Icon/SVG2.php

21
lib/Database.php

@ -37,7 +37,7 @@ use JKingWeb\Arsse\Misc\URL;
* associations with articles. There has been an effort to keep public method
* names consistent throughout, but protected methods, having different
* concerns, will typically follow different conventions.
*
*
* Note that operations on users should be performed with the User class rather
* than the Database class directly. This is to allow for alternate user sources.
*/
@ -298,7 +298,7 @@ class Database {
$this->db->prepare("UPDATE arsse_users set password = ? where id = ?", "str", "str")->run($hash, $user);
return true;
}
public function userPropertiesGet(string $user): array {
$out = $this->db->prepare("SELECT num, admin, lang, tz, sort_asc from arsse_users where id = ?", "str")->run($user)->getRow();
if (!$out) {
@ -309,7 +309,7 @@ class Database {
settype($out['sort_asc'], "bool");
return $out;
}
public function userPropertiesSet(string $user, array $data): bool {
if (!$this->userExists($user)) {
throw new User\ExceptionConflict("doesNotExist", ["action" => __FUNCTION__, "user" => $user]);
@ -325,7 +325,6 @@ class Database {
return false;
}
return (bool) $this->db->prepare("UPDATE arsse_users set $setClause where id = ?", $setTypes, "str")->run($setValues, $user)->changes();
}
/** Creates a new session for the given user and returns the session identifier */
@ -874,16 +873,16 @@ class Database {
$out = $this->db->prepare("SELECT $field from arsse_tags where id in (select tag from arsse_tag_members where subscription = ? and assigned = 1) order by $field", "int")->run($id)->getAll();
return $out ? array_column($out, $field) : [];
}
/** Retrieves detailed information about the icon for a subscription.
*
*
* The returned information is:
*
*
* - "id": The umeric identifier of the icon (not the subscription)
* - "url": The URL of the icon
* - "type": The Content-Type of the icon e.g. "image/png"
* - "data": The icon itself, as a binary sring; if $withData is false this will be null
*
*
* @param string|null $user The user who owns the subscription being queried; using null here is supported for TT-RSS and SHOULD NOT be used elsewhere as it leaks information
* @param int $subscription The numeric identifier of the subscription
* @param bool $includeData Whether to include the binary data of the icon itself in the result
@ -1219,14 +1218,14 @@ class Database {
}
/** Lists icons for feeds to which a user is subscribed
*
*
* The returned information for each icon is:
*
*
* - "id": The umeric identifier of the icon
* - "url": The URL of the icon
* - "type": The Content-Type of the icon e.g. "image/png"
* - "data": The icon itself, as a binary sring
*
*
* @param string $user The user whose subscription icons are to be retrieved
*/
public function iconList(string $user): Db\Result {

2
lib/Db/PostgreSQL/PDOResult.php

@ -13,7 +13,7 @@ class PDOResult extends \JKingWeb\Arsse\Db\PDOResult {
public function valid() {
$this->cur = $this->set->fetch(\PDO::FETCH_ASSOC);
if ($this->cur !== false) {
foreach($this->cur as $k => $v) {
foreach ($this->cur as $k => $v) {
if (is_resource($v)) {
$this->cur[$k] = stream_get_contents($v);
fclose($v);

2
lib/Db/PostgreSQL/Result.php

@ -48,7 +48,7 @@ class Result extends \JKingWeb\Arsse\Db\AbstractResult {
public function valid() {
$this->cur = pg_fetch_row($this->r, null, \PGSQL_ASSOC);
if ($this->cur !== false) {
foreach($this->blobs as $f) {
foreach ($this->blobs as $f) {
if ($this->cur[$f]) {
$this->cur[$f] = hex2bin(substr($this->cur[$f], 2));
}

5
lib/REST/Miniflux/V1.php

@ -7,19 +7,14 @@ declare(strict_types=1);
namespace JKingWeb\Arsse\REST\Miniflux;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Service;
use JKingWeb\Arsse\Context\Context;
use JKingWeb\Arsse\Misc\ValueInfo;
use JKingWeb\Arsse\AbstractException;
use JKingWeb\Arsse\Db\ExceptionInput;
use JKingWeb\Arsse\Feed\Exception as FeedException;
use JKingWeb\Arsse\Misc\HTTP;
use JKingWeb\Arsse\REST\Exception;
use JKingWeb\Arsse\REST\Exception404;
use JKingWeb\Arsse\REST\Exception405;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Laminas\Diactoros\Response\JsonResponse as Response;
use Laminas\Diactoros\Response\EmptyResponse;
class V1 extends \JKingWeb\Arsse\REST\AbstractHandler {

1
lib/User.php

@ -69,7 +69,6 @@ class User {
}
return $out;
}
public function remove(string $user): bool {
try {

26
lib/User/Driver.php

@ -16,12 +16,12 @@ interface Driver {
public function auth(string $user, string $password): bool;
/** Adds a new user and returns their password
*
*
* When given no password the implementation may return null; the user
* manager will then generate a random password and try again with that
* password. Alternatively the implementation may generate its own
* password. Alternatively the implementation may generate its own
* password if desired
*
*
* @param string $user The username to create
* @param string|null $password The cleartext password to assign to the user, or null to generate a random password
*/
@ -34,45 +34,45 @@ interface Driver {
public function userList(): array;
/** Sets a user's password
*
*
* When given no password the implementation may return null; the user
* manager will then generate a random password and try again with that
* password. Alternatively the implementation may generate its own
* password. Alternatively the implementation may generate its own
* password if desired
*
*
* @param string $user The user for whom to change the password
* @param string|null $password The cleartext password to assign to the user, or null to generate a random password
* @param string|null $oldPassword The user's previous password, if known
*/
public function userPasswordSet(string $user, ?string $newPassword, string $oldPassword = null);
/** Removes a user's password; this makes authentication fail unconditionally
*
/** Removes a user's password; this makes authentication fail unconditionally
*
* @param string $user The user for whom to change the password
* @param string|null $oldPassword The user's previous password, if known
*/
public function userPasswordUnset(string $user, string $oldPassword = null): bool;
/** Retrieves metadata about a user
*
*
* Any expected keys not returned by the driver are taken from the internal
* database instead; the expected keys at this time are:
*
*
* - admin: A boolean denoting whether the user has administrator privileges
* - lang: A BCP 47 language tag e.g. "en", "hy-Latn-IT-arevela"
* - tz: A zoneinfo timezone e.g. "Asia/Jakarta", "America/Argentina/La_Rioja"
* - sort_asc: A boolean denoting whether the user prefers articles to be sorted oldest-first
*
*
* Any other keys will be ignored.
*/
public function userPropertiesGet(string $user): array;
/** Sets metadata about a user
*
*
* Output should be the same as the input, unless input is changed prior to storage
* (if it is, for instance, normalized in some way), which which case the changes
* should be reflected in the output.
*
*
* @param string $user The user for which to set metadata
* @param array $data The input data; see userPropertiesGet for keys
*/

4
tests/cases/Database/SeriesCleanup.php

@ -68,8 +68,8 @@ trait SeriesCleanup {
],
'arsse_icons' => [
'columns' => [
'id' => "int",
'url' => "str",
'id' => "int",
'url' => "str",
'orphaned' => "datetime",
],
'rows' => [

18
tests/cases/Database/SeriesUser.php

@ -104,12 +104,12 @@ trait SeriesUser {
$this->assertException("doesNotExist", "User", "ExceptionConflict");
Arsse::$db->userPasswordSet("john.doe@example.org", "secret");
}
/** @dataProvider provideMetaData */
public function testGetMetadata(string $user, array $exp): void {
$this->assertSame($exp, Arsse::$db->userPropertiesGet($user));
}
public function provideMetadata(): iterable {
return [
["admin@example.net", ['num' => 1, 'admin' => true, 'lang' => "en", 'tz' => "America/Toronto", 'sort_asc' => false]],
@ -122,12 +122,12 @@ trait SeriesUser {
$this->assertException("doesNotExist", "User", "ExceptionConflict");
Arsse::$db->userPropertiesGet("john.doe@example.org");
}
public function testSetMetadata(): void {
$in = [
'admin' => true,
'lang' => "en-ca",
'tz' => "Atlantic/Reykjavik",
'admin' => true,
'lang' => "en-ca",
'tz' => "Atlantic/Reykjavik",
'sort_asc' => true,
];
$this->assertTrue(Arsse::$db->userPropertiesSet("john.doe@example.com", $in));
@ -135,11 +135,11 @@ trait SeriesUser {
$state['arsse_users']['rows'][2] = ["john.doe@example.com", 3, 1, "en-ca", "Atlantic/Reykjavik", 1];
$this->compareExpectations(static::$drv, $state);
}
public function testSetNoMetadata(): void {
$in = [
'num' => 2112,
'blah' => "bloo"
'num' => 2112,
'blah' => "bloo",
];
$this->assertFalse(Arsse::$db->userPropertiesSet("john.doe@example.com", $in));
$state = $this->primeExpectations($this->data, ['arsse_users' => ['id', 'num', 'admin', 'lang', 'tz', 'sort_asc']]);

5
tests/cases/Db/BaseUpdate.php

@ -134,10 +134,11 @@ class BaseUpdate extends \JKingWeb\Arsse\Test\AbstractTest {
$this->drv->schemaUpdate(Database::SCHEMA_VERSION);
$this->assertTrue($this->drv->maintenance());
}
public function testUpdateTo7(): void {
$this->drv->schemaUpdate(6);
$this->drv->exec(<<<QUERY_TEXT
$this->drv->exec(
<<<QUERY_TEXT
INSERT INTO arsse_users values('a', 'xyz');
INSERT INTO arsse_users values('b', 'abc');
INSERT INTO arsse_folders(owner,name) values('a', '1');

8
tests/cases/User/TestInternal.php

@ -121,14 +121,14 @@ class TestInternal extends \JKingWeb\Arsse\Test\AbstractTest {
$this->assertException("doesNotExist", "User", "ExceptionConflict");
(new Driver)->userPasswordUnset("john.doe@example.com");
}
public function testGetUserProperties(): void {
\Phake::when(Arsse::$db)->userExists->thenReturn(true);
$this->assertSame([], (new Driver)->userPropertiesGet("john.doe@example.com"));
\Phake::verify(Arsse::$db)->userExists("john.doe@example.com");
\Phake::verifyNoFurtherInteraction(Arsse::$db);
}
public function testGetPropertiesForAMissingUser(): void {
\Phake::when(Arsse::$db)->userExists->thenReturn(false);
$this->assertException("doesNotExist", "User", "ExceptionConflict");
@ -139,7 +139,7 @@ class TestInternal extends \JKingWeb\Arsse\Test\AbstractTest {
\Phake::verifyNoFurtherInteraction(Arsse::$db);
}
}
public function testSetUserProperties(): void {
$in = ['admin' => true];
\Phake::when(Arsse::$db)->userExists->thenReturn(true);
@ -147,7 +147,7 @@ class TestInternal extends \JKingWeb\Arsse\Test\AbstractTest {
\Phake::verify(Arsse::$db)->userExists("john.doe@example.com");
\Phake::verifyNoFurtherInteraction(Arsse::$db);
}
public function testSetPropertiesForAMissingUser(): void {
\Phake::when(Arsse::$db)->userExists->thenReturn(false);
$this->assertException("doesNotExist", "User", "ExceptionConflict");

11
tests/cases/User/TestUser.php

@ -9,7 +9,6 @@ namespace JKingWeb\Arsse\TestCase\User;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Database;
use JKingWeb\Arsse\User;
use JKingWeb\Arsse\AbstractException as Exception;
use JKingWeb\Arsse\User\ExceptionConflict;
use JKingWeb\Arsse\User\ExceptionInput;
use JKingWeb\Arsse\User\Driver;
@ -25,7 +24,7 @@ class TestUser extends \JKingWeb\Arsse\Test\AbstractTest {
// create a mock user driver
$this->drv = \Phake::mock(Driver::class);
}
public function tearDown(): void {
\Phake::verifyNoOtherInteractions($this->drv);
\Phake::verifyNoOtherInteractions(Arsse::$db);
@ -159,7 +158,7 @@ class TestUser extends \JKingWeb\Arsse\Test\AbstractTest {
\Phake::verify($this->drv)->userAdd($user, $pass);
\Phake::verify(Arsse::$db)->userExists($user);
}
public function testRemoveAUser(): void {
$user = "john.doe@example.com";
$pass = "secret";
@ -171,7 +170,7 @@ class TestUser extends \JKingWeb\Arsse\Test\AbstractTest {
\Phake::verify(Arsse::$db)->userRemove($user);
\Phake::verify($this->drv)->userRemove($user);
}
public function testRemoveAUserWeDoNotKnow(): void {
$user = "john.doe@example.com";
$pass = "secret";
@ -182,7 +181,7 @@ class TestUser extends \JKingWeb\Arsse\Test\AbstractTest {
\Phake::verify(Arsse::$db)->userExists($user);
\Phake::verify($this->drv)->userRemove($user);
}
public function testRemoveAMissingUser(): void {
$user = "john.doe@example.com";
$pass = "secret";
@ -198,7 +197,7 @@ class TestUser extends \JKingWeb\Arsse\Test\AbstractTest {
\Phake::verify($this->drv)->userRemove($user);
}
}
public function testRemoveAMissingUserWeDoNotKnow(): void {
$user = "john.doe@example.com";
$pass = "secret";

2
tests/docroot/Icon/SVG1.php

@ -1,4 +1,4 @@
<?php return [
'mime' => "image/svg+xml",
'content' => '<svg xmlns="http://www.w3.org/2000/svg" width="900" height="600"><rect fill="#fff" height="600" width="900"/><circle fill="#bc002d" cx="450" cy="300" r="180"/></svg>'
'content' => '<svg xmlns="http://www.w3.org/2000/svg" width="900" height="600"><rect fill="#fff" height="600" width="900"/><circle fill="#bc002d" cx="450" cy="300" r="180"/></svg>',
];

2
tests/docroot/Icon/SVG2.php

@ -1,4 +1,4 @@
<?php return [
'mime' => "image/svg+xml",
'content' => '<svg xmlns="http://www.w3.org/2000/svg" width="900" height="600"><rect width="900" height="600" fill="#ED2939"/><rect width="600" height="600" fill="#fff"/><rect width="300" height="600" fill="#002395"/></svg>'
'content' => '<svg xmlns="http://www.w3.org/2000/svg" width="900" height="600"><rect width="900" height="600" fill="#ED2939"/><rect width="600" height="600" fill="#fff"/><rect width="300" height="600" fill="#002395"/></svg>',
];

Loading…
Cancel
Save