public static function init()
 {
     // Load the user-defined test configuration file, if it exists; otherwise, load
     if (is_readable(__DIR__ . '/TestConfig.php')) {
         $testConfig = (include __DIR__ . '/TestConfig.php');
     } else {
         $testConfig = (include __DIR__ . '/TestConfig.php.dist');
     }
     $zf2ModulePaths = array();
     if (isset($testConfig['module_listener_options']['module_paths'])) {
         $modulePaths = $testConfig['module_listener_options']['module_paths'];
         foreach ($modulePaths as $modulePath) {
             if ($path = static::findParentPath($modulePath)) {
                 $zf2ModulePaths[] = $path;
             }
         }
     }
     $zf2ModulePaths = implode(PATH_SEPARATOR, $zf2ModulePaths) . PATH_SEPARATOR;
     $zf2ModulePaths .= getenv('ZF2_MODULES_TEST_PATHS') ?: (defined('ZF2_MODULES_TEST_PATHS') ? ZF2_MODULES_TEST_PATHS : '');
     static::initAutoloader();
     // use ModuleManager to load this module and it's dependencies
     $baseConfig = array('module_listener_options' => array('module_paths' => explode(PATH_SEPARATOR, $zf2ModulePaths)));
     $config = ArrayUtils::merge($baseConfig, $testConfig);
     $serviceManager = new ServiceManager(new ServiceManagerConfig());
     $serviceManager->setService('ApplicationConfig', $config);
     $serviceManager->get('ModuleManager')->loadModules();
     static::$serviceManager = $serviceManager;
     static::$config = $config;
 }
 public function testCreateService()
 {
     $sm = new ServiceManager();
     $sm->setService('Acelaya\\Yaml\\View\\Renderer\\YamlRenderer', new YamlRenderer());
     $service = $this->factory->createService($sm);
     $this->assertInstanceOf('Acelaya\\Yaml\\View\\Strategy\\YamlStrategy', $service);
 }
 public function setUp()
 {
     $this->pluginManager = new RulePluginManager();
     $serviceManager = new ServiceManager();
     $serviceManager->setService('MvcTranslator', new Translator());
     $this->pluginManager->setServiceLocator($serviceManager);
 }
 /**
  * Init an instance of QueueWriter and configure an internal instance of ServiceManager
  *
  * @param array $config
  * @return QueueWriterInterface
  */
 public static function get(array $config)
 {
     $serviceConfig = (include dirname(dirname(dirname(__DIR__))) . '/config/services.config.php');
     $services = new ServiceManager(new Config($serviceConfig['service_manager']));
     $services->setService("Config", $config);
     return $services->get('recommerce.queue-manager.queue-writer');
 }
Example #5
0
 /**
  * {@inheritDoc}
  */
 public function setUp()
 {
     $this->serviceManager = Bootstrap::getServiceManager();
     $this->doa = new Doa();
     $this->doa->setId(1);
     $program = new Program();
     $program->setId(1);
     $program->setProgram('Program');
     $this->doa->setProgram($program);
     $organisation = new Organisation();
     $organisation->setId(1);
     $organisation->setOrganisation("Organisation");
     $this->doa->setOrganisation($organisation);
     $this->authorizeService = $this->serviceManager->get('BjyAuthorize\\Service\\Authorize');
     if (!$this->authorizeService->getAcl()->hasResource($this->doa)) {
         $this->authorizeService->getAcl()->addResource($this->doa);
         $this->authorizeService->getAcl()->allow([], $this->doa, []);
     }
     /**
      * Add the resource on the fly
      */
     if (!$this->authorizeService->getAcl()->hasResource(new Doa())) {
         $this->authorizeService->getAcl()->addResource(new Doa());
     }
     $this->authorizeService->getAcl()->allow([], new Doa(), []);
     $this->doaLink = $this->serviceManager->get('viewhelpermanager')->get('programDoaLink');
     /**
      * Bootstrap the application to have the other information available
      */
     $application = $this->serviceManager->get('application');
     $application->bootstrap();
 }
 public function configureServiceManager(\Zend\ServiceManager\ServiceManager $serviceManager)
 {
     $serviceManager->setFactory('A', function () {
         return new A();
     });
     $serviceManager->setShared('A', false);
 }
