Initial implementation of controller unit tests.
This commit is contained in:
parent
90bbe57148
commit
1260a8384a
5 changed files with 231 additions and 6 deletions
|
@ -33,6 +33,16 @@ interface DatabaseHostRepositoryInterface extends RepositoryInterface
|
|||
*/
|
||||
public function getWithViewDetails();
|
||||
|
||||
/**
|
||||
* Return a database host with the databases and associated servers that are attached to said databases.
|
||||
*
|
||||
* @param int $id
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function getWithServers($id);
|
||||
|
||||
/**
|
||||
* Delete a database host from the DB if there are no databases using it.
|
||||
*
|
||||
|
|
|
@ -90,16 +90,16 @@ class DatabaseController extends Controller
|
|||
/**
|
||||
* Display database host to user.
|
||||
*
|
||||
* @param \Pterodactyl\Models\DatabaseHost $host
|
||||
* @param int $host
|
||||
* @return \Illuminate\View\View
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function view(DatabaseHost $host)
|
||||
public function view($host)
|
||||
{
|
||||
$host->load('databases.server');
|
||||
|
||||
return view('admin.databases.view', [
|
||||
'locations' => $this->locationRepository->getAllWithNodes(),
|
||||
'host' => $host,
|
||||
'host' => $this->repository->getWithServers($host),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
namespace Pterodactyl\Repositories\Eloquent;
|
||||
|
||||
use Webmozart\Assert\Assert;
|
||||
use Pterodactyl\Models\DatabaseHost;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
|
||||
|
@ -47,13 +48,26 @@ class DatabaseHostRepository extends EloquentRepository implements DatabaseHostR
|
|||
return $this->getBuilder()->withCount('databases')->with('node')->get();
|
||||
}
|
||||
|
||||
public function getWithServers($id)
|
||||
{
|
||||
Assert::numeric($id, 'First argument passed to getWithServers must be numeric, recieved %s.');
|
||||
|
||||
$instance = $this->getBuilder()->with('databases.server')->find($id, $this->getColumns());
|
||||
if (! $instance) {
|
||||
throw new RecordNotFoundException();
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function deleteIfNoDatabases($id)
|
||||
{
|
||||
$instance = $this->getBuilder()->withCount('databases')->find($id);
|
||||
Assert::numeric($id, 'First argument passed to deleteIfNoDatabases must be numeric, recieved %s.');
|
||||
|
||||
$instance = $this->getBuilder()->withCount('databases')->find($id);
|
||||
if (! $instance) {
|
||||
throw new RecordNotFoundException();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue