use a helper class to make users

This commit is contained in:
Spine
2023-03-20 08:05:25 +00:00
parent 7bbb25c37b
commit bb4ef047ef
14 changed files with 301 additions and 239 deletions

View File

@@ -81,9 +81,9 @@ class ApplicantRole extends Base {
Modified = ?
WHERE ID = ?
", $this->title, $this->published, $this->description, $this->modified,
$this->id);
self::$cache->delete_value(self::CACHE_KEY_ALL);
self::$cache->delete_value(self::CACHE_KEY_PUBLISHED);
$this->id
);
self::$cache->delete_multi([self::CACHE_KEY_ALL, self::CACHE_KEY_PUBLISHED]);
self::$cache->cache_value(sprintf(self::CACHE_KEY, $this->id),
[
'Title' => $this->title,
@@ -96,4 +96,14 @@ class ApplicantRole extends Base {
);
return $this;
}
public function remove(): int {
self::$db->prepared_query("
DELETE FROM applicant_role WHERE ID = ?
", $this->id
);
$affected = self::$db->affected_rows();
self::$cache->delete_multi([self::CACHE_KEY_ALL, self::CACHE_KEY_PUBLISHED]);
return $affected;
}
}

View File

@@ -963,33 +963,13 @@ class User extends BaseObject {
}
public function remove(): int {
self::$db->begin_transaction();
self::$db->prepared_query("
DELETE FROM bonus_history WHERE UserID = ?
", $this->id
);
self::$db->prepared_query("
DELETE FROM user_bonus WHERE user_id = ?
", $this->id
);
self::$db->prepared_query("
DELETE FROM user_flt WHERE user_id = ?
", $this->id
);
self::$db->prepared_query("
DELETE FROM user_has_attr WHERE UserID = ?
", $this->id
);
self::$db->prepared_query("
DELETE FROM users_leech_stats WHERE UserID = ?
", $this->id
);
// Many, but not all, of the associated user tables will drop their entries via foreign key cascades.
// But some won't. If this call fails, you will need to decide what to do about the tables in question.
self::$db->prepared_query("
DELETE FROM users_main WHERE ID = ?
", $this->id
);
$affected = self::$db->affected_rows();
self::$db->commit();
$this->flush();
return $affected;
}

View File

@@ -0,0 +1,69 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class UserDeleteCascade extends AbstractMigration {
public function up(): void {
$cascade = ['delete' => 'CASCADE', 'update' => 'CASCADE'];
$this->table('bonus_history')
->dropForeignKey('UserID')
->addForeignKey('UserID', 'users_main', 'ID', $cascade)
->save();
$this->table('staff_blog_visits')
->dropForeignKey('UserID')
->addForeignKey('UserID', 'users_main', 'ID', $cascade)
->save();
$this->table('user_bonus')
->dropForeignKey('user_id')
->addForeignKey('user_id', 'users_main', 'ID', $cascade)
->save();
$this->table('user_flt')
->dropForeignKey('user_id')
->addForeignKey('user_id', 'users_main', 'ID', $cascade)
->save();
$this->table('user_has_attr')
->dropForeignKey('UserID')
->addForeignKey('UserID', 'users_main', 'ID', $cascade)
->save();
$this->table('user_last_access')
->dropForeignKey('user_id')
->addForeignKey('user_id', 'users_main', 'ID', $cascade)
->save();
$this->table('users_leech_stats')
->dropForeignKey('UserID')
->addForeignKey('UserID', 'users_main', 'ID', $cascade)
->save();
}
public function down(): void {
$this->table('bonus_history')
->dropForeignKey('UserID')
->addForeignKey('UserID', 'users_main', 'ID')
->save();
$this->table('staff_blog_visits')
->dropForeignKey('UserID')
->addForeignKey('UserID', 'users_main', 'ID')
->save();
$this->table('user_bonus')
->dropForeignKey('user_id')
->addForeignKey('user_id', 'users_main', 'ID')
->save();
$this->table('user_flt')
->dropForeignKey('user_id')
->addForeignKey('user_id', 'users_main', 'ID')
->save();
$this->table('user_has_attr')
->dropForeignKey('UserID')
->addForeignKey('UserID', 'users_main', 'ID')
->save();
$this->table('user_last_access')
->dropForeignKey('user_id')
->addForeignKey('user_id', 'users_main', 'ID')
->save();
$this->table('users_leech_stats')
->dropForeignKey('UserID')
->addForeignKey('UserID', 'users_main', 'ID')
->save();
}
}

