From 5cdd4c8f0b1bec40ecbadee4116ae4ab01ca2e16 Mon Sep 17 00:00:00 2001 From: Spine Date: Fri, 30 Jan 2026 01:00:02 +0000 Subject: [PATCH] simplify naming in unit tests for easier local cleaning --- bin/ut-garbage-collect | 32 ++++++++----------- tests/phpunit/CategoryTest.php | 4 +-- tests/phpunit/CollageTest.php | 10 +++--- tests/phpunit/ForumSearchTest.php | 6 ++-- tests/phpunit/ForumTest.php | 4 +-- tests/phpunit/NotificationUploadTest.php | 4 +-- tests/phpunit/RequestSearchTest.php | 2 +- tests/phpunit/RequestTest.php | 6 ++-- tests/phpunit/StaffPMTest.php | 10 +++--- tests/phpunit/TagTest.php | 8 ++--- tests/phpunit/TrackerTest.php | 8 ++--- .../phpunit/manager/CollageFreeleechTest.php | 4 +-- .../manager/TorrentReportManagerTest.php | 2 +- 13 files changed, 49 insertions(+), 51 deletions(-) diff --git a/bin/ut-garbage-collect b/bin/ut-garbage-collect index d31dd4999..2a19caf5e 100755 --- a/bin/ut-garbage-collect +++ b/bin/ut-garbage-collect @@ -24,9 +24,9 @@ foreach($tableList as $t) { $db->prepared_query("DROP TABLE $t"); } -// clean artists - $db->prepared_query("SET foreign_key_checks = 0"); + +// artists $db->prepared_query(" DELETE aa, ag FROM artists_alias aa @@ -34,20 +34,16 @@ $db->prepared_query(" ag.ArtistID = aa.ArtistID AND ag.PrimaryAlias = aa.AliasID ) - WHERE aa.name REGEXP '^(phpunit (?:req|artist merge) |(?:qqqq|qqqb|qqbb|qbbb|bbbb)\.phpunit\.)[a-z]{6}$' + WHERE aa.name REGEXP '^phpunit ' "); + +// contests $db->prepared_query(" - DELETE aa, ag - FROM artists_alias aa - INNER JOIN artists_group ag on ( - ag.ArtistID = aa.ArtistID - AND ag.PrimaryAlias = aa.AliasID - ) - WHERE aa.name REGEXP '^(phpunit\.|Tag Girl |Notify Man )' -"); -$db->prepared_query(" - DELETE FROM artists_alias - WHERE Name REGEXP '^(?:phpunit\.|new artist |Tracker Girl )'; + DELETE c, chbp, bp + FROM contest c + LEFT JOIN contest_has_bonus_pool chbp USING (contest_id) + LEFT JOIN bonus_pool bp USING (bonus_pool_id) + WHERE c.name LIKE 'phpunit contest %'; "); $db->prepared_query("SET foreign_key_checks = 1"); @@ -121,7 +117,7 @@ $collageMan->requestContext()->setViewer( $db->prepared_query(" SELECT ID FROM collages - WHERE Name regexp '^(?:phpunit (?:collage (?:ajax|artist|comment|contrib|personal|report)|merge artist|search report) )' + WHERE Name LIKE 'phpunit %' "); foreach ($db->collect(0) as $collageId) { $collage = $collageMan->findById($collageId); @@ -133,7 +129,7 @@ foreach ($db->collect(0) as $collageId) { $db->prepared_query(" SELECT ID FROM requests - WHERE Title regexp '^(?:The [a-z]{6} Test Sessions|phpunit request(?: report)?)$' + WHERE Title LIKE 'phpunit %' "); $reqMan = new Manager\Request(); @@ -147,7 +143,7 @@ foreach ($db->collect(0) as $requestId) { $db->prepared_query(" SELECT ID FROM forums - WHERE Name regexp '^(phpunit |forum .{6}$)' + WHERE Name LIKE 'phpunit %' "); $forMan = new Manager\Forum(); @@ -170,7 +166,7 @@ $db->prepared_query(" SELECT tg.ID as gid, t.ID as tid FROM torrents_group tg LEFT JOIN torrents t on (t.GroupID = tg.ID) - WHERE tg.Name regexp '^(?:phpunit (?:category new|collfree|live in|notify|reaper|request|seedbox|tgvote|torman|torrent) [a-z]{6}|(?:php(?: split title|unit artist (?:autocomp|merge[12]))|tracker) [a-z]{10}|Some (?:(?:boppy|live|more) )?[a-z]{8} (?:contest )?songs)$' + WHERE tg.Name regexp '^(?:phpunit (?:category (?:change|new)|collfree|feat|live in|log(?:checker)?|notify|reaper|request|seedbox|tag|tgvote|torman|torrent) [a-z]{6}|(?:php(?: split title|unit artist (?:autocomp|merge[12]))|tracker) [a-z]{10}|Some (?:(?:boppy|live|more) )?[a-z]{8} (?:contest )?songs)$' "); $groupList = $db->collect('gid'); $torrentList = $db->collect('tid'); diff --git a/tests/phpunit/CategoryTest.php b/tests/phpunit/CategoryTest.php index 6d9de3de5..d33ec1ca3 100644 --- a/tests/phpunit/CategoryTest.php +++ b/tests/phpunit/CategoryTest.php @@ -44,7 +44,7 @@ class CategoryTest extends TestCase { $idList = array_map(fn($t) => $t->id, $torrentList); // move one torrent to new category - $artistName = 'new artist ' . randomString(6); + $artistName = 'phpunit chgcat ' . randomString(6); $new = $tgMan->changeCategory( old: $tgroup, torrent: $torrentList[1], @@ -90,7 +90,7 @@ class CategoryTest extends TestCase { categoryId: $tgroup->categoryId(), // same category as the original, null expected name: 'phpunit category new ' . randomString(6), year: (int)date('Y'), - artistName: 'new artist ' . randomString(6), + artistName: 'phpunit chgcat ' . randomString(6), releaseType: new ReleaseType()->findIdByName('EP'), artistMan: new Manager\Artist(), user: $user, diff --git a/tests/phpunit/CollageTest.php b/tests/phpunit/CollageTest.php index 95109f676..333124ddd 100644 --- a/tests/phpunit/CollageTest.php +++ b/tests/phpunit/CollageTest.php @@ -30,11 +30,11 @@ class CollageTest extends TestCase { ]; $this->userList['u1']->requestContext()->setViewer($this->userList['u1']); $this->artistName = [ - 'The phpunit ' . randomString(8) . ' Band', - 'The phpunit ' . randomString(8) . ' Sisters', - 'The phpunit ' . randomString(8) . ' Brothers', - 'The phpunit ' . randomString(8) . ' Mothers', - 'The phpunit ' . randomString(8) . ' Fathers', + 'phpunit collage ' . randomString(6), + 'phpunit collage ' . randomString(6), + 'phpunit collage ' . randomString(6), + 'phpunit collage ' . randomString(6), + 'phpunit collage ' . randomString(6), ]; $this->tgroupList = []; diff --git a/tests/phpunit/ForumSearchTest.php b/tests/phpunit/ForumSearchTest.php index 1059b7dd1..bddd77aa5 100644 --- a/tests/phpunit/ForumSearchTest.php +++ b/tests/phpunit/ForumSearchTest.php @@ -31,7 +31,7 @@ class ForumSearchTest extends TestCase { name: 'Search forum', description: 'This is where it is found', ); - $title = 'search thread ' . randomString(10); + $title = 'phpunit search thread ' . randomString(10); $body = 'search body ' . randomString(10); $threadMan = new Manager\ForumThread(); $this->thread = $threadMan->create($this->forum, $this->user, $title, $body); @@ -74,7 +74,7 @@ class ForumSearchTest extends TestCase { name: 'Search forum', description: 'This is where it is found', ); - $title = 'search thread ' . randomString(10); + $title = 'phpunit search thread ' . randomString(10); $body = 'search body ' . randomString(10); $threadMan = new Manager\ForumThread(); $this->thread = $threadMan->create($this->forum, $this->user, $title, $body); @@ -96,7 +96,7 @@ class ForumSearchTest extends TestCase { name: 'Search forum', description: 'This is where it is found', ); - $title = 'search thread ' . randomString(10); + $title = 'phpunit search thread ' . randomString(10); $body = 'search body ' . randomString(10); $threadMan = new Manager\ForumThread(); $this->thread = $threadMan->create($this->forum, $this->user, $title, $body); diff --git a/tests/phpunit/ForumTest.php b/tests/phpunit/ForumTest.php index 022242520..a9e8a2485 100644 --- a/tests/phpunit/ForumTest.php +++ b/tests/phpunit/ForumTest.php @@ -147,7 +147,7 @@ class ForumTest extends TestCase { // Forum Threads $threadMan = new Manager\ForumThread(); - $thread = $threadMan->create($this->forum, $admin, 'thread title', 'this is a new thread'); + $thread = $threadMan->create($this->forum, $admin, 'phpunit thread title', 'this is a new thread'); $this->assertEquals('this is a new thread', $thread->body(), 'fthread-body'); $this->assertEquals(1, $thread->postTotal(), 'fthread-post-total'); $this->assertEquals(0, $thread->lastPage(), 'fthread-last-page'); @@ -159,7 +159,7 @@ class ForumTest extends TestCase { $this->assertEquals($this->forum->id, $thread->forumId(), 'fthread-forum-id'); $this->assertEquals($this->forum->name(), $thread->forum()->name(), 'fthread-forum-title'); $this->assertEquals($admin->id, $thread->lastAuthorId(), 'fthread-forum-title'); - $this->assertEquals('thread title', $thread->title(), 'thread-title'); + $this->assertEquals('phpunit thread title', $thread->title(), 'thread-title'); $this->assertEquals(0, $thread->pinnedPostId(), 'fthread-pinned-post-id'); $this->assertFalse($thread->hasPoll(), 'fthread-has-poll-no'); diff --git a/tests/phpunit/NotificationUploadTest.php b/tests/phpunit/NotificationUploadTest.php index cedbc419d..36f4d45ee 100644 --- a/tests/phpunit/NotificationUploadTest.php +++ b/tests/phpunit/NotificationUploadTest.php @@ -11,7 +11,7 @@ class NotificationUploadTest extends TestCase { protected Manager\Torrent $torMan; protected Torrent $torrent; - protected array $userList; + protected array $userList; public function setUp(): void { $user = Helper::makeUser('uploader.' . randomString(10), 'notification-ticket'); @@ -27,7 +27,7 @@ class NotificationUploadTest extends TestCase { catalogueNumber: 'UA-246', showcase: false, ); - $tgroup->addArtists([ARTIST_MAIN], ['Notify Man ' . randomString(12)]); + $tgroup->addArtists([ARTIST_MAIN], ['phpunit notify ' . randomString(6)]); $tagMan = new Manager\Tag(); foreach (['electronic', 'funk', 'jazz'] as $name) { diff --git a/tests/phpunit/RequestSearchTest.php b/tests/phpunit/RequestSearchTest.php index 051790476..2ce03e606 100644 --- a/tests/phpunit/RequestSearchTest.php +++ b/tests/phpunit/RequestSearchTest.php @@ -138,7 +138,7 @@ class RequestSearchTest extends TestCase { $this->userList[] = $user; $this->tgroup = Helper::makeTGroupMusic( $user, - 'phpunit ' . randomString(10), + 'phpunit reqfill ' . randomString(10), [[ARTIST_MAIN], ['phpunit reqfill ' . randomString(6)]], [ new Manager\Tag()->create('ut-' . randomString(8), $this->userList[0])->id, diff --git a/tests/phpunit/RequestTest.php b/tests/phpunit/RequestTest.php index 9a767e761..452432705 100644 --- a/tests/phpunit/RequestTest.php +++ b/tests/phpunit/RequestTest.php @@ -45,7 +45,7 @@ class RequestTest extends TestCase { $user = $this->userList['user']; $manager = new Manager\Request(); - $title = 'phpunit ' . randomString(6) . ' Test Sessions (bonus VIP)'; + $title = 'phpunit create ' . randomString(6); $image = 'https://example.com/req.jpg'; $year = 2002; $this->request = Helper::makeRequestMusic($admin, $title, image: $image, year: $year); @@ -789,9 +789,9 @@ class RequestTest extends TestCase { public function testRequestFTS(): void { $user = $this->userList['admin']; - $title = 'phpunit reqfts ' . randomString(); + $title = 'phpunit reqfts ' . randomString(6); $this->request = Helper::makeRequestMusic($user, $title); - $artistName = 'artist ftsreq ' . randomString(); + $artistName = 'phpunit ftsreq ' . randomString(6); $this->request->artistRole()->set([ARTIST_MAIN => [$artistName]], $user); $this->assertEquals( diff --git a/tests/phpunit/StaffPMTest.php b/tests/phpunit/StaffPMTest.php index 2eb4cb578..9fb24c231 100644 --- a/tests/phpunit/StaffPMTest.php +++ b/tests/phpunit/StaffPMTest.php @@ -35,6 +35,9 @@ class StaffPMTest extends TestCase { WHERE spm.UserID IN (?, ?, ?, ?) ", $this->fls->id, $this->mod->id, $this->sysop->id, $this->user->id ); + $db->prepared_query(" + DELETE FROM staff_pm_responses WHERE Name LIKE '^phpunit ' + "); $this->fls->remove(); $this->mod->remove(); $this->sysop->remove(); @@ -213,14 +216,14 @@ class StaffPMTest extends TestCase { public function testCommonAnswer(): void { $initial = count($this->spMan->commonAnswerList()); $answer = 'because we can'; - $first = $this->spMan->createCommonAnswer('why', $answer); + $first = $this->spMan->createCommonAnswer('phpunit common ' . randomString(6), $answer); $this->assertGreaterThan(0, $first, 'spm-common-add-1'); $this->assertEquals($answer, $this->spMan->commonAnswer($first), 'spm-common-get'); - $second = $this->spMan->createCommonAnswer('why not', 'because we cannot'); + $second = $this->spMan->createCommonAnswer('phpunit why not', 'because we cannot'); $this->assertEquals($first + 1, $second, 'spm-common-add-2'); - $third = $this->spMan->createCommonAnswer('third', 'third common answer'); + $third = $this->spMan->createCommonAnswer('phpunit third', 'third common answer'); $this->assertEquals($first + 2, $third, 'spm-common-add-3'); $this->assertEquals(1, $this->spMan->modifyCommonAnswer($third, 'third', 'because we might'), 'spm-common-modify'); $this->assertCount($initial + 3, $this->spMan->commonAnswerList(), 'spm-common-list'); @@ -229,7 +232,6 @@ class StaffPMTest extends TestCase { $this->assertCount($initial + 2, $this->spMan->commonAnswerList(), 'spm-common-list'); $this->assertEquals(1, $this->spMan->removeCommonAnswer($third), 'spm-common-tidy'); - // flush the context to play nicely with the CI $this->assertStringStartsWith( "TextareaPreview.factory([[0, 'answer-", Textarea::factory(), diff --git a/tests/phpunit/TagTest.php b/tests/phpunit/TagTest.php index bcf2574c1..4811b5ccf 100644 --- a/tests/phpunit/TagTest.php +++ b/tests/phpunit/TagTest.php @@ -226,7 +226,7 @@ class TagTest extends TestCase { $this->user->requestContext()->setViewer($this->user); $tgroup = Helper::makeTGroupMusic( name: 'phpunit tag ' . randomString(6), - artistName: [[ARTIST_MAIN], ['Tag Girl ' . randomString(12)]], + artistName: [[ARTIST_MAIN], ['phpunit tag ' . randomString(6)]], tagName: ['phpunit.electronic', 'phpunit.folk', 'phpunit.disco'], user: $this->user, ); @@ -271,7 +271,7 @@ class TagTest extends TestCase { $tag = $manager->create($name, $this->user); $tgroup = Helper::makeTGroupMusic( name: 'phpunit tag ' . randomString(6), - artistName: [[ARTIST_MAIN], ['Tag Girl ' . randomString(12)]], + artistName: [[ARTIST_MAIN], ['phpunit tag ' . randomString(6)]], tagName: [$name], user: $this->user, ); @@ -291,7 +291,7 @@ class TagTest extends TestCase { $this->assertEquals(1, $tag->flush()->uses(), 'tag-instance-use-1'); $tgroup = Helper::makeTGroupMusic( name: 'phpunit tag ' . randomString(6), - artistName: [[ARTIST_MAIN], ['Tag Girl ' . randomString(12)]], + artistName: [[ARTIST_MAIN], ['phpunit tag ' . randomString(6)]], tagName: [$name], user: $this->user, ); @@ -341,7 +341,7 @@ class TagTest extends TestCase { $tag->addRequest($this->request); $tgroup = Helper::makeTGroupMusic( name: 'phpunit tag ' . randomString(6), - artistName: [[ARTIST_MAIN], ['Tag Girl ' . randomString(12)]], + artistName: [[ARTIST_MAIN], ['phpunit tag ' . randomString(6)]], tagName: [$name], user: $this->user, ); diff --git a/tests/phpunit/TrackerTest.php b/tests/phpunit/TrackerTest.php index ee85c9e18..ecda22720 100644 --- a/tests/phpunit/TrackerTest.php +++ b/tests/phpunit/TrackerTest.php @@ -36,7 +36,7 @@ class TrackerTest extends TestCase { $torrent = Helper::makeTorrentMusic( Helper::makeTGroupMusic( name: 'tracker ' . randomString(10), - artistName: [[ARTIST_MAIN], ['Tracker Girl ' . randomString(12)]], + artistName: [[ARTIST_MAIN], ['phpunit trk ' . randomString(6)]], tagName: ['trap'], user: $this->user, ), @@ -61,7 +61,7 @@ class TrackerTest extends TestCase { $torrent = Helper::makeTorrentMusic( Helper::makeTGroupMusic( name: 'tracker ' . randomString(10), - artistName: [[ARTIST_MAIN], ['Tracker Girl ' . randomString(12)]], + artistName: [[ARTIST_MAIN], ['phpunit trk ' . randomString(6)]], tagName: ['trap'], user: $this->user, ), @@ -157,7 +157,7 @@ class TrackerTest extends TestCase { $torrent = Helper::makeTorrentMusic( Helper::makeTGroupMusic( name: 'tracker ' . randomString(10), - artistName: [[ARTIST_MAIN], ['Tracker Girl ' . randomString(12)]], + artistName: [[ARTIST_MAIN], ['phpunit trk ' . randomString(6)]], tagName: ['trap'], user: $this->user, ), @@ -185,7 +185,7 @@ class TrackerTest extends TestCase { $torrent = Helper::makeTorrentMusic( Helper::makeTGroupMusic( name: 'tracker ' . randomString(10), - artistName: [[ARTIST_MAIN], ['Tracker Girl ' . randomString(12)]], + artistName: [[ARTIST_MAIN], ['phpunit trk ' . randomString(6)]], tagName: ['trap'], user: $this->user, ), diff --git a/tests/phpunit/manager/CollageFreeleechTest.php b/tests/phpunit/manager/CollageFreeleechTest.php index adff99cdc..eaadd6e84 100644 --- a/tests/phpunit/manager/CollageFreeleechTest.php +++ b/tests/phpunit/manager/CollageFreeleechTest.php @@ -18,13 +18,13 @@ class CollageFreeleechTest extends TestCase { $this->tgroupList = [ Helper::makeTGroupMusic( name: 'phpunit collfree ' . randomString(6), - artistName: [[ARTIST_MAIN], ['Dr Collfree ' . randomString(12)]], + artistName: [[ARTIST_MAIN], ['phpunit collfree ' . randomString(6)]], tagName: ['hip.hop'], user: $this->user, ), Helper::makeTGroupMusic( name: 'phpunit collfree ' . randomString(6), - artistName: [[ARTIST_MAIN], ['Dr Collfree ' . randomString(12)]], + artistName: [[ARTIST_MAIN], ['phpunit collfree ' . randomString(6)]], tagName: ['hip.hop'], user: $this->user, ), diff --git a/tests/phpunit/manager/TorrentReportManagerTest.php b/tests/phpunit/manager/TorrentReportManagerTest.php index 9b0b4a9db..94449760f 100644 --- a/tests/phpunit/manager/TorrentReportManagerTest.php +++ b/tests/phpunit/manager/TorrentReportManagerTest.php @@ -20,7 +20,7 @@ class TorrentReportManagerTest extends TestCase { // create a torrent group $this->tgroup = Helper::makeTGroupMusic( name: 'phpunit torrent report ' . randomString(6), - artistName: [[ARTIST_MAIN], ['Report Dog ' . randomString(12)]], + artistName: [[ARTIST_MAIN], ['phpunit torrent report ' . randomString(6)]], tagName: ['electronic'], user: $this->userList[0], );