Beispiel #1
0
 /**
  * Check module validity
  *
  * @param UploadedFile $file
  * @param ExecutionContextInterface $context
  */
 public function checkModuleValidity(UploadedFile $file, ExecutionContextInterface $context)
 {
     $modulePath = $this->unzipModule($file);
     if ($modulePath !== false) {
         try {
             // get the first directory
             $moduleFiles = $this->getDirContents($modulePath);
             if (count($moduleFiles['directories']) !== 1) {
                 throw new Exception(Translator::getInstance()->trans("Your zip must contain 1 root directory which is the root folder directory of your module"));
             }
             $moduleDirectory = $moduleFiles['directories'][0];
             $this->modulePath = sprintf('%s/%s', $modulePath, $moduleDirectory);
             $moduleValidator = new ModuleValidator($this->modulePath);
             $moduleValidator->validate();
             $this->moduleDefinition = $moduleValidator->getModuleDefinition();
         } catch (Exception $ex) {
             $context->addViolation(Translator::getInstance()->trans("The module is not valid : %message", ['%message' => $ex->getMessage()]));
         }
     }
 }
Beispiel #2
0
 /**
  * @dataProvider validatorProvider
  */
 public function testValidator($path, $exceptionExpected, $exceptionMessage)
 {
     $modulePath = __DIR__ . "/" . $path;
     /** @var \Exception $exception */
     $exception = null;
     try {
         $moduleValidator = new ModuleValidator($modulePath, $this->getStubTranslator("opiopi"));
         $moduleValidator->validate(true);
     } catch (\Exception $ex) {
         $exception = $ex;
     }
     if (null !== $exceptionExpected) {
         $this->assertInstanceOf($exceptionExpected, $exception, $path . " module should return exception " . $exceptionExpected);
         if (null !== $exceptionMessage) {
             $this->assertNotEmpty($exception->getMessage(), $path . " module exception should not be empty");
             $this->assertTrue(false !== strpos($exception->getMessage(), $exceptionMessage), $path . " module exception should contain : " . $exceptionMessage);
         }
     } else {
         $this->assertNull($exception, $path . " module should not return exception [" . $exception->getMessage() . ']');
     }
 }
Beispiel #3
0
 /**
  * Check if module can be activated : supported version of Thelia, module dependencies.
  *
  * @param  \Thelia\Model\Module $module
  * @throws Exception            if activation fails.
  * @return bool                 true if the module can be activated, otherwise false
  */
 private function checkActivation($module)
 {
     try {
         $moduleValidator = new ModuleValidator($module->getAbsoluteBaseDir());
         $moduleValidator->validate(false);
     } catch (\Exception $ex) {
         throw $ex;
     }
     return true;
 }