1313use Tests \TestCase ;
1414use Pterodactyl \Models \DatabaseHost ;
1515use Prologue \Alerts \AlertsMessageBag ;
16+ use Illuminate \Pagination \LengthAwarePaginator ;
1617use Tests \Assertions \ControllerAssertionsTrait ;
1718use Pterodactyl \Http \Controllers \Admin \DatabaseController ;
1819use Pterodactyl \Services \Databases \Hosts \HostUpdateService ;
1920use Pterodactyl \Services \Databases \Hosts \HostCreationService ;
2021use Pterodactyl \Services \Databases \Hosts \HostDeletionService ;
22+ use Pterodactyl \Contracts \Repository \DatabaseRepositoryInterface ;
2123use Pterodactyl \Contracts \Repository \LocationRepositoryInterface ;
2224use Pterodactyl \Contracts \Repository \DatabaseHostRepositoryInterface ;
2325
@@ -35,6 +37,11 @@ class DatabaseControllerTest extends TestCase
3537 */
3638 private $ creationService ;
3739
40+ /**
41+ * @var \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface|\Mockery\Mock
42+ */
43+ private $ databaseRepository ;
44+
3845 /**
3946 * @var \Pterodactyl\Services\Databases\Hosts\HostDeletionService|\Mockery\Mock
4047 */
@@ -64,6 +71,7 @@ public function setUp()
6471
6572 $ this ->alert = m::mock (AlertsMessageBag::class);
6673 $ this ->creationService = m::mock (HostCreationService::class);
74+ $ this ->databaseRepository = m::mock (DatabaseRepositoryInterface::class);
6775 $ this ->deletionService = m::mock (HostDeletionService::class);
6876 $ this ->locationRepository = m::mock (LocationRepositoryInterface::class);
6977 $ this ->repository = m::mock (DatabaseHostRepositoryInterface::class);
@@ -94,18 +102,25 @@ public function testIndexController()
94102 public function testViewController ()
95103 {
96104 $ model = factory (DatabaseHost::class)->make ();
105+ $ paginator = new LengthAwarePaginator ([], 1 , 1 );
97106
98107 $ this ->locationRepository ->shouldReceive ('getAllWithNodes ' )->withNoArgs ()->once ()->andReturn (collect (['getAllWithNodes ' ]));
99- $ this ->repository ->shouldReceive ('getWithServers ' )->with (1 )->once ()->andReturn ($ model );
108+ $ this ->repository ->shouldReceive ('find ' )->with (1 )->once ()->andReturn ($ model );
109+ $ this ->databaseRepository ->shouldReceive ('getDatabasesForHost ' )
110+ ->once ()
111+ ->with (1 )
112+ ->andReturn ($ paginator );
100113
101114 $ response = $ this ->getController ()->view (1 );
102115
103116 $ this ->assertIsViewResponse ($ response );
104117 $ this ->assertViewNameEquals ('admin.databases.view ' , $ response );
105118 $ this ->assertViewHasKey ('locations ' , $ response );
106119 $ this ->assertViewHasKey ('host ' , $ response );
120+ $ this ->assertViewHasKey ('databases ' , $ response );
107121 $ this ->assertViewKeyEquals ('locations ' , collect (['getAllWithNodes ' ]), $ response );
108122 $ this ->assertViewKeyEquals ('host ' , $ model , $ response );
123+ $ this ->assertViewKeyEquals ('databases ' , $ paginator , $ response );
109124 }
110125
111126 /**
@@ -118,6 +133,7 @@ private function getController(): DatabaseController
118133 return new DatabaseController (
119134 $ this ->alert ,
120135 $ this ->repository ,
136+ $ this ->databaseRepository ,
121137 $ this ->creationService ,
122138 $ this ->deletionService ,
123139 $ this ->updateService ,
0 commit comments