Beispiel #1
0
 /**
  * @dataProvider compareProvider
  */
 public function testCompare($version, $expression, $result, $strict = false, $message = null)
 {
     if (null === $message) {
         $message = sprintf("Version: %s, expression: %s, expected: %s", $version, $expression, $result ? "true" : "false");
     }
     $this->assertSame($result, Tester::test($version, $expression, $strict), $message);
 }
 public function configure()
 {
     if (null !== ($response = $this->checkAuth(AdminResources::MODULE, 'forcephone', AccessManager::UPDATE))) {
         return $response;
     }
     $configurationForm = $this->createForm('forcephone_configuration');
     $message = null;
     try {
         $form = $this->validateForm($configurationForm);
         // Get the form field values
         $data = $form->getData();
         foreach ($data as $name => $value) {
             if (is_array($value)) {
                 $value = implode(';', $value);
             }
             ForcePhone::setConfigValue($name, $value);
         }
         // Log configuration modification
         $this->adminLogAppend("forcephone.configuration.message", AccessManager::UPDATE, "ForcePhone configuration updated");
         // Redirect to the success URL,
         if ($this->getRequest()->get('save_mode') == 'stay') {
             // If we have to stay on the same page, redisplay the configuration page/
             $url = '/admin/module/ForcePhone';
         } else {
             // If we have to close the page, go back to the module back-office page.
             $url = '/admin/modules';
         }
         return $this->generateRedirect(URL::getInstance()->absoluteUrl($url));
     } catch (FormValidationException $ex) {
         $message = $this->createStandardFormValidationErrorMessage($ex);
     } catch (\Exception $ex) {
         $message = $ex->getMessage();
     }
     $this->setupFormErrorContext($this->getTranslator()->trans("ForcePhone configuration", [], ForcePhone::DOMAIN_NAME), $message, $configurationForm, $ex);
     // Before 2.2, the errored form is not stored in session
     if (Version::test(Thelia::THELIA_VERSION, '2.2', false, "<")) {
         return $this->render('module-configure', ['module_code' => 'ForcePhone']);
     } else {
         return $this->generateRedirect(URL::getInstance()->absoluteUrl('/admin/module/ForcePhone'));
     }
 }
 public function testVirtualProductDelivery()
 {
     $modulePath = THELIA_MODULE_DIR . "VirtualProductDelivery";
     $moduleValidator = new ModuleValidator($modulePath, $this->getStubTranslator());
     $moduleDescriptor = $moduleValidator->getModuleDescriptor();
     $this->assertInstanceOf('SimpleXMLElement', $moduleDescriptor);
     $this->assertEquals("2", $moduleValidator->getModuleVersion());
     $moduleDefinition = $moduleValidator->getModuleDefinition();
     $this->assertInstanceOf('Thelia\\Module\\Validator\\ModuleDefinition', $moduleDefinition);
     $this->assertEquals("VirtualProductDelivery", $moduleDefinition->getCode());
     $this->assertEquals("VirtualProductDelivery\\VirtualProductDelivery", $moduleDefinition->getNamespace());
     $this->assertEquals(2, count($moduleDefinition->getLanguages()));
     $this->assertEquals(0, count($moduleDefinition->getDependencies()));
     $this->assertEquals(1, count($moduleDefinition->getAuthors()));
     $this->assertEquals("", $moduleDefinition->getDocumentation());
     $this->assertEquals("", $moduleDefinition->getLogo());
     $this->assertEquals("2.2.0", $moduleDefinition->getTheliaVersion());
     $this->assertTrue(Version::test(Thelia::THELIA_VERSION, $moduleDefinition->getTheliaVersion(), false, ">="));
     // validate
     $moduleValidator->validate(false);
 }
Beispiel #4
0
 protected function checkModuleDependencies()
 {
     $errors = [];
     foreach ($this->moduleDefinition->getDependencies() as $dependency) {
         $module = ModuleQuery::create()->findOneByCode($dependency[0]);
         $pass = false;
         if (null !== $module) {
             if ($module->getActivate() === BaseModule::IS_ACTIVATED) {
                 if ("" == $dependency[1] || Version::test($module->getVersion(), $dependency[1], false, ">=")) {
                     $pass = true;
                 }
             }
         }
         if (false === $pass) {
             if ('' !== $dependency[1]) {
                 $errors[] = $this->getTranslator()->trans('%module (version: %version)', ['%module' => $dependency[0], '%version' => $dependency[1]]);
             } else {
                 $errors[] = sprintf('%s', $dependency[0]);
             }
         }
     }
     if (count($errors) > 0) {
         $errorsMessage = $this->getTranslator()->trans('To activate module %name, the following modules should be activated first: %modules', ['%name' => $this->moduleDirName, '%modules' => implode(', ', $errors)]);
         throw new ModuleException($errorsMessage);
     }
 }
Beispiel #5
0
 public function configure()
 {
     if (null !== ($response = $this->checkAuth(AdminResources::MODULE, 'atos', AccessManager::UPDATE))) {
         return $response;
     }
     $configurationForm = $this->createForm('atos_configuration');
     $message = null;
     try {
         $form = $this->validateForm($configurationForm);
         // Get the form field values
         $data = $form->getData();
         foreach ($data as $name => $value) {
             if (is_array($value)) {
                 $value = implode(';', $value);
             }
             Atos::setConfigValue($name, $value);
         }
         $merchantId = $data['atos_merchantId'];
         $this->checkExecutable('request');
         $this->checkExecutable('response');
         $this->copyDistFile('parmcom', $merchantId);
         $certificateFile = $this->copyDistFile('certif.fr', $merchantId);
         // Write certificate
         if (!@file_put_contents($certificateFile, $data['atos_certificate'])) {
             throw new FileException($this->getTranslator()->trans("Failed to write certificate data in file '%file'. Please check file permission", ['%file' => $certificateFile], Atos::MODULE_DOMAIN));
         }
         // Log configuration modification
         $this->adminLogAppend("atos.configuration.message", AccessManager::UPDATE, "Atos configuration updated");
         // Redirect to the success URL,
         if ($this->getRequest()->get('save_mode') == 'stay') {
             // If we have to stay on the same page, redisplay the configuration page/
             $url = '/admin/module/Atos';
         } else {
             // If we have to close the page, go back to the module back-office page.
             $url = '/admin/modules';
         }
         return $this->generateRedirect(URL::getInstance()->absoluteUrl($url));
     } catch (FormValidationException $ex) {
         $message = $this->createStandardFormValidationErrorMessage($ex);
     } catch (\Exception $ex) {
         $message = $ex->getMessage();
     }
     $this->setupFormErrorContext($this->getTranslator()->trans("Atos configuration", [], Atos::MODULE_DOMAIN), $message, $configurationForm, $ex);
     // Before 2.2, the errored form is not stored in session
     if (Version::test(Thelia::THELIA_VERSION, '2.2', false, "<")) {
         return $this->render('module-configure', ['module_code' => 'Atos']);
     } else {
         return $this->generateRedirect(URL::getInstance()->absoluteUrl('/admin/module/Atos'));
     }
 }