diff --git a/tests/unit/Espo/Core/ControllerManagerTest.php b/tests/unit/Espo/Core/ControllerManagerTest.php new file mode 100644 index 0000000000..8734b408e9 --- /dev/null +++ b/tests/unit/Espo/Core/ControllerManagerTest.php @@ -0,0 +1,82 @@ +classFinder = $this->getMockBuilder(ClassFinder::class)->disableOriginalConstructor()->getMock(); + $this->injectableFactory = $this->getMockBuilder(InjectableFactory::class)->disableOriginalConstructor()->getMock(); + $this->request = $this->getMockBuilder(RequestWrapper::class)->disableOriginalConstructor()->getMock(); + $this->response = $this->getMockBuilder(ResponseWrapper::class)->disableOriginalConstructor()->getMock(); + + $this->controllerManager = new ControllerManager($this->injectableFactory, $this->classFinder); + } + + public function testAction1() + { + $controller = $this->getMockBuilder(TestController::class)->disableOriginalConstructor()->getMock(); + + $this->classFinder + ->expects($this->once()) + ->method('find') + ->with('Controllers', 'Test') + ->willReturn(TestController::class); + + $this->request + ->expects($this->once()) + ->method('getMethod') + ->willReturn('POST'); + + $this->injectableFactory + ->expects($this->once()) + ->method('createWith') + ->with(TestController::class, ['name' => 'Test']) + ->willReturn($controller); + + $controller + ->expects($this->once()) + ->method('postActionHello') + ->with($this->request, $this->response); + + $this->controllerManager->process('Test', 'hello', $this->request, $this->response); + } +} diff --git a/tests/unit/testClasses/Controllers/TestController.php b/tests/unit/testClasses/Controllers/TestController.php new file mode 100644 index 0000000000..2beb657a1b --- /dev/null +++ b/tests/unit/testClasses/Controllers/TestController.php @@ -0,0 +1,43 @@ +