phpstan level 8 preparation

This commit is contained in:
Spine
2025-04-22 23:19:44 +00:00
parent 889766f032
commit 3e9b2bcb4f
37 changed files with 560 additions and 330 deletions

View File

@@ -30,42 +30,31 @@ class ReportAutoType extends \Gazelle\BaseManager {
/**
* $name must be a valid php class name (class does not have to exist)
*
* returns > 0 on success, null otherwise (including if the category already exists)
* returns > 0 on success
*/
public function createCategory(string $name): ?int {
public function createCategory(string $name): int {
return $this->pg()->scalar("
INSERT INTO report_auto_category (name) VALUES (?)
ON CONFLICT (name) DO NOTHING
RETURNING id_report_auto_category", // does not work for DO NOTHING
$name);
RETURNING id_report_auto_category
", $name);
}
/**
* returns newly created type, null on error or if type with name already exists
*/
public function create(string $name, string $description, string|null $category = null): ?\Gazelle\ReportAuto\Type {
public function create(string $name, string $description, string|null $category = null): \Gazelle\ReportAuto\Type {
if ($category) {
$catId = $this->findCategory($category);
if (!$catId) {
$catId = $this->createCategory($category);
if (!$catId) { // probably invalid name
return null;
}
}
} else {
$catId = null;
}
try {
return $this->findById($this->pg()->scalar("
INSERT INTO report_auto_type
(name, id_report_auto_category, description)
VALUES
(?, ?, ?)
RETURNING id_report_auto_type
", $name, $catId, $description));
} catch (\PDOException) {
return null;
}
return $this->findById($this->pg()->scalar("
INSERT INTO report_auto_type
(name, id_report_auto_category, description)
VALUES
(?, ?, ?)
RETURNING id_report_auto_type
", $name, $catId, $description));
}
protected function findCategory(string $name): ?int {

View File

@@ -48,7 +48,7 @@ class Helper {
return (new \Gazelle\Manager\Request())->create(
user: $user,
bounty: 100 * 1024 ** 3,
categoryId: (new \Gazelle\Manager\Category())->findIdByName('Music'),
categoryId: (int)(new \Gazelle\Manager\Category())->findIdByName('Music'),
year: (int)date('Y'),
title: $title,
image: $image,
@@ -69,7 +69,7 @@ class Helper {
string $name,
): \Gazelle\TGroup {
return (new \Gazelle\Manager\TGroup())->create(
categoryId: (new \Gazelle\Manager\Category())->findIdByName('E-Books'),
categoryId: (int)(new \Gazelle\Manager\Category())->findIdByName('E-Books'),
name: $name,
description: 'phpunit ebook description',
image: '',
@@ -88,7 +88,7 @@ class Helper {
int $releaseType = 1
): \Gazelle\TGroup {
$tgroup = (new \Gazelle\Manager\TGroup())->create(
categoryId: (new \Gazelle\Manager\Category())->findIdByName('Music'),
categoryId: (int)(new \Gazelle\Manager\Category())->findIdByName('Music'),
releaseType: $releaseType,
name: $name,
description: 'phpunit music description',

View File

@@ -58,7 +58,7 @@ class ArtistTest extends TestCase {
// If the following test fails locally:
// before test run: TRUNCATE TABLE artist_usage;
// after test run: (new Stats\Artists)->updateUsage();
$this->assertEquals($artist->id, $manager->findRandom()->id, 'artist-find-random');
$this->assertEquals($artist->id, $manager->findRandom()?->id, 'artist-find-random');
$this->assertNull($manager->findByIdAndRevision($artist->id, -666), 'artist-find-revision-fail');
$this->assertGreaterThan(0, $artist->id, 'artist-create-artist-id');
@@ -113,6 +113,7 @@ class ArtistTest extends TestCase {
$this->assertEquals('phpunit body test', $artistV1->body(), 'artist-body-rev-1');
$artistV2 = $manager->findByIdAndRevision($artist->id, $rev2);
$this->assertInstanceOf(Artist::class, $artistV2, 'artist-found-by-id-and-rev');
$this->assertEquals('https://example.com/artist-revised.jpg', $artistV2->image(), 'artist-image-rev-2');
$list = $artist->revisionList();
@@ -130,8 +131,8 @@ class ArtistTest extends TestCase {
$this->artistIdList[] = $artist->id;
$this->assertEquals($artist->id, $artist->id, 'artist-find-by-alias-id');
$this->assertEquals($artist->id, $manager->findByName($artist->name())->id, 'artist-find-by-alias-name');
$this->assertEquals($artist->aliasId(), $manager->findByName($artist->name())->aliasId(), 'artist-find-aliasid-by-alias-name');
$this->assertEquals($artist->id, $manager->findByName($artist->name())?->id, 'artist-find-by-alias-name');
$this->assertEquals($artist->aliasId(), $manager->findByName($artist->name())?->aliasId(), 'artist-find-aliasid-by-alias-name');
$this->assertEquals(1, $manager->aliasUseTotal($artist->aliasId()), 'artist-sole-alias');
$this->assertCount(0, $manager->tgroupList($artist->aliasId(), new Manager\TGroup()), 'artist-no-tgroup');
@@ -140,9 +141,9 @@ class ArtistTest extends TestCase {
$this->assertEquals($artist->aliasId() + 1, $newId, 'artist-new-alias');
$this->assertEquals(2, $manager->aliasUseTotal($artist->aliasId()), 'artist-two-alias');
$artist = $manager->findByName($aliasName);
$this->assertEquals($artist->id, $artist->id, 'artist-fetch-artist-id');
$this->assertEquals($newId, $artist->aliasId(), 'artist-fetch-alias-id');
$alias = $manager->findByName($aliasName);
$this->assertEquals($artist->id, $alias?->id, 'artist-fetch-artist-id');
$this->assertEquals($newId, $alias?->aliasId(), 'artist-fetch-alias-id');
$this->assertEquals(1, $artist->removeAlias($newId), 'artist-remove-alias');
}
@@ -227,7 +228,7 @@ class ArtistTest extends TestCase {
// FIXME: flushed collage objects cannot be refreshed
$merged = $collMan->findById($this->collage->id);
$this->assertEquals([$new->id], $merged->entryList(), 'art-merge-collage');
$this->assertEquals([$new->id], $merged?->entryList(), 'art-merge-collage');
$comment = new Comment\Artist($new->id, 1, 0);
$comment->load(); // FIXME: load() should not be necessary
@@ -305,7 +306,7 @@ class ArtistTest extends TestCase {
$request = $requestMan->create(
user: $this->user,
bounty: 100 * 1024 ** 2,
categoryId: (new Manager\Category())->findIdByName('Music'),
categoryId: (int)(new Manager\Category())->findIdByName('Music'),
year: (int)date('Y'),
title: 'phpunit smart rename ' . randomString(6),
image: '',
@@ -320,6 +321,11 @@ class ArtistTest extends TestCase {
checksum: true,
oclc: '',
);
$this->assertInstanceOf(
ArtistRole\Request::class,
$request->artistRole(),
'request-rename-has-artistrole'
);
$request->artistRole()->set(
[ARTIST_MAIN => [$artist->name()]],
$this->user,
@@ -352,6 +358,11 @@ class ArtistTest extends TestCase {
$this->assertEquals($post->id, $threadList[0]['postId'], 'artist-renamed-comments');
$request->flush();
$this->assertInstanceOf(
ArtistRole\Request::class,
$request->artistRole(),
'request-has-artistrole'
);
$idList = $request->artistRole()->idList();
$this->assertEquals($artist->id, $idList[ARTIST_MAIN][0]['id'], 'artist-renamed-request');
$request->remove();

View File

@@ -38,7 +38,7 @@ class BaseObjectTest extends TestCase {
$date = $object->banDate();
$this->assertTrue($object->setFieldNow('BanDate')->modify(), 'base-object-aux-now');
$this->assertNotEquals($date, $object->banDate(), 'base-object-aux-remodified');
$this->assertTrue(Helper::recentDate($object->banDate()), 'base-object-aux-recent');
$this->assertTrue(Helper::recentDate((string)$object->banDate()), 'base-object-aux-recent');
}
public function testObjectGenerator(): void {

View File

@@ -47,6 +47,7 @@ class BonusTest extends TestCase {
$itemList = (new Manager\Bonus())->itemList();
$this->assertArrayHasKey('token-1', $itemList, 'item-token-1');
$token = $giver->item('token-1');
$this->assertArrayHasKey('Price', $token, 'item-price-1');
$price = $token['Price'];
$this->assertEquals($price, $giver->effectivePrice('token-1'), 'item-price-token-1');

View File

@@ -41,14 +41,14 @@ class CategoryTest extends TestCase {
['description' => 'Abridged version'],
]
);
$idList = array_map(fn($t) => $t->id(), $torrentList);
$idList = array_map(fn($t) => $t->id, $torrentList);
// move one torrent to new category
$artistName = 'new artist ' . randomString(6);
$new = $tgMan->changeCategory(
old: $tgroup,
torrent: $torrentList[1],
categoryId: (new Manager\Category())->findIdByName('Music'),
categoryId: (int)(new Manager\Category())->findIdByName('Music'),
name: 'phpunit category new ' . randomString(6),
year: (int)date('Y'),
artistName: $artistName,
@@ -59,24 +59,28 @@ class CategoryTest extends TestCase {
$this->assertInstanceOf(TGroup::class, $new, 'cat-change-to-music');
$this->assertTrue($new->hasArtistRole(), 'tgroup-cat-is-music');
$artist = (new Manager\Artist())->findByName($artistName);
$this->assertEquals($artistName, $artist->name(), 'cat-new-artist');
$this->assertInstanceOf(Artist::class, $artist, 'cat-new-artist-found');
$this->assertEquals(
[
ARTIST_MAIN => [
['id' => $artist->id(), 'name' => $artist->name(), 'aliasid' => $artist->aliasId()],
],
ARTIST_MAIN => [[
'id' => $artist->id,
'name' => $artist->name(),
'aliasid' => $artist->aliasId()
]],
],
$new->artistRole()->idList(),
$new->artistRole()?->idList(),
'cat-new-artist-role'
);
$tgroup->flush();
// rebuild the torrent object caches
$torrentList = array_map(fn($id) => $torMan->findById($id), $idList);
$torrentList = array_map(fn ($id) => $torMan->findById($id), $idList);
$this->assertInstanceOf(Torrent::class, $torrentList[0], 'cat-old-t0-found');
$this->assertInstanceOf(Torrent::class, $torrentList[1], 'cat-old-t1-found');
$this->assertEquals([$torrentList[0]->id()], $tgroup->torrentIdList(), 'cat-old-tidlist');
$this->assertEquals($torrentList[1]->groupId(), $new->id(), 'cat-new-groupid');
$this->assertEquals([$torrentList[0]->id], $tgroup->torrentIdList(), 'cat-old-tidlist');
$this->assertEquals($torrentList[1]->groupId(), $new->id, 'cat-new-groupid');
// move remaining torrent to same category
$new = $tgMan->changeCategory(
@@ -93,11 +97,11 @@ class CategoryTest extends TestCase {
$this->assertNull($new, 'cat-change-to-same');
// move last torrent to new category, nuking old group
$tgroupId = $tgroup->id();
$tgroupId = $tgroup->id;
$new = $tgMan->changeCategory(
old: $tgroup,
torrent: $torrentList[0],
categoryId: (new Manager\Category())->findIdByName('Comedy'),
categoryId: (int)(new Manager\Category())->findIdByName('Comedy'),
name: 'phpunit category new ' . randomString(6),
year: (int)date('Y'),
artistName: null,
@@ -112,7 +116,7 @@ class CategoryTest extends TestCase {
// clean up
foreach ($torrentList as $torrent) {
$torrent->removeTorrent($user, 'phpunit');
$torrent?->removeTorrent($user, 'phpunit');
}
$tgroup->remove();
$this->assertEquals(0, (int)DB::DB()->scalar("

View File

@@ -145,14 +145,14 @@ class CollageTest extends TestCase {
$this->assertEquals($total + 1, $stats->collageTotal(), 'collage-stats-total');
$this->assertEquals($total + 2, $stats->increment(), 'collage-stats-increment');
$this->assertEquals($collage->id(), $manager->findById($collage->id())?->id(), 'collage-find-by-id');
$this->assertEquals($collage->id, $manager->findById($collage->id)?->id, 'collage-find-by-id');
$this->assertEquals(0, $collage->maxGroups(), 'collage-max-group');
$this->assertEquals(0, $collage->maxGroupsPerUser(), 'collage-max-per-user');
$this->assertEquals(0, $collage->numEntries(), 'collage-num-subcribers');
$this->assertEquals(1, $collage->categoryId(), 'collage-id');
$this->assertEquals($description, $collage->description(), 'collage-description');
$this->assertEquals($name, $collage->name(), 'collage-name');
$this->assertEquals($this->userList['u1']->id(), $collage->ownerId(), 'collage-owner-id');
$this->assertEquals($this->userList['u1']->id, $collage->ownerId(), 'collage-owner-id');
$this->assertEquals($tagList, $collage->tags(), 'collage-tag-list');
$this->assertFalse($collage->sortNewest(), 'collage-sort-initial');
$this->assertFalse($collage->isArtist(), 'collage-is-not-artist');
@@ -170,7 +170,7 @@ class CollageTest extends TestCase {
);
$find = $manager->findByName($name);
$this->assertEquals($collage->id(), $find->id(), 'collage-find-by-name');
$this->assertEquals($collage->id, $find?->id, 'collage-find-by-name');
$this->userList['u1']->addCustomPrivilege('site_collages_manage');
}
@@ -267,14 +267,16 @@ class CollageTest extends TestCase {
$default = $manager->addToArtistCollageDefault($artistList[1], $this->userList['u1']);
$this->assertCount(1, $default, 'collage-default-add-acollage-added');
$this->assertEquals($this->collageList[2]->id(), $default[0]->id(), 'collage-default-artist-suggestion');
$this->assertEquals($this->collageList[2]->id, $default[0]->id, 'collage-default-artist-suggestion');
$this->assertEquals(1, $this->collageList[1]->toggleSubscription($this->userList['u1']), 'collage-artist-subscribe');
$this->collageList[1]->addEntry($artistList[2], $this->userList['u2']);
$this->collageList[1]->addEntry($artistList[3], $this->userList['u3']);
$this->assertEquals(3, $this->collageList[1]->numContributors(), 'collage-artist-contributor');
$summary = $manager->artistSummary($artistMan->findByName($this->artistName[2]));
$artist = $artistMan->findByName($this->artistName[2]);
$this->assertInstanceOf(Artist::class, $artist, 'collage-artist-found');
$summary = $manager->artistSummary($artist);
$this->assertEquals(2, $summary['total'], 'collage-artist-summary-total');
$this->assertCount(2, $summary['above'], 'collage-artist-summary-above');
$this->assertCount(0, $summary['below'], 'collage-artist-summary-below');
@@ -320,7 +322,7 @@ class CollageTest extends TestCase {
$collage->addEntry($this->tgroupList[0], $u1);
$default = $manager->addToCollageDefault($this->tgroupList[1], $u1);
$this->assertCount(1, $default, 'collage-default-add-tcollage-added');
$this->assertEquals($collage->id(), $default[0]->id(), 'collage-default-suggestion');
$this->assertEquals($collage->id, $default[0]->id, 'collage-default-suggestion');
$this->assertInstanceOf(
Manager\Collage::class,
$manager->flushDefaultGroup($u1),
@@ -335,8 +337,8 @@ class CollageTest extends TestCase {
$this->assertEquals(2, $collage->numContributors(), 'collage-two-contributors');
$this->assertEquals(
[
$this->userList['u1']->id() => 1,
$this->userList['u3']->id() => 3,
$this->userList['u1']->id => 1,
$this->userList['u3']->id => 3,
],
$collage->contributors(),
'collage-contributor-list'
@@ -345,9 +347,9 @@ class CollageTest extends TestCase {
$this->assertFalse($collage->userHasContributed($u2), 'collage-user-2-no-contrib');
$this->assertTrue($collage->userHasContributed($u3), 'collage-user-3-has-contrib');
$this->assertEquals(3, $collage->contributionTotal($u3), 'collage-contributor-three');
$this->assertEquals($u1->id(), $collage->entryUserId($this->tgroupList[0]), 'collage-contribution-by');
$this->assertEquals($u1->id, $collage->entryUserId($this->tgroupList[0]), 'collage-contribution-by');
$idList = array_map(fn($n) => $this->tgroupList[$n]->id(), range(0, 3));
$idList = array_map(fn($n) => $this->tgroupList[$n]->id, range(0, 3));
$this->assertEquals([$idList[0], $idList[1], $idList[2], $idList[3]], $collage->entryList(), 'collage-entry-list');
$this->assertEquals(1, $collage->updateSequenceEntry($this->tgroupList[2], 1000), 'collage-entry-to-last');
@@ -365,7 +367,7 @@ class CollageTest extends TestCase {
'collage-manager-image-proxy'
);
$cover = $manager->tgroupCover($this->tgroupList[0]);
$this->assertStringContainsString("image_group_{$this->tgroupList[0]->id()}", $cover, 'collage-tgroup-cover-id');
$this->assertStringContainsString("image_group_{$this->tgroupList[0]->id}", $cover, 'collage-tgroup-cover-id');
$this->assertStringContainsString($this->tgroupList[0]->name(), $cover, 'collage-tgroup-cover-name');
$this->assertEquals(1, $collage->removeEntry($this->tgroupList[1]), 'collage-remove-entry');
@@ -412,15 +414,15 @@ class CollageTest extends TestCase {
];
$personal = $manager->findPersonalByUser($user);
$this->assertEquals(
array_map(fn($c) => $c->id(), [$this->collageList[0], $this->collageList[1], $this->collageList[2], $this->collageList[3]]),
array_map(fn($c) => $c->id(), $personal),
array_map(fn($c) => $c->id, [$this->collageList[0], $this->collageList[1], $this->collageList[2], $this->collageList[3]]),
array_map(fn($c) => $c->id, $personal),
'collage-personal-list'
);
$this->assertTrue($personal[2]->setFeatured()->modify(), 'collage-set-featured');
$personal = $manager->findPersonalByUser($user);
$this->assertEquals(
array_map(fn($c) => $c->id(), [$this->collageList[2], $this->collageList[0], $this->collageList[1], $this->collageList[3]]),
array_map(fn($c) => $c->id(), $personal),
array_map(fn($c) => $c->id, [$this->collageList[2], $this->collageList[0], $this->collageList[1], $this->collageList[3]]),
array_map(fn($c) => $c->id, $personal),
'collage-personal-list-featured'
);
@@ -445,7 +447,7 @@ class CollageTest extends TestCase {
foreach (range(0, 3) as $n) {
$collage->addEntry($this->tgroupList[$n], $this->userList['u3']);
}
$this->assertTrue((new User\Bookmark($this->userList['u1']))->create('collage', $collage->id()), 'collage-bookmark');
$this->assertTrue((new User\Bookmark($this->userList['u1']))->create('collage', $collage->id), 'collage-bookmark');
$payload = (new Json\Collage(
$collage,
@@ -454,7 +456,7 @@ class CollageTest extends TestCase {
new Manager\TGroup(),
new Manager\Torrent(),
))->payload();
$this->assertEquals($collage->id(), $payload['id'], 'collage-json-id');
$this->assertEquals($collage->id, $payload['id'], 'collage-json-id');
$this->assertEquals('Staff picks', $payload['collageCategoryName'], 'collage-json-cat-name');
$this->assertCount(4, $payload['torrentGroupIDList'], 'collage-json-entry-count');
$this->assertTrue($payload['hasBookmarked'], 'collage-json-bookmarked');
@@ -564,9 +566,9 @@ class CollageTest extends TestCase {
$collage->addEntry($this->tgroupList[3], $this->userList['u3']);
$this->assertEquals(
[
$this->tgroupList[3]->id(),
$this->tgroupList[1]->id(),
$this->tgroupList[0]->id(),
$this->tgroupList[3]->id,
$this->tgroupList[1]->id,
$this->tgroupList[0]->id,
],
$collage->entryList(),
'collage-personal-newest-first'
@@ -578,10 +580,10 @@ class CollageTest extends TestCase {
$collage->addEntry($this->tgroupList[2], $this->userList['u2']);
$this->assertEquals(
[
$this->tgroupList[3]->id(),
$this->tgroupList[1]->id(),
$this->tgroupList[0]->id(),
$this->tgroupList[2]->id(),
$this->tgroupList[3]->id,
$this->tgroupList[1]->id,
$this->tgroupList[0]->id,
$this->tgroupList[2]->id,
],
$collage->entryList(),
'collage-personal-newest-last'
@@ -591,11 +593,11 @@ class CollageTest extends TestCase {
$collage->addEntry($this->tgroupList[4], $this->userList['u2']);
$this->assertEquals(
[
$this->tgroupList[4]->id(),
$this->tgroupList[3]->id(),
$this->tgroupList[1]->id(),
$this->tgroupList[0]->id(),
$this->tgroupList[2]->id(),
$this->tgroupList[4]->id,
$this->tgroupList[3]->id,
$this->tgroupList[1]->id,
$this->tgroupList[0]->id,
$this->tgroupList[2]->id,
],
$collage->entryList(),
'collage-personal-newest-not-last'
@@ -629,7 +631,7 @@ class CollageTest extends TestCase {
$this->assertInstanceOf(Collage::class, $manager->recoverByName($name), 'collage-recover-by-name');
$collage->remove();
$this->assertInstanceOf(Collage::class, $manager->recoverById($collage->id()), 'collage-recover-by-id');
$this->assertInstanceOf(Collage::class, $manager->recoverById($collage->id), 'collage-recover-by-id');
}
public function testCollageAjaxAdd(): void {
@@ -716,7 +718,7 @@ class CollageTest extends TestCase {
$this->assertCount(1, $list, 'collage-user-sub-list-total');
$entry = current($list);
$this->assertEquals(
$collage->id(),
$collage->id,
$entry['collageId'],
'collage-user-entry-collageid',
);
@@ -730,13 +732,13 @@ class CollageTest extends TestCase {
'collage-user-entry-last-visit',
);
$this->assertEquals(
[$this->tgroupList[0]->id()],
[$this->tgroupList[0]->id],
$entry['groupIds'],
'collage-user-group-id',
);
$this->assertEquals(
$this->tgroupList[0]->id(),
$entry['tgroup_list'][0]->id(),
$this->tgroupList[0]->id,
$entry['tgroup_list'][0]->id,
'collage-user-tgroup-list-id',
);

View File

@@ -39,18 +39,18 @@ class CommentTest extends TestCase {
$artMan = new Manager\Artist();
$this->artist = $artMan->create('phpunit.' . randomString(12));
$comment = $manager->create($this->user, 'artist', $this->artist->id(), 'phpunit comment ' . randomString(10));
$comment = $manager->create($this->user, 'artist', $this->artist->id, 'phpunit comment ' . randomString(10));
$this->assertInstanceOf(Comment\Artist::class, $comment, 'comment-artist-create');
$this->assertEquals('artist', $comment->page(), 'comment-artist-page');
$this->assertEquals(
"<a href=\"artist.php?id={$this->artist->id()}&amp;postid={$comment->id()}#post{$comment->id()}\">Comment #{$comment->id()}</a>",
"<a href=\"artist.php?id={$this->artist->id}&amp;postid={$comment->id}#post{$comment->id}\">Comment #{$comment->id}</a>",
$comment->link(),
'comment-artist-link'
);
$this->assertEquals(0, $comment->lastRead(), 'comment-artist-last-read');
$this->assertEquals(0, $comment->pageNum(), 'comment-artist-page-num');
$reply = $manager->create($this->user, 'artist', $this->artist->id(), 'phpunit reply ' . randomString(10));
$reply = $manager->create($this->user, 'artist', $this->artist->id, 'phpunit reply ' . randomString(10));
$this->assertInstanceOf(Comment\Artist::class, $comment->load(), 'comment-artist-load');
$thread = $comment->thread();
$this->assertCount(2, $thread, 'comment-artist-thread');
@@ -61,7 +61,7 @@ class CommentTest extends TestCase {
$this->assertInstanceOf(
Comment\Artist::class,
$manager->findById($comment->id()),
$manager->findById($comment->id),
'comment-artist-find-by-id'
);
}
@@ -77,23 +77,23 @@ class CommentTest extends TestCase {
$manager = new Manager\Comment();
$body = 'phpunit comment ' . randomString(10);
$comment = $manager->create($this->user, 'collages', $this->collage->id(), $body);
$this->assertEquals($body, $manager->findBodyById($comment->id()), 'comment-find-body');
$comment = $manager->create($this->user, 'collages', $this->collage->id, $body);
$this->assertEquals($body, $manager->findBodyById($comment->id), 'comment-find-body');
$this->assertInstanceOf(Comment\Collage::class, $comment, 'comment-collage-create');
$this->assertEquals('collages', $comment->page(), 'comment-collage-page');
$this->assertEquals(
"<a href=\"collages.php?action=comments&amp;collageid={$this->collage->id()}&amp;postid={$comment->id()}#post{$comment->id()}\">Comment #{$comment->id()}</a>",
"<a href=\"collages.php?action=comments&amp;collageid={$this->collage->id}&amp;postid={$comment->id}#post{$comment->id}\">Comment #{$comment->id}</a>",
$comment->link(),
'comment-collage-link'
);
$this->assertEquals(1, $manager->remove($comment->page(), $this->collage->id()), 'comment-collage-remove-all');
$this->assertEquals(1, $manager->remove($comment->page(), $this->collage->id), 'comment-collage-remove-all');
}
public function testCommentRequest(): void {
$this->request = (new Manager\Request())->create(
user: $this->user,
bounty: REQUEST_MIN * 1024 * 1024,
categoryId: (new Manager\Category())->findIdByName('Music'),
categoryId: (int)(new Manager\Category())->findIdByName('Music'),
year: (int)date('Y'),
title: 'phpunit request comment',
image: '',
@@ -110,11 +110,11 @@ class CommentTest extends TestCase {
);
$manager = new Manager\Comment();
$comment = $manager->create($this->user, 'requests', $this->request->id(), 'phpunit comment ' . randomString(10));
$comment = $manager->create($this->user, 'requests', $this->request->id, 'phpunit comment ' . randomString(10));
$this->assertInstanceOf(Comment\Request::class, $comment, 'comment-request-create');
$this->assertEquals('requests', $comment->page(), 'comment-request-page');
$this->assertEquals(
"<a href=\"requests.php?action=view&amp;id={$this->request->id()}&amp;postid={$comment->id()}#post{$comment->id()}\">Comment #{$comment->id()}</a>",
"<a href=\"requests.php?action=view&amp;id={$this->request->id}&amp;postid={$comment->id}#post{$comment->id}\">Comment #{$comment->id}</a>",
$comment->link(),
'comment-request-link'
);
@@ -146,11 +146,11 @@ class CommentTest extends TestCase {
->modify(),
'comment-torrent-edit'
);
$this->assertCount(1, $manager->loadEdits($comment->page(), $comment->id()), 'comment-torrent-load-edits');
$this->assertCount(1, $manager->loadEdits($comment->page(), $comment->id), 'comment-torrent-load-edits');
$this->assertInstanceOf(
Comment\Torrent::class,
$manager->findById($comment->id()),
$manager->findById($comment->id),
'comment-torrent-find-by-id'
);
$this->assertEquals(1, $manager->remove($comment->page(), $tgroupId), 'comment-torrent-remove-all');
@@ -162,10 +162,10 @@ class CommentTest extends TestCase {
$this->artist = $artMan->create('phpunit.' . randomString(12));
$artistExtra = $artMan->create('phpunit.' . randomString(12));
$comment = $manager->create($this->user, 'artist', $this->artist->id(), 'phpunit-merge-keep-artist');
$manager->create($this->user, 'artist', $artistExtra->id(), 'phpunit-merge-comment');
$comment = $manager->create($this->user, 'artist', $this->artist->id, 'phpunit-merge-keep-artist');
$manager->create($this->user, 'artist', $artistExtra->id, 'phpunit-merge-comment');
$manager->merge('artist', $artistExtra->id(), $this->artist->id());
$manager->merge('artist', $artistExtra->id, $this->artist->id);
$this->assertInstanceOf(Comment\Artist::class, $comment->load(), 'comment-merge-load');
$this->assertCount(2, $comment->thread(), 'comment-artist-merged-thread');
$artistExtra->remove();

View File

@@ -48,6 +48,7 @@ class ContestTest extends TestCase {
public function test00ContestBasic(): void {
$manager = new Manager\Contest();
$contestTypes = $manager->contestTypes();
$this->assertIsArray($contestTypes, 'conteest-manager-array-of-types');
$this->assertCount(4, array_keys($contestTypes), 'contest-manager-types');
// these may be a bit fragile, time will tell
$this->assertEquals(1, $contestTypes[1]['id'], 'contest-type-id');
@@ -80,7 +81,11 @@ class ContestTest extends TestCase {
$this->assertEquals(0, $this->contest->totalEntries(), 'contest-no-entries-yet');
$this->assertNull($this->contest->rank($this->userList[0]), 'contest-no-rank-yet');
$this->assertEquals('none', $this->contest->bonusStatus(), 'contest-status-no-bonus-pool');
$this->assertEquals($this->contest->id, $manager->findById($this->contest->id)->id, 'contest-find-by-id');
$this->assertEquals(
$this->contest->id,
$manager->findById($this->contest->id)?->id,
'contest-find-by-id',
);
$this->assertEquals(1, $this->contest->remove(), 'contest-remove');
unset($this->contest);
@@ -221,6 +226,11 @@ class ContestTest extends TestCase {
$donorBonus = new User\Bonus($donor);
$points = 100000;
$donorBonus->setPoints($points);
$this->assertInstanceOf(
BonusPool::class,
$this->contest->bonusPool(),
'ct-up-flac-bonus-pool'
);
$this->assertTrue(
$donorBonus->donate($this->contest->bonusPool(), $points),
'ct-up-flac-pool-donate',
@@ -385,6 +395,11 @@ class ContestTest extends TestCase {
// payout
$donorBonus = new User\Bonus($this->userList[0]);
$donorBonus->setPoints(1000);
$this->assertInstanceOf(
BonusPool::class,
$this->contest->bonusPool(),
'ct-reqfill-bonus-pool'
);
$donorBonus->donate($this->contest->bonusPool(), 1000);
$this->contest->paymentReady();
$this->assertGreaterThanOrEqual(
@@ -465,6 +480,11 @@ class ContestTest extends TestCase {
// payout
$donorBonus = new User\Bonus($this->userList[1]);
$donorBonus->setPoints(1000);
$this->assertInstanceOf(
BonusPool::class,
$this->contest->bonusPool(),
'ct-up-nosng;-bonus-pool'
);
$donorBonus->donate($this->contest->bonusPool(), 1000);
$this->contest->paymentReady();
$this->assertGreaterThanOrEqual(
@@ -544,6 +564,11 @@ class ContestTest extends TestCase {
$donorBonus = new User\Bonus($this->userList[0]);
$donorBonus->setPoints(1000);
$this->assertInstanceOf(
BonusPool::class,
$this->contest->bonusPool(),
'ct-perfect-bonus-pool'
);
$donorBonus->donate($this->contest->bonusPool(), 1000);
$this->contest->paymentReady();
$this->assertGreaterThanOrEqual(

View File

@@ -17,6 +17,7 @@ class CounterTest extends TestCase {
$this->assertEquals(1, $counter->value(), 'counter-final-increment');
$clone = $manager->find($counter->name());
$this->assertInstanceOf(Counter::class, $clone, 'counter-found');
$this->assertEquals($name, $clone->name(), 'counter-find');
$this->assertEquals(2, $clone->increment(), 'counter-clone-increment');

View File

@@ -39,7 +39,7 @@ class DebugTest extends TestCase {
$this->assertEquals(["a", "b"], $case->trace(), 'errorlog-trace');
$this->assertEquals(
$case->id,
$manager->findByDigest("a\nb", [])->id,
$manager->findByDigest("a\nb", [])?->id,
'errorlog-find-by-digest',
);

View File

@@ -62,7 +62,10 @@ class DownloadTest extends TestCase {
// torrent snatch list is handled in another test
$ratelimit = new User\UserclassRateLimit($this->userList['down']);
$this->assertFalse(is_nan($ratelimit->userclassFactor()), 'download-ratelimit-userclass-factor');
$this->assertFalse(
is_nan($ratelimit->userclassFactor()),
'download-ratelimit-userclass-factor',
);
$this->assertTrue(is_nan($ratelimit->userFactor()), 'download-ratelimit-user-factor');
$this->assertFalse($ratelimit->hasExceededFactor(), 'download-ratelimit-factor');
$this->assertFalse($ratelimit->hasExceededTotal(), 'download-ratelimit-total');

View File

@@ -64,6 +64,7 @@ class ForumTest extends TestCase {
$this->assertCount($initial + 2, $fcatMan->usageList(), 'forum-cat-usage-list');
$find = $fcatMan->findById($this->category->id);
$this->assertInstanceOf(ForumCategory::class, $find, 'forum-category-found');
$find->setField('Name', 'phpunit renamed')->modify();
$this->assertEquals($this->category->id, $find->id, 'forum-cat-find');
$this->assertEquals('phpunit renamed', $find->name(), 'forum-cat-name');
@@ -116,7 +117,7 @@ class ForumTest extends TestCase {
$this->assertNull($this->forum->lastThreadName(), 'forum-last-thread-name');
$find = $forumMan->findById($this->forum->id);
$this->assertEquals($this->forum->id, $find->id, 'forum-forum-find');
$this->assertEquals($this->forum->id, $find?->id, 'forum-forum-find');
$this->extra = Helper::makeForum(
user: $this->userList['admin'],
@@ -250,7 +251,7 @@ class ForumTest extends TestCase {
(new Manager\Subscription())->flushThread($thread);
$this->assertEquals(
$thread->id,
$threadMan->findByPostId($reply->id)->id,
$threadMan->findByPostId($reply->id)?->id,
'fpost-find-thread',
);
@@ -264,7 +265,11 @@ class ForumTest extends TestCase {
$page = $quote->page(10, 0);
$this->assertCount(1, $page, 'fpost-quote-page-count');
$this->assertEquals($admin->id, $page[0]['quoter_id'], 'fpost-quote-page-0-quoter');
$this->assertEquals($postMan->findById($reply->id)->url(), $page[0]['jump'], 'fpost-quote-page-0-jump');
$this->assertEquals(
$postMan->findById($reply->id)?->url(),
$page[0]['jump'],
'fpost-quote-page-0-jump',
);
$this->assertEquals(1, $quote->clearThread($thread, $post->id, $reply->id), 'fpost-clear-thread');
$this->assertEquals(0, $quote->total(), 'fpost-quote-admin-total-clear');
@@ -502,7 +507,7 @@ class ForumTest extends TestCase {
$this->assertEquals($answer[1], $poll->vote()[1]['answer'], 'forum-poll-vote-1');
$find = $pollMan->findById($poll->id);
$this->assertEquals($poll->id, $find->id, 'forum-poll-find-by-id');
$this->assertEquals($poll->id, $find?->id, 'forum-poll-find-by-id');
$this->assertEquals(1, $poll->addAnswer('sushi'), 'forum-poll-add-answer');
@@ -593,13 +598,18 @@ class ForumTest extends TestCase {
$this->assertEquals(1, $thread->postTotalSummary(), 'fthread-post-total-summary');
$slice = $thread->slice(1, 1);
$post = (new Manager\ForumPost())->findById($slice[0]['ID']);
$this->assertInstanceOf(ForumPost::class, $post, 'thread-initial-found');
$this->assertEquals($thread->body(), $post->body(), 'thread-initial-body');
$post->setField('Body', 'edit')->modify();
// flush thread object to pick up out-of-band modification
$this->assertEquals('edit', $thread->flush()->body(), 'thread-edit-body');
$this->assertEquals($post->created(), $thread->lastPostTime(), 'thread-last-post-date');
$this->assertEquals(1, $thread->mergePost($post, $user, 'merge this'), 'thread-merge-post');
$this->assertEquals(
1,
$thread->mergePost($post, $user, 'merge this'),
'thread-merge-post'
);
$newBody = "edit\n\nmerge this";
$this->assertEquals($newBody, $post->body());
$this->assertEquals(1, $thread->postTotalSummary(), 'fthread-merge-post-total-summary');
@@ -607,7 +617,7 @@ class ForumTest extends TestCase {
$slice = $thread->slice(1, 1);
$this->assertEquals($newBody, $slice[0]['Body'], 'thread-merge-post-slice');
$merged = (new Manager\ForumPost())->findById($slice[0]['ID']);
$this->assertEquals($newBody, $merged->body(), 'thread-merged-body');
$this->assertEquals($newBody, $merged?->body(), 'thread-merged-body');
$post = $thread->addPost($user, 'second');
$this->assertEquals(2, $thread->postTotalSummary(), 'fthread-merge-post-add-summary');

View File

@@ -117,6 +117,7 @@ class InboxTest extends TestCase {
$postList = $rlist[2]->postList(2, 0);
$postId = $postList[0]['id'];
$pm = $pmReceiverManager->findByPostId($postId);
$this->assertInstanceOf(PM::class, $pm, 'inbox-pm-found');
$this->assertEquals($bodyList[1], $pm->postBody($postId), 'inbox-pm-post-body');
// unread first
@@ -193,7 +194,7 @@ class InboxTest extends TestCase {
Helper::makeUser('inbox.recv.' . randomString(6), 'inbox'),
];
$pm = $this->userList[0]->inbox()->createSystem('system', 'body');
$this->assertEquals(0, $pm->senderId(), 'inbox-system-sender-id');
$this->assertEquals(1, $pm->remove(), 'inbox-system-remove');
$this->assertEquals(0, $pm?->senderId(), 'inbox-system-sender-id');
$this->assertEquals(1, $pm?->remove(), 'inbox-system-remove');
}
}

View File

@@ -66,13 +66,13 @@ class InviteTest extends TestCase {
$this->assertTrue($manager->inviteExists($invite->key()), 'invite-key-found');
$this->invitee = Helper::makeUserByInvite('invitee.' . randomString(6), $invite->key());
$this->assertInstanceOf(User::class, $this->invitee, 'invitee-class');
$this->assertEquals($this->user->id, $this->invitee->inviter()->id(), 'invitee-invited-by');
$this->assertEquals($this->user->id, $this->invitee->inviter()?->id, 'invitee-invited-by');
$this->assertEquals($this->user->id, $this->invitee->inviterId(), 'invitee-invited-id');
$this->assertEquals(1, $this->user->stats()->invitedTotal(), 'invite-total-1');
$this->assertEquals(0, $this->user->flush()->invite()->pendingTotal(), 'invite-pending-back-to-0');
$inviteList = $this->user->invite()->page('um.ID', 'ASC', 1, 0);
$this->assertCount(1, $inviteList, 'invite-invite-list-total');
$this->assertEquals($this->invitee->id(), $inviteList[0], 'invite-list-has-invitee');
$this->assertEquals($this->invitee->id, $inviteList[0], 'invite-list-has-invitee');
$this->assertTrue($this->invitee->isUnconfirmed(), 'invitee-unconfirmed');
$this->assertInstanceOf(
@@ -87,7 +87,7 @@ class InviteTest extends TestCase {
$this->assertTrue($inviteTree->hasInvitees(), 'invite-tree-has-invitees');
$list = $inviteTree->inviteeList();
$this->assertCount(1, $list, 'invite-tree-list');
$this->assertEquals($this->invitee->id(), $list[0], 'invite-tree-user-id');
$this->assertEquals($this->invitee->id, $list[0], 'invite-tree-user-id');
// new invite tree functionality
$summary = $inviteTree->summary();
@@ -119,6 +119,7 @@ class InviteTest extends TestCase {
reason: '',
source: '',
);
$this->assertInstanceOf(Invite::class, $invite, 'invite-ancestor-found');
$this->invitee = (new UserCreator())
->setUsername('create.' . randomString(6))
->setEmail(randomString(6) . '@example.com')
@@ -177,6 +178,7 @@ class InviteTest extends TestCase {
reason: '',
source: '',
);
$this->assertInstanceOf(Invite::class, $invite, 'invite-manipulate-found');
$this->invitee = (new UserCreator())
->setUsername('create.' . randomString(6))
->setEmail(randomString(6) . '@example.com')
@@ -335,6 +337,7 @@ class InviteTest extends TestCase {
reason: $profile,
source: $sourceName,
);
$this->assertInstanceOf(Invite::class, $invite, 'invite-source-found');
$this->assertEquals(
1,
$inviteSourceMan->createPendingInviteSource($sourceId, $invite->key()),
@@ -365,11 +368,11 @@ class InviteTest extends TestCase {
$this->assertCount(1, $inviteeList, 'invite-source-invited-list');
$this->assertEquals(
[
"user_id" => $this->invitee->id(),
"user_id" => $this->invitee->id,
"invite_source_id" => $sourceId,
"name" => $sourceName,
],
$inviteeList[$this->invitee->id()],
$inviteeList[$this->invitee->id],
'invite-source-invited-invitee'
);
@@ -391,8 +394,8 @@ class InviteTest extends TestCase {
// change the invitee source and profile
$newProfile = $profile . "/new";
$new = [
$this->invitee->id() => [
"user_id" => $this->invitee->id(),
$this->invitee->id => [
"user_id" => $this->invitee->id,
"source" => 0,
"profile" => $newProfile,
]
@@ -406,11 +409,11 @@ class InviteTest extends TestCase {
$inviteeList = $inviteSourceMan->userSource($this->user);
$this->assertEquals(
[
"user_id" => $this->invitee->id(),
"user_id" => $this->invitee->id,
"invite_source_id" => null,
"name" => null,
],
$inviteeList[$this->invitee->id()],
$inviteeList[$this->invitee->id],
'invite-source-invitee-unsourced'
);
@@ -443,8 +446,14 @@ class InviteTest extends TestCase {
'unittest invite remove reason',
''
);
$this->assertTrue($manager->removeInviteKey($invite->key()), 'invite-remove-key');
$this->assertNull($manager->findUserByKey($invite->key()), 'invite-removed-key');
$this->assertTrue(
$manager->removeInviteKey((string)$invite?->key()),
'invite-remove-key'
);
$this->assertNull(
$manager->findUserByKey((string)$invite?->key()),
'invite-removed-key'
);
}
public function testExpireInvite(): void {
@@ -464,7 +473,7 @@ class InviteTest extends TestCase {
UPDATE invites SET
Expires = now() - INTERVAL 1 SECOND
WHERE InviteKey = ?
", $invite->key()
", (string)$invite?->key()
);
$this->assertEquals(1, DB::DB()->affected_rows(), 'invite-modify-expiry');
$this->assertEquals(1, $manager->expire(), 'invite-manager-expire');
@@ -495,7 +504,7 @@ class InviteTest extends TestCase {
);
$this->assertEquals(
$this->user->id,
$manager->findUserByKey($invite->key(), new Manager\User())->id,
(int)$manager->findUserByKey((string)$invite?->key(), new Manager\User())?->id,
'invite-manager-find-by-key',
);
$pending = $manager->pendingInvites(1, 0);
@@ -506,7 +515,7 @@ class InviteTest extends TestCase {
'invite-pending-array-keys',
);
$this->assertEquals($this->user->id, $pending[0]['user_id'], 'invite-pending-id');
$this->assertEquals($invite->key(), $pending[0]['key'], 'invite-pending-id');
$this->assertEquals((string)$invite?->key(), $pending[0]['key'], 'invite-pending-id');
$this->assertTrue(
$manager->emailExists($this->user, $email),
'invite-email-exists',
@@ -518,7 +527,7 @@ class InviteTest extends TestCase {
);
$this->assertEquals(
2,
$this->user->invite()->revoke($invite->key()),
$this->user->invite()->revoke((string)$invite?->key()),
'invite-revoke-existing',
);
$this->assertEquals(

View File

@@ -87,6 +87,11 @@ class NotificationUploadTest extends TestCase {
];
// create some notification filters for the users
$this->assertInstanceOf(
ArtistRole\TGroup::class,
$this->torrent->group()->artistRole(),
'filter-tgroup-artist-role'
);
$artistName = $this->torrent->group()->artistRole()->idList()[ARTIST_MAIN][0]['name'];
$artistFilter = (new Notification\Filter())
->setLabel('Artists')
@@ -207,13 +212,15 @@ class NotificationUploadTest extends TestCase {
// it should be pending, so make it active
$this->assertNull($ticketManager->findByExclusion(NotificationTicketState::Pending, exclude: [$this->torrent->id()]), 'ntick-pending-exclude');
$ticket = $ticketManager->findByExclusion(NotificationTicketState::Pending, exclude: []);
$this->assertEquals($this->torrent->id(), $ticket->torrentId(), 'ntick-pending-torrent-id');
$ticket->setActive();
$this->assertEquals($ticket->state(), NotificationTicketState::Active, 'ntick-active-value');
$this->assertEquals($this->torrent->id(), $ticket?->torrentId(), 'ntick-pending-torrent-id');
$ticket?->setActive();
$this->assertEquals($ticket?->state(), NotificationTicketState::Active, 'ntick-active-value');
$this->assertEquals(1, (new Manager\Notification())->ticketStats()['active']['total'], 'notifier-ticket-stats-now-active');
// send the IRC notification
$notification = new Notification\Upload($this->torMan->findById($ticket->torrentId()));
$torrent = $this->torMan->findById((int)$ticket?->torrentId());
$this->assertInstanceOf(Torrent::class, $torrent, 'ntick-torrent-found');
$notification = new Notification\Upload($torrent);
$message = $notification->ircNotification();
$this->assertStringContainsString($this->torrent->group()->name(), $message, 'ntick-irc-tgroup-name');
$this->assertStringContainsString(implode(',', $this->torrent->group()->tagNameList()), $message, 'ntick-irc-tgroup-taglist');
@@ -308,7 +315,7 @@ class NotificationUploadTest extends TestCase {
// ticket has been handled
unset($ticket);
$ticket = $ticketManager->findById($this->torrent->id());
$this->assertTrue($ticket->isDone(), 'ntick-is-done');
$this->assertTrue($ticket?->isDone(), 'ntick-is-done');
}
public function testProcessBacklog(): void {
@@ -337,7 +344,7 @@ class NotificationUploadTest extends TestCase {
// ticket has been handled
unset($ticket);
$ticket = $ticketManager->findById($this->torrent->id());
$this->assertTrue($ticket->isDone(), 'backlog-is-done');
$this->assertTrue($ticket?->isDone(), 'backlog-is-done');
$rss = (new Feed())->byFeedName($this->userList['backlog'], 'torrents_music');
$link = SITE_URL . "/torrents.php?id={$this->torrent->groupId()}&amp;torrentid={$this->torrent->id()}&amp;action=download&amp;torrent_pass={$this->userList['backlog']->announceKey()}";
@@ -366,12 +373,12 @@ class NotificationUploadTest extends TestCase {
unset($ticket);
$ticket = $ticketManager->findById($this->torrent->id());
$this->assertTrue($ticket->isPending(), 'ntick-stale-is-pending');
$this->assertTrue($ticket?->isPending(), 'ntick-stale-is-pending');
$manager->processBacklog($ticketManager, $this->torMan);
unset($ticket);
$ticket = $ticketManager->findById($this->torrent->id());
$this->assertTrue($ticket->isStale(), 'ntick-stale-is-stale');
$this->assertTrue($ticket?->isStale(), 'ntick-stale-is-stale');
}
public function testNewGroup(): void {

View File

@@ -54,30 +54,53 @@ class PrivilegeTest extends TestCase {
);
$find = $manager->findByLevel(FAKE_LEVEL);
$this->assertInstanceOf(Privilege::class, $find, 'privilege-find-by-level');
$this->assertEquals($privilege->id(), $find->id(), 'privilege-found-self');
$this->assertEquals($privilege->id, $find->id, 'privilege-found-self');
$this->assertEquals($badge, $privilege->badge(), 'privilege-badge');
$this->assertEquals(FAKE_LEVEL, $privilege->level(), 'privilege-level');
$this->assertCount(0, $privilege->permittedForums(), 'privilege-permitted-forums');
$this->assertFalse($privilege->displayStaff(), 'privilege-display-staff');
$this->assertTrue($privilege->isSecondary(), 'privilege-is-secondary');
$this->assertEquals($privilege->id(), $manager->findById($privilege->id())->id(), 'privilege-find-by-id');
$this->assertNull($manager->findById(1 + $privilege->id()), 'privilege-find-null');
$this->assertInstanceOf(
Privilege::class,
$manager->findById($privilege->id),
'privilege-find-by-id'
);
$this->assertNull(
$manager->findById(1 + $privilege->id),
'privilege-find-null'
);
// assign privilege to user
$this->assertEquals(0, $privilege->userTotal(), 'privilege-has-no-users-yet');
$this->assertEquals(0, $this->userList['user']->privilege()->secondaryClassesList()[$privilege->name()]['isSet'], 'privilege-user-no-secondary-yet');
$this->assertEquals(1, $this->userList['user']->addClasses([$privilege->id()]), 'privilege-add-secondary');
$this->assertEquals(1, $this->userList['user']->privilege()->secondaryClassesList()[$privilege->name()]['isSet'], 'privilege-user-no-secondary-yet');
$this->assertEquals(1, $privilege->flush()->userTotal(), 'privilege-has-one-user');
$this->assertEquals(
0,
$this->userList['user']->privilege()->secondaryClassesList()[$privilege->name()]['isSet'],
'privilege-user-no-secondary-yet'
);
$this->assertEquals(
1,
$this->userList['user']->addClasses([$privilege->id]),
'privilege-add-secondary'
);
$this->assertEquals(
1,
$this->userList['user']->privilege()->secondaryClassesList()[$privilege->name()]['isSet'],
'privilege-user-no-secondary-yet'
);
$this->assertEquals(
1,
$privilege->flush()->userTotal(),
'privilege-has-one-user'
);
// TODO: User\Privilege should take care of adding and removing secondary classes
$userPriv = $this->userList['user']->privilege();
$this->assertEquals(FAKE_LEVEL, $userPriv->maxSecondaryLevel(), 'privilege-user-max-level');
$this->assertEquals([$privilege->id() => $name], $userPriv->secondaryClassList(), 'privilege-user-list');
$this->assertEquals([$privilege->id => $name], $userPriv->secondaryClassList(), 'privilege-user-list');
$this->assertEquals([$badge => $name], $userPriv->badgeList(), 'privilege-user-badge');
// revoke privilege
$this->assertEquals(1, $this->userList['user']->removeClasses([$privilege->id()]), 'privilege-remove-secondary');
$this->assertEquals(1, $this->userList['user']->removeClasses([$privilege->id]), 'privilege-remove-secondary');
$this->assertEquals(0, $this->userList['user']->privilege()->secondaryClassesList()[$privilege->name()]['isSet'], 'privilege-user-no-more-secondary');
$this->assertEquals(0, $privilege->flush()->userTotal(), 'privilege-has-no-users');
@@ -101,10 +124,10 @@ class PrivilegeTest extends TestCase {
$this->assertEquals(1, $user->privilege()->addSecondaryClass($privilegeId, "privilege-add-$label"));
$this->assertTrue($user->$method(), "privilege-user-now-$label");
// TODO: the method name and parameter could be improved
$this->assertTrue($user->privilege()->hasSecondaryClassId($privilege->id()), "privilege-has-secondary-$label");
$this->assertTrue($user->privilege()->hasSecondaryClassId($privilege->id), "privilege-has-secondary-$label");
$this->assertEquals(1, $user->removeClasses([$privilegeId]), "privilege-remove-$label");
$this->assertFalse($user->$method(), "privilege-user-no-longer-$label");
$this->assertFalse($user->privilege()->hasSecondaryClassId($privilege->id()), "privilege-no-longerhas-secondary-$label");
$this->assertFalse($user->privilege()->hasSecondaryClassId($privilege->id), "privilege-no-longerhas-secondary-$label");
}
public function testPrivilegeBadge(): void {

View File

@@ -51,6 +51,7 @@ class RequestTest extends TestCase {
$this->assertStringNotContainsString(' (bonus VIP)', $this->request->urlencodeTitle(), 'request-urlencode-title');
$artistMan = new Manager\Artist();
$artistName = 'phpunit req ' . randomString(6);
$this->assertInstanceOf(ArtistRole\Request::class, $this->request->artistRole(), 'request-add-artist-role');
$this->assertEquals(
1,
$this->request->artistRole()->set(

View File

@@ -28,7 +28,7 @@ class SearchReportTest extends TestCase {
$this->request = (new Manager\Request())->create(
user: $this->userList[1],
bounty: REQUEST_MIN * 1024 * 1024,
categoryId: (new Manager\Category())->findIdByName('Music'),
categoryId: (int)(new Manager\Category())->findIdByName('Music'),
year: (int)date('Y'),
title: 'phpunit request report',
image: '',

View File

@@ -88,7 +88,7 @@ class TGroupTest extends TestCase {
$this->assertEquals($this->catalogueNumber, $this->tgroup->catalogueNumber(), 'tgroup-create-catalogue-number');
$this->assertEquals(0, $this->tgroup->unresolvedReportsTotal(), 'tgroup-create-unresolved-reports');
$this->assertEquals($this->tgroup->name(), $this->tgroup->flush()->name(), 'tgroup-create-flush');
$this->assertStringStartsWith('https://example.com/', $this->tgroup->image(), 'tgroup-create-image');
$this->assertStringStartsWith('https://example.com/', (string)$this->tgroup->image(), 'tgroup-create-image');
$this->assertStringStartsWith('https://example.com/', $this->tgroup->cover(), 'tgroup-create-cover');
$this->assertTrue($this->tgroup->isOwner($this->userList['user']), 'tgroup-user-is-owner');
@@ -102,6 +102,7 @@ class TGroupTest extends TestCase {
$torMan = new Manager\Torrent();
$torrent = $torMan->findById($this->tgroup->torrentIdList()[0]);
$this->assertInstanceOf(Torrent::class, $torrent, 'tgroup-found-torrent');
$this->assertEquals(1, $torrent->tokenCount(), 'tgroup-torrent-fl-cost');
$this->assertFalse($this->userList['user']->canSpendFLToken($torrent), 'tgroup-user-no-fltoken');
@@ -146,12 +147,16 @@ class TGroupTest extends TestCase {
$this->assertEquals($artistName, $first['name'], 'tgroup-artist-first-name');
$foundByArtist = $this->manager->findByArtistReleaseYear(
$this->tgroup->artistRole()->text(),
(string)$this->tgroup->artistRole()?->text(),
$this->tgroup->name(),
$this->tgroup->releaseType(),
$this->tgroup->year(),
(int)$this->tgroup->releaseType(),
(int)$this->tgroup->year(),
);
$this->assertEquals(
$this->tgroup->id,
$foundByArtist?->id,
'tgroup-find-name'
);
$this->assertEquals($this->tgroup->id, $foundByArtist->id, 'tgroup-find-name');
$this->assertEquals(
2,
@@ -162,6 +167,11 @@ class TGroupTest extends TestCase {
),
'tgroup-artist-add-2'
);
$this->assertInstanceOf(
ArtistRole\TGroup::class,
$this->tgroup->artistRole(),
'tgroup-has-artistrole'
);
$this->assertEquals(
[
ARTIST_MAIN => [$artistName, "$artistName-2"],
@@ -172,25 +182,30 @@ class TGroupTest extends TestCase {
);
/* turn the two Main and Guest into DJs */
$roleList = $this->tgroup->artistRole()->roleList();
$roleList = $this->tgroup->artistRole()?->roleList();
$this->assertIsArray($roleList, 'tgroup-dj-role');
$roleAliasList = [
...array_map(fn ($artist) => [ARTIST_MAIN, $artist['aliasid']], $roleList['main']),
...array_map(fn ($artist) => [ARTIST_GUEST, $artist['aliasid']], $roleList['guest']),
];
$this->assertEquals(
3,
$this->tgroup->artistRole()->modifyList($roleAliasList, ARTIST_DJ, $user),
$this->tgroup->artistRole()?->modifyList($roleAliasList, ARTIST_DJ, $user),
'tgroup-a-dj-saved-my-life'
);
$this->assertEquals('Various DJs', $this->tgroup->flush()->artistRole()->text(), 'tgroup-2manydjs');
$this->assertEquals(
'Various DJs',
$this->tgroup->flush()->artistRole()?->text(),
'tgroup-2manydjs'
);
$this->assertEquals(
1,
$this->tgroup->artistRole()->removeList([[ARTIST_DJ, $roleAliasList[0][1]]], $user),
$this->tgroup->artistRole()?->removeList([[ARTIST_DJ, $roleAliasList[0][1]]], $user),
'tgroup-hang-the-dj'
);
$this->assertEquals(
"$artistName-2 and $artistName-guest",
$this->tgroup->flush()->artistRole()->text(),
$this->tgroup->flush()->artistRole()?->text(),
'tgroup-dj-final'
);
}

View File

@@ -61,12 +61,12 @@ class TagTest extends TestCase {
$this->user->requestContext()->setViewer($this->user);
$tag = $manager->create($name, $this->user);
$this->assertInstanceOf(Tag::class, $tag, 'tag-find-by-id');
$this->assertEquals($tag->id(), $manager->findByName($tag->name())->id(), 'tag-method-lookup');
$this->assertEquals($tag->id, $manager->findByName($tag->name())?->id, 'tag-method-lookup');
$this->assertEquals($name, $tag->name(), 'tag-method-name');
$this->assertEquals($name, $manager->findByName($tag->name())->name(), 'tag-find-by-name');
$this->assertEquals($name, $manager->findByName($tag->name())?->name(), 'tag-find-by-name');
$find = $manager->findById($tag->id());
$this->assertEquals($tag->id(), $find->id(), 'tag-find-by-id');
$find = $manager->findById($tag->id);
$this->assertEquals($tag->id, $find?->id, 'tag-find-by-id');
$this->user->addBounty(500 * 1024 ** 3);
$this->request = Helper::makeRequestMusic($this->user, 'phpunit tag create request');
@@ -76,20 +76,29 @@ class TagTest extends TestCase {
$new = "$name." . randomString(4);
$this->assertNull($manager->findByName($new), 'tag-lookup-new-fail');
$newTag = $manager->softCreate($new, $this->user);
$this->assertInstanceOf(\Gazelle\Tag::class, $newTag, 'tag-new-found');
$this->assertEquals(
1,
$manager->rename( $tag, [$newTag], $this->user),
'tag-rename'
);
$find = $manager->findByName($new);
$this->assertInstanceOf(\Gazelle\Tag::class, $find, 'tag-find');
$this->assertEquals($find->id(), $newTag->id(), 'tag-lookup-new-success');
$this->assertInstanceOf(\Gazelle\Tag::class, $find, 'tag-found');
$this->assertEquals($find->id, $newTag->id, 'tag-lookup-new-success');
// rename to an existing tag
$new2 = "$name." . randomString(5);
$new2Tag = $manager->create($new2, $this->user);
$this->assertEquals(1, $manager->rename($newTag, [$new2Tag], $this->user), 'tag-existing-rename');
$this->assertEquals($new2Tag->id(), $manager->findByName($new2Tag->name())->id(), 'tag-lookup-existing-success');
$this->assertEquals(
1,
$manager->rename($newTag, [$new2Tag], $this->user),
'tag-existing-rename'
);
$this->assertEquals(
$new2Tag->id,
(int)$manager->findByName($new2Tag->name())?->id,
'tag-lookup-existing-success'
);
// Is empty because vote counts below 10 are ignored,
// but at least we know the SQL is syntactically valid.
@@ -104,7 +113,9 @@ class TagTest extends TestCase {
$this->assertTrue($manager->validName($valid), 'tag-valid-name');
$t1 = $manager->softCreate($valid, $this->user);
$t2 = $manager->softCreate($valid, $this->user);
$this->assertEquals($t1->id(), $t2->id(), 'tag-soft-create-valid');
$this->assertInstanceOf(Tag::class, $t1, 'tag-t1-found');
$this->assertInstanceOf(Tag::class, $t2, 'tag-t2-found');
$this->assertEquals($t1->id, $t2->id, 'tag-soft-create-valid');
}
public function testAlias(): void {
@@ -113,7 +124,7 @@ class TagTest extends TestCase {
$bad = $manager->create(self::PREFIX . randomString(10), $this->user);
$good = $manager->create(self::PREFIX . randomString(10), $this->user);
$this->assertNotEquals($bad->id(), $good->id(), 'tag-just-try-again');
$this->assertNotEquals($bad->id, $good->id, 'tag-just-try-again');
$aliasId = $manager->createAlias($bad->name(), $good->name());
$this->assertEquals($aliasId, $manager->lookupBad($bad->name()), 'tag-lookup-bad');
@@ -186,19 +197,19 @@ class TagTest extends TestCase {
$manager = new Manager\Tag();
$this->user = Helper::makeUser('tag.' . randomString(6), 'tag');
$tag = $manager->create(self::PREFIX . randomString(10), $this->user);
$this->assertEquals($tag->id(), $manager->officialize($tag->name(), $this->user)->id(), 'tag-officalize-existing');
$this->assertEquals($tag->id, $manager->officialize($tag->name(), $this->user)->id, 'tag-officalize-existing');
$list = array_filter($manager->genreList(), fn($t) => $t == $tag->name());
$this->assertCount(1, $list, 'tag-genre-list');
$official = $manager->officialize(self::PREFIX . 'off.' . randomString(10), $this->user);
$this->assertNotEquals($tag->id(), $official->id(), 'tag-officialize-new');
$this->assertNotEquals($tag->id, $official->id, 'tag-officialize-new');
$officialName = $official->name();
$list = array_filter(
$manager->officialList(),
fn($t) => $t->name() == $officialName
);
$this->assertCount(1, $list, 'tag-official-list');
$this->assertEquals(1, $manager->unofficialize([$official->id()]), 'tag-unofficialize');
$this->assertEquals(1, $manager->unofficialize([$official->id]), 'tag-unofficialize');
$this->assertCount(
0,
array_filter($manager->officialList(), fn($t) => $t->name() == $officialName),
@@ -222,15 +233,17 @@ class TagTest extends TestCase {
$manager = new Manager\Tag();
$folk = $manager->findByName('phpunit.folk');
$this->assertInstanceOf(Tag::class, $folk, 'tag-folk-found');
$this->assertFalse(
$folk->hasVoteTGroup($this->tgroup, $this->user),
'tag-has-no-vote'
);
$tag = $manager->findByName('phpunit.electronic');
$this->assertInstanceOf(Tag::class, $tag, 'tag-tag-found');
$result = $tag->tgroupList();
$item = current($result);
$this->assertCount(1, $result, 'tag-torrent-lookup');
$this->assertEquals($this->tgroup->id(), $item['torrentGroupId'], 'tag-found-tgroup');
$this->assertEquals($this->tgroup->id, $item['torrentGroupId'], 'tag-found-tgroup');
$this->assertEquals(
1,
$folk->voteTGroup($this->tgroup, $this->user, 'up'),
@@ -307,7 +320,7 @@ class TagTest extends TestCase {
$this->assertNull($manager->findByName($name), 'tag-new-gone');
$this->assertEquals(
2,
$manager->findByName("$name.2")->uses(),
$manager->findByName("$name.2")?->uses(),
'tag-new-uses',
);
}
@@ -358,7 +371,7 @@ class TagTest extends TestCase {
$this->assertNull($manager->findByName($name), 'tag-existing-gone');
$this->assertEquals(
2,
$manager->findByName("$name.3")->uses(),
$manager->findByName("$name.3")?->uses(),
'tag-existing-uses',
);
}

View File

@@ -111,19 +111,19 @@ class TextTest extends TestCase {
$collage = (new Manager\Collage())->create($this->userList['admin'], 1, $name, 'phpunit collage', 'jazz,disco');
$this->assertInstanceOf(Collage::class, $collage, 'text-create-collage');
$this->assertEquals(
"<a href=\"collages.php?id={$collage->id()}\">{$collage->name()}</a>",
\Text::full_format("[collage]{$collage->id()}[/collage]"),
"<a href=\"collages.php?id={$collage->id}\">{$collage->name()}</a>",
\Text::full_format("[collage]{$collage->id}[/collage]"),
'text-collage-bb'
);
$this->assertEquals(
"<a href=\"collages.php?id={$collage->id()}\">{$collage->name()}</a>",
"<a href=\"collages.php?id={$collage->id}\">{$collage->name()}</a>",
\Text::full_format($collage->publicLocation()),
'text-collage-url'
);
$commentMan = new Manager\Comment();
$comment = $commentMan->create($this->userList['admin'], 'collages', $collage->id(), "nice collage!");
$comment = $commentMan->create($this->userList['admin'], 'collages', $collage->id, "nice collage!");
$this->assertEquals(
"<a href=\"{$comment->url()}\">Collages Comment #{$comment->id()}</a>",
"<a href=\"{$comment->url()}\">Collages Comment #{$comment->id}</a>",
\Text::full_format($comment->publicLocation()),
'text-collage-comment-link'
);
@@ -145,8 +145,8 @@ class TextTest extends TestCase {
);
$this->assertInstanceOf(Forum::class, $forum, 'text-create-forum');
$this->assertEquals(
"<a href=\"forums.php?action=viewforum&amp;forumid={$forum->id()}\" class=\"tooltip\" title=\"{$forum->name()}\">{$forum->name()}</a>",
\Text::full_format("[forum]{$forum->id()}[/forum]"),
"<a href=\"forums.php?action=viewforum&amp;forumid={$forum->id}\" class=\"tooltip\" title=\"{$forum->name()}\">{$forum->name()}</a>",
\Text::full_format("[forum]{$forum->id}[/forum]"),
'text-forum'
);
@@ -160,8 +160,8 @@ class TextTest extends TestCase {
INNER JOIN forums_topics ft ON (ft.ID = fp.TopicID)
");
$post = (new Manager\ForumPost())->findById($postId);
$threadId = $post->thread()->id();
$title = $post->thread()->title();
$threadId = $post?->thread()->id;
$title = $post?->thread()->title();
$this->assertMatchesRegularExpression(
"@^<a href=\"forums\.php\?action=viewthread&amp;threadid={$threadId}\">\Q{$title}\E</a>$@",
@@ -334,7 +334,7 @@ END_HTML;
$this->assertEquals("<a href=\"user.php?action=search&amp;search=$username\">$username</a>", \Text::full_format("[user]{$username}[/user]"), "text-user-1");
$url = "<a href=\"user.php?id={$this->userList['user']->id()}\">@$username</a>";
$url = "<a href=\"user.php?id={$this->userList['user']->id}\">@$username</a>";
$this->assertEquals($url, \Text::full_format("@$username"), "text-user-2");
$this->assertEquals("$url.", \Text::full_format("@$username."), "text-user-3");

View File

@@ -78,7 +78,7 @@ class UserActivityTest extends TestCase {
// send a message from admin to user
$pm = $user->inbox()->create($admin, 'unit test message', 'unit test body');
$this->assertGreaterThan(0, $pm->id(), 'alert-inbox-send');
$this->assertInstanceOf(PM::class, $pm, 'alert-inbox-send');
// check out the notifications
$notifier = new User\Notification($user);
@@ -115,7 +115,8 @@ class UserActivityTest extends TestCase {
$this->assertGreaterThan(0, $newsId, 'alert-news-create');
$this->assertNull($manager->fetch(-1), 'alert-no-news-is-null-news');
$info = $manager->fetch($newsId);
$this->assertCount(2, $info, 'alert-latest-news');
$this->assertIsArray($info, 'alert-latest-news-array');
$this->assertCount(2, $info, 'alert-latest-news-count');
$notifier = new User\Notification($this->userList['user']);
// if this fails, the CI database has drifted (or another UT has clobbered the expected value here)

View File

@@ -39,7 +39,8 @@ class UserMultiFactorAuthTest extends TestCase {
$this->assertEquals(0, $this->countTokens(), 'utest-no-mfa');
$recovery = $mfa->create($manager, $secret);
$this->assertCount(10, $recovery, 'utest-setup-mfa');
$this->assertIsArray($recovery, 'utest-setup-mfa-array');
$this->assertCount(10, $recovery, 'utest-setup-mfa-count');
$this->assertTrue($this->user->auditTrail()->hasEvent(UserAuditEvent::mfa), 'utest-mfa-audit');
$burn = array_pop($recovery);

View File

@@ -39,6 +39,7 @@ class UserTest extends TestCase {
public function testUserFind(): void {
$userMan = new Manager\User();
$admin = $userMan->find('@' . $this->user->username());
$this->assertInstanceOf(User::class, $admin, 'user-find-@');
$this->user->setField('PermissionID', SYSOP)->modify();
$this->assertTrue($admin->isStaff(), 'admin-is-admin');
$this->assertTrue($admin->permitted('site_upload'), 'admin-permitted-site_upload');
@@ -50,6 +51,7 @@ class UserTest extends TestCase {
public function testFindById(): void {
$userMan = new Manager\User();
$user = $userMan->findById($this->user->id);
$this->assertInstanceOf(User::class, $user, 'user-find-by-id');
$this->assertFalse($user->isStaff(), 'user-is-not-admin');
$this->assertStringStartsWith('user.', $user->username(), 'user-username');
$this->assertStringEndsWith('@user.example.com', $user->email(), 'user-email');
@@ -260,33 +262,55 @@ class UserTest extends TestCase {
$this->assertTrue($this->modifyAvatarRender(AvatarDisplay::none, AvatarSynthetic::robot1), 'utest-avatar-update-none');
$this->assertEquals(AvatarDisplay::none, $this->user->avatarMode(), 'utest-has-avatar-none');
$new = $userMan->findById($this->user->id);
$this->assertEquals(USER_DEFAULT_AVATAR, $new->avatarComponentList($this->user->flush())['image'], 'utest-avatar-none');
$this->assertEquals(
USER_DEFAULT_AVATAR,
$new?->avatarComponentList($this->user->flush())['image'],
'utest-avatar-none'
);
$url = 'https://www.example.com/avatar.jpg';
$this->assertTrue($this->user->setField('avatar', $url)->modify(), 'utest-avatar-set');
$this->assertEquals($url, $this->user->avatar(), 'utest-avatar-url');
$new = $userMan->findById($this->user->id);
$this->assertEquals(USER_DEFAULT_AVATAR, $new->avatarComponentList($this->user->flush())['image'], 'utest-avatar-override-none');
$this->assertTrue($this->modifyAvatarRender(AvatarDisplay::forceSynthetic, AvatarSynthetic::identicon), 'utest-avatar-update-synthetic-identicon');
$this->assertEquals(AvatarDisplay::forceSynthetic, $this->user->flush()->avatarMode(), 'utest-clone-avatar-forceSynthetic');
$this->assertTrue($this->modifyAvatarRender(AvatarDisplay::show, AvatarSynthetic::robot1), 'utest-avatar-update-show');
$this->assertEquals(
USER_DEFAULT_AVATAR,
$new?->avatarComponentList($this->user->flush())['image'],
'utest-avatar-override-none'
);
$this->assertTrue(
$this->modifyAvatarRender(AvatarDisplay::forceSynthetic,
AvatarSynthetic::identicon),
'utest-avatar-update-synthetic-identicon'
);
$this->assertEquals(
AvatarDisplay::forceSynthetic,
$this->user->flush()->avatarMode(),
'utest-clone-avatar-forceSynthetic'
);
$this->assertTrue(
$this->modifyAvatarRender(AvatarDisplay::show,
AvatarSynthetic::robot1),
'utest-avatar-update-show'
);
$new = $userMan->findById($this->user->id);
$this->assertEquals('https://www.example.com/avatar.jpg', $new->avatarComponentList($this->user->flush())['image'], 'utest-avatar-show');
$this->assertEquals(
'https://www.example.com/avatar.jpg',
$new?->avatarComponentList($this->user->flush())['image'],
'utest-avatar-show'
);
}
public function testLastAccess(): void {
$this->assertNull($this->user->lastAccess(), 'utest-no-last-access');
$this->assertEquals(1, $this->user->refreshLastAccess(), 'utest-refresh-last-access');
$this->assertTrue(
Helper::recentDate($this->user->lastAccessRealtime()),
Helper::recentDate((string)$this->user->lastAccessRealtime()),
'utest-realtime-last-access'
);
$userMan = new Manager\User();
$this->assertGreaterThan(0, $userMan->refreshLastAccess(), 'utest-userman-refresh-last-access');
$this->assertTrue(
Helper::recentDate($this->user->lastAccess()),
Helper::recentDate((string)$this->user->lastAccess()),
'utest-has-last-access'
);
}
@@ -309,23 +333,28 @@ class UserTest extends TestCase {
$manager = new Manager\User();
$next = $this->user->nextClass($manager);
$this->assertIsArray($next, 'user-next-array');
$this->assertEquals('Member', $next['class'], 'user-next-class-is-member');
$goal = $next['goal'];
$this->assertCount(3, $goal, 'user-next-requirements');
$this->assertIsArray($goal, 'user-next-requirements-array');
$this->assertCount(3, $goal, 'user-next-requirements-count');
$this->assertStringContainsString('100%', $goal['Ratio']['percent'], 'user-next-ratio');
$this->assertStringContainsString('0%', $goal['Time']['percent'], 'user-next-time');
$this->assertStringContainsString('30%', $goal['Upload']['percent'], 'user-next-upload');
$this->user->setField('created', date('Y-m-d H:i:s', strtotime('-2 day')))->modify();
$next = $this->user->nextClass($manager);
$this->assertIsArray($next, 'user-next-requirements-next-array');
$this->assertStringContainsString('29%', $next['goal']['Time']['percent'], 'user-next-closer-time');
$this->user->setField('created', date('Y-m-d H:i:s', strtotime('-7 day')))->modify();
$next = $this->user->nextClass($manager);
$this->assertIsArray($next, 'user-next-requirements-next-2-array');
$this->assertStringContainsString('100%', $next['goal']['Time']['percent'], 'user-next-has-time');
$this->user->addBounty(7 * 1024 * 1024 * 1024);
$next = $this->user->nextClass($manager);
$this->assertIsArray($next, 'user-next-requirements-next-3-array');
$this->assertStringContainsString('100%', $next['goal']['Upload']['percent'], 'user-next-has-upload');
$manager->promote();

View File

@@ -56,18 +56,25 @@ class WikiTest extends TestCase {
);
$this->assertInstanceOf(Wiki::class, $article, 'wiki-create-open');
$this->assertEquals($article->id(), $manager->findById($article->id())->id(), 'wiki-find-by-id');
$this->assertEquals($article->id(), $manager->findByTitle($article->title())->id(), 'wiki-find-by-title');
$this->assertEquals(
$article->id,
$manager->findById($article->id)?->id,
'wiki-find-by-id');
$this->assertEquals(
$article->id,
$manager->findByTitle($article->title())?->id,
'wiki-find-by-title'
);
$this->assertInstanceOf(Wiki::class, $article->flush(), 'wiki-flush');
$this->assertEquals("<a href=\"{$article->url()}\">{$article->title()}</a>", $article->link(), 'wiki-link');
$this->assertEquals("wiki.php?action=article&id={$article->id()}", $article->location(), 'wiki-location');
$this->assertEquals("wiki.php?action=article&id={$article->id}", $article->location(), 'wiki-location');
$this->assertEquals($alias, array_keys($article->alias())[0], 'wiki-alias');
$this->assertEquals('wiki body', $article->body(), 'wiki-body');
$this->assertStringStartsWith(date('Y-m-d H'), $article->date(), 'wiki-date');
$this->assertEquals($title, $article->title(), 'wiki-title');
$this->assertEquals($title, $article->shortName($title), 'wiki-short-name');
$this->assertEquals($this->userList['admin']->id(), $article->authorId(), 'wiki-author-id');
$this->assertEquals($this->userList['admin']->id, $article->authorId(), 'wiki-author-id');
$this->assertEquals($this->userList['user']->privilege()->effectiveClassLevel(), $article->minClassRead(), 'wiki-min-read');
$this->assertEquals($this->userList['user']->privilege()->effectiveClassLevel(), $article->minClassEdit(), 'wiki-min-edit');
@@ -94,17 +101,17 @@ class WikiTest extends TestCase {
\Text::setViewer($this->userList['user']);
$this->assertEquals(
"<a href=\"wiki.php\">Wiki</a> <a href=\"wiki.php?action=article&amp;id={$article->id()}\">$title</a>",
"<a href=\"wiki.php\">Wiki</a> <a href=\"wiki.php?action=article&amp;id={$article->id}\">$title</a>",
\Text::full_format(SITE_URL . "/wiki.php?action=article&name=$alias"),
'text-wiki-name-location',
);
$this->assertEquals(
"<a href=\"wiki.php\">Wiki</a> <a href=\"wiki.php?action=article&amp;id={$article->id()}\">$title</a>",
"<a href=\"wiki.php\">Wiki</a> <a href=\"wiki.php?action=article&amp;id={$article->id}\">$title</a>",
\Text::full_format("{$article->publicLocation()}"),
'text-wiki-id-location',
);
$this->assertEquals(
"<a href=\"wiki.php\">Wiki</a> <a href=\"wiki.php?action=article&amp;id={$article->id()}\">$title</a>",
"<a href=\"wiki.php\">Wiki</a> <a href=\"wiki.php?action=article&amp;id={$article->id}\">$title</a>",
\Text::full_format("[[{$alias}]]"),
'wiki-bbcode-alias'
);
@@ -132,7 +139,7 @@ class WikiTest extends TestCase {
$this->assertEquals(0, $article->removeAlias($newAlias), 'wiki-remove-missing-alias');
$this->assertEquals(1, $article->addAlias($newAlias, $this->userList['admin']), 'wiki-add-alias');
$this->assertCount(2, $article->alias(), 'wiki-alias-list');
$this->assertEquals($article->id(), $manager->findByAlias($newAlias)->id(), 'wiki-find-by-alias');
$this->assertEquals($article->id, $manager->findByAlias($newAlias)?->id, 'wiki-find-by-alias');
$this->assertEquals(1, $article->removeAlias($newAlias), 'wiki-remove-alias');
}
@@ -215,9 +222,9 @@ class WikiTest extends TestCase {
$this->assertTrue($article->setField('Body', 'wiki body edit')->modify(), 'wiki-edit-body');
$this->assertCount(1, $article->revisionList(), 'wiki-revision');
$clone = $manager->findById($article->id());
$this->assertEquals(2, $clone->revision(), 'wiki-n-revision');
$this->assertEquals('wiki body', $clone->revisionBody(1), 'wiki-body-revision');
$clone = $manager->findById($article->id);
$this->assertEquals(2, $clone?->revision(), 'wiki-n-revision');
$this->assertEquals('wiki body', $clone?->revisionBody(1), 'wiki-body-revision');
}
public function testConfigureAccess(): void {

View File

@@ -37,7 +37,7 @@ class BlogTest extends TestCase {
);
$this->assertEquals(
$this->blog->id,
$manager->findById($this->blog->id)->id,
$manager->findById($this->blog->id)?->id,
'blog-find'
);
$this->assertEquals($this->blog->id, $manager->latestId(), 'blog-latest');
@@ -56,12 +56,20 @@ class BlogTest extends TestCase {
'blog-link'
);
$this->assertEquals(min(20, 1 + count($initial)), count($manager->headlines()), 'blog-headlines');
$this->assertEquals($this->blog->id, $manager->latest()->id, 'blog-latest');
$this->assertEquals(
min(20, 1 + count($initial)),
count($manager->headlines()),
'blog-headlines'
);
$this->assertEquals($this->blog->id, $manager->latestId(), 'blog-id-latest');
$this->assertEquals($this->blog->id, $manager->latest()?->id, 'blog-latest');
$find = $manager->findById($this->blog->id);
$this->assertEquals($this->blog->id, $find->id, 'blog-find');
$this->assertEquals((int)strtotime($find->created()), $manager->latestEpoch(), 'blog-epoch');
$this->assertEquals($this->blog->id, $find?->id, 'blog-find');
$this->assertEquals(
(int)strtotime((string)$find?->created()),
$manager->latestEpoch(),
'blog-epoch'
);
$this->assertInstanceOf(Blog::class, $this->blog->flush(), 'blog-flush');
$this->assertEquals(1, $this->blog->remove(), 'blog-remove');
@@ -86,7 +94,7 @@ class BlogTest extends TestCase {
$this->assertFalse($this->blog->notify(), 'blog-no-notify');
$this->assertEquals(
"thread $title title",
$this->blog->thread()->title(),
$this->blog->thread()?->title(),
'blog-thread-title',
);
$this->assertEquals(1, $this->blog->removeThread(), 'blog-thread-detach');

View File

@@ -60,7 +60,8 @@ class CollageFreeleechTest extends TestCase {
foreach ($this->tgroupList as $tgroup) {
$this->collage->removeEntry($tgroup);
foreach ($tgroup->torrentIdList() as $torrentId) {
$torMan->findById($torrentId)->removeTorrent($this->user, 'collfree unit test');
$torMan->findById($torrentId)
?->removeTorrent($this->user, 'collfree unit test');
}
$tgroup->remove($this->user);
}
@@ -89,10 +90,25 @@ class CollageFreeleechTest extends TestCase {
++$n;
$idList = $tgroup->torrentIdList();
sort($idList);
$torrentList = array_map(fn($id) => $torMan->findById($id)->flush(), $idList);
$this->assertEquals(LeechType::Free, $torrentList[0]->leechType(), "collfree-t0-free-$n");
$this->assertEquals(LeechType::Neutral, $torrentList[1]->leechType(), "collfree-t1-neutral-$n");
$this->assertEquals(LeechType::Normal, $torrentList[2]->leechType(), "collfree-t2-normal-$n");
$torrentList = array_map(
fn ($id) => $torMan->findById($id)?->flush(),
$idList
);
$this->assertEquals(
LeechType::Free,
$torrentList[0]?->leechType(),
"collfree-t0-free-$n"
);
$this->assertEquals(
LeechType::Neutral,
$torrentList[1]?->leechType(),
"collfree-t1-neutral-$n"
);
$this->assertEquals(
LeechType::Normal,
$torrentList[2]?->leechType(),
"collfree-t2-normal-$n"
);
}
$this->assertEquals(
@@ -108,8 +124,14 @@ class CollageFreeleechTest extends TestCase {
);
$n = 0;
foreach ($this->tgroupList as $tgroup) {
foreach (array_map(fn($id) => $torMan->findById($id)->flush(), $tgroup->torrentIdList()) as $torrent) {
foreach (
array_map(
fn ($id) => $torMan->findById($id)?->flush(),
$tgroup->torrentIdList(),
) as $torrent
) {
++$n;
$this->assertInstanceOf(Torrent::class, $torrent, "collfree-tgroup-found-$n");
$this->assertEquals(LeechType::Normal, $torrent->leechType(), "collfree-now-normal-$n");
}
}

View File

@@ -31,7 +31,7 @@ class FeaturedAlbumTest extends TestCase {
", $this->user->id
)
);
(new Manager\FeaturedAlbum())->findById($this->tgroup->id())?->remove();
(new Manager\FeaturedAlbum())->findById($this->tgroup->id)?->remove();
$this->tgroup->remove();
$this->user->remove();
}
@@ -54,14 +54,16 @@ class FeaturedAlbumTest extends TestCase {
leechType: LeechType::Free,
threshold: 20000,
);
$this->assertEquals($this->tgroup->id(), $aotm->tgroupId(), 'aotm-tgroupid');
$this->assertEquals($this->tgroup->id(), $aotm->tgroup()->id(), 'aotm-tgroup-id');
$this->assertEquals($this->tgroup->id, $aotm->tgroupId(), 'aotm-tgroupid');
$this->assertEquals($this->tgroup->id, $aotm->tgroup()->id, 'aotm-tgroup-id');
$find = $manager->findByType(FeaturedAlbumType::AlbumOfTheMonth);
$this->assertEquals($aotm->id(), $find->id(), 'aotm-find-by-type');
$this->assertInstanceOf(FeaturedAlbum::class, $find, 'aotm-found-by-type');
$this->assertEquals($aotm->id, $find->id, 'aotm-find-by-type');
$find = $manager->findById($this->tgroup->id());
$this->assertEquals($aotm->id(), $find->id(), 'aotm-find-by-id');
$find = $manager->findById($this->tgroup->id);
$this->assertInstanceOf(FeaturedAlbum::class, $find, 'aotm-found-by-id');
$this->assertEquals($aotm->id, $find->id, 'aotm-find-by-id');
$this->assertEquals(FeaturedAlbumType::AlbumOfTheMonth, $find->type(), 'aotm-type');
$this->assertEquals(1, $aotm->unfeature(), 'aotm-unfeature');
@@ -86,13 +88,15 @@ class FeaturedAlbumTest extends TestCase {
leechType: LeechType::Free,
threshold: 20000,
);
$this->assertEquals($this->tgroup->id(), $showcase->tgroupId(), 'showcase-tgroupid');
$this->assertEquals($this->tgroup->id, $showcase->tgroupId(), 'showcase-tgroupid');
$find = $manager->findByType(FeaturedAlbumType::Showcase);
$this->assertEquals($showcase->id(), $find->id(), 'showcase-find-by-type');
$this->assertInstanceOf(FeaturedAlbum::class, $find, 'showcase-found-by-type');
$this->assertEquals($showcase->id, $find->id, 'showcase-find-by-type');
$find = $manager->findById($this->tgroup->id());
$this->assertEquals($showcase->id(), $find->id(), 'showcase-find-by-id');
$find = $manager->findById($this->tgroup->id);
$this->assertInstanceOf(FeaturedAlbum::class, $find, 'showcase-found-by-id');
$this->assertEquals($showcase->id, $find->id, 'showcase-find-by-id');
$this->assertEquals(FeaturedAlbumType::Showcase, $find->type(), 'showcase-type');
$this->assertEquals(1, $showcase->unfeature(), 'aotm-unfeature');

View File

@@ -77,14 +77,14 @@ class IPv4Test extends TestCase {
$manager->findByIp('127.100.0.1'),
'ip-ban-class-1',
);
$this->assertEquals(
$ban->id,
$manager->findByIp('127.100.1.1')->id,
$this->assertInstanceOf(
Ban::class,
$manager->findByIp('127.100.1.1'),
'ip-ban-class-2',
);
$this->assertEquals(
$ban->id,
$manager->findByIp('127.100.2.1')->id,
$this->assertInstanceOf(
Ban::class,
$manager->findByIp('127.100.2.1'),
'ip-ban-class-3',
);
$this->assertEquals('127.100.0.0/22', $ban->ip(), 'ip-ban-ip');

View File

@@ -24,7 +24,7 @@ class ManagerReportAutoTest extends TestCase {
$raMan = new Manager\ReportAuto();
$type = $ratMan->create('raman test create type' . randomString(6), 'description', 'ReportAutoTest');
$report = $raMan->create($this->user1, $type, ['a' => 'b']);
$this->assertGreaterThan(0, $report->id(), 'raman-create-id');
$this->assertGreaterThan(0, $report->id, 'raman-create-id');
$report2 = $raMan->create($this->user1, $type, ['a' => 'b']);
$this->assertNotEquals($report, $report2, 'raman-create-unique');
@@ -32,9 +32,9 @@ class ManagerReportAutoTest extends TestCase {
$report3 = $raMan->create($this->user1, $type, ['c' => 'd'], '2024-01-01T00:00+0');
$this->assertStringStartsWith('2024-01-01 00:00', $report3->created(), 'raman-create-time');
$report3_n = $raMan->findById($report3->id());
$report3_n = $raMan->findById($report3->id);
$this->assertNotNull($report3_n, 'raman-find-id');
$this->assertEquals($report3->id(), $report3_n->id(), 'raman-find-identity');
$this->assertEquals($report3->id, $report3_n->id, 'raman-find-identity');
$this->assertEquals($report3->state(), $report3_n->state(), 'raman-find-identity-status');
$this->assertEquals($report3->typeId(), $report3_n->typeId(), 'raman-find-identity-typeid');
$this->assertEquals($report3->ownerId(), $report3_n->ownerId(), 'raman-find-identity-ownerid');
@@ -46,17 +46,27 @@ class ManagerReportAutoTest extends TestCase {
$raMan = new Manager\ReportAuto();
$type = $ratMan->create('raman test claimall type' . randomString(6), 'description', 'ReportAutoTest');
$type2 = $ratMan->create('raman test claimall type2' . randomString(6), 'description', 'ReportAutoTest');
$this->assertInstanceOf(ReportAuto\Type::class, $type, 'ratman-type-create-1');
$this->assertInstanceOf(ReportAuto\Type::class, $type2, 'ratman-type-create-2');
$r1 = $raMan->create($this->user1, $type, ['a' => 'b']);
$r2 = $raMan->create($this->user1, $type, ['a' => 'b']);
$r3 = $raMan->create($this->user1, $type2, ['a' => 'b']);
$r4 = $raMan->create($this->user2, $type, ['a' => 'b']);
$this->assertInstanceOf(ReportAuto::class, $r1, 'ratman-create-1');
$this->assertInstanceOf(ReportAuto::class, $r2, 'ratman-create-2');
$this->assertInstanceOf(ReportAuto::class, $r3, 'ratman-create-3');
$this->assertInstanceOf(ReportAuto::class, $r4, 'ratman-create-4');
$raMan->claimAll($this->user2, $this->user1->id(), $type->id());
$raMan->claimAll($this->user2, $this->user1->id, $type->id);
$r1n = $raMan->findById($r1->id());
$r2n = $raMan->findById($r2->id());
$r3n = $raMan->findById($r3->id());
$r4n = $raMan->findById($r4->id());
$r1n = $raMan->findById($r1->id);
$r2n = $raMan->findById($r2->id);
$r3n = $raMan->findById($r3->id);
$r4n = $raMan->findById($r4->id);
$this->assertInstanceOf(ReportAuto::class, $r1n, 'ratman-create-n-1');
$this->assertInstanceOf(ReportAuto::class, $r2n, 'ratman-create-n-2');
$this->assertInstanceOf(ReportAuto::class, $r3n, 'ratman-create-n-3');
$this->assertInstanceOf(ReportAuto::class, $r4n, 'ratman-create-n-4');
$this->assertTrue($r1n->isClaimed(), 'raman-claimall-1-1');
$this->assertFalse($r1n->isResolved(), 'raman-claimall-1-2');
$this->assertTrue($r2n->isClaimed(), 'raman-claimall-2-1');
@@ -66,25 +76,29 @@ class ManagerReportAutoTest extends TestCase {
$this->assertFalse($r4n->isClaimed(), 'raman-claimall-4-1');
$this->assertFalse($r4n->isResolved(), 'raman-claimall-4-2');
$raMan->claimAll($this->user1, $this->user1->id(), $type2->id());
$raMan->claimAll($this->user1, $this->user1->id, $type2->id);
$r1n = $raMan->findById($r1->id());
$r2n = $raMan->findById($r2->id());
$r3n = $raMan->findById($r3->id());
$r4n = $raMan->findById($r4->id());
$r1n = $raMan->findById($r1->id);
$r2n = $raMan->findById($r2->id);
$r3n = $raMan->findById($r3->id);
$r4n = $raMan->findById($r4->id);
$this->assertInstanceOf(ReportAuto::class, $r1n, 'ratman-create-n2-1');
$this->assertInstanceOf(ReportAuto::class, $r2n, 'ratman-create-n2-2');
$this->assertInstanceOf(ReportAuto::class, $r3n, 'ratman-create-n2-3');
$this->assertInstanceOf(ReportAuto::class, $r4n, 'ratman-create-n2-4');
$this->assertTrue($r1n->isClaimed(), 'raman-claimall-1-1');
$this->assertTrue($r2n->isClaimed(), 'raman-claimall-2-1');
$this->assertTrue($r3n->isClaimed(), 'raman-claimall-3-1');
$this->assertFalse($r4n->isClaimed(), 'raman-claimall-4-1');
$this->assertEquals($this->user2->id(), $r1n->ownerId(), 'raman-claimall-owner-1');
$this->assertEquals($this->user2->id(), $r2n->ownerId(), 'raman-claimall-owner-2');
$this->assertEquals($this->user1->id(), $r3n->ownerId(), 'raman-claimall-owner-3');
$this->assertEquals($this->user2->id, $r1n->ownerId(), 'raman-claimall-owner-1');
$this->assertEquals($this->user2->id, $r2n->ownerId(), 'raman-claimall-owner-2');
$this->assertEquals($this->user1->id, $r3n->ownerId(), 'raman-claimall-owner-3');
$this->assertEquals(null, $r4n->ownerId(), 'raman-claimall-owner-4');
$raMan->claimAll($this->user2, $this->user2->id(), null);
$r4n = $raMan->findById($r4->id());
$this->assertEquals($this->user2->id(), $r4n->ownerId(), 'raman-claimall-owner-5');
$raMan->claimAll($this->user2, $this->user2->id, null);
$r4n = $raMan->findById($r4->id);
$this->assertEquals($this->user2->id, $r4n->ownerId(), 'raman-claimall-owner-5');
$this->assertTrue($r4n->isClaimed(), 'raman-claimall-4-4');
}
@@ -98,12 +112,12 @@ class ManagerReportAutoTest extends TestCase {
$r3 = $raMan->create($this->user1, $type2, ['a' => 'b']);
$r4 = $raMan->create($this->user2, $type, ['a' => 'b']);
$raMan->resolveAll($this->user2, $this->user1->id(), $type->id());
$raMan->resolveAll($this->user2, $this->user1->id, $type->id);
$r1n = $raMan->findById($r1->id());
$r2n = $raMan->findById($r2->id());
$r3n = $raMan->findById($r3->id());
$r4n = $raMan->findById($r4->id());
$r1n = $raMan->findById($r1->id);
$r2n = $raMan->findById($r2->id);
$r3n = $raMan->findById($r3->id);
$r4n = $raMan->findById($r4->id);
$this->assertTrue($r1n->isClaimed(), 'raman-resolveall-1-1');
$this->assertTrue($r1n->isResolved(), 'raman-resolveall-1-2');
$this->assertTrue($r2n->isClaimed(), 'raman-resolveall-2-1');
@@ -113,25 +127,25 @@ class ManagerReportAutoTest extends TestCase {
$this->assertFalse($r4n->isClaimed(), 'raman-resolveall-4-1');
$this->assertFalse($r4n->isResolved(), 'raman-resolveall-4-2');
$raMan->resolveAll($this->user1, $this->user1->id(), $type2->id());
$raMan->resolveAll($this->user1, $this->user1->id, $type2->id);
$r1n = $raMan->findById($r1->id());
$r2n = $raMan->findById($r2->id());
$r3n = $raMan->findById($r3->id());
$r4n = $raMan->findById($r4->id());
$r1n = $raMan->findById($r1->id);
$r2n = $raMan->findById($r2->id);
$r3n = $raMan->findById($r3->id);
$r4n = $raMan->findById($r4->id);
$this->assertTrue($r1n->isResolved(), 'raman-resolveall-1-3');
$this->assertTrue($r2n->isResolved(), 'raman-resolveall-2-3');
$this->assertTrue($r3n->isResolved(), 'raman-resolveall-3-3');
$this->assertFalse($r4n->isResolved(), 'raman-resolveall-4-3');
$this->assertEquals($this->user2->id(), $r1n->ownerId(), 'raman-resolveall-owner-1');
$this->assertEquals($this->user2->id(), $r2n->ownerId(), 'raman-resolveall-owner-2');
$this->assertEquals($this->user1->id(), $r3n->ownerId(), 'raman-resolveall-owner-3');
$this->assertEquals($this->user2->id, $r1n->ownerId(), 'raman-resolveall-owner-1');
$this->assertEquals($this->user2->id, $r2n->ownerId(), 'raman-resolveall-owner-2');
$this->assertEquals($this->user1->id, $r3n->ownerId(), 'raman-resolveall-owner-3');
$this->assertEquals(null, $r4n->ownerId(), 'raman-resolveall-owner-4');
$raMan->resolveAll($this->user2, $this->user2->id(), null);
$r4n = $raMan->findById($r4->id());
$this->assertEquals($this->user2->id(), $r4n->ownerId(), 'raman-resolveall-owner-5');
$raMan->resolveAll($this->user2, $this->user2->id, null);
$r4n = $raMan->findById($r4->id);
$this->assertEquals($this->user2->id, $r4n->ownerId(), 'raman-resolveall-owner-5');
$this->assertTrue($r4n->isResolved(), 'raman-resolveall-4-4');
}
@@ -144,7 +158,7 @@ class ManagerReportAutoTest extends TestCase {
$this->assertTrue($r->hasComments(), 'raman-delcomment-1');
$this->assertLessThan(1, $raMan->deleteComment($commentId, $this->user2), 'raman-delcomment-2');
$raMan->deleteComment($commentId, $this->user1);
$r = $raMan->findById($r->id());
$r = $raMan->findById($r->id);
$this->assertFalse($r->hasComments(), 'raman-delcomment-3');
}
@@ -157,7 +171,7 @@ class ManagerReportAutoTest extends TestCase {
$this->assertLessThan(1, $raMan->editComment($commentId, $this->user2, "nomessage"), 'raman-editcomment-1');
$this->assertEquals("testcomment", $r->comments()[0]['comment'], 'raman-editcomment-2');
$this->assertEquals(1, $raMan->editComment($commentId, $this->user1, "newmessage"), 'raman-editcomment-3');
$r = $raMan->findById($r->id());
$r = $raMan->findById($r->id);
$this->assertEquals("newmessage", $r->comments()[0]['comment'], 'raman-editcomment-4');
}
}

View File

@@ -18,30 +18,26 @@ class ReportAutoTypeTest extends TestCase {
public function testCreate(): void {
$type = $this->ratMan->create('type name', 'useful description');
$this->assertNotNull($type, 'ratman-create-nocat1');
$this->assertEquals('type name', $type->name(), 'ratman-create-nocat2');
$type2 = $this->ratMan->create('type name', 'useful description');
$this->assertNull($type2, 'ratman-create-exists');
$catId = $this->ratMan->createCategory('somecategory');
$this->assertGreaterThan(0, $catId, 'ratman-create-cat-valid');
$type2 = $this->ratMan->create('type2 name', 'useful description', 'somecategory');
$this->assertNotNull($type2, 'ratman-create-cat1');
$this->assertEquals($catId, $type2->categoryId(), 'ratman-create-cat2');
$type3 = $this->ratMan->create('type3 name', 'useful description', 'newcat');
$this->assertNotNull($type3, 'ratman-create-newcat1');
$this->assertEquals('newcat', $type3->category(), 'ratman-create-newcat2');
$type4 = $this->ratMan->create('type4 name', 'useful description', 'newcat');
$this->assertEquals('newcat', $type4->category(), 'ratman-create-newcat4');
$this->assertEquals($type3->categoryId(), $type4->categoryId(), 'ratman-create-newcat5');
$type4_n = $this->ratMan->findById($type4->id());
$type4_n = $this->ratMan->findById($type4->id);
$this->assertInstanceOf(ReportAuto\Type::class, $type4_n, 'ratman-find-instance-n');
$this->assertEquals($type4, $type4_n, 'ratman-find-id');
$type4_nn = $this->ratMan->findByName($type4->name());
$this->assertInstanceOf(ReportAuto\Type::class, $type4_nn, 'ratman-find-instance-nn');
$this->assertEquals($type4, $type4_nn, 'ratman-find-name');
}
}

View File

@@ -42,13 +42,13 @@ class ReportManagerTest extends TestCase {
tagList: 'disco funk metal',
);
$manager = new Manager\Report(new Manager\User());
$report = $manager->create($this->userList[1], $this->collage->id(), 'collage', 'phpunit collage report');
$report = $manager->create($this->userList[1], $this->collage->id, 'collage', 'phpunit collage report');
$this->reportList[] = $report;
$this->assertEquals("phpunit collage report", $report->reason(), 'collage-report-reason');
$this->assertEquals($this->collage->id(), $report->subjectId(), 'collage-report-subject-id');
$this->assertEquals($this->collage->id, $report->subjectId(), 'collage-report-subject-id');
$this->assertEquals(1, $report->resolve($this->userList[0]));
$reportSubject = new Report\Collage($report->id(), $this->collage);
$reportSubject = new Report\Collage($report->id, $this->collage);
$this->assertFileExists(TEMPLATE_PATH . $reportSubject->template(), 'collage-report-template');
$this->assertStringContainsString($this->collage->url(), $reportSubject->bbLink(), 'collage-report-bblink');
$this->assertEquals('Collage Report: ', $reportSubject->titlePrefix(), 'collage-report-title-prefix');
@@ -56,10 +56,12 @@ class ReportManagerTest extends TestCase {
}
public function testReportRequest(): void {
$categoryId = (new Manager\Category())->findIdByName('Comics');
$this->assertNotNull($categoryId, 'report-cat-not-null');
$this->request = (new Manager\Request())->create(
user: $this->userList[1],
bounty: REQUEST_MIN * 1024 * 1024,
categoryId: (new Manager\Category())->findIdByName('Comics'),
categoryId: $categoryId,
year: (int)date('Y'),
title: 'phpunit request report',
image: '',
@@ -78,17 +80,17 @@ class ReportManagerTest extends TestCase {
$manager = new Manager\Report(new Manager\User());
$initial = $manager->remainingTotal();
$report = $manager->create($this->userList[1], $this->request->id(), 'request', 'phpunit report');
$report = $manager->create($this->userList[1], $this->request->id, 'request', 'phpunit report');
$this->reportList[] = $report;
$this->assertEquals($initial + 1, $manager->remainingTotal(), 'request-report-one-more');
$this->assertEquals('New', $report->status(), 'request-report-status-new');
$this->assertEquals('phpunit report', $report->reason(), 'request-report-reason');
$this->assertEquals($this->userList[1]->id(), $report->reporter()?->id(), 'request-report-reporter-id');
$this->assertEquals($this->userList[1]->id, $report->reporter()?->id, 'request-report-reporter-id');
$this->assertEquals('request', $report->subjectType(), 'request-report-subject-type');
$this->assertEquals($this->request->id(), $report->subjectId(), 'request-report-subject-id');
$this->assertEquals($this->request->id, $report->subjectId(), 'request-report-subject-id');
$this->assertEquals(
"<a href=\"reports.php?id={$report->id()}#report{$report->id()}\">Report #{$report->id()}</a>",
"<a href=\"reports.php?id={$report->id}#report{$report->id}\">Report #{$report->id}</a>",
$report->link(),
'request-report-link'
);
@@ -99,7 +101,7 @@ class ReportManagerTest extends TestCase {
$this->assertFalse($report->isClaimed(), 'request-report-not-yet-claimed');
// report specifics
$reqReport = new Report\Request($report->id(), $this->request);
$reqReport = new Report\Request($report->id, $this->request);
$this->assertFileExists(TEMPLATE_PATH . $reqReport->template(), 'request-report-template');
$this->assertStringContainsString($this->request->url(), $reqReport->bbLink(), 'request-report-bblink');
$this->assertEquals('Request Report: ', $reqReport->titlePrefix(), 'request-report-title-prefix');
@@ -117,14 +119,14 @@ class ReportManagerTest extends TestCase {
$this->assertEquals('InProgress', $report->flush()->status(), 'request-report-in-progress');
$claimer = $report->claimer();
$this->assertNotNull($claimer, 'request-report-has-claimer'); /** @phpstan-ignore-line phpstan cannot decide if $resolver is null or not */
$this->assertEquals($this->userList[0]->id(), $claimer->id(), 'request-report-claimer-id');
$this->assertEquals($this->userList[0]->id, $claimer->id, 'request-report-claimer-id');
$this->assertEquals(1, $report->claim(null), 'request-report-unclaim');
$this->assertFalse($report->isClaimed(), 'request-report-is-unclaimed');
// search
$this->assertCount(
1,
(new Search\Report())->setId($report->id())->page(2, 0),
(new Search\Report())->setId($report->id)->page(2, 0),
'request-report-search-id'
);
$this->assertEquals(
@@ -142,7 +144,7 @@ class ReportManagerTest extends TestCase {
$total = $search->setStatus(['InProgress'])->total();
$page = $search->page($total, 0);
$this->assertEquals($total, count($page), 'request-report-page-list');
$this->assertEquals($report->id(), $page[0], 'request-report-page-id');
$this->assertEquals($report->id, $page[0], 'request-report-page-id');
// resolve
$this->assertEquals(1, $report->resolve($this->userList[0]), 'request-report-claim');
@@ -150,31 +152,31 @@ class ReportManagerTest extends TestCase {
$this->assertEquals('Resolved', $report->status(), 'request-report-resolved-status');
$resolver = $report->resolver();
$this->assertNotNull($resolver, 'request-report-has-resolver'); /** @phpstan-ignore-line phpstan cannot decide if $resolver is null or not */
$this->assertEquals($this->userList[0]->id(), $resolver->id(), 'request-report-resolver-id');
$this->assertEquals($this->userList[0]->id, $resolver->id, 'request-report-resolver-id');
$this->assertEquals($initial, $manager->remainingTotal(), 'request-report-initial-total');
}
public function testReportUser(): void {
$manager = new Manager\Report(new Manager\User());
$report = $manager->create($this->userList[0], $this->userList[1]->id(), 'user', 'phpunit user report');
$report = $manager->create($this->userList[0], $this->userList[1]->id, 'user', 'phpunit user report');
$this->reportList[] = $report;
$this->assertInstanceOf(Report::class, $report, 'report-user-create');
$this->assertEquals(
"<a href=\"{$report->url()}\">Report #{$report->id()}</a>",
"<a href=\"{$report->url()}\">Report #{$report->id}</a>",
$report->link(),
'report-link'
);
$this->assertEquals(
"reports.php?id={$report->id()}#report{$report->id()}",
"reports.php?id={$report->id}#report{$report->id}",
$report->location(),
'report-location'
);
$this->assertEquals('phpunit user report', $report->reason(), 'report-reason');
$this->assertEquals('New', $report->status(), 'report-new-status');
$this->assertEquals($this->userList[1]->id(), $report->subjectId(), 'report-subject-id');
$this->assertEquals($this->userList[1]->id, $report->subjectId(), 'report-subject-id');
$this->assertEquals('user', $report->subjectType(), 'report-subject-type');
$this->assertEquals($this->userList[0]->id(), $report->reporter()->id(), 'report-reporter');
$this->assertEquals($this->userList[0]->id, $report->reporter()?->id, 'report-reporter');
$this->assertFalse($report->isClaimed(), 'report-is-not-claimed');
$this->assertNull($report->resolved(), 'report-not-resolved');
$this->assertMatchesRegularExpression('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/', $report->created(), 'report-created');
@@ -183,9 +185,13 @@ class ReportManagerTest extends TestCase {
$report->addNote('phpunit add note');
$this->assertEquals('phpunit add note', $report->notes(), 'report-add-notes');
$this->assertEquals($report->id(), $manager->findById($report->id())->id(), 'report-user-find');
$this->assertInstanceOf(
Report::class,
$manager->findById($report->id),
'report-user-find'
);
$reportSubject = new Report\User($report->id(), $this->userList[1]);
$reportSubject = new Report\User($report->id, $this->userList[1]);
$this->assertFileExists(TEMPLATE_PATH . $reportSubject->template(), 'user-report-template');
$this->assertStringContainsString($this->userList[1]->username(), $reportSubject->bbLink(), 'user-report-bblink');
$this->assertEquals('User Report: ', $reportSubject->titlePrefix(), 'user-report-title-prefix');
@@ -202,13 +208,13 @@ class ReportManagerTest extends TestCase {
description: 'phpunit collage report description',
tagList: 'disco funk metal',
);
$report = $manager->create($this->userList[1], $this->collage->id(), 'collage', 'phpunit collage report');
$report = $manager->create($this->userList[1], $this->collage->id, 'collage', 'phpunit collage report');
$this->reportList[] = $report;
$report = $manager->create($this->userList[0], $this->userList[1]->id(), 'user', 'phpunit user report');
$report = $manager->create($this->userList[0], $this->userList[1]->id, 'user', 'phpunit user report');
$this->reportList[] = $report;
$list = $manager->decorate(
array_map(fn($r) => $r->id(), $this->reportList),
array_map(fn($r) => $r->id, $this->reportList),
new Manager\Collage(),
new Manager\Comment(),
new Manager\ForumThread(),
@@ -217,7 +223,7 @@ class ReportManagerTest extends TestCase {
);
$this->assertCount(2, $list, 'report-decorate-list');
$this->assertEquals('collage', $list[0]['label'], 'report-list-label');
$this->assertEquals($this->collage->id(), $list[0]['subject']->id(), 'report-list-subject-id');
$this->assertEquals($this->collage->id, $list[0]['subject']->id, 'report-list-subject-id');
$this->assertNull($list[0]['context'], 'report-list-collage-context-null');
}
}

View File

@@ -40,9 +40,9 @@ class TGroupManagerTest extends TestCase {
public function testFindByTorrentId(): void {
$manager = new Manager\TGroup();
$torrentId = $this->torrentList[0]->id();
$this->assertEquals(
$this->tgroupList[0]->id(),
$manager->findByTorrentId($torrentId)->id(),
$this->assertInstanceOf(
TGroup::class,
$manager->findByTorrentId($torrentId),
'tgman-find-by-torrent-id'
);
}
@@ -50,9 +50,9 @@ class TGroupManagerTest extends TestCase {
public function testFindByInfohash(): void {
$manager = new Manager\TGroup();
$infohash = $this->torrentList[0]->infohash();
$this->assertEquals(
$this->tgroupList[0]->id(),
$manager->findByTorrentInfohash($infohash)->id(),
$this->assertInstanceOf(
TGroup::class,
$manager->findByTorrentInfohash($infohash),
'tgman-find-by-torrent-id'
);
}

View File

@@ -45,6 +45,7 @@ class TorrentReportManagerTest extends TestCase {
public function testWorkflowReport(): void {
$torMan = new Manager\Torrent();
$torrent = $torMan->findById($this->tgroup->torrentIdList()[0]);
$this->assertInstanceOf(Torrent::class, $torrent, 'trep-workflow-found');
$title = [
'torrent extra 1 ' . randomString(10),
'torrent extra 2 ' . randomString(10),
@@ -61,14 +62,16 @@ class TorrentReportManagerTest extends TestCase {
title: $title[1],
),
];
$extraIdList = [$extra[0]->id(), $extra[1]->id()];
$extraIdList = [$extra[0]->id, $extra[1]->id];
$manager = new Manager\Torrent\Report($torMan);
$typeManager = new Manager\Torrent\ReportType();
$type = $typeManager->findByName('other');
$this->assertInstanceOf(Torrent\ReportType::class, $type, 'trep-type-found');
$this->assertCount(8, $manager->categories(), 'trep-categories');
$report = $manager->create(
torrent: $torrent,
user: $this->userList[1],
reportType: $typeManager->findByName('other'),
reportType: $type,
reason: 'phpunit other report',
otherIdList: implode(' ', $extraIdList),
irc: new Util\Irc(),
@@ -78,28 +81,28 @@ class TorrentReportManagerTest extends TestCase {
'trep-recent',
);
$this->assertEquals(
$report->id,
$manager->findById($report->id)->id,
$this->assertInstanceOf(
Torrent\Report::class,
$manager->findById($report->id),
'trep-find-by-id'
);
$this->assertEquals(
$report->id,
$manager->findNewest()->id,
$this->assertInstanceOf(
Torrent\Report::class,
$manager->findNewest(),
'trep-newest'
);
$this->assertTrue(Helper::recentDate($report->created()), 'trep-created');
$this->assertCount(0, $report->externalLink(), 'trep-external-link');
$this->assertCount(0, $report->trackList(), 'trep-track-list');
$this->assertStringEndsWith("id={$report->id()}", $report->location(), 'trep-location');
$this->assertStringEndsWith("id={$report->id}", $report->location(), 'trep-location');
$this->assertEquals('phpunit other report', $report->reason(), 'trep-reason');
$this->assertEquals($this->userList[1]->id(), $report->reporterId(), 'trep-reporter-id');
$this->assertEquals($this->userList[1]->id, $report->reporterId(), 'trep-reporter-id');
$this->assertEquals('New', $report->status(), 'trep-report-status');
$this->assertEquals('Other', $report->reportType()->name(), 'trep-report-type-name');
$this->assertEquals('other', $report->type(), 'trep-name');
$this->assertEquals($this->tgroup->torrentIdList()[2], $report->torrentId(), 'trep-torrent-id');
$this->assertEquals($this->tgroup->torrentIdList()[2], $report->torrent()->id(), 'trep-torrent-object');
$this->assertEquals($this->tgroup->torrentIdList()[2], $report->torrent()?->id, 'trep-torrent-object');
$other = current(array_filter($manager->newSummary(), fn ($r) => $r['type'] === 'other'));
$this->assertEquals(1, $other['total'], 'trep-new-summary-other');
$this->assertEquals(
@@ -154,10 +157,14 @@ class TorrentReportManagerTest extends TestCase {
public function testModeratorResolve(): void {
$torMan = new Manager\Torrent();
$manager = new Manager\Torrent\Report($torMan);
$torrent = $torMan->findById($this->tgroup->torrentIdList()[0]);
$this->assertInstanceOf(Torrent::class, $torrent, 'trep-mod-resolver-found');
$reportType = (new Manager\Torrent\ReportType())->findByName('other');
$this->assertInstanceOf(Torrent\ReportType::class, $reportType, 'trep-report-type-search-found');
$report = $manager->create(
torrent: $torMan->findById($this->tgroup->torrentIdList()[0]),
torrent: $torrent,
user: $this->userList[1],
reportType: (new Manager\Torrent\ReportType())->findByName('other'),
reportType: $reportType,
reason: 'phpunit other report',
otherIdList: '123 234',
irc: new Util\Irc(),
@@ -175,10 +182,13 @@ class TorrentReportManagerTest extends TestCase {
$torMan = new Manager\Torrent();
$manager = new Manager\Torrent\Report($torMan);
$torrent = $torMan->findById($this->tgroup->torrentIdList()[0]);
$this->assertInstanceOf(Torrent::class, $torrent, 'trep-search-found');
$reportType = (new Manager\Torrent\ReportType())->findByName('other');
$this->assertInstanceOf(Torrent\ReportType::class, $reportType, 'trep-report-type-search-found');
$report = $manager->create(
torrent: $torrent,
user: $this->userList[1],
reportType: (new Manager\Torrent\ReportType())->findByName('other'),
reportType: $reportType,
reason: 'phpunit search report',
otherIdList: '1234 5678',
irc: new Util\Irc(),
@@ -200,6 +210,7 @@ class TorrentReportManagerTest extends TestCase {
public function testModifyReport(): void {
$reportType = (new Manager\Torrent\ReportType())->findByName('other');
$this->assertInstanceOf(Torrent\ReportType::class, $reportType, 'report-torrent-found');
$reportType->setChangeset($this->userList[0], [['field' => 'is_admin', 'old' => $reportType->isAdmin(), 'new' => 0]]);
$this->assertFalse($reportType->setField('is_admin', false)->modify(), 'trep-modify');
}
@@ -215,6 +226,7 @@ class TorrentReportManagerTest extends TestCase {
$torrentId = $this->tgroup->torrentIdList()[0];
$torrent = $torMan->findById($torrentId);
$this->assertInstanceOf(Torrent::class, $torrent, 'trep-torrent-find');
$report = (new Manager\Torrent\Report($torMan))->create(
torrent: $torrent,
user: $this->userList[1],
@@ -226,6 +238,7 @@ class TorrentReportManagerTest extends TestCase {
$this->assertEquals([], $torrent->labelList($this->userList[0]), 'uploader-report-label');
$urgent = $torMan->findById($torrentId);
$this->assertInstanceOf(Torrent::class, $urgent, 'trep-urgent-find');
$labelList = $urgent->labelList($this->userList[1]);
$this->assertCount(1, $labelList, 'reporter-report-label');
$this->assertStringContainsString('Reported', $labelList[0], 'reporter-report-urgent');
@@ -245,6 +258,7 @@ class TorrentReportManagerTest extends TestCase {
);
$dupe = $manager->findById(1);
$this->assertInstanceOf(Torrent\ReportType::class, $dupe, 'trep-dupe-find');
$this->assertEquals(
'Dupe',
$dupe->name(),
@@ -257,12 +271,12 @@ class TorrentReportManagerTest extends TestCase {
);
$this->assertEquals(
'dupe',
$manager->findByName('Dupe')->type(),
$manager->findByName('Dupe')?->type(),
'trep-type-find-by-name',
);
$this->assertEquals(
1,
$manager->findByType('dupe')->id,
$manager->findByType('dupe')?->id,
'trep-type-find-by-type',
);

View File

@@ -369,11 +369,20 @@ class UserManagerTest extends TestCase {
$pmMan = new Manager\PM($receiver->user());
$this->assertEquals(1, $receiver->messageTotal(), 'uman-custom-pm-count');
$list = $receiver->messageList($pmMan, 2, 0);
$this->assertEquals('phpunit sendCustomPMTest', $list[0]->subject(), 'uman-custom-pm-subject');
$this->assertEquals(
'phpunit sendCustomPMTest',
$list[0]->subject(),
'uman-custom-pm-subject'
);
$postlist = $list[0]->postlist(10, 0);
$postId = $postlist[0]['id'];
$pm = $pmMan->findByPostId($postId);
$this->assertStringContainsString($this->userList[2]->username(), $pm->postBody($postId), 'uman-custom-pm-body');
$this->assertInstanceOf(PM::class, $pm, 'uman-found-pm');
$this->assertStringContainsString(
$this->userList[2]->username(),
(string)$pm->postBody($postId),
'uman-custom-pm-body'
);
}
public function testUserclassFlush(): void {
@@ -403,9 +412,9 @@ class UserManagerTest extends TestCase {
public function testUserFind(): void {
$manager = new Manager\User();
$this->assertEquals(
$this->userList[0]->id,
$manager->findByEmail($this->userList[0]->email())->id,
$this->assertInstanceOf(
User::class,
$manager->findByEmail($this->userList[0]->email()),
'userman-find-by-email'
);
}

View File

@@ -173,8 +173,12 @@ class SearchReportAutoTest extends TestCase {
public function testId(): void {
$search = new Search\ReportAuto(self::$raMan, self::$ratMan);
$search->setId(self::$report->id());
$this->matchThingList($search->typeTotalList(), self::$ratMan->findById(self::$report->typeId()), 1, 'id-1');
$this->matchThingList(
$search->typeTotalList(),
self::$ratMan->findById(self::$report->typeId()),
1,
'id-1'
);
}
public function testIdNoExist(): void {