public function testIndexActionReturnsTrueOnSuccess() { $postData = ['email' => '*****@*****.**']; $messageServiceMock = $this->getMock(Subscriber::class); $messageServiceMock->method('getForm')->willReturn(new PreferencesForm()); $messageServiceMock->method('removeSubscriberFromList')->willReturn(1); $serviceManager = $this->getApplicationServiceLocator(); $serviceManager->setAllowOverride(true); $serviceManager->get('UthandoServiceManager')->setService('UthandoNewsletterSubscriber', $messageServiceMock); $oPrg = $this->getMock(PostRedirectGet::class); $oPrg->expects($this->any())->method('__invoke')->willReturn($postData); $pluginManager = $serviceManager->get('ControllerPluginManager'); $pluginManager->setService('prg', $oPrg); $controller = new Preferences(); $controller->setServiceLocator($serviceManager); $controller->setPluginManager($pluginManager); $result = $controller->indexAction(); $this->assertEquals(1, $result['result']); }
public function testPreferencesControllerRules() { $serviceManager = $this->getServiceManager(); $resource = 'UthandoNewsletter\\Controller\\Preferences'; $controller = new Preferences(); $controller->setServiceLocator($serviceManager); $controller->setPluginManager($serviceManager->get('ControllerPluginManager')); /* @var \UthandoUser\Controller\Plugin\IsAllowed $acl */ $acl = $controller->plugin('isAllowed'); // guest rules $identity = null; $acl->setIdentity($identity); $this->assertInstanceOf(GenericRole::class, $acl->getIdentity()); $this->assertTrue($acl->isAllowed($resource, 'index')); // registered user rules $identity = $this->getRegisteredUser(); $acl->setIdentity($controller->identity()); $this->assertEquals($identity, $acl->getIdentity()); $this->assertTrue($acl->isAllowed($resource, 'index')); // admin user rules $identity = $this->getAdminUser(); $acl->setIdentity($controller->identity()); $this->assertEquals($identity, $acl->getIdentity()); $this->assertTrue($acl->isAllowed($resource, 'index')); }