the browser-facing portion of osu!
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

add test

+58
+31
database/factories/UsernameChangeHistoryFactory.php
··· 1 + <?php 2 + 3 + // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0. 4 + // See the LICENCE file in the repository root for full licence text. 5 + 6 + declare(strict_types=1); 7 + 8 + namespace Database\Factories; 9 + 10 + use App\Models\User; 11 + use App\Models\UsernameChangeHistory; 12 + use Carbon\Carbon; 13 + 14 + class UsernameChangeHistoryFactory extends Factory 15 + { 16 + protected $model = UsernameChangeHistory::class; 17 + 18 + public function definition(): array 19 + { 20 + return [ 21 + 'timestamp' => Carbon::now(), 22 + 'type' => 'paid', 23 + 'user_id' => User::factory(), 24 + 25 + // depend on user_id; the username will be incorrect when factorying multiple names at once, 26 + // so they should be handled separately if realistic name changes are wanted. 27 + 'username' => fn (array $attr) => User::find($attr['user_id'])->username, 28 + 'username_last' => fn (array $attr) => "{$attr['username']}_prev", 29 + ]; 30 + } 31 + }
+27
tests/Models/UserTest.php
··· 10 10 use App\Libraries\Session\Store; 11 11 use App\Models\OAuth\Token; 12 12 use App\Models\User; 13 + use App\Models\UsernameChangeHistory; 13 14 use Database\Factories\OAuth\RefreshTokenFactory; 14 15 use Tests\TestCase; 15 16 16 17 class UserTest extends TestCase 17 18 { 19 + public static function dataProviderForUsernameChangeCost() 20 + { 21 + return [ 22 + [0, 0], 23 + [1, 8], 24 + [2, 16], 25 + [3, 32], 26 + [4, 64], 27 + [5, 100], 28 + [6, 100], 29 + [10, 100], 30 + ]; 31 + } 32 + 18 33 /** 19 34 * @dataProvider dataProviderForAttributeTwitter 20 35 */ ··· 23 38 $user = new User(['user_twitter' => $setValue]); 24 39 25 40 $this->assertSame($getValue, $user->user_twitter); 41 + } 42 + 43 + /** 44 + * @dataProvider dataProviderForUsernameChangeCost 45 + */ 46 + public function testChangeUsernameChangeCost(int $changes, int $cost) 47 + { 48 + $user = User::factory() 49 + ->has(UsernameChangeHistory::factory()->count($changes)->state(['type' => 'paid'])) 50 + ->create(); 51 + 52 + $this->assertSame($user->usernameChangeCost(), $cost); 26 53 } 27 54 28 55 public function testEmailLoginDisabled()