View File

@@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class ApplicantRoleCascade extends AbstractMigration {
public function up(): void {
$this->table('applicant')
->dropForeignKey('RoleID')
->addForeignKey('RoleID', 'applicant_role', 'ID', ['delete' => 'CASCADE', 'update' => 'CASCADE'])
->save();
}
public function down(): void {
$this->table('appplicant')
->dropForeignKey('RoleID')
->addForeignKey('RoleID', 'applicant_role', 'ID')
->save();
}
}

View File

@@ -47,7 +47,7 @@ parameters:
message: '/^Method [^:]+::\w+\(\) has parameter \S+ with no (?:type specified|value type specified in iterable type array)\.$/'
paths:
- ../app/*
- ../tests/phpunit/*
- ../tests/*
-
message: '/^Method [^:]+::\w+\(\) return type has no value type specified in iterable type array\.$/'
paths:

81
tests/helper.php Normal file
View File

@@ -0,0 +1,81 @@
<?php
class Helper {
public static function makeTGroupMusic(
\Gazelle\User $user,
string $name,
array $artistName,
array $tagName,
int $releaseType = 1
): \Gazelle\TGroup {
$tgroup = (new \Gazelle\Manager\TGroup)->create(
categoryId: 1,
releaseType: $releaseType,
name: $name,
description: 'phpunit description',
image: '',
year: (int)date('Y') - 1,
recordLabel: 'Unitest Artists Corporation',
catalogueNumber: 'UA-' . random_int(10000, 99999),
showcase: false,
);
$tgroup->addArtists($user, $artistName[0], $artistName[1]);
$tagMan = new \Gazelle\Manager\Tag;
foreach ($tagName as $tag) {
$tagMan->createTorrentTag($tagMan->create($tag, $user->id()), $tgroup->id(), $user->id(), 10);
}
$tgroup->refresh();
return $tgroup;
}
public static function makeTorrentMusic(
int $tgroupId,
\Gazelle\User $user,
string $media = 'WEB',
string $format = 'FLAC',
string $encoding = 'Lossless',
string $title = '',
): \Gazelle\Torrent {
return (new \Gazelle\Manager\Torrent)->create(
tgroupId: $tgroupId,
userId: $user->id(),
description: 'phpunit release description',
media: $media,
format: $format,
encoding: $encoding,
infohash: 'infohash-' . randomString(10),
filePath: 'unit-test',
fileList: [],
size: random_int(10_000_000, 99_999_999),
isScene: false,
isRemaster: true,
remasterYear: (int)date('Y'),
remasterTitle: $title,
remasterRecordLabel: 'Unitest Artists',
remasterCatalogueNumber: 'UA-REM-' . random_int(10000, 99999),
);
}
public static function makeUser(string $username, string $tag): \Gazelle\User {
$_SERVER['HTTP_USER_AGENT'] = 'phpunit';
return (new Gazelle\UserCreator)
->setUsername($username)
->setEmail(randomString(6) . "@{$tag}.example.com")
->setPassword(randomString())
->setIpaddr('127.0.0.1')
->setAdminComment("Created by tests/helper/User($tag)")
->create();
}
public static function makeUserByInvite(string $username, string $key): \Gazelle\User {
$_SERVER['HTTP_USER_AGENT'] = 'phpunit';
return (new Gazelle\UserCreator)
->setUsername($username)
->setEmail(randomString(6) . "@key.invite.example.com")
->setPassword(randomString())
->setIpaddr('127.0.0.1')
->setInviteKey($key)
->setAdminComment("Created by tests/helper/User(InviteKey)")
->create();
}
}

View File

@@ -3,34 +3,35 @@
use \PHPUnit\Framework\TestCase;
require_once(__DIR__ . '/../../lib/bootstrap.php');
require_once(__DIR__ . '/../helper.php');
class applicantTest extends TestCase {
protected \Gazelle\Manager\ApplicantRole $roleManager;
protected \Gazelle\Manager\Applicant $manager;
public function setUp(): void {
$this->roleManager = new \Gazelle\Manager\ApplicantRole;
$this->manager = new \Gazelle\Manager\Applicant;
}
public function testApplicant(): void {
$this->assertIsArray($this->roleManager->list(), 'role-manager-list-published-is-array');
$new = $this->manager->newApplicantCount();
$admin = (new Gazelle\Manager\User)->find('@admin');
$user = (new Gazelle\Manager\User)->find('@user');
$roleManager = new \Gazelle\Manager\ApplicantRole;
$manager = new \Gazelle\Manager\Applicant;
$this->assertIsArray($roleManager->list(), 'role-manager-list-published-is-array');
$new = $manager->newApplicantCount();
$admin = Helper::makeUser('admin.' . randomString(10), 'applicant');
$user = Helper::makeUser('user.' . randomString(10), 'applicant');
$admin->setUpdate('PermissionID', SYSOP)->modify();
$role = 'published-' . randomString(6);
$published = $this->roleManager->create($role, 'this is a published role', true, 1);
$this->assertInstanceOf('\\Gazelle\\ApplicantRole', $published, 'applicant-role-instance');
$published = $roleManager->create($role, 'this is a published role', true, 1);
$this->assertInstanceOf(Gazelle\ApplicantRole::class, $published, 'applicant-role-instance');
$unpublished = $this->roleManager->create('unpublished-' . randomString(6), 'this is an unpublished role', false, $admin->id());
$unpublished = $roleManager->create('unpublished-' . randomString(6), 'this is an unpublished role', false, $admin->id());
$this->assertEquals($role, $roleManager->title($published->id()), 'role-manager-title');
$apply = $manager->create($user->id(), $published->id(), 'application message');
$this->assertInstanceOf(Gazelle\Applicant::class, $apply, 'applicant-instance');
$this->assertTrue($manager->userIsApplicant($user->id()), 'applicant-user-applied');
$this->assertEquals($new + 1, $manager->newApplicantCount(), 'applicant-new-count');
$this->assertEquals($role, $this->roleManager->title($published->id()), 'role-manager-title');
$this->assertEquals(1, $published->remove(), 'role-published-remove');
$this->assertEquals(1, $unpublished->remove(), 'role-unpublished-remove');
$apply = $this->manager->create($user->id(), $published->id(), 'application message');
$this->assertInstanceOf('\\Gazelle\\Applicant', $apply, 'applicant-instance');
$this->assertTrue($this->manager->userIsApplicant($user->id()), 'applicant-user-applied');
$this->assertEquals($new + 1, $this->manager->newApplicantCount(), 'applicant-new-count');
$admin->remove();
$user->remove();
}
}

View File

@@ -3,72 +3,57 @@
use \PHPUnit\Framework\TestCase;
require_once(__DIR__ . '/../../lib/bootstrap.php');
require_once(__DIR__ . '/../helper.php');
class FriendTest extends TestCase {
public function testFriend(): void {
$_SERVER['HTTP_USER_AGENT'] = 'phpunit';
$manager = new Gazelle\Manager\User;
$creator = new Gazelle\UserCreator;
protected array $friend;
$friend = [
new Gazelle\User\Friend(
$creator->setUsername('friend1.' . randomString(6))
->setEmail(randomString(6) . "@friend1.example.com")
->setPassword(randomString())
->setIpaddr('127.0.0.1')
->setAdminComment('Created by tests/phpunit/InviteTest.php')
->create()
),
new Gazelle\User\Friend(
$creator->setUsername('friend2.' . randomString(6))
->setEmail(randomString(6) . "@friend2.example.com")
->setPassword(randomString())
->setIpaddr('127.0.0.1')
->setAdminComment('Created by tests/phpunit/InviteTest.php')
->create()
),
new Gazelle\User\Friend(
$creator->setUsername('friend3.' . randomString(6))
->setEmail(randomString(6) . "@friend3.example.com")
->setPassword(randomString())
->setIpaddr('127.0.0.1')
->setAdminComment('Created by tests/phpunit/InviteTest.php')
->create()
),
public function tearDown(): void {
foreach ($this->friend as $f) {
$f->user()->remove();
}
}
public function testFriend(): void {
$manager = new Gazelle\Manager\User;
$this->friend = [
new Gazelle\User\Friend(Helper::makeUser('friend1.' . randomString(6), 'friend1')),
new Gazelle\User\Friend(Helper::makeUser('friend2.' . randomString(6), 'friend2')),
new Gazelle\User\Friend(Helper::makeUser('friend3.' . randomString(6), 'friend3')),
];
// in the beginning
$this->assertEquals(0, $friend[0]->total(), 'friend-i-have-no-friends');
$this->assertCount(0, $friend[1]->page($manager, 10, 0), 'friend-empty-page');
$this->assertCount(0, $friend[2]->userList(), 'friend-empty-user-list');
$this->assertEquals(0, $this->friend[0]->total(), 'friend-i-have-no-friends');
$this->assertCount(0, $this->friend[1]->page($manager, 10, 0), 'friend-empty-page');
$this->assertCount(0, $this->friend[2]->userList(), 'friend-empty-user-list');
// add a friend
$this->assertFalse($friend[0]->isFriend($friend[1]->user()->id()), 'friend-1-not-friend');
$this->assertEquals(1, $friend[0]->add($friend[1]->user()->id()), 'friend-1-add-friend');
$this->assertTrue($friend[0]->isFriend($friend[1]->user()->id()), 'friend-1-now-friend');
$this->assertFalse($friend[0]->isMutual($friend[1]->user()->id()), 'friend-1-not-yet-mutual');
$this->assertFalse($friend[1]->isFriend($friend[0]->user()->id()), 'friend-1-not-mutual');
$this->assertFalse($this->friend[0]->isFriend($this->friend[1]->user()->id()), 'friend-1-not-friend');
$this->assertEquals(1, $this->friend[0]->add($this->friend[1]->user()->id()), 'friend-1-add-friend');
$this->assertTrue($this->friend[0]->isFriend($this->friend[1]->user()->id()), 'friend-1-now-friend');
$this->assertFalse($this->friend[0]->isMutual($this->friend[1]->user()->id()), 'friend-1-not-yet-mutual');
$this->assertFalse($this->friend[1]->isFriend($this->friend[0]->user()->id()), 'friend-1-not-mutual');
// comment
$comment = 'comment ' . randomString();
$this->assertEquals(1, $friend[0]->addComment($friend[1]->user()->id(), $comment), 'friend-1-add-friend');
$this->assertEquals(1, $this->friend[0]->addComment($this->friend[1]->user()->id(), $comment), 'friend-1-add-friend');
// get a page
$page = $friend[0]->page($manager, 10, 0);
$page = $this->friend[0]->page($manager, 10, 0);
$this->assertCount(1, $page, 'friend-page');
$this->assertEquals(0, $page[$friend[1]->user()->id()]['mutual'], 'friend-not-mutual');
$this->assertEquals(0, $page[$this->friend[1]->user()->id()]['mutual'], 'friend-not-mutual');
// mutual
$this->assertEquals(1, $friend[1]->add($friend[0]->user()->id()), 'friend-0-add-back');
$this->assertTrue($friend[0]->isMutual($friend[1]->user()->id()), 'friend-1-is-mutual');
$this->assertTrue($friend[1]->isMutual($friend[0]->user()->id()), 'friend-reciprocal');
$page = $friend[0]->page($manager, 10, 0);
$this->assertEquals(1, $page[$friend[1]->user()->id()]['mutual'], 'friend-the-feeling-is-mutual');
$this->assertEquals(1, $this->friend[1]->add($this->friend[0]->user()->id()), 'friend-0-add-back');
$this->assertTrue($this->friend[0]->isMutual($this->friend[1]->user()->id()), 'friend-1-is-mutual');
$this->assertTrue($this->friend[1]->isMutual($this->friend[0]->user()->id()), 'friend-reciprocal');
$page = $this->friend[0]->page($manager, 10, 0);
$this->assertEquals(1, $page[$this->friend[1]->user()->id()]['mutual'], 'friend-the-feeling-is-mutual');
if (getenv('CI') === false) {
// FIXME: figure out why causes Twig footer() to fail when running in CI
// FIXME
$current = (new Gazelle\User\Session($friend[0]->user()))->create([
$current = (new Gazelle\User\Session($this->friend[0]->user()))->create([
'keep-logged' => '0',
'browser' => ['BrowserVersion' => null, 'OperatingSystemVersion' => null],
'ipaddr' => '127.0.0.1',
@@ -77,27 +62,27 @@ class FriendTest extends TestCase {
global $Document, $SessionID, $Viewer;
$Document = 'friends';
$SessionID = $current['SessionID'];
$Viewer = $friend[0]->user();
$Viewer = $this->friend[0]->user();
// render
$paginator = new Gazelle\Util\Paginator(FRIENDS_PER_PAGE, 1);
$paginator->setTotal($friend[0]->total());
$paginator->setTotal($this->friend[0]->total());
$html = Gazelle\Util\Twig::factory()->render('user/friend.twig', [
'list' => $friend[0]->page($manager, $paginator->limit(), $paginator->offset()),
'list' => $this->friend[0]->page($manager, $paginator->limit(), $paginator->offset()),
'paginator' => $paginator,
'viewer' => $friend[0]->user(),
'viewer' => $this->friend[0]->user(),
]);
$this->assertStringContainsString($comment, $html, 'friend-page-comment');
$this->assertStringContainsString($friend[1]->user()->username(), $html, 'friend-page-username');
$this->assertStringContainsString($this->friend[1]->user()->username(), $html, 'friend-page-username');
}
// remove
$friend[0]->add($friend[2]->user()->id());
$this->assertEquals(2, $friend[0]->total(), 'friend-has-friends');
$this->assertEquals(1, $friend[0]->remove($friend[1]->user()->id()), 'friend-unfriend');
$this->friend[0]->add($this->friend[2]->user()->id());
$this->assertEquals(2, $this->friend[0]->total(), 'friend-has-friends');
$this->assertEquals(1, $this->friend[0]->remove($this->friend[1]->user()->id()), 'friend-unfriend');
foreach (array_keys($friend) as $n) {
$this->assertEquals(1, $friend[$n]->user()->remove(), "friend-remove-$n");
foreach (array_keys($this->friend) as $n) {
$this->assertEquals(1, $this->friend[$n]->user()->remove(), "friend-remove-$n");
}
}
}

View File

@@ -3,6 +3,7 @@
use \PHPUnit\Framework\TestCase;
require_once(__DIR__ . '/../../lib/bootstrap.php');
require_once(__DIR__ . '/../helper.php');
class InboxTest extends TestCase {
protected array $userList;
@@ -13,24 +14,19 @@ class InboxTest extends TestCase {
}
}
public function testInbox(): void {
$_SERVER['HTTP_USER_AGENT'] = 'phpunit';
$creator = new Gazelle\UserCreator;
$this->userList = [
'sender' => $creator->setUsername('inbox.send.' . randomString(6))
->setEmail(randomString(6) . "@inbox.example.com")
->setPassword(randomString())
->setIpaddr('127.0.0.1')
->setAdminComment('Created by tests/phpunit/InviteTest.php')
->create(),
'receiver' => $creator->setUsername('inbox.recv.' . randomString(6))
->setEmail(randomString(6) . "@inbox.example.com")
->setPassword(randomString())
->setIpaddr('127.0.0.1')
->setAdminComment('Created by tests/phpunit/InviteTest.php')
->create(),
'sender' => Helper::makeUser('inbox.send', 'inbox'),
'receiver' => Helper::makeUser('inbox.recv', 'inbox'),
];
$senderId = $this->userList['sender']->id();
$receiverId = $this->userList['receiver']->id();
// wipe their inboxes (there is only one message)
foreach ($this->userList as $user) {
$pmMan = new Gazelle\Manager\PM($user);
foreach ((new Gazelle\User\Inbox($user))->messageList($pmMan, 1, 0) as $pm) {
$pm->remove();
}
}
$sender = new Gazelle\User\Inbox($this->userList['sender']);
$this->assertEquals('inbox.php?sort=latest', $sender->folderLink('inbox', false), 'inbox-folder-latest');

View File

@@ -3,21 +3,11 @@
use \PHPUnit\Framework\TestCase;
require_once(__DIR__ . '/../../lib/bootstrap.php');
require_once(__DIR__ . '/../helper.php');
class InviteTest extends TestCase {
public function setUp(): void {
$_SERVER['HTTP_USER_AGENT'] = 'phpunit';
}
public function testInvite(): void {
$creator = new Gazelle\UserCreator;
$user = $creator
->setUsername('invite.' . randomString(6))
->setEmail(randomString(6) . "@invite.example.com")
->setPassword(randomString())
->setIpaddr('127.0.0.1')
->setAdminComment('Created by tests/phpunit/InviteTest.php')
->create();
$user = Helper::makeUser('invite.' . randomString(6), 'invite');
$this->assertFalse($user->disableInvites(), 'invite-not-disabled');
$this->assertFalse($user->permitted('users_view_invites'), 'invite-users-view-invites');
@@ -55,12 +45,7 @@ class InviteTest extends TestCase {
// respond to invite
$this->assertTrue($manager->inviteExists($invite->key()), 'invite-key-found');
$invitee = $creator->setUsername('invitee.' . randomString(6))
->setEmail($email)
->setPassword(randomString())
->setIpaddr('127.0.0.1')
->setInviteKey($invite->key())
->create();
$invitee = Helper::makeUserByInvite('invitee.' . randomString(6), $invite->key());
$this->assertInstanceOf(Gazelle\User::class, $invitee, 'invitee-class');
$this->assertEquals($user->id(), $invitee->inviter()->id(), 'invitee-invited-by');
$this->assertEquals(1, $user->invitedTotal(), 'invite-total-1');
@@ -76,13 +61,7 @@ class InviteTest extends TestCase {
}
public function testEtm(): void {
$etm = (new Gazelle\UserCreator)
->setUsername('etm.' . randomString(6))
->setEmail(randomString(6) . "@etm.example.com")
->setPassword(randomString())
->setIpaddr('127.0.0.1')
->setAdminComment('Created by tests/phpunit/InviteTest.php')
->create()
$etm = Helper::makeUser('etm.' . randomString(6), 'etm')
->setUpdate('PermissionID', ELITE_TM);
$etm->modify();

View File

@@ -22,6 +22,7 @@ use \PHPUnit\Framework\TestCase;
*/
require_once(__DIR__ . '/../../lib/bootstrap.php');
require_once(__DIR__ . '/../helper.php');
class ReaperTest extends TestCase {
protected string $tgroupName;
@@ -30,22 +31,9 @@ class ReaperTest extends TestCase {
public function setUp(): void {
// we need two users, one who uploads and one who snatches
$_SERVER['HTTP_USER_AGENT'] = 'phpunit';
$creator = new Gazelle\UserCreator;
$this->userList = [
$creator->setUsername('reaper.' . randomString(10))
->setEmail(randomString(10) . '@reaper.example.com')
->setPassword(randomString())
->setIpaddr('127.0.0.1')
->setAdminComment('created by phpunit ReaperTest')
->create(),
$creator->setUsername('reaper.' . randomString(10))
->setUsername('reaper-' . randomString(10))
->setEmail(randomString(10) . '@reaper.example.com')
->setPassword(randomString())
->setIpaddr('127.0.0.1')
->setAdminComment('created by phpunit ReaperTest')
->create(),
Helper::makeUser('reaper.' . randomString(10), 'reaper'),
Helper::makeUser('reaper.' . randomString(10), 'reaper'),
];
// enable them and wipe their inboxes (there is only one message)
foreach ($this->userList as $user) {
@@ -58,50 +46,22 @@ class ReaperTest extends TestCase {
// create a torrent group
$this->tgroupName = 'phpunit reaper ' . randomString(6);
$tgroup = (new Gazelle\Manager\TGroup)->create(
categoryId: 1,
releaseType: 1,
name: $this->tgroupName,
description: 'phpunit reaper description',
image: '',
year: 2022,
recordLabel: 'Unitest Artists Corporation',
catalogueNumber: 'UA-808',
showcase: false,
$tgroup = Helper::makeTGroupMusic(
name: $this->tgroupName,
artistName: [[ARTIST_MAIN], ['Reaper Girl ' . randomString(12)]],
tagName: ['electronic'],
user: $this->userList[0],
);
$tgroup->addArtists($this->userList[0], [ARTIST_MAIN], ['Reaper Girl ' . randomString(12)]);
$tagMan = new Gazelle\Manager\Tag;
$tagId = $tagMan->create('electronic', $this->userList[0]->id());
$tagMan->createTorrentTag($tagId, $tgroup->id(), $this->userList[0]->id(), 10);
$tgroup->refresh();
// and add some torrents to the group
$this->torrentList = array_map(fn($info) => (new \Gazelle\Manager\Torrent)->create(
tgroupId: $tgroup->id(),
userId: $this->userList[0]->id(),
description: 'reaper release description',
media: 'WEB',
format: 'FLAC',
encoding: 'Lossless',
infohash: 'infohash-' . randomString(10),
filePath: 'unit-test',
fileList: [],
size: $info['size'],
isScene: false,
isRemaster: true,
remasterYear: 2023,
remasterTitle: $info['title'],
remasterRecordLabel: 'Unitest Artists',
remasterCatalogueNumber: 'UA-REAP-1',
$this->torrentList = array_map(fn($info) =>
Helper::makeTorrentMusic(
tgroupId: $tgroup->id(),
user: $this->userList[0],
title: $info['title'],
), [
[
'title' => 'Deluxe Edition',
'size' => 20_000_000,
], [
'title' => 'Limited Edition',
'size' => 15_000_000,
]
['title' => 'Deluxe Edition'],
['title' => 'Limited Edition'],
]
);
}
@@ -387,7 +347,7 @@ class ReaperTest extends TestCase {
$initialUnseededStats = $reaper->stats();
$unseededInitial = $reaper->initialUnseededList();
$this->assertCount(0, $unseededInitial, 'nseeded-initial-0-count');
$this->assertCount(0, $unseededInitial, 'unseeded-initial-0-count');
// reset the last action and time of the unseeded alert back in time to hit the initial timeout
foreach ($this->torrentList as $torrent) {

View File

@@ -3,17 +3,12 @@
use \PHPUnit\Framework\TestCase;
require_once(__DIR__ . '/../../lib/bootstrap.php');
require_once(__DIR__ . '/../helper.php');
class StaffBlogTest extends TestCase {
public function testStaffBlog(): void {
$_SERVER['HTTP_USER_AGENT'] = 'phpunit';
$mod = (new Gazelle\UserCreator)
->setUsername('mod.' . randomString(6))
->setEmail(randomString(6) . "@mod.example.com")
->setPassword(randomString())
->setIpaddr('127.0.0.1')
->setAdminComment('Created by tests/phpunit/StaffBlogTest.php')
->create()
$mod = Helper::makeUser('mod.' . randomString(6), 'mod')
->setUpdate('PermissionID', MOD);
$mod->modify();
$this->assertEquals('Moderator', $mod->userclassName(), 'mod-userclass-check');

View File

@@ -3,6 +3,7 @@
use \PHPUnit\Framework\TestCase;
require_once(__DIR__ . '/../../lib/bootstrap.php');
require_once(__DIR__ . '/../helper.php');
class StaffPMTest extends TestCase {
protected \Gazelle\Manager\StaffPM $spMan;
@@ -13,43 +14,23 @@ class StaffPMTest extends TestCase {
protected \Gazelle\User $user;
public function setUp(): void {
$_SERVER['HTTP_USER_AGENT'] = 'phpunit';
$this->fls = (new \Gazelle\UserCreator)->setUsername('spm_fls_' . randomString(10))
->setEmail('spm-fls@example.com')
->setPassword('secret123456')
->setIpaddr('127.0.0.1')
->setAdminComment('StaffPMTest')
->create();
$this->fls->addClasses([FLS_TEAM]);
$this->mod = (new \Gazelle\UserCreator)->setUsername('spm_mod_' . randomString(10))
->setEmail('spm-mod@example.com')
->setPassword('secret123456')
->setIpaddr('127.0.0.1')
->setAdminComment('StaffPMTest')
->create();
$this->mod->setUpdate('PermissionID', MOD)->modify();
$this->sysop = (new \Gazelle\UserCreator)->setUsername('spm_sysop_' . randomString(10))
->setEmail('spm-sysop@example.com')
->setPassword('secret123456')
->setIpaddr('127.0.0.1')
->setAdminComment('StaffPMTest')
->create();
$this->sysop->setUpdate('PermissionID', SYSOP)->modify();
$this->user = (new \Gazelle\UserCreator)->setUsername('spm_user_' . randomString(10))
->setEmail('spm-user@example.com')
->setPassword('secret123456')
->setIpaddr('127.0.0.1')
->setAdminComment('StaffPMTest')
->create();
$this->spMan = new \Gazelle\Manager\StaffPM;
$this->fls = Helper::makeUser('spm_fls_' . randomString(10), 'staffpm');
$this->mod = Helper::makeUser('spm_mod_' . randomString(10), 'staffpm');
$this->sysop = Helper::makeUser('spm_sysop_' . randomString(10), 'staffpm');
$this->user = Helper::makeUser('spm_user_' . randomString(10), 'staffpm');
$this->fls->addClasses([FLS_TEAM]);
$this->mod->setUpdate('PermissionID', MOD)->modify();
$this->sysop->setUpdate('PermissionID', SYSOP)->modify();
}
public function tearDown(): void {}
public function tearDown(): void {
$this->fls->remove();
$this->mod->remove();
$this->sysop->remove();
$this->user->remove();
}
public function testCreate(): void {
$spm = $this->spMan->create($this->user, 0, 'for FLS', 'message handled by FLS');

View File

@@ -3,6 +3,7 @@
use \PHPUnit\Framework\TestCase;
require_once(__DIR__ . '/../../lib/bootstrap.php');
require_once(__DIR__ . '/../helper.php');
class UserActivityTest extends TestCase {
protected Gazelle\Manager\User $userMan;
@@ -12,7 +13,9 @@ class UserActivityTest extends TestCase {
}
public function testActivity(): void {
$admin = $this->userMan->find('@admin');
$admin = Helper::makeUser('admin.' . randomString(10), 'activity');
$admin->setUpdate('PermissionID', SYSOP)->modify();
$activity = new Gazelle\User\Activity($admin);
$this->assertInstanceOf(Gazelle\User\Activity::class, $activity, 'user-activity-instance');
@@ -30,6 +33,8 @@ class UserActivityTest extends TestCase {
$this->assertInstanceOf(Gazelle\User\Activity::class, $activity->setScheduler(new Gazelle\Schedule\Scheduler), 'user-activity-scheduler');
$this->assertInstanceOf(Gazelle\User\Activity::class, $activity->setStaff(new Gazelle\Staff($admin)), 'user-activity-staff-set');
$this->assertInstanceOf(Gazelle\User\Activity::class, $activity->setStaffPM(new Gazelle\Manager\StaffPM), 'user-activity-staffpm');
$admin->remove();
}
public function testBlog(): void {