Example #7
0
 /**
  * Setup
  */
 protected function setUp()
 {
     // get service manager
     $this->serviceLocator = FileManagerBootstrap::getServiceLocator();
     // get base user model instance
     $this->userModel = $this->serviceLocator->get('Application\\Model\\ModelManager')->getInstance('User\\Model\\UserBase');
 }
Example #8
0
 /**
  * Setup
  */
 protected function setUp()
 {
     // get service manager
     $this->serviceLocator = ApplicationBootstrap::getServiceLocator();
     // get base model instance
     $this->model = $this->serviceLocator->get('Application\\Model\\ModelManager')->getInstance('Application\\Model\\ApplicationBase');
 }
Example #9
0
 /**
  * @covers Hermes\Api\ClientFactory::createService
  */
 public function testCreateService()
 {
     $sm = new ServiceManager(new Config([]));
     $sm->setService('config', ['hermes' => ['uri' => 'http://localhost:8000', 'depth' => 0, 'headers' => [], 'http_client' => ['options' => []]]]);
     $client = $this->object->createService($sm);
     $this->assertInstanceOf(Client::class, $client);
 }
 public function testInvoke()
 {
     $sm = new ServiceManager();
     $sm->setService('config', ['recaptcha' => ['private_key' => 'foo']]);
     $instance = $this->factory->__invoke($sm, '');
     $this->assertInstanceOf(ReCaptcha::class, $instance);
 }
 public function testCreateService()
 {
     $this->sm->setService('Matryoshka\\Model\\Object\\ObjectManager', $this->om);
     $this->pm->setServiceLocator($this->sm);
     $object = $this->factory->createService($this->pm);
     $this->assertInstanceOf('Matryoshka\\Module\\Controller\\Plugin\\Object', $object);
 }
Example #12
0
 /**
  * Sends the mail to user with info about successfull registration
  *
  * @param \User\Entity\User $user
  * @param string $password
  * @param string $siteName
  */
 public function noticeOfCreation(UserEntity $user, $password, $siteName, $actUrl = null)
 {
     $template = $this->storage->getByKey(2);
     $serverUrl = $this->serviceManager->get('ViewHelperManager')->get('serverUrl');
     $body = str_replace(array("[NAME]", "[SITENAME]", "[LOGINNAME]", "[PASSWORD]", "[SITEURL]", "[ACTIVATIONLINK]"), array($user->username, $siteName, $user->username, $password, $serverUrl(), sprintf('<a href="%s">%s</a>', $actUrl, $actUrl)), $template->emailBody);
     return $this->send($user->username, $template->emailSubject, $body);
 }
Example #13
0
 public function wp_authenticate($hash, $password, ServiceManager $sm)
 {
     /** @var PasswordHash $wp_hasher */
     $wp_hasher = $sm->get('wp_hasher');
     $result = $wp_hasher->CheckPassword($password, $hash);
     return $result;
 }
Example #14
0
 /**
  * Generates certificate of exellence and
  * triggers an event when the file is generated
  * @param \User\Model\Entity\User $user
  * @param string $examName
  */
 public function generateCertificate($user, $examName)
 {
     $config = $this->services->get('config');
     $pdf = PdfDocument::load($config['pdf']['exam_certificate']);
     // get the first page
     $page = $pdf->pages[0];
     // Extract the AdineKirnberg-Script font included in the PDF sample
     $font = $page->extractFont('AdineKirnberg-Script');
     $page->setFont($font, 80);
     // and write the name of the user with it
     $page->drawText($user->getName(), 200, 280);
     // after that use Time Bold to write the name of the exam
     $font = PdfFont::fontWithName(PdfFont::FONT_TIMES_BOLD);
     $page->setFont($font, 40);
     $page->drawText($examName, 200, 120);
     // We use the png image from the public/images folder
     $imageFile = 'public/images/zf2-logo.png';
     // get the right size to do some calculations
     $size = getimagesize($imageFile);
     // load the image
     $image = \ZendPdf\Image::imageWithPath($imageFile);
     $x = 580;
     $y = 440;
     // and finally draw the image
     $page->drawImage($image, $x, $y, $x + $size[0], $y + $size[1]);
     return $pdf;
 }
