public function testCreateService() { $helperPluginManager = new HelperPluginManager(); $helperPluginManager->setServiceLocator(Bootstrap::getServiceManager()); $result = $this->testedObj->createService($helperPluginManager); $this->assertInstanceOf(FlashMessages::class, $result); }
public function __invoke(ContainerInterface $container) { $config = $container->has('config') ? $container->get('config') : []; $config = isset($config['view_helpers']) ? $config['view_helpers'] : []; $manager = new HelperPluginManager(new Config($config)); $manager->setServiceLocator($container); return $manager; }
/** * @test * @covers Cocur\Slugify\Bridge\ZF2\SlugifyViewHelperFactory::__invoke() */ public function createService() { $sm = new ServiceManager(); $sm->setService('Cocur\\Slugify\\Slugify', new Slugify()); $vhm = new HelperPluginManager(); $vhm->setServiceLocator($sm); $viewHelper = call_user_func($this->factory, $vhm); $this->assertInstanceOf('Cocur\\Slugify\\Bridge\\ZF2\\SlugifyViewHelper', $viewHelper); }
protected function setUp() { $this->request = new Request(); $serviceManager = new ServiceManager(); $serviceManager->setService('request', $this->request); $pluginManager = new HelperPluginManager(); $pluginManager->setServiceLocator($serviceManager); $this->pluginManager = $pluginManager; }
public function testFactory() { $serviceManager = new ServiceManager(); $pluginManager = new HelperPluginManager(); $pluginManager->setServiceLocator($serviceManager); $serviceManager->setService('ZfjRbac\\Service\\RoleService', $this->getMock('ZfjRbac\\Service\\RoleService', [], [], '', false)); $factory = new HasRoleViewHelperFactory(); $viewHelper = $factory->createService($pluginManager); $this->assertInstanceOf('ZfjRbac\\View\\Helper\\HasRole', $viewHelper); }
public function testFactory() { $serviceManager = new ServiceManager(); $pluginManager = new HelperPluginManager(); $pluginManager->setServiceLocator($serviceManager); $serviceManager->setService('ZfcRbac\\Service\\AuthorizationService', $this->getMock('ZfcRbac\\Service\\AuthorizationServiceInterface')); $factory = new IsGrantedViewHelperFactory(); $isGranted = $factory->createService($pluginManager); $this->assertInstanceOf('ZfcRbac\\View\\Helper\\IsGranted', $isGranted); }
public function testFactory() { $sm = new ServiceManager(); $sm->setService(BlockPoolInterface::class, $this->blockPool); $helperManager = new HelperPluginManager(); $helperManager->setServiceLocator($sm); $factory = new BlockFactory(); $helper = $factory->createService($helperManager); $this->assertInstanceOf(Block::class, $helper); $this->assertInstanceOf(AbstractHelper::class, $helper); }
public function testCanCreateServiceWithName() { $moduleOptions = new ModuleOptions(['view_helpers' => ['headLink' => ['proxy' => TestProxy::class]]]); $sm = new ServiceManager(); $sm->setService(ModuleOptions::class, $moduleOptions); $viewHelperManager = new HelperPluginManager(); $viewHelperManager->setServiceLocator($sm); $viewHelperManager->setInvokableClass(TestProxy::class, TestProxy::class); $factory = new ViewHelperProxyAbstractFactory(); $this->assertTrue($factory->canCreateServiceWithName($viewHelperManager, TestProxy::class, TestProxy::class)); $this->assertFalse($factory->canCreateServiceWithName($viewHelperManager, 'not-exist', 'not-exist')); }
protected function setUp() { $router = new Router(); $router->addRoute('home', array('type' => 'Zend\\Mvc\\Router\\Http\\Literal', 'options' => array('route' => '/'))); $router->addRoute('default', array('type' => 'Zend\\Mvc\\Router\\Http\\Segment', 'options' => array('route' => '/:controller[/:action]'))); $this->request = new Request(); $serviceManager = new ServiceManager(); $serviceManager->setService('router', $router); $serviceManager->setService('request', $this->request); $pluginManager = new HelperPluginManager(); $pluginManager->setServiceLocator($serviceManager); $this->pluginManager = $pluginManager; }
public function testFactoryReturnsInstanceOfParamsHelper() { $factory = new Factory(); $sm = new ServiceManager(); $event = new MvcEvent(); $application = $this->getMockBuilder('\\Zend\\Mvc\\Application')->disableOriginalConstructor()->setMethods(array('getMvcEvent'))->getMock(); $application->expects($this->once())->method('getMvcEvent')->will($this->returnValue($event)); $sm->setService('Application', $application); $hm = new HelperPluginManager(); $hm->setServiceLocator($sm); $helper = $factory->createService($hm); $this->assertInstanceOf('\\Core\\View\\Helper\\Params', $helper); }
public function testCreateService() { $this->applicationMock->expects($this->once())->method('getMvcEvent')->willReturnSelf(); $this->applicationMock->expects($this->once())->method('getRouteMatch')->willReturn(new RouteMatch([])); $sl = Bootstrap::getServiceManager(); $sl->setAllowOverride(true); $sl->setService('Application', $this->applicationMock); $sl->setAllowOverride(false); $helperPluginManager = new HelperPluginManager(); $helperPluginManager->setServiceLocator($sl); $result = $this->testedObj->createService($helperPluginManager); $this->assertInstanceOf(LanguagesSwitcher::class, $result); }
public function testGenerateViewHelpers() { $config = (new Module())->getConfig(); $helperPluginManager = new HelperPluginManager(); $helperPluginManager->setServiceLocator(new ServiceManager()); $filterManager = new FilterPluginManager(); $basePath = $helperPluginManager->get('basePath'); $basePath->setBasePath('/assets'); $basePathFilter = new BasePathFilter($basePath); $filterManager->setService('basePath', $basePathFilter); $cacheBusterFilter = new CacheBusterFilter(__DIR__ . '/_files'); $filterManager->setService('cacheBuster', $cacheBusterFilter); $generator = new ViewHelperGenerator($filterManager, $helperPluginManager, $config['con-layout']['view_helpers']); $renderer = new PhpRenderer(); $renderer->setHelperPluginManager($helperPluginManager); /* @var $headLink HeadLink */ $headLink = $helperPluginManager->get('headLink'); $headLinkProxy = new HeadLinkProxy($headLink); $helperPluginManager->setService(get_class($headLinkProxy), $headLinkProxy); /* @var $headScript HeadScript */ $headScript = $helperPluginManager->get('headScript'); $headScriptProxy = new HeadScriptProxy($headScript); $helperPluginManager->setService(get_class($headScriptProxy), $headScriptProxy); /* @var $doctype Doctype */ $doctype = $helperPluginManager->get('doctype'); $doctype('HTML5'); /* @var $headTitle HeadTitle */ $headTitle = $helperPluginManager->get('headTitle'); $headTitleProxy = new HeadTitleProxy($headTitle); $helperPluginManager->setService(get_class($headTitleProxy), $headTitleProxy); /* @var $headMeta HeadMeta */ $headMeta = $helperPluginManager->get('headMeta'); $headMetaProxy = new HeadMetaProxy($headMeta); $helperPluginManager->setService(get_class($headMetaProxy), $headMetaProxy); $headMeta->setView($renderer); $generator->generate($this->getLayoutStructure()); foreach (['/assets/css/test.css', '/assets/css/main.css'] as $expected) { $this->assertContains($expected, $headLink->toString()); } foreach (['jquery.min.js', 'jquery-ui.min.js'] as $expected) { $this->assertContains($expected, $headScript->toString()); } $this->assertEquals('<!DOCTYPE html>', (string) $doctype); $headTitle->setSeparator(' | '); $expected = 'First | My Title | Another Title'; $this->assertContains($expected, $headTitle->toString()); $contains = ['charset="utf8"', 'name="description" content="My description"', 'name="keywords" content="keyword1, keyword2, keyword3"']; foreach ($contains as $expected) { $this->assertContains($expected, $headMeta->toString()); } }
/** * @return ServiceLocatorInterface */ private function createServiceLocator(MvcEvent $e = null) { $sm = new ServiceManager(); $sm->setService('Request', new Request()); $sm->setService('Response', new Response()); $sm->setService('EventManager', new EventManager()); $sm->setService('Router', TreeRouteStack::factory(['routes' => []])); $e = $e ?: new MvcEvent(); $app = $this->prophesize('Zend\\Mvc\\Application'); $app->getMvcEvent()->willReturn($e); $sm->setService('Application', $app->reveal()); $helperManager = new HelperPluginManager(); $helperManager->setServiceLocator($sm); return $helperManager; }
/** * @return ServiceLocatorInterface */ private function createServiceLocator(MvcEvent $e = null) { $sm = new ServiceManager(); $sm->setService('Request', new Request()); $sm->setService('Response', new Response()); $sm->setService('EventManager', new EventManager()); $sm->setService('Router', TreeRouteStack::factory(['routes' => []])); $e = $e ?: new MvcEvent(); $app = $this->getMock('Zend\\Mvc\\Application', [], [[], $sm]); $app->expects($this->any())->method('getMvcEvent')->willReturn($e); $sm->setService('Application', $app); $helperManager = new HelperPluginManager(); $helperManager->setServiceLocator($sm); return $helperManager; }
public function testInvokeAppendsJsApiUrlToHeadScriptHelper() { $cleengApi = $this->getMock('Cleeng_Api', array('getJsApiUrl')); $cleengApi->expects($this->once())->method('getJsApiUrl')->will($this->returnValue('https://cleeng.com/api-endpoint')); $headScript = $this->getMock('Zend\\View\\Helper\\HeadScript', array('appendFile')); $headScript->expects($this->once())->method('appendFile')->with('https://cleeng.com/api-endpoint'); $sm = new ServiceManager(); $sm->setService('Cleeng\\Api', $cleengApi); $pluginManager = new HelperPluginManager(); $pluginManager->setServiceLocator($sm); $view = $this->getMock('Zend\\View\\Renderer\\PhpRenderer', array('plugin')); $view->expects($this->once())->method('plugin')->with('headScript')->will($this->returnValue($headScript)); $helper = new EnableCleengJsApi(); $helper->setServiceLocator($pluginManager); $helper->setView($view); $helper->__invoke(); }
/** * Generic test for the constructor * * @return null * @covers \Rcm\Factory\ContainerViewHelperFactory */ public function testCreateService() { $mockPluginManager = $this->getMockBuilder('\\Rcm\\Service\\PluginManager')->disableOriginalConstructor()->getMock(); $mockEntityManager = $this->getMockBuilder('\\Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $mockContainerRepo = $this->getMockBuilder('\\Rcm\\Repository\\Container')->disableOriginalConstructor()->getMock(); $mockEntityManager->expects($this->any())->method('getRepository')->will($this->returnValue($mockContainerRepo)); $site = new Site(); $site->setSiteId(1); $sm = new ServiceManager(); $sm->setService('Doctrine\\ORM\\EntityManager', $mockEntityManager); $sm->setService('Rcm\\Service\\PluginManager', $mockPluginManager); $sm->setService('Rcm\\Service\\CurrentSite', $site); $helperManager = new HelperPluginManager(); $helperManager->setServiceLocator($sm); $factory = new ContainerViewHelperFactory(); $object = $factory->createService($helperManager); $this->assertTrue($object instanceof Container); }
private function createZendView(ServiceLocatorInterface $serviceLocator) { $config = $serviceLocator->get('Configuration'); if (isset($config['view_manager'], $config['view_manager']['template_path_stack'])) { $templatePaths = $config['view_manager']['template_path_stack']; } else { $templatePaths = []; } $resolver = new TemplatePathStack(['script_paths' => $templatePaths]); $phpRenderer = new PhpRenderer(); $phpRenderer->setResolver($resolver); $zendView = new ZendView(); $zendView->getEventManager()->attach(ViewEvent::EVENT_RENDERER, function () use($phpRenderer) { return $phpRenderer; }); // view helpers? if (isset($config['view_helpers'])) { $helperManagerConfig = new Config($config['view_helpers']); $pluginManager = new HelperPluginManager($helperManagerConfig); $pluginManager->setServiceLocator($serviceLocator); $phpRenderer->setHelperPluginManager($pluginManager); } return $zendView; }
public function createPluginManager(ServiceManager $serviceManager) { $pluginManager = new HelperPluginManager(); $pluginManager->setServiceLocator($serviceManager); return $pluginManager; }
public function testCanDisplayListOfCurrentMessagesCustomisedByConfigSeparator() { $this->seedCurrentMessages(); $config = array('view_helper_config' => array('flashmessenger' => array('message_open_format' => '<div><ul><li%s>', 'message_separator_string' => '</li><li%s>', 'message_close_string' => '</li></ul></div>'))); $sm = new ServiceManager(); $sm->setService('Config', $config); $helperPluginManager = new HelperPluginManager(new Config(array('factories' => array('flashmessenger' => 'Zend\\View\\Helper\\Service\\FlashMessengerFactory')))); $controllerPluginManager = new PluginManager(new Config(array('invokables' => array('flashmessenger' => 'Zend\\Mvc\\Controller\\Plugin\\FlashMessenger')))); $helperPluginManager->setServiceLocator($sm); $controllerPluginManager->setServiceLocator($sm); $sm->setService('ControllerPluginManager', $controllerPluginManager); $helper = $helperPluginManager->get('flashmessenger'); $displayInfoAssertion = '<div><ul><li class="foo-baz foo-bar">foo</li><li class="foo-baz foo-bar">bar</li></ul></div>'; $displayInfo = $helper->renderCurrent(PluginFlashMessenger::NAMESPACE_DEFAULT, array('foo-baz', 'foo-bar')); $this->assertEquals($displayInfoAssertion, $displayInfo); }
public function testCanDisplayListOfMessagesCustomisedByConfig() { $this->seedMessages(); $config = array( 'view_helper_config' => array( 'flashmessenger' => array( 'message_open_format' => '<div%s><ul><li>', 'message_separator_string' => '</li><li>', 'message_close_string' => '</li></ul></div>', ), ), ); $sm = new ServiceManager(); $sm->setService('Config', $config); $helperPluginManager = new HelperPluginManager(new Config(array( 'factories' => array( 'flashmessenger' => 'Zend\View\Helper\Service\FlashMessengerFactory', ), ))); $controllerPluginManager = new PluginManager(new Config(array( 'invokables' => array( 'flashmessenger' => 'Zend\Mvc\Controller\Plugin\FlashMessenger', ), ))); $helperPluginManager->setServiceLocator($sm); $controllerPluginManager->setServiceLocator($sm); $sm->setService('ControllerPluginManager', $controllerPluginManager); $helper = $helperPluginManager->get('flashmessenger'); $displayInfoAssertion = '<div class="info"><ul><li>bar-info</li></ul></div>'; $displayInfo = $helper->render(PluginFlashMessenger::NAMESPACE_INFO); $this->assertEquals($displayInfoAssertion, $displayInfo); }
/** * @dataProvider serviceManagerProvider */ public function testCreateService(ServiceManager $sm) { $this->viewHelperPluginManager->setServiceLocator($sm); $helper = $this->viewHelperPluginManager->get('hangerSnippet'); $this->assertInstanceOf('\\HangerSnippet\\View\\Helper\\SnippetHelper', $helper); }
public function testServiceManagerIsUsedToRetrieveContainer() { $container = new Container(); $serviceManager = new ServiceManager(); $serviceManager->setService('navigation', $container); $pluginManager = new View\HelperPluginManager(); $pluginManager->setServiceLocator($serviceManager); $this->_helper->setServiceLocator($pluginManager); $this->_helper->setContainer('navigation'); $expected = $this->_helper->getContainer(); $actual = $container; $this->assertEquals($expected, $actual); }
/** * @param Version $version * * @return array */ private function parseProjectEvaluation(Version $version) { $rows = []; $cols = []; $cols['dt'] = ['width' => 3000, 'align' => '']; $cols['di'] = ['width' => 2000, 'align' => '']; $cols['dd'] = ['width' => $this->tableWidth - 5000, 'align' => '']; $countries = $this->getGeneralService()->findCountryByProject($version->getProject(), AffiliationService::WHICH_ONLY_ACTIVE); $evaluationType = $this->getEvaluationService()->findEntityById('Evaluation\\Type', $version->getVersionType()->getEvaluationType()); $evaluation = new CreateEvaluation(); $pluginServiceManager = new HelperPluginManager(); $pluginServiceManager->setServiceLocator($this->getServiceLocator()); $evaluation->setServiceLocator($pluginServiceManager); $evaluationResult = $evaluation->create([$version->getProject()], $evaluationType, Evaluation::DISPLAY_EFFORT, MatrixFilter::SOURCE_VERSION); $rows[] = ['dt' => 'Country', 'di' => 'Evaluation', 'dd' => 'Review']; foreach ($countries as $country) { $projectEvaluation = $evaluationResult[$country->getId()][$version->getProject()->getId()]; $evaluation = $projectEvaluation['evaluation']; $rows[] = ['dt' => $country, 'di' => $evaluation->getStatus()->getStatusEvaluation(), 'dd' => $evaluation->getDescription()]; } return ['cols' => $cols, 'rows' => $rows]; }