mirror of
https://github.com/OPSnet/Gazelle.git
synced 2026-01-16 18:04:34 -05:00
660 lines
27 KiB
PHP
660 lines
27 KiB
PHP
<?php
|
|
|
|
namespace Gazelle;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use GazelleUnitTest\Helper;
|
|
use Gazelle\Enum\CollageType;
|
|
|
|
class ArtistTest extends TestCase {
|
|
protected Artist $artist;
|
|
protected Collage $collage;
|
|
protected array $tgroupList;
|
|
protected User $user;
|
|
protected User $extra;
|
|
protected array $artistIdList = [];
|
|
|
|
public function setUp(): void {
|
|
$this->user = Helper::makeUser('arty.' . randomString(10), 'artist');
|
|
$this->user->requestContext()->setViewer($this->user);
|
|
}
|
|
|
|
public function tearDown(): void {
|
|
$manager = new Manager\Artist();
|
|
foreach ($this->artistIdList as $artistId) {
|
|
$manager->findById($artistId)?->remove();
|
|
}
|
|
if (isset($this->extra)) {
|
|
$this->extra->remove();
|
|
}
|
|
if (isset($this->collage)) {
|
|
$this->collage->hardRemove();
|
|
}
|
|
if (isset($this->tgroupList)) {
|
|
foreach ($this->tgroupList as $tgroup) {
|
|
Helper::removeTGroup($tgroup, $this->user);
|
|
}
|
|
}
|
|
$this->user->remove();
|
|
}
|
|
|
|
public function testArtistCreate(): void {
|
|
$manager = new Manager\Artist();
|
|
$this->assertNull($manager->findById(-666), 'artist-find-fail');
|
|
|
|
$artist = $manager->create('phpunit.' . randomString(12));
|
|
$this->artistIdList[] = $artist->id;
|
|
|
|
// fake it
|
|
DB::DB()->prepared_query("
|
|
INSERT INTO artist_usage
|
|
(artist_id, artist_role_id, uses)
|
|
VALUES (?, ?, ?)
|
|
", $artist->id, 1, RANDOM_ARTIST_MIN_ENTRIES
|
|
);
|
|
|
|
// before test run: TRUNCATE TABLE artst_usage;
|
|
// and then: new Stats\Artists()->updateUsage();
|
|
$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');
|
|
$this->assertGreaterThan(0, $artist->aliasId(), 'artist-create-alias-id');
|
|
$artist = $manager->findById($artist->id);
|
|
$this->assertInstanceOf(Artist::class, $artist, 'artist-is-an-artist');
|
|
|
|
$this->assertNull($manager->findByIdAndRevision($artist->id, -1), 'artist-is-an-unrevised-artist');
|
|
// empty, but at least it tests the SQL
|
|
$this->assertCount(0, $artist->tagLeaderboard(), 'artist-tag-leaderboard');
|
|
}
|
|
|
|
public function testArtistInfo(): void {
|
|
$manager = new Manager\Artist();
|
|
$artist = $manager->create('phpunit.' . randomString(12));
|
|
$this->artistIdList[] = $artist->id;
|
|
|
|
$this->assertEquals("<a href=\"artist.php?id={$artist->id}\">{$artist->name()}</a>", $artist->link(), 'artist-link');
|
|
$this->assertEquals("artist.php?id={$artist->id}", $artist->location(), 'artist-location');
|
|
$this->assertNull($artist->body(), 'artist-body-null');
|
|
$this->assertNull($artist->image(), 'artist-image-null');
|
|
$this->assertFalse($artist->isLocked(), 'artist-is-unlocked');
|
|
$this->assertTrue($artist->toggleAttr('locked', true), 'artist-toggle-locked');
|
|
$this->assertTrue($artist->isLocked(), 'artist-is-locked');
|
|
}
|
|
|
|
public function testArtistAPI(): void {
|
|
$manager = new Manager\Artist();
|
|
$artist = $manager->create('phpunit.' . randomString(12));
|
|
$this->artistIdList[] = $artist->id;
|
|
$_GET['req'] = 'artist';
|
|
$_GET['artist_id'] = $artist->id;
|
|
$this->assertEquals(
|
|
[
|
|
'ArtistID' => $artist->id,
|
|
'Name' => $artist->name(),
|
|
],
|
|
new API\Artist([])->run(),
|
|
'artist-api',
|
|
);
|
|
}
|
|
|
|
public function testArtistRevision(): void {
|
|
$manager = new Manager\Artist();
|
|
$artist = $manager->create('phpunit.' . randomString(12));
|
|
$this->artistIdList[] = $artist->id;
|
|
|
|
$revision = $artist->createRevision(
|
|
body: 'phpunit body test',
|
|
image: 'https://example.com/artist.jpg',
|
|
summary: ['phpunit first revision'],
|
|
user: $this->user,
|
|
);
|
|
$this->assertGreaterThan(0, $revision, 'artist-revision-1-id');
|
|
$this->assertEquals('phpunit body test', $artist->body(), 'artist-body-revised');
|
|
|
|
$rev2 = $artist->createRevision(
|
|
body: 'phpunit body test revised',
|
|
image: 'https://example.com/artist-revised.jpg',
|
|
summary: ['phpunit second revision'],
|
|
user: $this->user,
|
|
);
|
|
$this->assertEquals($revision + 1, $rev2, 'artist-revision-2');
|
|
$this->assertEquals('https://example.com/artist-revised.jpg', $artist->image(), 'artist-image-revised');
|
|
|
|
$artistV1 = $manager->findByIdAndRevision($artist->id, $revision);
|
|
$this->assertNotNull($artistV1, 'artist-revision-1-found');
|
|
$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();
|
|
$this->assertEquals('phpunit second revision', $list[0]['summary']);
|
|
$this->assertEquals($revision, $list[1]['revision']);
|
|
|
|
$artist->revertRevision($revision, $this->user);
|
|
$this->assertCount(3, $artist->revisionList());
|
|
$this->assertEquals($artistV1->body(), $artist->body(), 'artist-body-rev-3');
|
|
}
|
|
|
|
public function testArtistAlias(): void {
|
|
$manager = new Manager\Artist();
|
|
$artist = $manager->create('phpunit.' . randomString(12));
|
|
$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(
|
|
1,
|
|
$manager->aliasUseTotal($artist->aliasId()),
|
|
'artist-sole-alias'
|
|
);
|
|
$this->assertCount(
|
|
0,
|
|
$manager->tgroupList($artist->aliasId(), new Manager\TGroup()),
|
|
'artist-no-tgroup'
|
|
);
|
|
|
|
$aliasName = $artist->name() . '-alias';
|
|
$newId = $artist->addAlias($aliasName, 0, $this->user);
|
|
$this->assertEquals($artist->aliasId() + 1, $newId, 'artist-new-alias');
|
|
$this->assertEquals(2, $manager->aliasUseTotal($artist->aliasId()), 'artist-two-alias');
|
|
|
|
$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');
|
|
}
|
|
|
|
public function testArtistNonRedirAlias(): void {
|
|
$manager = new Manager\Artist();
|
|
$artist = $manager->create('phpunit.' . randomString(12));
|
|
$this->artistIdList[] = $artist->id;
|
|
|
|
$aliasName = $artist->name() . '-reformed';
|
|
$newId = $artist->addAlias($aliasName, $artist->id, $this->user);
|
|
$this->assertEquals(
|
|
$artist->aliasId() + 1,
|
|
$newId,
|
|
'artist-new-non-redirect'
|
|
);
|
|
$aliasInfo = $artist->aliasInfo();
|
|
$this->assertCount(2, $aliasInfo, 'artist-alias-count');
|
|
$aliasId = $artist->aliasId();
|
|
$this->assertEquals(
|
|
[
|
|
'alias' => [],
|
|
'alias_id' => $aliasId,
|
|
'name' => $artist->name(),
|
|
'user' => null,
|
|
],
|
|
$aliasInfo[$aliasId],
|
|
'artist-alias-alias-id'
|
|
);
|
|
$artistInfo = $aliasInfo[$artist->id];
|
|
$this->assertArrayHasKey('alias', $artistInfo, 'artist-alias-has-key');
|
|
$alias = current($artistInfo['alias']);
|
|
$this->assertEquals($newId, $alias['alias_id'], 'artist-alias-artist-id');
|
|
$this->assertEquals($aliasName, $alias['name'], 'artist-alias-name');
|
|
$this->assertEquals($this->user->id, $alias['user']->id, 'artist-alias-user');
|
|
}
|
|
|
|
public function testArtistMerge(): void {
|
|
$manager = new Manager\Artist();
|
|
$oldName = 'phpunit.artist.' . randomString(12);
|
|
$old = $manager->create($oldName);
|
|
$oldAliasId = $old->aliasId();
|
|
$this->artistIdList[] = $old->id;
|
|
|
|
$newName = 'phpunit.artist.' . randomString(12);
|
|
$new = $manager->create($newName);
|
|
$this->artistIdList[] = $new->id;
|
|
|
|
$userBk = new User\Bookmark($this->user);
|
|
$userBk->create($old);
|
|
|
|
$commentMan = new Manager\Comment();
|
|
$postList = [
|
|
$commentMan->create($this->user, 'artist', $old->id, 'phpunit merge ' . randomString(6)),
|
|
$commentMan->create($this->user, 'artist', $new->id, 'phpunit merge ' . randomString(6)),
|
|
];
|
|
|
|
$this->extra = Helper::makeUser('merge.' . randomString(10), 'merge');
|
|
$extraBk = new User\Bookmark($this->extra);
|
|
$extraBk->create($old);
|
|
$extraBk->create($new);
|
|
|
|
$collMan = new Manager\Collage();
|
|
$this->collage = $collMan->create(
|
|
user: $this->user,
|
|
categoryId: CollageType::artist->value,
|
|
name: 'phpunit merge artist ' . randomString(10),
|
|
description: 'phpunit merge artist description',
|
|
tagList: 'jazz',
|
|
);
|
|
$this->collage->addEntry($old, $this->user);
|
|
|
|
$this->tgroupList = [
|
|
Helper::makeTGroupMusic(
|
|
$this->user,
|
|
'phpunit artist merge1 ' . randomString(10),
|
|
[[ARTIST_MAIN], [$oldName]],
|
|
['hip.hop'],
|
|
),
|
|
Helper::makeTGroupMusic(
|
|
$this->user,
|
|
'phpunit artist merge2 ' . randomString(10),
|
|
[[ARTIST_MAIN], [$oldName, $newName]],
|
|
['hip.hop'],
|
|
),
|
|
];
|
|
|
|
$this->assertEquals(
|
|
1,
|
|
$new->merge(
|
|
$old,
|
|
false,
|
|
$this->user,
|
|
),
|
|
'artist-merge-n',
|
|
);
|
|
$this->assertNull($manager->findById($old->id), 'art-merge-no-old');
|
|
$this->assertTrue($userBk->isBookmarked($new), 'art-merge-user-bookmarked-new');
|
|
$this->assertTrue($extraBk->isBookmarked($new), 'art-merge-extra-bookmarked-new');
|
|
$this->assertCount(1, $extraBk->artistList(), 'art-merge-extra-bookmarked-list');
|
|
|
|
// FIXME: flushed collage objects cannot be refreshed
|
|
$merged = $collMan->findById($this->collage->id);
|
|
$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
|
|
$this->assertEquals(
|
|
[$postList[0]->id, $postList[1]->id],
|
|
array_map(fn($p) => $p['ID'], $comment->thread()),
|
|
'art-merge-comments'
|
|
);
|
|
|
|
$n = 0;
|
|
foreach ($this->tgroupList as $tgroup) {
|
|
++$n;
|
|
$artistRole = $tgroup->flush()->artistRole();
|
|
$this->assertEquals(
|
|
[ARTIST_MAIN => [['id' => $new->id, 'name' => $oldName, 'aliasid' => $oldAliasId]]],
|
|
$artistRole->idList(),
|
|
"art-merge-ar-$n"
|
|
);
|
|
}
|
|
}
|
|
|
|
public function testArtistModify(): void {
|
|
$manager = new Manager\Artist();
|
|
$artist = $manager->create('phpunit.' . randomString(12));
|
|
$this->artistIdList[] = $artist->id;
|
|
|
|
$this->assertTrue(
|
|
$artist->setField('body', 'body modification')->setUpdateUser($this->user)->modify(),
|
|
'artist-modify-body'
|
|
);
|
|
$this->assertCount(1, $artist->revisionList());
|
|
$this->assertTrue(
|
|
$artist->setField('VanityHouse', true)->setUpdateUser($this->user)->modify(),
|
|
'artist-modify-showcase'
|
|
);
|
|
$this->assertCount(1, $artist->revisionList());
|
|
|
|
$this->assertTrue(
|
|
$artist ->setField('image', 'https://example.com/update.png')
|
|
->setField('summary', 'You look nice in a suit')
|
|
->setUpdateUser($this->user)
|
|
->modify(),
|
|
'artist-modify-image'
|
|
);
|
|
$this->assertCount(2, $artist->revisionList());
|
|
}
|
|
|
|
public function testArtistRenameBasic(): void {
|
|
$manager = new Manager\Artist();
|
|
$artist = $manager->create('phpunit.' . randomString(12));
|
|
$this->artistIdList[] = $artist->id;
|
|
|
|
$oldName = $artist->name();
|
|
$rename = $artist->name() . '-rename';
|
|
$this->assertEquals(
|
|
$artist->aliasId() + 1,
|
|
$artist->renameAlias($artist->aliasId(), $rename, $this->user),
|
|
'alias-rename'
|
|
);
|
|
$this->assertContains($rename, $artist->aliasNameList(), 'alias-is-renamed');
|
|
$newAlias = array_filter($artist->aliasList(), fn($v) => $v['name'] == $rename)[0];
|
|
$oldAlias = array_filter($artist->aliasList(), fn($v) => $v['name'] == $oldName)[0];
|
|
$this->assertEquals($newAlias['alias_id'], $oldAlias['redirect_id'], 'alias-is-redirected');
|
|
}
|
|
|
|
public function testArtistRenamePrimary(): void {
|
|
$manager = new Manager\Artist();
|
|
$artist = $manager->create('phpunit.' . randomString(12));
|
|
$this->artistIdList[] = $artist->id;
|
|
|
|
$commentMan = new Manager\Comment();
|
|
$post = $commentMan->create($this->user, 'artist', $artist->id, 'phpunit smart rename ' . randomString(6));
|
|
|
|
$requestMan = new Manager\Request();
|
|
$request = Helper::makeRequestMusic(
|
|
user: $this->user,
|
|
title: 'phpunit smart rename ' . randomString(6),
|
|
releaseType: 1,
|
|
encoding: new Request\Encoding(list: ['Lossless']),
|
|
format: new Request\Format(list: ['MP3']),
|
|
media: new Request\Media(list: ['CD']),
|
|
);
|
|
$this->assertInstanceOf(
|
|
ArtistRole\Request::class,
|
|
$request->artistRole(),
|
|
'request-rename-has-artistrole'
|
|
);
|
|
$request->artistRole()->set(
|
|
[ARTIST_MAIN => [$artist->name()]],
|
|
$this->user,
|
|
new Manager\Artist(),
|
|
);
|
|
|
|
$this->tgroupList = [
|
|
Helper::makeTGroupMusic(
|
|
$this->user,
|
|
'phpunit artist smart rename ' . randomString(10),
|
|
[[ARTIST_MAIN], [$artist->name()]],
|
|
['deep.house'],
|
|
),
|
|
];
|
|
|
|
$name = $artist->name() . '-rename2';
|
|
$artist->renameAlias($artist->primaryAliasId(), $name, $this->user);
|
|
$this->assertEquals($name, $artist->name(), 'artist-is-smart-renamed');
|
|
|
|
$commentPage = new Comment\Artist($artist->id, 1, 0);
|
|
$commentPage->load();
|
|
$threadList = $commentPage->threadList(new Manager\User());
|
|
$this->assertCount(1, $threadList, 'artist-renamed-comments');
|
|
$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();
|
|
|
|
$this->tgroupList[0]->artistRole()->flush();
|
|
$idList = $this->tgroupList[0]->artistRole()->idList();
|
|
$this->assertEquals($artist->id, $idList[ARTIST_MAIN][0]['id'], 'artist-renamed-tgroup');
|
|
}
|
|
|
|
public function testRenameAliasCapchange(): void {
|
|
$artistMan = new Manager\Artist();
|
|
$reqMan = new Manager\Request();
|
|
$tgMan = new Manager\TGroup();
|
|
$mainName = 'phpunit.' . randomString(12);
|
|
$artist = $artistMan->create($mainName);
|
|
$mainAliasId = $artist->aliasId();
|
|
$aliasName = 'phpunit.' . randomString(12) . '-alias';
|
|
$artist->addAlias($aliasName, null, $this->user);
|
|
|
|
$aliasUpper = strtoupper($aliasName);
|
|
$aliasId = $artist->getAlias($aliasName);
|
|
$this->assertNotNull($aliasId, 'artist-rename-capchange-create');
|
|
$this->assertEquals(
|
|
$aliasId,
|
|
$artist->renameAlias($aliasId, $aliasUpper, $this->user),
|
|
'artist-rename-capchange-1',
|
|
);
|
|
$this->assertEquals(
|
|
$aliasId,
|
|
$artist->getAlias($aliasName),
|
|
'artist-rename-capchange-2',
|
|
);
|
|
$this->assertEquals(
|
|
$mainAliasId,
|
|
$artist->primaryAliasId(),
|
|
'artist-rename-capchange-sanity',
|
|
);
|
|
}
|
|
|
|
public function testRenameAliasNraMerge(): void {
|
|
$artistMan = new Manager\Artist();
|
|
$reqMan = new Manager\Request();
|
|
$tgMan = new Manager\TGroup();
|
|
$mainName = 'phpunit.' . randomString(12);
|
|
$artist = $artistMan->create($mainName);
|
|
$mainAliasId = $artist->aliasId();
|
|
|
|
// create NRA
|
|
$a1Name = 'phpunit.' . randomString(12) . '-alias';
|
|
$a1Id = $artist->addAlias($a1Name, null, $this->user);
|
|
|
|
// add RA
|
|
$raAliasName = $a1Name . '-raalias';
|
|
$raId = $artist->addAlias($raAliasName, $a1Id, $this->user);
|
|
|
|
// create second NRA
|
|
$a2Name = 'phpunit.' . randomString(12) . '-alias';
|
|
$a2Id = $artist->addAlias($a2Name, null, $this->user);
|
|
|
|
$this->assertEquals(
|
|
$a2Id,
|
|
$artist->renameAlias($a1Id, $a2Name, $this->user),
|
|
'artist-rename-nramerge-1',
|
|
);
|
|
|
|
$a1 = $artist->aliasList()[$a1Id];
|
|
$a2 = $artist->aliasList()[$a2Id];
|
|
$ra = $artist->aliasList()[$raId];
|
|
|
|
$this->assertEquals($a2Id, $a1['redirect_id'], 'artist-rename-nramerge-2');
|
|
$this->assertEquals($a2Id, $ra['redirect_id'], 'artist-rename-nramerge-3');
|
|
$this->assertEquals($a1Name, $a1['name'], 'artist-rename-nramerge-4');
|
|
$this->assertEquals($a2Id, $a2['alias_id'], 'artist-rename-nramerge-5');
|
|
$this->assertEquals($mainAliasId, $artist->primaryAliasId(), 'artist-rename-nramerge-sanity');
|
|
|
|
// rename a2 and test redirects
|
|
$a2NewName = 'phpunit.' . randomString(12) . '-new';
|
|
$a3Id = $artist->renameAlias($a2Id, $a2NewName, $this->user);
|
|
$this->assertNotEquals($a2Id, $a3Id, 'artist-rename-nramerge-6');
|
|
|
|
$a1 = $artist->aliasList()[$a1Id];
|
|
$a2 = $artist->aliasList()[$a2Id];
|
|
$ra = $artist->aliasList()[$raId];
|
|
$a3 = $artist->aliasList()[$a3Id];
|
|
$this->assertEquals($a3Id, $a3['alias_id'], 'artist-rename-id-simple');
|
|
$this->assertEquals($a2NewName, $a3['name'], 'artist-rename-name-simple');
|
|
$this->assertEquals($a3Id, $a1['redirect_id'], 'artist-rename-redirect-1');
|
|
$this->assertEquals($a3Id, $a2['redirect_id'], 'artist-rename-redirect-2');
|
|
$this->assertEquals($a3Id, $ra['redirect_id'], 'artist-rename-redirect-3');
|
|
}
|
|
|
|
public function testArtistSimilar(): void {
|
|
$manager = new Manager\Artist();
|
|
$artist = $manager->create('phpunit.artsim.' . randomString(12));
|
|
$this->artistIdList[] = $artist->id;
|
|
$this->extra = Helper::makeUser('art2.' . randomString(10), 'artist');
|
|
|
|
$other1 = $manager->create('phpunit.other1.' . randomString(12));
|
|
$other2 = $manager->create('phpunit.other2.' . randomString(12));
|
|
|
|
$this->artistIdList[] = $other1->id;
|
|
$this->artistIdList[] = $other2->id;
|
|
|
|
$this->assertFalse($artist->similar()->voteSimilar($this->extra, $artist, true), 'artist-vote-self');
|
|
|
|
$this->assertEquals(1, $artist->similar()->addSimilar($other1, $this->user), 'artist-add-other1');
|
|
$this->assertEquals(0, $artist->similar()->addSimilar($other1, $this->user), 'artist-read-other1');
|
|
$this->assertEquals(1, $artist->similar()->addSimilar($other2, $this->user), 'artist-add-other2');
|
|
$this->assertEquals(1, $other1->similar()->addSimilar($other2, $this->user), 'artist-other1-add-other2');
|
|
|
|
$this->assertTrue($artist->similar()->voteSimilar($this->extra, $other1, true), 'artist-vote-up-other1');
|
|
$this->assertFalse($artist->similar()->voteSimilar($this->extra, $other1, true), 'artist-revote-up-other1');
|
|
$this->assertTrue($other1->similar()->voteSimilar($this->extra, $other2, false), 'artist-vote-down-other2');
|
|
|
|
$this->assertEquals(
|
|
[
|
|
[
|
|
'artist_id' => $other1->id,
|
|
'name' => $other1->name(),
|
|
'score' => 300,
|
|
'similar_id' => $artist->similar()->findSimilarId($other1),
|
|
],
|
|
[
|
|
'artist_id' => $other2->id,
|
|
'name' => $other2->name(),
|
|
'score' => 200,
|
|
'similar_id' => $artist->similar()->findSimilarId($other2),
|
|
],
|
|
],
|
|
$artist->similar()->info(),
|
|
'artist-similar-list'
|
|
);
|
|
|
|
$graph = $artist->similar()->similarGraph(100, 100);
|
|
$this->assertCount(2, $graph, 'artist-similar-count');
|
|
$this->assertEquals(
|
|
[$other1->id, $other2->id],
|
|
array_values(array_map(fn($sim) => $sim['artist_id'], $graph)),
|
|
'artist-similar-id-list'
|
|
);
|
|
$this->assertEquals($other2->id, $graph[$other1->id]['related'][0], 'artist-sim-related');
|
|
$this->assertLessThan($graph[$other1->id]['proportion'], $graph[$other2->id]['proportion'], 'artist-sim-proportion');
|
|
|
|
$this->assertFalse($artist->similar()->removeSimilar($artist, $this->extra), 'artist-remove-similar-self');
|
|
$this->assertTrue($artist->similar()->removeSimilar($other2, $this->extra), 'artist-remove-other');
|
|
$this->assertFalse($artist->similar()->removeSimilar($other2, $this->extra), 'artist-re-remove-other');
|
|
}
|
|
|
|
public function testArtistJson(): void {
|
|
$manager = new Manager\Artist();
|
|
$artist = $manager->create('phpunit.' . randomString(12));
|
|
$this->artistIdList[] = $artist->id;
|
|
|
|
$json = (new Json\Artist(
|
|
$artist,
|
|
$this->user,
|
|
new User\Bookmark($this->user),
|
|
new Manager\Request(),
|
|
new Manager\TGroup(),
|
|
new Manager\Torrent(),
|
|
));
|
|
$this->assertInstanceOf(Json\Artist::class, $json->setReleasesOnly(true), 'artist-json-set-releases');
|
|
$payload = $json->payload();
|
|
$this->assertEquals(
|
|
["id", "name", "notificationsEnabled", "hasBookmarked", "image",
|
|
"body", "bodyBbcode", "vanityHouse", "tags", "similarArtists",
|
|
"statistics", "torrentgroup", "requests"],
|
|
array_keys($payload),
|
|
'artist-json-payload'
|
|
);
|
|
$this->assertEquals($artist->id, $payload['id'], 'artist-payload-id');
|
|
$this->assertEquals($artist->name(), $payload['name'], 'artist-payload-name');
|
|
$this->assertCount(0, $payload['tags'], 'artist-payload-tags');
|
|
$this->assertCount(0, $payload['similarArtists'], 'artist-payload-similar-artists');
|
|
$this->assertCount(0, $payload['torrentgroup'], 'artist-payload-torrentgroup');
|
|
$this->assertCount(0, $payload['requests'], 'artist-payload-requests');
|
|
$this->assertIsArray($payload['statistics'], 'artist-payload-statistics');
|
|
}
|
|
|
|
public function testArtistAutocomplete(): void {
|
|
$manager = new Manager\Artist();
|
|
$composer = null;
|
|
foreach (['qqqq', 'qqqb', 'qqbb', 'qbbb', 'bbbb'] as $auto) {
|
|
$name = "$auto.phpunit." . randomString(6);
|
|
if (is_null($composer)) {
|
|
$composer = $name;
|
|
}
|
|
$artist = $manager->create($name);
|
|
$this->artistIdList[] = $artist->id;
|
|
$tgroup = Helper::makeTGroupMusic(
|
|
$this->user,
|
|
'phpunit artist autocomp ' . randomString(10),
|
|
[[ARTIST_MAIN], [$name]],
|
|
['punk'],
|
|
);
|
|
Helper::makeTorrentMusic($tgroup, $this->user);
|
|
$this->tgroupList[] = $tgroup;
|
|
}
|
|
$this->tgroupList[0]
|
|
->addArtists([ARTIST_COMPOSER], [$composer]);
|
|
global $Cache;
|
|
$Cache->delete_multi([
|
|
$manager->autocompleteKey("%"),
|
|
$manager->autocompleteKey("qq"),
|
|
$manager->autocompleteKey("qqqq"),
|
|
]);
|
|
$this->assertCount(0, $manager->autocompleteList("%"), 'artist-autocomp-wildcard');
|
|
$this->assertCount(3, $manager->autocompleteList("qq"), 'artist-autocomp-2');
|
|
$this->assertCount(1, $manager->autocompleteList("qqqq"), 'artist-autocomp-4');
|
|
}
|
|
|
|
public function testArtistBookmark(): void {
|
|
$name = 'phpunit.' . randomString(12);
|
|
$manager = new Manager\Artist();
|
|
$artist = $manager->create($name);
|
|
$this->artistIdList[] = $artist->id;
|
|
|
|
new User\Bookmark($this->user)->create($artist);
|
|
$json = new Json\Bookmark\Artist(new User\Bookmark($this->user));
|
|
$this->assertEquals(
|
|
[[
|
|
'artistId' => $artist->id,
|
|
'artistName' => $name,
|
|
]],
|
|
$json->payload(),
|
|
'artist-json-bookmark-payload'
|
|
);
|
|
}
|
|
|
|
public function testArtistDiscogs(): void {
|
|
$manager = new Manager\Artist();
|
|
$artist = $manager->create('phpunit.' . randomString(12));
|
|
$this->artistIdList[] = $artist->id;
|
|
|
|
$id = (int)DB::DB()->scalar("
|
|
SELECT 1+coalesce(max(artist_discogs_id), 0) FROM artist_discogs
|
|
");
|
|
$name = 'discogs phpunit ' . randomString(10);
|
|
$discogs = new Util\Discogs(
|
|
id: $id,
|
|
stem: $name,
|
|
name: $name,
|
|
sequence: 2,
|
|
);
|
|
$this->assertEquals($id, $discogs->id, 'artist-discogs-id');
|
|
$this->assertEquals($name, $discogs->name(), 'artist-discogs-name');
|
|
$this->assertEquals($name, $discogs->stem(), 'artist-discogs-stem');
|
|
$this->assertEquals(2, $discogs->sequence(), 'artist-discogs-sequence');
|
|
$this->assertTrue(
|
|
$artist->setField('discogs', $discogs)->setUpdateUser($this->user)->modify(),
|
|
'artist-add-discogs'
|
|
);
|
|
$this->assertEquals($name, $artist->discogs()->name(), 'artist-self-discogs-name');
|
|
$this->assertEquals(1, $artist->removeDiscogsRelation(), 'artist-discogs-remove');
|
|
}
|
|
|
|
public function testArtistRole(): void {
|
|
$manager = new Manager\Artist();
|
|
$this->assertTrue($manager->roleExists(0, ARTIST_MAIN), 'artist-role-main');
|
|
$this->assertFalse($manager->roleExists(0, 99), 'artist-role-inexistent');
|
|
}
|
|
}
|