Example #15
0
 public function getServiceLocator(array $config = array())
 {
     $serviceLocator = new ServiceManager();
     $serviceLocator->setFactory('MQUtil\\Service\\ShortUrl', 'MQUtil\\Service\\ShortUrlFactory');
     $serviceLocator->setService('config', $config);
     return $serviceLocator;
 }
 public function testEquals()
 {
     $ids = array("B004UMO24E", "B00B6U14XA", "B00HQ2N52K", "B00B8XYO9G", "B00L3S2LWS", "B00L3S2LWS", "c3d33ab7-5dc5-41e6-8d2a-0aadbcffb738", "B00NH3GL96", "B00EKH4FP0", "50d98962-9561-4028-9282-37191f8772e3", "B008TUNEFG", "B00GG0GKDO", "B00CO79BXO", "B00O6BO6O0", "B00NPO529C", "B00NPIB7Z6", "B00H6MMV20", "B00NPLNUQ2", "B00NPLNRWY", "B00O5NGFBQ", "B00FXYJ568", "B005K00TLU", "B00IJEFRSY", "B00JQ4KY5C", "B00IJEFRSY", "B00J6ZHEHC", "B00J6ZHEHC", "B00B9CFYBI", "e6bb95b8-6af6-4dc8-bcd8-c6950c0ab046", "B00N02YOJ8", "B00EDGGW54", "B00D83XPTE", "B00M4YVHLQ", "B00NAGZB4Q", "B00L7N451E", "B00N1Q6Z86", "B00O1AJBU0", "B00H377PVK", "B00JPXT2WK", "B005SG6ELU", "B00LWXT17C", "B00LWXT22G", "B00O09LGIW", "B00NEF3KNW", "B00NN7B7FE", "B00JJWLB4O", "B00HS0H41S", "B00JQQPEC8", "B00O1HTQ0I", "B00GS02S8S");
     $config = $this->getApplicationConfig()['amazon-apai'];
     $apaiIoWrapper = new ApaiIOWrapper($config);
     /*
        #     $result2 =  $apaiIoWrapper->getByASIN('B00EDGGW54', 'de');
               #      $result2 =  $apaiIoWrapper->getByASIN('B00N02YOJ8', 'de');
        #     $result =  $apaiIoWrapper->getByASIN('B00GS02S8S', 'de');
                     #$result2 =  $apaiIoWrapper->getByASIN('B00EDGGW54', 'de');
     */
     /**
      * @var $itemNotFoundService ItemNotFoundServiceInterface
      */
     $itemNotFoundService = $this->serviceManager->get(ItemNotFoundServiceInterface::class);
     $countryCode = 'de';
     $resultSet = $apaiIoWrapper->getByASINS($ids, $countryCode);
     $notFound = $apaiIoWrapper->getItemsNotFound();
     foreach ($notFound[$countryCode] as $item) {
         $itemNotFound = new ItemNotFound();
         $itemNotFound->setAsin($item);
         $itemNotFound->setSearchedDe(true);
         $itemNotFoundService->getEntityManager()->persist($itemNotFound);
     }
     $itemNotFoundService->getEntityManager()->flush();
     $break = true;
 }
Example #17
0
    /**
     * Sends award certificate
     *
     * @param \User\Model\Entity\User $user
     * @param array $exam
     * @param \ZendPdf\Document $pdf
     */
    public function sendCertificate($user, $exam, $pdf)
    {
        $translator = $this->services->get('translator');
        $mail = new Message();
        $mail->addTo($user->getEmail(), $user->getName());
        $text = 'You are genius!
You answered all the questions correctly.
Therefore we are sending you as a gratitude this free award certificate.

';
        // we create a new mime message
        $mimeMessage = new MimeMessage();
        // create the original body as part
        $textPart = new MimePart($text);
        $textPart->type = "text/plain";
        // add the pdf document as a second part
        $pdfPart = new MimePart($pdf->render());
        $pdfPart->type = 'application/pdf';
        $mimeMessage->setParts(array($textPart, $pdfPart));
        $mail->setBody($mimeMessage);
        $mail->setFrom('*****@*****.**', 'Slavey Karadzhov');
        $mail->setSubject($translator->translate('Congratulations: Here is your award certificate'));
        $transport = $this->services->get('mail-transport');
        $transport->send($mail);
    }
