user = Helper::makeUser('collfree.' . randomString(10), 'collage.manager'); $this->user->requestContext()->setViewer($this->user); $this->tgroupList = [ Helper::makeTGroupMusic( name: 'phpunit collfree ' . randomString(6), artistName: [[ARTIST_MAIN], ['phpunit collfree ' . randomString(6)]], tagName: ['hip.hop'], user: $this->user, ), Helper::makeTGroupMusic( name: 'phpunit collfree ' . randomString(6), artistName: [[ARTIST_MAIN], ['phpunit collfree ' . randomString(6)]], tagName: ['hip.hop'], user: $this->user, ), ]; $this->collage = new Manager\Collage()->create( user: $this->user, categoryId: 2, name: 'phpunit collfree ' . randomString(10), description: 'phpunit collfree', tagList: 'pop', ); foreach ($this->tgroupList as $tgroup) { foreach ( [ ['format' => 'FLAC', 'size' => 10_000_000], ['format' => 'FLAC', 'size' => 15_000_000], ['format' => 'MP3', 'size' => 2_000_000], ] as $info ) { $torrent = Helper::makeTorrentMusic( tgroup: $tgroup, format: $info['format'], size: $info['size'], user: $this->user, ); } $this->collage->addEntry($tgroup->flush(), $this->user); } } public function tearDown(): void { $this->collage->hardRemove(); Helper::removeUser($this->user); } public function testCollageFreeleech(): void { $torMan = new Manager\Torrent(); $idList = $this->collage->entryFlacList(); $this->assertCount(4, $idList, 'collfree-flac-list'); $this->assertEquals( 4, $this->collage->setFreeleech( leechType: LeechType::Free, reason: LeechReason::Permanent, threshold: 12_000_000, user: $this->user, ), 'collfree-free' ); $n = 0; foreach ($this->tgroupList as $tgroup) { ++$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" ); } $this->assertEquals( 4, $this->collage->setFreeleech( torMan: $torMan, tracker: new Tracker(), user: $this->user, leechType: LeechType::Normal, reason: LeechReason::Normal, ), 'collfree-normal' ); $n = 0; foreach ($this->tgroupList as $tgroup) { 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"); } } } }