2017-09-03 02:35:33 +00:00
|
|
|
<?php
|
2017-09-26 02:43:01 +00:00
|
|
|
/**
|
2017-09-03 02:35:33 +00:00
|
|
|
* Pterodactyl - Panel
|
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
|
|
|
*
|
2017-09-26 02:43:01 +00:00
|
|
|
* This software is licensed under the terms of the MIT license.
|
|
|
|
* https://opensource.org/licenses/MIT
|
2017-09-03 02:35:33 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Tests\Unit\Http\Controllers\Server;
|
|
|
|
|
|
|
|
use Mockery as m;
|
2017-09-03 21:41:03 +00:00
|
|
|
use Pterodactyl\Models\Server;
|
2017-09-03 02:35:33 +00:00
|
|
|
use Illuminate\Contracts\Config\Repository;
|
2017-11-03 21:43:28 +00:00
|
|
|
use Tests\Unit\Http\Controllers\ControllerTestCase;
|
2017-09-03 21:41:03 +00:00
|
|
|
use Pterodactyl\Http\Controllers\Server\ConsoleController;
|
2017-09-03 02:35:33 +00:00
|
|
|
|
2017-11-03 21:43:28 +00:00
|
|
|
class ConsoleControllerTest extends ControllerTestCase
|
2017-09-03 02:35:33 +00:00
|
|
|
{
|
|
|
|
/**
|
2017-11-03 21:43:28 +00:00
|
|
|
* @var \Illuminate\Contracts\Config\Repository|\Mockery\Mock
|
2017-09-03 02:35:33 +00:00
|
|
|
*/
|
|
|
|
protected $config;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup tests.
|
|
|
|
*/
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->config = m::mock(Repository::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test both controllers as they do effectively the same thing.
|
|
|
|
*
|
|
|
|
* @dataProvider controllerDataProvider
|
|
|
|
*/
|
|
|
|
public function testAllControllers($function, $view)
|
|
|
|
{
|
2017-11-03 21:43:28 +00:00
|
|
|
$controller = $this->getController();
|
2017-09-03 02:35:33 +00:00
|
|
|
$server = factory(Server::class)->make();
|
2017-11-03 21:43:28 +00:00
|
|
|
$this->setRequestAttribute('server', $server);
|
|
|
|
$this->mockInjectJavascript();
|
2017-09-03 02:35:33 +00:00
|
|
|
|
|
|
|
$this->config->shouldReceive('get')->with('pterodactyl.console.count')->once()->andReturn(100);
|
|
|
|
$this->config->shouldReceive('get')->with('pterodactyl.console.frequency')->once()->andReturn(10);
|
|
|
|
|
2017-11-03 21:43:28 +00:00
|
|
|
$response = $controller->$function($this->request);
|
2017-09-03 02:35:33 +00:00
|
|
|
$this->assertIsViewResponse($response);
|
|
|
|
$this->assertViewNameEquals($view, $response);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Provide data for the tests.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function controllerDataProvider()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
['index', 'server.index'],
|
|
|
|
['console', 'server.console'],
|
|
|
|
];
|
|
|
|
}
|
2017-11-03 21:43:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a mocked instance of the controller to allow access to authorization functionality.
|
|
|
|
*
|
|
|
|
* @return \Pterodactyl\Http\Controllers\Server\ConsoleController|\Mockery\Mock
|
|
|
|
*/
|
|
|
|
private function getController()
|
|
|
|
{
|
|
|
|
return $this->buildMockedController(ConsoleController::class, [$this->config]);
|
|
|
|
}
|
2017-09-03 02:35:33 +00:00
|
|
|
}
|