Example #18
0
 public static function init()
 {
     if (is_readable(__DIR__ . '/config.php')) {
         $testConfig = (include __DIR__ . '/config.php');
     } else {
         $testConfig = (include __DIR__ . '/config.php.dist');
     }
     $moduleName = pathinfo(realpath(dirname(__DIR__)), PATHINFO_BASENAME);
     if (defined('MODULE_NAME')) {
         $moduleName = MODULE_NAME;
     }
     $zf2ModulePaths = array(dirname(dirname(__DIR__)));
     if ($path = static::findParentPath('vendor')) {
         $modulePaths[] = $path;
     }
     if (($path = static::findParentPath('module')) !== $modulePaths[0]) {
         $modulePaths[] = $path;
     }
     if (isset($additionalModulePaths)) {
         $zf2ModulePaths = array_merge($modulePaths, $additionalModulePaths);
     } else {
         $zf2ModulePaths = $modulePaths;
     }
     $zf2ModulePaths = implode(PATH_SEPARATOR, $zf2ModulePaths) . PATH_SEPARATOR;
     static::initAutoloader();
     $baseConfig = ['module_listener_options' => ['module_paths' => explode(PATH_SEPARATOR, $zf2ModulePaths)], 'modules' => [$moduleName]];
     $config = ArrayUtils::merge($baseConfig, $testConfig);
     $serviceManager = new ServiceManager(new ServiceManagerConfig());
     $serviceManager->setService('ApplicationConfig', $config);
     $serviceManager->get('ModuleManager')->loadModules();
     static::$serviceManager = $serviceManager;
 }
 /**
  * Check var/generation read and write access
  *
  * @return bool
  */
 public function check()
 {
     $initParams = $this->serviceManager->get(InitParamListener::BOOTSTRAP_PARAM);
     $filesystemDirPaths = isset($initParams[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS]) ? $initParams[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS] : [];
     $directoryList = new DirectoryList(BP, $filesystemDirPaths);
     $generationDirectoryPath = $directoryList->getPath(DirectoryList::GENERATION);
     $driverPool = new DriverPool();
     $fileWriteFactory = new WriteFactory($driverPool);
     /** @var \Magento\Framework\Filesystem\DriverInterface $driver */
     $driver = $driverPool->getDriver(DriverPool::FILE);
     $directoryWrite = new Write($fileWriteFactory, $driver, $generationDirectoryPath);
     if ($directoryWrite->isExist()) {
         if ($directoryWrite->isDirectory() || $directoryWrite->isReadable()) {
             try {
                 $probeFilePath = $generationDirectoryPath . DIRECTORY_SEPARATOR . uniqid(mt_rand()) . 'tmp';
                 $fileWriteFactory->create($probeFilePath, DriverPool::FILE, 'w');
                 $driver->deleteFile($probeFilePath);
             } catch (\Exception $e) {
                 return false;
             }
         } else {
             return false;
         }
     } else {
         try {
             $directoryWrite->create();
         } catch (\Exception $e) {
             return false;
         }
     }
     return true;
 }
