ExecuteSolutionControllerTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace Facade\Ignition\Tests\Http\Controllers;
  3. use Facade\Ignition\Tests\TestCase;
  4. class ExecuteSolutionControllerTest extends TestCase
  5. {
  6. protected function resolveApplicationConfiguration($app)
  7. {
  8. parent::resolveApplicationConfiguration($app);
  9. // Routes wont register in a console environment.
  10. $_ENV['APP_RUNNING_IN_CONSOLE'] = false;
  11. }
  12. /** @test */
  13. public function it_can_execute_solutions_on_a_local_environment_with_debugging_enabled()
  14. {
  15. $this->app['env'] = 'local';
  16. $this->app['config']->set('app.debug', true);
  17. $this->postJson(route('ignition.executeSolution'), $this->solutionPayload())
  18. ->assertSuccessful();
  19. }
  20. /** @test */
  21. public function it_wont_execute_solutions_on_a_production_environment()
  22. {
  23. $this->app['env'] = 'production';
  24. $this->app['config']->set('app.debug', true);
  25. $this->postJson(route('ignition.executeSolution'), $this->solutionPayload())
  26. ->assertForbidden();
  27. }
  28. /** @test */
  29. public function it_wont_execute_solutions_when_debugging_is_disabled()
  30. {
  31. $this->app['env'] = 'local';
  32. $this->app['config']->set('app.debug', false);
  33. $this->postJson(route('ignition.executeSolution'), $this->solutionPayload())
  34. ->assertNotFound();
  35. }
  36. /** @test */
  37. public function it_wont_execute_solutions_for_a_non_local_ip()
  38. {
  39. $this->app['env'] = 'local';
  40. $this->app['config']->set('app.debug', true);
  41. $this->withServerVariables(['REMOTE_ADDR' => '138.197.187.74']);
  42. $this->postJson(route('ignition.executeSolution'), $this->solutionPayload())
  43. ->assertForbidden();
  44. }
  45. protected function solutionPayload(): array
  46. {
  47. return [
  48. 'parameters' => [
  49. 'variableName' => 'test',
  50. 'viewFile' => 'resources/views/welcome.blade.php',
  51. ],
  52. 'solution' => 'Facade\\Ignition\\Solutions\\MakeViewVariableOptionalSolution',
  53. ];
  54. }
  55. }