Update command unit tests to use helper functions
This commit is contained in:
parent
8df5d5beaf
commit
6e5b0b8027
13 changed files with 615 additions and 100 deletions
|
@ -25,15 +25,14 @@
|
|||
namespace Tests\Unit\Commands\User;
|
||||
|
||||
use Mockery as m;
|
||||
use Tests\TestCase;
|
||||
use Pterodactyl\Models\User;
|
||||
use Tests\Unit\Commands\CommandTestCase;
|
||||
use Tests\Assertions\CommandAssertionsTrait;
|
||||
use Pterodactyl\Services\Users\UserDeletionService;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Pterodactyl\Console\Commands\User\DeleteUserCommand;
|
||||
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
|
||||
|
||||
class DeleteUserCommandTest extends TestCase
|
||||
class DeleteUserCommandTest extends CommandTestCase
|
||||
{
|
||||
use CommandAssertionsTrait;
|
||||
|
||||
|
@ -43,12 +42,12 @@ class DeleteUserCommandTest extends TestCase
|
|||
protected $command;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Users\UserDeletionService
|
||||
* @var \Pterodactyl\Services\Users\UserDeletionService|\Mockery\Mock
|
||||
*/
|
||||
protected $deletionService;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface
|
||||
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface|\Mockery\Mock
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
|
@ -80,11 +79,8 @@ class DeleteUserCommandTest extends TestCase
|
|||
->shouldReceive('all')->withNoArgs()->once()->andReturn($users);
|
||||
$this->deletionService->shouldReceive('handle')->with($user1->id)->once()->andReturnNull();
|
||||
|
||||
$response = new CommandTester($this->command);
|
||||
$response->setInputs([$user1->username, $user1->id, 'yes']);
|
||||
$response->execute([]);
|
||||
$display = $this->runCommand($this->command, [], [$user1->username, $user1->id, 'yes']);
|
||||
|
||||
$display = $response->getDisplay();
|
||||
$this->assertNotEmpty($display);
|
||||
$this->assertTableContains($user1->id, $display);
|
||||
$this->assertTableContains($user1->email, $display);
|
||||
|
@ -107,11 +103,8 @@ class DeleteUserCommandTest extends TestCase
|
|||
->shouldReceive('all')->withNoArgs()->once()->andReturn($users);
|
||||
$this->deletionService->shouldReceive('handle')->with($user1->id)->once()->andReturnNull();
|
||||
|
||||
$response = new CommandTester($this->command);
|
||||
$response->setInputs(['noResults', $user1->username, $user1->id, 'yes']);
|
||||
$response->execute([]);
|
||||
$display = $this->runCommand($this->command, [], ['noResults', $user1->username, $user1->id, 'yes']);
|
||||
|
||||
$display = $response->getDisplay();
|
||||
$this->assertNotEmpty($display);
|
||||
$this->assertContains(trans('command/messages.user.no_users_found'), $display);
|
||||
$this->assertTableContains($user1->id, $display);
|
||||
|
@ -133,11 +126,8 @@ class DeleteUserCommandTest extends TestCase
|
|||
->shouldReceive('all')->withNoArgs()->twice()->andReturn($users);
|
||||
$this->deletionService->shouldReceive('handle')->with($user1->id)->once()->andReturnNull();
|
||||
|
||||
$response = new CommandTester($this->command);
|
||||
$response->setInputs([$user1->username, 0, $user1->username, $user1->id, 'yes']);
|
||||
$response->execute([]);
|
||||
$display = $this->runCommand($this->command, [], [$user1->username, 0, $user1->username, $user1->id, 'yes']);
|
||||
|
||||
$display = $response->getDisplay();
|
||||
$this->assertNotEmpty($display);
|
||||
$this->assertContains(trans('command/messages.user.select_search_user'), $display);
|
||||
$this->assertTableContains($user1->id, $display);
|
||||
|
@ -159,11 +149,8 @@ class DeleteUserCommandTest extends TestCase
|
|||
->shouldReceive('all')->withNoArgs()->once()->andReturn($users);
|
||||
$this->deletionService->shouldNotReceive('handle');
|
||||
|
||||
$response = new CommandTester($this->command);
|
||||
$response->setInputs([$user1->username, $user1->id, 'no']);
|
||||
$response->execute([]);
|
||||
$display = $this->runCommand($this->command, [], [$user1->username, $user1->id, 'no']);
|
||||
|
||||
$display = $response->getDisplay();
|
||||
$this->assertNotEmpty($display);
|
||||
$this->assertNotContains(trans('command/messages.user.deleted'), $display);
|
||||
}
|
||||
|
@ -181,10 +168,8 @@ class DeleteUserCommandTest extends TestCase
|
|||
->shouldReceive('all')->withNoArgs()->once()->andReturn($users);
|
||||
$this->deletionService->shouldReceive('handle')->with($user1)->once()->andReturnNull();
|
||||
|
||||
$response = new CommandTester($this->command);
|
||||
$response->execute(['--user' => $user1->username], ['interactive' => false]);
|
||||
$display = $this->withoutInteraction()->runCommand($this->command, ['--user' => $user1->username]);
|
||||
|
||||
$display = $response->getDisplay();
|
||||
$this->assertNotEmpty($display);
|
||||
$this->assertContains(trans('command/messages.user.deleted'), $display);
|
||||
}
|
||||
|
@ -203,10 +188,8 @@ class DeleteUserCommandTest extends TestCase
|
|||
->shouldReceive('all')->withNoArgs()->once()->andReturn($users);
|
||||
$this->deletionService->shouldNotReceive('handle');
|
||||
|
||||
$response = new CommandTester($this->command);
|
||||
$response->execute(['--user' => $user1->username], ['interactive' => false]);
|
||||
$display = $this->withoutInteraction()->runCommand($this->command, ['--user' => $user1->username]);
|
||||
|
||||
$display = $response->getDisplay();
|
||||
$this->assertNotEmpty($display);
|
||||
$this->assertContains(trans('command/messages.user.multiple_found'), $display);
|
||||
}
|
||||
|
@ -219,10 +202,8 @@ class DeleteUserCommandTest extends TestCase
|
|||
$this->repository->shouldReceive('search')->with(123456)->once()->andReturnSelf()
|
||||
->shouldReceive('all')->withNoArgs()->once()->andReturn([]);
|
||||
|
||||
$response = new CommandTester($this->command);
|
||||
$response->execute(['--user' => 123456], ['interactive' => false]);
|
||||
$display = $this->withoutInteraction()->runCommand($this->command, ['--user' => 123456]);
|
||||
|
||||
$display = $response->getDisplay();
|
||||
$this->assertNotEmpty($display);
|
||||
$this->assertContains(trans('command/messages.user.no_users_found'), $display);
|
||||
}
|
||||
|
|
|
@ -25,13 +25,12 @@
|
|||
namespace Tests\Unit\Commands\User;
|
||||
|
||||
use Mockery as m;
|
||||
use Tests\TestCase;
|
||||
use Pterodactyl\Models\User;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Tests\Unit\Commands\CommandTestCase;
|
||||
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
|
||||
use Pterodactyl\Console\Commands\User\DisableTwoFactorCommand;
|
||||
|
||||
class DisableTwoFactorCommandTest extends TestCase
|
||||
class DisableTwoFactorCommandTest extends CommandTestCase
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Console\Commands\User\DisableTwoFactorCommand
|
||||
|
@ -39,10 +38,13 @@ class DisableTwoFactorCommandTest extends TestCase
|
|||
protected $command;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface
|
||||
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface|\Mockery\Mock
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* Setup tests.
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
@ -68,11 +70,8 @@ class DisableTwoFactorCommandTest extends TestCase
|
|||
'totp_secret' => null,
|
||||
])->once()->andReturnNull();
|
||||
|
||||
$response = new CommandTester($this->command);
|
||||
$response->setInputs([$user->email]);
|
||||
$response->execute([]);
|
||||
$display = $this->runCommand($this->command, [], [$user->email]);
|
||||
|
||||
$display = $response->getDisplay();
|
||||
$this->assertNotEmpty($display);
|
||||
$this->assertContains(trans('command/messages.user.2fa_disabled', ['email' => $user->email]), $display);
|
||||
}
|
||||
|
@ -92,12 +91,7 @@ class DisableTwoFactorCommandTest extends TestCase
|
|||
'totp_secret' => null,
|
||||
])->once()->andReturnNull();
|
||||
|
||||
$response = new CommandTester($this->command);
|
||||
$response->execute([
|
||||
'--email' => $user->email,
|
||||
]);
|
||||
|
||||
$display = $response->getDisplay();
|
||||
$display = $this->withoutInteraction()->runCommand($this->command, ['--email' => $user->email]);
|
||||
$this->assertNotEmpty($display);
|
||||
$this->assertContains(trans('command/messages.user.2fa_disabled', ['email' => $user->email]), $display);
|
||||
}
|
||||
|
|
|
@ -25,13 +25,12 @@
|
|||
namespace Tests\Unit\Commands\User;
|
||||
|
||||
use Mockery as m;
|
||||
use Tests\TestCase;
|
||||
use Pterodactyl\Models\User;
|
||||
use Tests\Unit\Commands\CommandTestCase;
|
||||
use Pterodactyl\Services\Users\UserCreationService;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Pterodactyl\Console\Commands\User\MakeUserCommand;
|
||||
|
||||
class MakeUserCommandTest extends TestCase
|
||||
class MakeUserCommandTest extends CommandTestCase
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Console\Commands\User\MakeUserCommand
|
||||
|
@ -72,13 +71,10 @@ class MakeUserCommandTest extends TestCase
|
|||
'root_admin' => $user->root_admin,
|
||||
])->once()->andReturn($user);
|
||||
|
||||
$response = new CommandTester($this->command);
|
||||
$response->setInputs([
|
||||
$display = $this->runCommand($this->command, [], [
|
||||
'yes', $user->email, $user->username, $user->name_first, $user->name_last, 'Password123',
|
||||
]);
|
||||
$response->execute([]);
|
||||
|
||||
$display = $response->getDisplay();
|
||||
$this->assertNotEmpty($display);
|
||||
$this->assertContains(trans('command/messages.user.ask_password_help'), $display);
|
||||
$this->assertContains($user->uuid, $display);
|
||||
|
@ -104,13 +100,10 @@ class MakeUserCommandTest extends TestCase
|
|||
'root_admin' => $user->root_admin,
|
||||
])->once()->andReturn($user);
|
||||
|
||||
$response = new CommandTester($this->command);
|
||||
$response->setInputs([
|
||||
$display = $this->runCommand($this->command, ['--no-password' => true], [
|
||||
'yes', $user->email, $user->username, $user->name_first, $user->name_last,
|
||||
]);
|
||||
$response->execute(['--no-password' => true]);
|
||||
|
||||
$display = $response->getDisplay();
|
||||
$this->assertNotEmpty($display);
|
||||
$this->assertNotContains(trans('command/messages.user.ask_password_help'), $display);
|
||||
}
|
||||
|
@ -131,8 +124,7 @@ class MakeUserCommandTest extends TestCase
|
|||
'root_admin' => $user->root_admin,
|
||||
])->once()->andReturn($user);
|
||||
|
||||
$response = new CommandTester($this->command);
|
||||
$response->execute([
|
||||
$display = $this->withoutInteraction()->runCommand($this->command, [
|
||||
'--email' => $user->email,
|
||||
'--username' => $user->username,
|
||||
'--name-first' => $user->name_first,
|
||||
|
@ -141,7 +133,6 @@ class MakeUserCommandTest extends TestCase
|
|||
'--admin' => 0,
|
||||
]);
|
||||
|
||||
$display = $response->getDisplay();
|
||||
$this->assertNotEmpty($display);
|
||||
$this->assertNotContains(trans('command/messages.user.ask_password_help'), $display);
|
||||
$this->assertContains($user->uuid, $display);
|
||||
|
|
Reference in a new issue