Example #20
0
File: Create.php Project: zfury/cmf
 /**
  * @return $this
  */
 protected function email()
 {
     $recordExistsValidator = new UniqueObject(array('object_repository' => $this->sm->get('Doctrine\\ORM\\EntityManager')->getRepository('Test\\Entity\\Test'), 'object_manager' => $this->sm->get('Doctrine\\ORM\\EntityManager'), 'fields' => 'email', 'use_context' => true));
     $recordExistsValidator->setMessage('This email already in use', UniqueObject::ERROR_OBJECT_NOT_UNIQUE);
     $this->add(array('name' => 'email', 'required' => true, 'validators' => array(array('name' => 'EmailAddress'), $recordExistsValidator), 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'))));
     return $this;
 }
 public function testFactory()
 {
     $serviceManager = new ServiceManager();
     $serviceManager->setService('zfcuser_module_options', new ModuleOptions());
     $factory = new ChangePasswordFormFactory();
     $this->assertInstanceOf('ZfcUser\\Form\\ChangePassword', $factory->createService($serviceManager));
 }
 public function setUp()
 {
     $addressService = $this->getMockBuilder('Ajasta\\Address\\Service\\AddressService')->disableOriginalConstructor()->getMock();
     $this->serviceLocator = new ServiceManager();
     $this->serviceLocator->setService('Ajasta\\Address\\Service\\AddressService', $addressService);
     $this->serviceLocator->setService('Ajasta\\Locale', 'en-US');
 }
 public function testWillNotInstantiateConfigWithInvalidNamingStrategyReference()
 {
     $config = array('doctrine' => array('configuration' => array('test_default' => array('naming_strategy' => 'test_naming_strategy'))));
     $this->serviceManager->setService('Config', $config);
     $this->setExpectedException('Zend\\ServiceManager\\Exception\\InvalidArgumentException');
     $this->factory->createService($this->serviceManager);
 }
 /**
  * @expectedException \HumusAmqpModule\Exception\InvalidArgumentException
  * @expectedExceptionMessage The logger invalid stuff is not configured
  */
 public function testCreateConsumerThrowsExceptionOnInvalidLogger()
 {
     $config = $this->services->get('Config');
     $config['humus_amqp_module']['rpc_servers']['test-rpc-server']['logger'] = 'invalid stuff';
     $this->services->setService('Config', $config);
     $this->components->createServiceWithName($this->services, 'test-rpc-server', 'test-rpc-server');
 }
 public function testFactory()
 {
     $serviceManager = new ServiceManager();
     $serviceManager->setService('HtImg\\Imagine', new Imagine());
     $factory = new ImageStrategyFactory();
     $this->assertInstanceOf('HtImgModule\\View\\Strategy\\ImageStrategy', $factory->createService($serviceManager));
 }
Example #26
0
 /**
  * Setup
  */
 protected function setUp()
 {
     // get service manager
     $this->serviceLocator = AclBootstrap::getServiceLocator();
     // get acl model
     $this->aclModelBase = $this->serviceLocator->get('Application\\Model\\ModelManager')->getInstance('Acl\\Model\\AclBase');
 }
Example #27
0
 /**
  * Generic plugin manager factory (support method).
  *
  * @param ServiceManager $sm Service manager.
  * @param string         $ns VuFind namespace containing plugin manager
  *
  * @return object
  */
 public static function getGenericPluginManager(ServiceManager $sm, $ns)
 {
     $className = 'Finna\\' . $ns . '\\PluginManager';
     $configKey = strtolower(str_replace('\\', '_', $ns));
     $config = $sm->get('Config');
     return new $className(new \Zend\ServiceManager\Config($config['vufind']['plugin_managers'][$configKey]));
 }
 public function testInvoke()
 {
     $sm = new ServiceManager();
     $sm->setService('config', ['translator' => []]);
     $instance = $this->factory->__invoke($sm, '');
     $this->assertInstanceOf(Translator::class, $instance);
 }
Example #29
0
 /**
  * Handle layout titles onDispatch.
  *
  * @param MvcEvent $event
  */
 public function setTitleAndTranslation(MvcEvent $event)
 {
     $route = $event->getRouteMatch();
     $title = $this->service->get('ControllerPluginManager')->get('systemsettings');
     $viewHelper = $this->service->get('ViewHelperManager');
     $lang = new Container('translations');
     $translator = $this->service->get('translator');
     /*
      * Load translations.
      */
     $renderer = $this->service->get('ViewManager')->getRenderer();
     $renderer->plugin('formRow')->setTranslator($translator, 'SD_Translations');
     $renderer->plugin('formCollection')->setTranslator($translator, 'SD_Translations');
     $renderer->plugin('formLabel')->setTranslator($translator, 'SD_Translations');
     $renderer->plugin('formSelect')->setTranslator($translator, 'SD_Translations');
     $renderer->plugin('formSubmit')->setTranslator($translator, 'SD_Translations');
     AbstractValidator::setDefaultTranslator($translator, 'formandtitle');
     $translator->setLocale($lang->offsetGet('languageName'))->setFallbackLocale('en');
     $viewModel = $event->getViewModel();
     $viewModel->setVariable('lang', $translator->getLocale());
     /*
      * Custom flash messenger.
      */
     $msg = $lang->offsetGet('flashMessages');
     $viewModel->setVariable('flashMessages', $msg);
     /*
      * Load page title
      */
     $action = $route->getParam('post') ? ' - ' . $route->getParam('post') : ucfirst($route->getParam('__CONTROLLER__'));
     $headTitleHelper = $viewHelper->get('headTitle');
     $headTitleHelper->append($title->__invoke('general', 'site_name') . ' ' . $action);
 }
 public function testFactory()
 {
     $serviceManager = new ServiceManager();
     $serviceManager->setService('HtImg\\ModuleOptions', new ModuleOptions());
     $factory = new CacheManagerFactory();
     $this->assertInstanceOf('HtImgModule\\Service\\CacheManager', $factory->createService($serviceManager));
 }