@@ -28,42 +28,42 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | class UploadAnnotation extends AbstractAnnotation |
| 30 | 30 | { |
| 31 | - /** |
|
| 31 | +/** |
|
| 32 | 32 | * The name of the upload field |
| 33 | 33 | * |
| 34 | 34 | * @var string |
| 35 | 35 | */ |
| 36 | - protected $sField = ''; |
|
| 36 | +protected $sField = ''; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 38 | +/** |
|
| 39 | 39 | * @inheritDoc |
| 40 | 40 | */ |
| 41 | - public static function parseAnnotation($value) |
|
| 42 | - { |
|
| 43 | - $aParams = preg_split('/[\s]+/', $value, 2); |
|
| 44 | - return count($aParams) === 1 ? ['field' => $aParams[0]] : |
|
| 45 | - ['field' => $aParams[0], 'extra' => $aParams[1]]; |
|
| 46 | - } |
|
| 41 | +public static function parseAnnotation($value) |
|
| 42 | +{ |
|
| 43 | +$aParams = preg_split('/[\s]+/', $value, 2); |
|
| 44 | +return count($aParams) === 1 ? ['field' => $aParams[0]] : |
|
| 45 | +['field' => $aParams[0], 'extra' => $aParams[1]]; |
|
| 46 | +} |
|
| 47 | 47 | |
| 48 | - /** |
|
| 48 | +/** |
|
| 49 | 49 | * @inheritDoc |
| 50 | 50 | * @throws AnnotationException |
| 51 | 51 | */ |
| 52 | - public function initAnnotation(array $properties) |
|
| 53 | - { |
|
| 54 | - if(count($properties) != 1 || !isset($properties['field']) || |
|
| 55 | - !is_string($properties['field'])) |
|
| 56 | - { |
|
| 57 | - throw new AnnotationException('The @upload annotation requires a property "field" of type string'); |
|
| 58 | - } |
|
| 59 | - $this->sField = $properties['field']; |
|
| 60 | - } |
|
| 52 | +public function initAnnotation(array $properties) |
|
| 53 | +{ |
|
| 54 | +if(count($properties) != 1 || !isset($properties['field']) || |
|
| 55 | +!is_string($properties['field'])) |
|
| 56 | +{ |
|
| 57 | +throw new AnnotationException('The @upload annotation requires a property "field" of type string'); |
|
| 58 | +} |
|
| 59 | +$this->sField = $properties['field']; |
|
| 60 | +} |
|
| 61 | 61 | |
| 62 | - /** |
|
| 62 | +/** |
|
| 63 | 63 | * @inheritDoc |
| 64 | 64 | */ |
| 65 | - public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void |
|
| 66 | - { |
|
| 67 | - $xMetadata->upload($sMethod)->setValue($this->sField); |
|
| 68 | - } |
|
| 65 | +public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void |
|
| 66 | +{ |
|
| 67 | +$xMetadata->upload($sMethod)->setValue($this->sField); |
|
| 68 | +} |
|
| 69 | 69 | } |
@@ -41,8 +41,7 @@ discard block |
||
| 41 | 41 | public static function parseAnnotation($value) |
| 42 | 42 | { |
| 43 | 43 | $aParams = preg_split('/[\s]+/', $value, 2); |
| 44 | - return count($aParams) === 1 ? ['field' => $aParams[0]] : |
|
| 45 | - ['field' => $aParams[0], 'extra' => $aParams[1]]; |
|
| 44 | + return count($aParams) === 1 ? ['field' => $aParams[0]] : ['field' => $aParams[0], 'extra' => $aParams[1]]; |
|
| 46 | 45 | } |
| 47 | 46 | |
| 48 | 47 | /** |
@@ -51,7 +50,7 @@ discard block |
||
| 51 | 50 | */ |
| 52 | 51 | public function initAnnotation(array $properties) |
| 53 | 52 | { |
| 54 | - if(count($properties) != 1 || !isset($properties['field']) || |
|
| 53 | + if (count($properties) != 1 || !isset($properties['field']) || |
|
| 55 | 54 | !is_string($properties['field'])) |
| 56 | 55 | { |
| 57 | 56 | throw new AnnotationException('The @upload annotation requires a property "field" of type string'); |
@@ -27,64 +27,64 @@ |
||
| 27 | 27 | |
| 28 | 28 | abstract class HookAnnotation extends AbstractAnnotation |
| 29 | 29 | { |
| 30 | - /** |
|
| 30 | +/** |
|
| 31 | 31 | * @var string |
| 32 | 32 | */ |
| 33 | - protected $sMethod = ''; |
|
| 33 | +protected $sMethod = ''; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 35 | +/** |
|
| 36 | 36 | * @var array |
| 37 | 37 | */ |
| 38 | - protected $aParams = []; |
|
| 38 | +protected $aParams = []; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 40 | +/** |
|
| 41 | 41 | * |
| 42 | 42 | */ |
| 43 | - abstract protected static function getType(): string; |
|
| 43 | +abstract protected static function getType(): string; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 45 | +/** |
|
| 46 | 46 | * @inheritDoc |
| 47 | 47 | */ |
| 48 | - public static function parseAnnotation($value) |
|
| 49 | - { |
|
| 50 | - $aParams = preg_split('/[\s]+/', $value, 2); |
|
| 51 | - if(count($aParams) === 1) |
|
| 52 | - { |
|
| 53 | - return ['call' => rtrim($aParams[0])]; |
|
| 54 | - } |
|
| 55 | - // The second parameter must be an array of callback parameter in json format. |
|
| 56 | - return ['call' => rtrim($aParams[0]), 'with' => json_decode($aParams[1], false)]; |
|
| 57 | - } |
|
| 48 | +public static function parseAnnotation($value) |
|
| 49 | +{ |
|
| 50 | +$aParams = preg_split('/[\s]+/', $value, 2); |
|
| 51 | +if(count($aParams) === 1) |
|
| 52 | +{ |
|
| 53 | +return ['call' => rtrim($aParams[0])]; |
|
| 54 | +} |
|
| 55 | +// The second parameter must be an array of callback parameter in json format. |
|
| 56 | +return ['call' => rtrim($aParams[0]), 'with' => json_decode($aParams[1], false)]; |
|
| 57 | +} |
|
| 58 | 58 | |
| 59 | - /** |
|
| 59 | +/** |
|
| 60 | 60 | * @inheritDoc |
| 61 | 61 | * @throws AnnotationException |
| 62 | 62 | */ |
| 63 | - public function initAnnotation(array $properties) |
|
| 64 | - { |
|
| 65 | - if(!isset($properties['call']) || !is_string($properties['call'])) |
|
| 66 | - { |
|
| 67 | - throw new AnnotationException('The @' . $this->getType() . |
|
| 68 | - ' annotation requires a property "call" of type string'); |
|
| 69 | - } |
|
| 70 | - foreach(array_keys($properties) as $propName) |
|
| 71 | - { |
|
| 72 | - if($propName !== 'call' && $propName !== 'with') |
|
| 73 | - { |
|
| 74 | - throw new AnnotationException('Unknown property "' . $propName . |
|
| 75 | - '" in the @' . $this->getType() . ' annotation'); |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - // Cannot use isset here, because it will return false in case $properties['with'] === null |
|
| 79 | - if(array_key_exists('with', $properties)) |
|
| 80 | - { |
|
| 81 | - if(!is_array($properties['with'])) |
|
| 82 | - { |
|
| 83 | - throw new AnnotationException('The "with" property of the @' . |
|
| 84 | - $this->getType() . ' annotation must be of type array'); |
|
| 85 | - } |
|
| 86 | - $this->aParams = $properties['with']; |
|
| 87 | - } |
|
| 88 | - $this->sMethod = $properties['call']; |
|
| 89 | - } |
|
| 63 | +public function initAnnotation(array $properties) |
|
| 64 | +{ |
|
| 65 | +if(!isset($properties['call']) || !is_string($properties['call'])) |
|
| 66 | +{ |
|
| 67 | +throw new AnnotationException('The @' . $this->getType() . |
|
| 68 | + ' annotation requires a property "call" of type string'); |
|
| 69 | +} |
|
| 70 | +foreach(array_keys($properties) as $propName) |
|
| 71 | +{ |
|
| 72 | +if($propName !== 'call' && $propName !== 'with') |
|
| 73 | +{ |
|
| 74 | + throw new AnnotationException('Unknown property "' . $propName . |
|
| 75 | + '" in the @' . $this->getType() . ' annotation'); |
|
| 76 | +} |
|
| 77 | +} |
|
| 78 | +// Cannot use isset here, because it will return false in case $properties['with'] === null |
|
| 79 | +if(array_key_exists('with', $properties)) |
|
| 80 | +{ |
|
| 81 | +if(!is_array($properties['with'])) |
|
| 82 | +{ |
|
| 83 | + throw new AnnotationException('The "with" property of the @' . |
|
| 84 | + $this->getType() . ' annotation must be of type array'); |
|
| 85 | +} |
|
| 86 | +$this->aParams = $properties['with']; |
|
| 87 | +} |
|
| 88 | +$this->sMethod = $properties['call']; |
|
| 89 | +} |
|
| 90 | 90 | } |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | public static function parseAnnotation($value) |
| 49 | 49 | { |
| 50 | 50 | $aParams = preg_split('/[\s]+/', $value, 2); |
| 51 | - if(count($aParams) === 1) |
|
| 51 | + if (count($aParams) === 1) |
|
| 52 | 52 | { |
| 53 | 53 | return ['call' => rtrim($aParams[0])]; |
| 54 | 54 | } |
@@ -62,23 +62,23 @@ discard block |
||
| 62 | 62 | */ |
| 63 | 63 | public function initAnnotation(array $properties) |
| 64 | 64 | { |
| 65 | - if(!isset($properties['call']) || !is_string($properties['call'])) |
|
| 65 | + if (!isset($properties['call']) || !is_string($properties['call'])) |
|
| 66 | 66 | { |
| 67 | 67 | throw new AnnotationException('The @' . $this->getType() . |
| 68 | 68 | ' annotation requires a property "call" of type string'); |
| 69 | 69 | } |
| 70 | - foreach(array_keys($properties) as $propName) |
|
| 70 | + foreach (array_keys($properties) as $propName) |
|
| 71 | 71 | { |
| 72 | - if($propName !== 'call' && $propName !== 'with') |
|
| 72 | + if ($propName !== 'call' && $propName !== 'with') |
|
| 73 | 73 | { |
| 74 | 74 | throw new AnnotationException('Unknown property "' . $propName . |
| 75 | 75 | '" in the @' . $this->getType() . ' annotation'); |
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | 78 | // Cannot use isset here, because it will return false in case $properties['with'] === null |
| 79 | - if(array_key_exists('with', $properties)) |
|
| 79 | + if (array_key_exists('with', $properties)) |
|
| 80 | 80 | { |
| 81 | - if(!is_array($properties['with'])) |
|
| 81 | + if (!is_array($properties['with'])) |
|
| 82 | 82 | { |
| 83 | 83 | throw new AnnotationException('The "with" property of the @' . |
| 84 | 84 | $this->getType() . ' annotation must be of type array'); |
@@ -114,21 +114,21 @@ discard block |
||
| 114 | 114 | fn($xAnnotation) => is_a($xAnnotation, AbstractAnnotation::class) |
| 115 | 115 | ); |
| 116 | 116 | // First check if the class is excluded. |
| 117 | - foreach($aAnnotations as $xAnnotation) |
|
| 117 | + foreach ($aAnnotations as $xAnnotation) |
|
| 118 | 118 | { |
| 119 | - if(is_a($xAnnotation, ExcludeAnnotation::class)) |
|
| 119 | + if (is_a($xAnnotation, ExcludeAnnotation::class)) |
|
| 120 | 120 | { |
| 121 | 121 | $xAnnotation->saveValue($this->xMetadata); |
| 122 | 122 | } |
| 123 | 123 | } |
| 124 | - if($this->xMetadata->isExcluded()) |
|
| 124 | + if ($this->xMetadata->isExcluded()) |
|
| 125 | 125 | { |
| 126 | 126 | return; |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - foreach($aAnnotations as $xAnnotation) |
|
| 129 | + foreach ($aAnnotations as $xAnnotation) |
|
| 130 | 130 | { |
| 131 | - if(!is_a($xAnnotation, ExcludeAnnotation::class)) |
|
| 131 | + if (!is_a($xAnnotation, ExcludeAnnotation::class)) |
|
| 132 | 132 | { |
| 133 | 133 | $xAnnotation->saveValue($this->xMetadata); |
| 134 | 134 | } |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | $this->xManager->getPropertyAnnotations($sClass, $sProperty), |
| 151 | 151 | function($xAnnotation) use($sProperty) { |
| 152 | 152 | // Save the property type |
| 153 | - if(is_a($xAnnotation, VarAnnotation::class)) |
|
| 153 | + if (is_a($xAnnotation, VarAnnotation::class)) |
|
| 154 | 154 | { |
| 155 | 155 | $this->aPropTypes[$sProperty] = $xAnnotation->type; |
| 156 | 156 | } |
@@ -158,12 +158,12 @@ discard block |
||
| 158 | 158 | return is_a($xAnnotation, ContainerAnnotation::class); |
| 159 | 159 | } |
| 160 | 160 | ); |
| 161 | - if(count($aAnnotations) > 1) |
|
| 161 | + if (count($aAnnotations) > 1) |
|
| 162 | 162 | { |
| 163 | 163 | throw new AnnotationException('Only one @di annotation is allowed on a property'); |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - foreach($aAnnotations as $xAnnotation) |
|
| 166 | + foreach ($aAnnotations as $xAnnotation) |
|
| 167 | 167 | { |
| 168 | 168 | $xAnnotation->setAttr($sProperty); |
| 169 | 169 | $xAnnotation->saveValue($this->xMetadata); |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | $this->xManager->getMethodAnnotations($sClass, $sMethod), |
| 186 | 186 | fn($xAnnotation) => is_a($xAnnotation, AbstractAnnotation::class) |
| 187 | 187 | ); |
| 188 | - foreach($aAnnotations as $xAnnotation) |
|
| 188 | + foreach ($aAnnotations as $xAnnotation) |
|
| 189 | 189 | { |
| 190 | 190 | $xAnnotation->saveValue($this->xMetadata, $sMethod); |
| 191 | 191 | } |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | $this->sCurrMemberType = AnnotationManager::MEMBER_CLASS; |
| 209 | 209 | |
| 210 | 210 | $this->getClassAttrs($sClass); |
| 211 | - if($this->xMetadata->isExcluded()) |
|
| 211 | + if ($this->xMetadata->isExcluded()) |
|
| 212 | 212 | { |
| 213 | 213 | // The entire class is not to be exported. |
| 214 | 214 | return $this->xMetadata; |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | $this->sCurrMemberType = AnnotationManager::MEMBER_PROPERTY; |
| 219 | 219 | |
| 220 | 220 | // Properties annotations |
| 221 | - foreach($xInput->getProperties() as $sProperty) |
|
| 221 | + foreach ($xInput->getProperties() as $sProperty) |
|
| 222 | 222 | { |
| 223 | 223 | $this->getPropertyAttrs($sClass, $sProperty); |
| 224 | 224 | } |
@@ -226,14 +226,14 @@ discard block |
||
| 226 | 226 | // Processing methods annotations |
| 227 | 227 | $this->sCurrMemberType = AnnotationManager::MEMBER_METHOD; |
| 228 | 228 | |
| 229 | - foreach($xInput->getMethods() as $sMethod) |
|
| 229 | + foreach ($xInput->getMethods() as $sMethod) |
|
| 230 | 230 | { |
| 231 | 231 | $this->getMethodAttrs($sClass, $sMethod); |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | return $this->xMetadata; |
| 235 | 235 | } |
| 236 | - catch(AnnotationException $e) |
|
| 236 | + catch (AnnotationException $e) |
|
| 237 | 237 | { |
| 238 | 238 | throw new SetupException($e->getMessage()); |
| 239 | 239 | } |
@@ -232,8 +232,7 @@ |
||
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | return $this->xMetadata; |
| 235 | - } |
|
| 236 | - catch(AnnotationException $e) |
|
| 235 | + } catch(AnnotationException $e) |
|
| 237 | 236 | { |
| 238 | 237 | throw new SetupException($e->getMessage()); |
| 239 | 238 | } |
@@ -36,206 +36,206 @@ |
||
| 36 | 36 | |
| 37 | 37 | class AnnotationReader implements MetadataReaderInterface |
| 38 | 38 | { |
| 39 | - /** |
|
| 39 | +/** |
|
| 40 | 40 | * @var AnnotationManager |
| 41 | 41 | */ |
| 42 | - protected $xManager; |
|
| 42 | +protected $xManager; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 44 | +/** |
|
| 45 | 45 | * @var Metadata |
| 46 | 46 | */ |
| 47 | - protected $xMetadata; |
|
| 47 | +protected $xMetadata; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 49 | +/** |
|
| 50 | 50 | * Properties types, read from the "var" annotations. |
| 51 | 51 | * |
| 52 | 52 | * @var array |
| 53 | 53 | */ |
| 54 | - protected $aPropTypes; |
|
| 54 | +protected $aPropTypes; |
|
| 55 | 55 | |
| 56 | - /** |
|
| 56 | +/** |
|
| 57 | 57 | * The type of the class member being currently processed. |
| 58 | 58 | * |
| 59 | 59 | * @var string |
| 60 | 60 | */ |
| 61 | - protected $sCurrMemberType; |
|
| 61 | +protected $sCurrMemberType; |
|
| 62 | 62 | |
| 63 | - /** |
|
| 63 | +/** |
|
| 64 | 64 | * The constructor |
| 65 | 65 | * |
| 66 | 66 | * @param AnnotationManager $xManager |
| 67 | 67 | */ |
| 68 | - public function __construct(AnnotationManager $xManager) |
|
| 69 | - { |
|
| 70 | - $this->xManager = $xManager; |
|
| 71 | - $this->xManager->registry['upload'] = UploadAnnotation::class; |
|
| 72 | - $this->xManager->registry['databag'] = DatabagAnnotation::class; |
|
| 73 | - $this->xManager->registry['exclude'] = ExcludeAnnotation::class; |
|
| 74 | - $this->xManager->registry['before'] = BeforeAnnotation::class; |
|
| 75 | - $this->xManager->registry['after'] = AfterAnnotation::class; |
|
| 76 | - $this->xManager->registry['di'] = ContainerAnnotation::class; |
|
| 77 | - $this->xManager->registry['callback'] = CallbackAnnotation::class; |
|
| 78 | - // Missing standard annotations. |
|
| 79 | - // We need to define this, otherwise they throw an exception, and make the whole processing fail. |
|
| 80 | - $this->xManager->registry['const'] = false; |
|
| 81 | - $this->xManager->registry['inheritDoc'] = false; |
|
| 82 | - $this->xManager->registry['template'] = false; |
|
| 83 | - $this->xManager->registry['param-closure-this'] = false; |
|
| 84 | - } |
|
| 68 | +public function __construct(AnnotationManager $xManager) |
|
| 69 | +{ |
|
| 70 | +$this->xManager = $xManager; |
|
| 71 | +$this->xManager->registry['upload'] = UploadAnnotation::class; |
|
| 72 | +$this->xManager->registry['databag'] = DatabagAnnotation::class; |
|
| 73 | +$this->xManager->registry['exclude'] = ExcludeAnnotation::class; |
|
| 74 | +$this->xManager->registry['before'] = BeforeAnnotation::class; |
|
| 75 | +$this->xManager->registry['after'] = AfterAnnotation::class; |
|
| 76 | +$this->xManager->registry['di'] = ContainerAnnotation::class; |
|
| 77 | +$this->xManager->registry['callback'] = CallbackAnnotation::class; |
|
| 78 | +// Missing standard annotations. |
|
| 79 | +// We need to define this, otherwise they throw an exception, and make the whole processing fail. |
|
| 80 | +$this->xManager->registry['const'] = false; |
|
| 81 | +$this->xManager->registry['inheritDoc'] = false; |
|
| 82 | +$this->xManager->registry['template'] = false; |
|
| 83 | +$this->xManager->registry['param-closure-this'] = false; |
|
| 84 | +} |
|
| 85 | 85 | |
| 86 | - /** |
|
| 86 | +/** |
|
| 87 | 87 | * @return array |
| 88 | 88 | */ |
| 89 | - public function getPropTypes(): array |
|
| 90 | - { |
|
| 91 | - return $this->aPropTypes; |
|
| 92 | - } |
|
| 89 | +public function getPropTypes(): array |
|
| 90 | +{ |
|
| 91 | +return $this->aPropTypes; |
|
| 92 | +} |
|
| 93 | 93 | |
| 94 | - /** |
|
| 94 | +/** |
|
| 95 | 95 | * @return bool |
| 96 | 96 | */ |
| 97 | - public function annotationIsOnProperty(): bool |
|
| 98 | - { |
|
| 99 | - return $this->sCurrMemberType === AnnotationManager::MEMBER_PROPERTY; |
|
| 100 | - } |
|
| 97 | +public function annotationIsOnProperty(): bool |
|
| 98 | +{ |
|
| 99 | +return $this->sCurrMemberType === AnnotationManager::MEMBER_PROPERTY; |
|
| 100 | +} |
|
| 101 | 101 | |
| 102 | - /** |
|
| 102 | +/** |
|
| 103 | 103 | * @param string $sClass |
| 104 | 104 | * |
| 105 | 105 | * @return void |
| 106 | 106 | * @throws AnnotationException |
| 107 | 107 | */ |
| 108 | - private function getClassAttrs(string $sClass): void |
|
| 109 | - { |
|
| 110 | - // Only keep the annotations declared in this package. |
|
| 111 | - /** @var array<AbstractAnnotation> */ |
|
| 112 | - $aAnnotations = array_filter( |
|
| 113 | - $this->xManager->getClassAnnotations($sClass), |
|
| 114 | - fn($xAnnotation) => is_a($xAnnotation, AbstractAnnotation::class) |
|
| 115 | - ); |
|
| 116 | - // First check if the class is excluded. |
|
| 117 | - foreach($aAnnotations as $xAnnotation) |
|
| 118 | - { |
|
| 119 | - if(is_a($xAnnotation, ExcludeAnnotation::class)) |
|
| 120 | - { |
|
| 121 | - $xAnnotation->saveValue($this->xMetadata); |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - if($this->xMetadata->isExcluded()) |
|
| 125 | - { |
|
| 126 | - return; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - foreach($aAnnotations as $xAnnotation) |
|
| 130 | - { |
|
| 131 | - if(!is_a($xAnnotation, ExcludeAnnotation::class)) |
|
| 132 | - { |
|
| 133 | - $xAnnotation->saveValue($this->xMetadata); |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - } |
|
| 108 | +private function getClassAttrs(string $sClass): void |
|
| 109 | +{ |
|
| 110 | +// Only keep the annotations declared in this package. |
|
| 111 | +/** @var array<AbstractAnnotation> */ |
|
| 112 | +$aAnnotations = array_filter( |
|
| 113 | +$this->xManager->getClassAnnotations($sClass), |
|
| 114 | +fn($xAnnotation) => is_a($xAnnotation, AbstractAnnotation::class) |
|
| 115 | +); |
|
| 116 | +// First check if the class is excluded. |
|
| 117 | +foreach($aAnnotations as $xAnnotation) |
|
| 118 | +{ |
|
| 119 | +if(is_a($xAnnotation, ExcludeAnnotation::class)) |
|
| 120 | +{ |
|
| 121 | + $xAnnotation->saveValue($this->xMetadata); |
|
| 122 | +} |
|
| 123 | +} |
|
| 124 | +if($this->xMetadata->isExcluded()) |
|
| 125 | +{ |
|
| 126 | +return; |
|
| 127 | +} |
|
| 137 | 128 | |
| 138 | - /** |
|
| 129 | +foreach($aAnnotations as $xAnnotation) |
|
| 130 | +{ |
|
| 131 | +if(!is_a($xAnnotation, ExcludeAnnotation::class)) |
|
| 132 | +{ |
|
| 133 | + $xAnnotation->saveValue($this->xMetadata); |
|
| 134 | +} |
|
| 135 | +} |
|
| 136 | +} |
|
| 137 | + |
|
| 138 | +/** |
|
| 139 | 139 | * @param string $sClass |
| 140 | 140 | * @param string $sProperty |
| 141 | 141 | * |
| 142 | 142 | * @return void |
| 143 | 143 | * @throws AnnotationException |
| 144 | 144 | */ |
| 145 | - private function getPropertyAttrs(string $sClass, string $sProperty): void |
|
| 145 | +private function getPropertyAttrs(string $sClass, string $sProperty): void |
|
| 146 | +{ |
|
| 147 | +/** @var array<ContainerAnnotation> */ |
|
| 148 | +// Only keep the annotations declared in this package. |
|
| 149 | +$aAnnotations = array_filter( |
|
| 150 | +$this->xManager->getPropertyAnnotations($sClass, $sProperty), |
|
| 151 | +function($xAnnotation) use($sProperty) { |
|
| 152 | + // Save the property type |
|
| 153 | + if(is_a($xAnnotation, VarAnnotation::class)) |
|
| 146 | 154 | { |
| 147 | - /** @var array<ContainerAnnotation> */ |
|
| 148 | - // Only keep the annotations declared in this package. |
|
| 149 | - $aAnnotations = array_filter( |
|
| 150 | - $this->xManager->getPropertyAnnotations($sClass, $sProperty), |
|
| 151 | - function($xAnnotation) use($sProperty) { |
|
| 152 | - // Save the property type |
|
| 153 | - if(is_a($xAnnotation, VarAnnotation::class)) |
|
| 154 | - { |
|
| 155 | - $this->aPropTypes[$sProperty] = $xAnnotation->type; |
|
| 156 | - } |
|
| 157 | - // Only container annotations are allowed on properties |
|
| 158 | - return is_a($xAnnotation, ContainerAnnotation::class); |
|
| 159 | - } |
|
| 160 | - ); |
|
| 161 | - if(count($aAnnotations) > 1) |
|
| 162 | - { |
|
| 163 | - throw new AnnotationException('Only one @di annotation is allowed on a property'); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - foreach($aAnnotations as $xAnnotation) |
|
| 167 | - { |
|
| 168 | - $xAnnotation->setAttr($sProperty); |
|
| 169 | - $xAnnotation->saveValue($this->xMetadata); |
|
| 170 | - } |
|
| 155 | + $this->aPropTypes[$sProperty] = $xAnnotation->type; |
|
| 171 | 156 | } |
| 157 | + // Only container annotations are allowed on properties |
|
| 158 | + return is_a($xAnnotation, ContainerAnnotation::class); |
|
| 159 | +} |
|
| 160 | +); |
|
| 161 | +if(count($aAnnotations) > 1) |
|
| 162 | +{ |
|
| 163 | +throw new AnnotationException('Only one @di annotation is allowed on a property'); |
|
| 164 | +} |
|
| 172 | 165 | |
| 173 | - /** |
|
| 166 | +foreach($aAnnotations as $xAnnotation) |
|
| 167 | +{ |
|
| 168 | +$xAnnotation->setAttr($sProperty); |
|
| 169 | +$xAnnotation->saveValue($this->xMetadata); |
|
| 170 | +} |
|
| 171 | +} |
|
| 172 | + |
|
| 173 | +/** |
|
| 174 | 174 | * @param string $sClass |
| 175 | 175 | * @param string $sMethod |
| 176 | 176 | * |
| 177 | 177 | * @return void |
| 178 | 178 | * @throws AnnotationException |
| 179 | 179 | */ |
| 180 | - private function getMethodAttrs(string $sClass, string $sMethod): void |
|
| 181 | - { |
|
| 182 | - // Only keep the annotations declared in this package. |
|
| 183 | - /** @var array<AbstractAnnotation> */ |
|
| 184 | - $aAnnotations = array_filter( |
|
| 185 | - $this->xManager->getMethodAnnotations($sClass, $sMethod), |
|
| 186 | - fn($xAnnotation) => is_a($xAnnotation, AbstractAnnotation::class) |
|
| 187 | - ); |
|
| 188 | - foreach($aAnnotations as $xAnnotation) |
|
| 189 | - { |
|
| 190 | - $xAnnotation->saveValue($this->xMetadata, $sMethod); |
|
| 191 | - } |
|
| 192 | - } |
|
| 180 | +private function getMethodAttrs(string $sClass, string $sMethod): void |
|
| 181 | +{ |
|
| 182 | +// Only keep the annotations declared in this package. |
|
| 183 | +/** @var array<AbstractAnnotation> */ |
|
| 184 | +$aAnnotations = array_filter( |
|
| 185 | +$this->xManager->getMethodAnnotations($sClass, $sMethod), |
|
| 186 | +fn($xAnnotation) => is_a($xAnnotation, AbstractAnnotation::class) |
|
| 187 | +); |
|
| 188 | +foreach($aAnnotations as $xAnnotation) |
|
| 189 | +{ |
|
| 190 | +$xAnnotation->saveValue($this->xMetadata, $sMethod); |
|
| 191 | +} |
|
| 192 | +} |
|
| 193 | 193 | |
| 194 | - /** |
|
| 194 | +/** |
|
| 195 | 195 | * @inheritDoc |
| 196 | 196 | * @throws SetupException |
| 197 | 197 | */ |
| 198 | - public function getAttributes(InputData $xInput): Metadata |
|
| 199 | - { |
|
| 200 | - ContainerAnnotation::$xReader = $this; |
|
| 201 | - $this->aPropTypes = []; |
|
| 202 | - $this->xMetadata = new Metadata(); |
|
| 203 | - $sClass = $xInput->getReflectionClass()->getName(); |
|
| 204 | - |
|
| 205 | - try |
|
| 206 | - { |
|
| 207 | - // Processing class annotations |
|
| 208 | - $this->sCurrMemberType = AnnotationManager::MEMBER_CLASS; |
|
| 209 | - |
|
| 210 | - $this->getClassAttrs($sClass); |
|
| 211 | - if($this->xMetadata->isExcluded()) |
|
| 212 | - { |
|
| 213 | - // The entire class is not to be exported. |
|
| 214 | - return $this->xMetadata; |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - // Processing properties annotations |
|
| 218 | - $this->sCurrMemberType = AnnotationManager::MEMBER_PROPERTY; |
|
| 219 | - |
|
| 220 | - // Properties annotations |
|
| 221 | - foreach($xInput->getProperties() as $sProperty) |
|
| 222 | - { |
|
| 223 | - $this->getPropertyAttrs($sClass, $sProperty); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - // Processing methods annotations |
|
| 227 | - $this->sCurrMemberType = AnnotationManager::MEMBER_METHOD; |
|
| 228 | - |
|
| 229 | - foreach($xInput->getMethods() as $sMethod) |
|
| 230 | - { |
|
| 231 | - $this->getMethodAttrs($sClass, $sMethod); |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - return $this->xMetadata; |
|
| 235 | - } |
|
| 236 | - catch(AnnotationException $e) |
|
| 237 | - { |
|
| 238 | - throw new SetupException($e->getMessage()); |
|
| 239 | - } |
|
| 240 | - } |
|
| 198 | +public function getAttributes(InputData $xInput): Metadata |
|
| 199 | +{ |
|
| 200 | +ContainerAnnotation::$xReader = $this; |
|
| 201 | +$this->aPropTypes = []; |
|
| 202 | +$this->xMetadata = new Metadata(); |
|
| 203 | +$sClass = $xInput->getReflectionClass()->getName(); |
|
| 204 | + |
|
| 205 | +try |
|
| 206 | +{ |
|
| 207 | +// Processing class annotations |
|
| 208 | +$this->sCurrMemberType = AnnotationManager::MEMBER_CLASS; |
|
| 209 | + |
|
| 210 | +$this->getClassAttrs($sClass); |
|
| 211 | +if($this->xMetadata->isExcluded()) |
|
| 212 | +{ |
|
| 213 | + // The entire class is not to be exported. |
|
| 214 | + return $this->xMetadata; |
|
| 215 | +} |
|
| 216 | + |
|
| 217 | +// Processing properties annotations |
|
| 218 | +$this->sCurrMemberType = AnnotationManager::MEMBER_PROPERTY; |
|
| 219 | + |
|
| 220 | +// Properties annotations |
|
| 221 | +foreach($xInput->getProperties() as $sProperty) |
|
| 222 | +{ |
|
| 223 | + $this->getPropertyAttrs($sClass, $sProperty); |
|
| 224 | +} |
|
| 225 | + |
|
| 226 | +// Processing methods annotations |
|
| 227 | +$this->sCurrMemberType = AnnotationManager::MEMBER_METHOD; |
|
| 228 | + |
|
| 229 | +foreach($xInput->getMethods() as $sMethod) |
|
| 230 | +{ |
|
| 231 | + $this->getMethodAttrs($sClass, $sMethod); |
|
| 232 | +} |
|
| 233 | + |
|
| 234 | +return $this->xMetadata; |
|
| 235 | +} |
|
| 236 | +catch(AnnotationException $e) |
|
| 237 | +{ |
|
| 238 | +throw new SetupException($e->getMessage()); |
|
| 239 | +} |
|
| 240 | +} |
|
| 241 | 241 | } |
@@ -21,604 +21,604 @@ |
||
| 21 | 21 | |
| 22 | 22 | class UploadHandlerTest extends TestCase |
| 23 | 23 | { |
| 24 | - /** |
|
| 24 | +/** |
|
| 25 | 25 | * @var string |
| 26 | 26 | */ |
| 27 | - protected $sNameWhite; |
|
| 27 | +protected $sNameWhite; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 29 | +/** |
|
| 30 | 30 | * @var string |
| 31 | 31 | */ |
| 32 | - protected $sPathWhite; |
|
| 32 | +protected $sPathWhite; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 34 | +/** |
|
| 35 | 35 | * @var int |
| 36 | 36 | */ |
| 37 | - protected $sSizeWhite; |
|
| 37 | +protected $sSizeWhite; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 39 | +/** |
|
| 40 | 40 | * @var string |
| 41 | 41 | */ |
| 42 | - protected $sNameBlue; |
|
| 42 | +protected $sNameBlue; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 44 | +/** |
|
| 45 | 45 | * @var string |
| 46 | 46 | */ |
| 47 | - protected $sPathBlue; |
|
| 47 | +protected $sPathBlue; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 49 | +/** |
|
| 50 | 50 | * @var int |
| 51 | 51 | */ |
| 52 | - protected $sSizeBlue; |
|
| 52 | +protected $sSizeBlue; |
|
| 53 | 53 | |
| 54 | - /** |
|
| 54 | +/** |
|
| 55 | 55 | * @throws SetupException |
| 56 | 56 | */ |
| 57 | - public function setUp(): void |
|
| 58 | - { |
|
| 59 | - jaxon()->di()->getPluginManager()->registerPlugins(); |
|
| 60 | - _register(); |
|
| 61 | - jaxon()->setOption('core.upload.enabled', true); |
|
| 62 | - jaxon()->setOption('core.response.send', false); |
|
| 63 | - |
|
| 64 | - $tmpDir = __DIR__ . '/../upload/tmp'; |
|
| 65 | - @mkdir($tmpDir); |
|
| 66 | - |
|
| 67 | - $sSrcWhite = __DIR__ . '/../upload/src/white.png'; |
|
| 68 | - $this->sNameWhite = 'white.png'; |
|
| 69 | - $this->sPathWhite = "$tmpDir/{$this->sNameWhite}"; |
|
| 70 | - $this->sSizeWhite = filesize($sSrcWhite); |
|
| 71 | - // Copy the file to the temp dir. |
|
| 72 | - @copy($sSrcWhite, $this->sPathWhite); |
|
| 73 | - |
|
| 74 | - $sSrcBlue = __DIR__ . '/../upload/src/blue.png'; |
|
| 75 | - $this->sNameBlue = 'blue.png'; |
|
| 76 | - $this->sPathBlue = "$tmpDir/{$this->sNameBlue}"; |
|
| 77 | - $this->sSizeBlue = filesize($sSrcBlue); |
|
| 78 | - // Copy the file to the temp dir. |
|
| 79 | - @copy($sSrcBlue, $this->sPathBlue); |
|
| 80 | - |
|
| 81 | - jaxon()->register(Jaxon::CALLABLE_CLASS, 'SampleUpload', __DIR__ . '/../src/sample.php'); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 57 | +public function setUp(): void |
|
| 58 | +{ |
|
| 59 | +jaxon()->di()->getPluginManager()->registerPlugins(); |
|
| 60 | +_register(); |
|
| 61 | +jaxon()->setOption('core.upload.enabled', true); |
|
| 62 | +jaxon()->setOption('core.response.send', false); |
|
| 63 | + |
|
| 64 | +$tmpDir = __DIR__ . '/../upload/tmp'; |
|
| 65 | +@mkdir($tmpDir); |
|
| 66 | + |
|
| 67 | +$sSrcWhite = __DIR__ . '/../upload/src/white.png'; |
|
| 68 | +$this->sNameWhite = 'white.png'; |
|
| 69 | +$this->sPathWhite = "$tmpDir/{$this->sNameWhite}"; |
|
| 70 | +$this->sSizeWhite = filesize($sSrcWhite); |
|
| 71 | +// Copy the file to the temp dir. |
|
| 72 | +@copy($sSrcWhite, $this->sPathWhite); |
|
| 73 | + |
|
| 74 | +$sSrcBlue = __DIR__ . '/../upload/src/blue.png'; |
|
| 75 | +$this->sNameBlue = 'blue.png'; |
|
| 76 | +$this->sPathBlue = "$tmpDir/{$this->sNameBlue}"; |
|
| 77 | +$this->sSizeBlue = filesize($sSrcBlue); |
|
| 78 | +// Copy the file to the temp dir. |
|
| 79 | +@copy($sSrcBlue, $this->sPathBlue); |
|
| 80 | + |
|
| 81 | +jaxon()->register(Jaxon::CALLABLE_CLASS, 'SampleUpload', __DIR__ . '/../src/sample.php'); |
|
| 82 | +} |
|
| 83 | + |
|
| 84 | +/** |
|
| 85 | 85 | * @throws SetupException |
| 86 | 86 | */ |
| 87 | - public function tearDown(): void |
|
| 88 | - { |
|
| 89 | - jaxon()->reset(); |
|
| 90 | - parent::tearDown(); |
|
| 91 | - } |
|
| 87 | +public function tearDown(): void |
|
| 88 | +{ |
|
| 89 | +jaxon()->reset(); |
|
| 90 | +parent::tearDown(); |
|
| 91 | +} |
|
| 92 | 92 | |
| 93 | - /** |
|
| 93 | +/** |
|
| 94 | 94 | * @throws RequestException |
| 95 | 95 | */ |
| 96 | - public function testAjaxUpload() |
|
| 97 | - { |
|
| 98 | - jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 99 | - // Send a request to the registered class |
|
| 100 | - jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 101 | - return $c->g(ServerRequestCreator::class) |
|
| 102 | - ->fromGlobals() |
|
| 103 | - ->withParsedBody([ |
|
| 104 | - 'jxncall' => json_encode([ |
|
| 105 | - 'type' => 'class', |
|
| 106 | - 'name' => 'SampleUpload', |
|
| 107 | - 'method' => 'myMethod', |
|
| 108 | - 'args' => [], |
|
| 109 | - ]), |
|
| 110 | - ]) |
|
| 111 | - ->withUploadedFiles([ |
|
| 112 | - 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 113 | - UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 114 | - ]) |
|
| 115 | - ->withMethod('POST'); |
|
| 116 | - }); |
|
| 117 | - |
|
| 118 | - $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 119 | - $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 120 | - jaxon()->processRequest(); |
|
| 121 | - |
|
| 122 | - // Uploaded files |
|
| 123 | - $aFiles = jaxon()->upload()->files(); |
|
| 124 | - $this->assertCount(1, $aFiles); |
|
| 125 | - $this->assertCount(1, $aFiles['image']); |
|
| 126 | - $xFile = $aFiles['image'][0]; |
|
| 127 | - $this->assertEquals('white', $xFile->name()); |
|
| 128 | - $this->assertEquals($this->sNameWhite, $xFile->filename()); |
|
| 129 | - $this->assertEquals('png', $xFile->type()); |
|
| 130 | - $this->assertEquals('png', $xFile->extension()); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 96 | +public function testAjaxUpload() |
|
| 97 | +{ |
|
| 98 | +jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 99 | +// Send a request to the registered class |
|
| 100 | +jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 101 | +return $c->g(ServerRequestCreator::class) |
|
| 102 | + ->fromGlobals() |
|
| 103 | + ->withParsedBody([ |
|
| 104 | + 'jxncall' => json_encode([ |
|
| 105 | + 'type' => 'class', |
|
| 106 | + 'name' => 'SampleUpload', |
|
| 107 | + 'method' => 'myMethod', |
|
| 108 | + 'args' => [], |
|
| 109 | + ]), |
|
| 110 | + ]) |
|
| 111 | + ->withUploadedFiles([ |
|
| 112 | + 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 113 | + UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 114 | + ]) |
|
| 115 | + ->withMethod('POST'); |
|
| 116 | +}); |
|
| 117 | + |
|
| 118 | +$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 119 | +$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 120 | +jaxon()->processRequest(); |
|
| 121 | + |
|
| 122 | +// Uploaded files |
|
| 123 | +$aFiles = jaxon()->upload()->files(); |
|
| 124 | +$this->assertCount(1, $aFiles); |
|
| 125 | +$this->assertCount(1, $aFiles['image']); |
|
| 126 | +$xFile = $aFiles['image'][0]; |
|
| 127 | +$this->assertEquals('white', $xFile->name()); |
|
| 128 | +$this->assertEquals($this->sNameWhite, $xFile->filename()); |
|
| 129 | +$this->assertEquals('png', $xFile->type()); |
|
| 130 | +$this->assertEquals('png', $xFile->extension()); |
|
| 131 | +} |
|
| 132 | + |
|
| 133 | +/** |
|
| 134 | 134 | * @throws RequestException |
| 135 | 135 | */ |
| 136 | - public function testAjaxUploadMultipleFiles() |
|
| 137 | - { |
|
| 138 | - jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 139 | - // Send a request to the registered class |
|
| 140 | - jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 141 | - return $c->g(ServerRequestCreator::class) |
|
| 142 | - ->fromGlobals() |
|
| 143 | - ->withParsedBody([ |
|
| 144 | - 'jxncall' => json_encode([ |
|
| 145 | - 'type' => 'class', |
|
| 146 | - 'name' => 'SampleUpload', |
|
| 147 | - 'method' => 'myMethod', |
|
| 148 | - 'args' => [], |
|
| 149 | - ]), |
|
| 150 | - ]) |
|
| 151 | - ->withUploadedFiles([ |
|
| 152 | - 'image' => [ |
|
| 153 | - new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 154 | - UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 155 | - new UploadedFile($this->sPathBlue, $this->sSizeBlue, |
|
| 156 | - UPLOAD_ERR_OK, $this->sNameBlue, 'png'), |
|
| 157 | - ], |
|
| 158 | - ]) |
|
| 159 | - ->withMethod('POST'); |
|
| 160 | - }); |
|
| 161 | - |
|
| 162 | - $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 163 | - $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 164 | - jaxon()->processRequest(); |
|
| 165 | - |
|
| 166 | - // Uploaded files |
|
| 167 | - $aFiles = jaxon()->upload()->files(); |
|
| 168 | - $this->assertCount(1, $aFiles); |
|
| 169 | - $this->assertCount(2, $aFiles['image']); |
|
| 170 | - $xFile = $aFiles['image'][0]; |
|
| 171 | - $this->assertEquals('white', $xFile->name()); |
|
| 172 | - $this->assertEquals($this->sNameWhite, $xFile->filename()); |
|
| 173 | - $this->assertEquals('png', $xFile->type()); |
|
| 174 | - $this->assertEquals('png', $xFile->extension()); |
|
| 175 | - $xFile = $aFiles['image'][1]; |
|
| 176 | - $this->assertEquals('blue', $xFile->name()); |
|
| 177 | - $this->assertEquals($this->sNameBlue, $xFile->filename()); |
|
| 178 | - $this->assertEquals('png', $xFile->type()); |
|
| 179 | - $this->assertEquals('png', $xFile->extension()); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 136 | +public function testAjaxUploadMultipleFiles() |
|
| 137 | +{ |
|
| 138 | +jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 139 | +// Send a request to the registered class |
|
| 140 | +jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 141 | +return $c->g(ServerRequestCreator::class) |
|
| 142 | + ->fromGlobals() |
|
| 143 | + ->withParsedBody([ |
|
| 144 | + 'jxncall' => json_encode([ |
|
| 145 | + 'type' => 'class', |
|
| 146 | + 'name' => 'SampleUpload', |
|
| 147 | + 'method' => 'myMethod', |
|
| 148 | + 'args' => [], |
|
| 149 | + ]), |
|
| 150 | + ]) |
|
| 151 | + ->withUploadedFiles([ |
|
| 152 | + 'image' => [ |
|
| 153 | + new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 154 | + UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 155 | + new UploadedFile($this->sPathBlue, $this->sSizeBlue, |
|
| 156 | + UPLOAD_ERR_OK, $this->sNameBlue, 'png'), |
|
| 157 | + ], |
|
| 158 | + ]) |
|
| 159 | + ->withMethod('POST'); |
|
| 160 | +}); |
|
| 161 | + |
|
| 162 | +$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 163 | +$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 164 | +jaxon()->processRequest(); |
|
| 165 | + |
|
| 166 | +// Uploaded files |
|
| 167 | +$aFiles = jaxon()->upload()->files(); |
|
| 168 | +$this->assertCount(1, $aFiles); |
|
| 169 | +$this->assertCount(2, $aFiles['image']); |
|
| 170 | +$xFile = $aFiles['image'][0]; |
|
| 171 | +$this->assertEquals('white', $xFile->name()); |
|
| 172 | +$this->assertEquals($this->sNameWhite, $xFile->filename()); |
|
| 173 | +$this->assertEquals('png', $xFile->type()); |
|
| 174 | +$this->assertEquals('png', $xFile->extension()); |
|
| 175 | +$xFile = $aFiles['image'][1]; |
|
| 176 | +$this->assertEquals('blue', $xFile->name()); |
|
| 177 | +$this->assertEquals($this->sNameBlue, $xFile->filename()); |
|
| 178 | +$this->assertEquals('png', $xFile->type()); |
|
| 179 | +$this->assertEquals('png', $xFile->extension()); |
|
| 180 | +} |
|
| 181 | + |
|
| 182 | +/** |
|
| 183 | 183 | * @throws RequestException |
| 184 | 184 | */ |
| 185 | - public function testAjaxUploadMultipleNames() |
|
| 186 | - { |
|
| 187 | - jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 188 | - // Send a request to the registered class |
|
| 189 | - jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 190 | - return $c->g(ServerRequestCreator::class) |
|
| 191 | - ->fromGlobals() |
|
| 192 | - ->withParsedBody([ |
|
| 193 | - 'jxncall' => json_encode([ |
|
| 194 | - 'type' => 'class', |
|
| 195 | - 'name' => 'SampleUpload', |
|
| 196 | - 'method' => 'myMethod', |
|
| 197 | - 'args' => [], |
|
| 198 | - ]), |
|
| 199 | - ]) |
|
| 200 | - ->withUploadedFiles([ |
|
| 201 | - 'white' => [ |
|
| 202 | - new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 203 | - UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 204 | - ], |
|
| 205 | - 'blue' => [ |
|
| 206 | - new UploadedFile($this->sPathBlue, $this->sSizeBlue, |
|
| 207 | - UPLOAD_ERR_OK, $this->sNameBlue, 'png'), |
|
| 208 | - ], |
|
| 209 | - ]) |
|
| 210 | - ->withMethod('POST'); |
|
| 211 | - }); |
|
| 212 | - |
|
| 213 | - $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 214 | - $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 215 | - jaxon()->processRequest(); |
|
| 216 | - |
|
| 217 | - // Uploaded files |
|
| 218 | - $aFiles = jaxon()->upload()->files(); |
|
| 219 | - $this->assertCount(2, $aFiles); |
|
| 220 | - $this->assertCount(1, $aFiles['white']); |
|
| 221 | - $this->assertCount(1, $aFiles['blue']); |
|
| 222 | - $xFile = $aFiles['white'][0]; |
|
| 223 | - $this->assertEquals('white', $xFile->name()); |
|
| 224 | - $this->assertEquals($this->sNameWhite, $xFile->filename()); |
|
| 225 | - $this->assertEquals('png', $xFile->type()); |
|
| 226 | - $this->assertEquals('png', $xFile->extension()); |
|
| 227 | - $xFile = $aFiles['blue'][0]; |
|
| 228 | - $this->assertEquals('blue', $xFile->name()); |
|
| 229 | - $this->assertEquals($this->sNameBlue, $xFile->filename()); |
|
| 230 | - $this->assertEquals('png', $xFile->type()); |
|
| 231 | - $this->assertEquals('png', $xFile->extension()); |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - /** |
|
| 185 | +public function testAjaxUploadMultipleNames() |
|
| 186 | +{ |
|
| 187 | +jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 188 | +// Send a request to the registered class |
|
| 189 | +jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 190 | +return $c->g(ServerRequestCreator::class) |
|
| 191 | + ->fromGlobals() |
|
| 192 | + ->withParsedBody([ |
|
| 193 | + 'jxncall' => json_encode([ |
|
| 194 | + 'type' => 'class', |
|
| 195 | + 'name' => 'SampleUpload', |
|
| 196 | + 'method' => 'myMethod', |
|
| 197 | + 'args' => [], |
|
| 198 | + ]), |
|
| 199 | + ]) |
|
| 200 | + ->withUploadedFiles([ |
|
| 201 | + 'white' => [ |
|
| 202 | + new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 203 | + UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 204 | + ], |
|
| 205 | + 'blue' => [ |
|
| 206 | + new UploadedFile($this->sPathBlue, $this->sSizeBlue, |
|
| 207 | + UPLOAD_ERR_OK, $this->sNameBlue, 'png'), |
|
| 208 | + ], |
|
| 209 | + ]) |
|
| 210 | + ->withMethod('POST'); |
|
| 211 | +}); |
|
| 212 | + |
|
| 213 | +$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 214 | +$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 215 | +jaxon()->processRequest(); |
|
| 216 | + |
|
| 217 | +// Uploaded files |
|
| 218 | +$aFiles = jaxon()->upload()->files(); |
|
| 219 | +$this->assertCount(2, $aFiles); |
|
| 220 | +$this->assertCount(1, $aFiles['white']); |
|
| 221 | +$this->assertCount(1, $aFiles['blue']); |
|
| 222 | +$xFile = $aFiles['white'][0]; |
|
| 223 | +$this->assertEquals('white', $xFile->name()); |
|
| 224 | +$this->assertEquals($this->sNameWhite, $xFile->filename()); |
|
| 225 | +$this->assertEquals('png', $xFile->type()); |
|
| 226 | +$this->assertEquals('png', $xFile->extension()); |
|
| 227 | +$xFile = $aFiles['blue'][0]; |
|
| 228 | +$this->assertEquals('blue', $xFile->name()); |
|
| 229 | +$this->assertEquals($this->sNameBlue, $xFile->filename()); |
|
| 230 | +$this->assertEquals('png', $xFile->type()); |
|
| 231 | +$this->assertEquals('png', $xFile->extension()); |
|
| 232 | +} |
|
| 233 | + |
|
| 234 | +/** |
|
| 235 | 235 | * @throws RequestException |
| 236 | 236 | */ |
| 237 | - public function testAjaxUploadNameSanitizer() |
|
| 238 | - { |
|
| 239 | - jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 240 | - jaxon()->upload()->sanitizer(function($sFilename, $sVarName) { |
|
| 241 | - return $sVarName === 'image' ? 'img_' . $sFilename : $sFilename; |
|
| 242 | - }); |
|
| 243 | - // Send a request to the registered class |
|
| 244 | - jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 245 | - return $c->g(ServerRequestCreator::class) |
|
| 246 | - ->fromGlobals() |
|
| 247 | - ->withParsedBody([ |
|
| 248 | - 'jxncall' => json_encode([ |
|
| 249 | - 'type' => 'class', |
|
| 250 | - 'name' => 'SampleUpload', |
|
| 251 | - 'method' => 'myMethod', |
|
| 252 | - 'args' => [], |
|
| 253 | - ]), |
|
| 254 | - ]) |
|
| 255 | - ->withUploadedFiles([ |
|
| 256 | - 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 257 | - UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 258 | - ]) |
|
| 259 | - ->withMethod('POST'); |
|
| 260 | - }); |
|
| 261 | - |
|
| 262 | - $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 263 | - $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 264 | - jaxon()->processRequest(); |
|
| 265 | - |
|
| 266 | - // Uploaded files |
|
| 267 | - $aFiles = jaxon()->upload()->files(); |
|
| 268 | - $this->assertCount(1, $aFiles); |
|
| 269 | - $this->assertCount(1, $aFiles['image']); |
|
| 270 | - $xFile = $aFiles['image'][0]; |
|
| 271 | - $this->assertEquals('img_white', $xFile->name()); |
|
| 272 | - $this->assertEquals('png', $xFile->type()); |
|
| 273 | - $this->assertEquals('png', $xFile->extension()); |
|
| 274 | - $this->assertEquals($this->sNameWhite, $xFile->filename()); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - /** |
|
| 237 | +public function testAjaxUploadNameSanitizer() |
|
| 238 | +{ |
|
| 239 | +jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 240 | +jaxon()->upload()->sanitizer(function($sFilename, $sVarName) { |
|
| 241 | +return $sVarName === 'image' ? 'img_' . $sFilename : $sFilename; |
|
| 242 | +}); |
|
| 243 | +// Send a request to the registered class |
|
| 244 | +jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 245 | +return $c->g(ServerRequestCreator::class) |
|
| 246 | + ->fromGlobals() |
|
| 247 | + ->withParsedBody([ |
|
| 248 | + 'jxncall' => json_encode([ |
|
| 249 | + 'type' => 'class', |
|
| 250 | + 'name' => 'SampleUpload', |
|
| 251 | + 'method' => 'myMethod', |
|
| 252 | + 'args' => [], |
|
| 253 | + ]), |
|
| 254 | + ]) |
|
| 255 | + ->withUploadedFiles([ |
|
| 256 | + 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 257 | + UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 258 | + ]) |
|
| 259 | + ->withMethod('POST'); |
|
| 260 | +}); |
|
| 261 | + |
|
| 262 | +$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 263 | +$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 264 | +jaxon()->processRequest(); |
|
| 265 | + |
|
| 266 | +// Uploaded files |
|
| 267 | +$aFiles = jaxon()->upload()->files(); |
|
| 268 | +$this->assertCount(1, $aFiles); |
|
| 269 | +$this->assertCount(1, $aFiles['image']); |
|
| 270 | +$xFile = $aFiles['image'][0]; |
|
| 271 | +$this->assertEquals('img_white', $xFile->name()); |
|
| 272 | +$this->assertEquals('png', $xFile->type()); |
|
| 273 | +$this->assertEquals('png', $xFile->extension()); |
|
| 274 | +$this->assertEquals($this->sNameWhite, $xFile->filename()); |
|
| 275 | +} |
|
| 276 | + |
|
| 277 | +/** |
|
| 278 | 278 | * @throws RequestException |
| 279 | 279 | */ |
| 280 | - public function testUploadFileTypeValidationOk() |
|
| 281 | - { |
|
| 282 | - jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 283 | - jaxon()->setOption('upload.default.types', ['png']); |
|
| 284 | - // Send a request to the registered class |
|
| 285 | - jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 286 | - return $c->g(ServerRequestCreator::class) |
|
| 287 | - ->fromGlobals() |
|
| 288 | - ->withParsedBody([ |
|
| 289 | - 'jxncall' => json_encode([ |
|
| 290 | - 'type' => 'class', |
|
| 291 | - 'name' => 'SampleUpload', |
|
| 292 | - 'method' => 'myMethod', |
|
| 293 | - 'args' => [], |
|
| 294 | - ]), |
|
| 295 | - ]) |
|
| 296 | - ->withUploadedFiles([ |
|
| 297 | - 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 298 | - UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 299 | - ]) |
|
| 300 | - ->withMethod('POST'); |
|
| 301 | - }); |
|
| 302 | - |
|
| 303 | - $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 304 | - $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 305 | - jaxon()->processRequest(); |
|
| 306 | - |
|
| 307 | - // Return the file name for the next test |
|
| 308 | - $aFiles = jaxon()->upload()->files(); |
|
| 309 | - $this->assertCount(1, $aFiles); |
|
| 310 | - $this->assertCount(1, $aFiles['image']); |
|
| 311 | - $xFile = $aFiles['image'][0]; |
|
| 312 | - $this->assertEquals('white', $xFile->name()); |
|
| 313 | - $this->assertEquals($this->sNameWhite, $xFile->filename()); |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - /** |
|
| 280 | +public function testUploadFileTypeValidationOk() |
|
| 281 | +{ |
|
| 282 | +jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 283 | +jaxon()->setOption('upload.default.types', ['png']); |
|
| 284 | +// Send a request to the registered class |
|
| 285 | +jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 286 | +return $c->g(ServerRequestCreator::class) |
|
| 287 | + ->fromGlobals() |
|
| 288 | + ->withParsedBody([ |
|
| 289 | + 'jxncall' => json_encode([ |
|
| 290 | + 'type' => 'class', |
|
| 291 | + 'name' => 'SampleUpload', |
|
| 292 | + 'method' => 'myMethod', |
|
| 293 | + 'args' => [], |
|
| 294 | + ]), |
|
| 295 | + ]) |
|
| 296 | + ->withUploadedFiles([ |
|
| 297 | + 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 298 | + UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 299 | + ]) |
|
| 300 | + ->withMethod('POST'); |
|
| 301 | +}); |
|
| 302 | + |
|
| 303 | +$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 304 | +$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 305 | +jaxon()->processRequest(); |
|
| 306 | + |
|
| 307 | +// Return the file name for the next test |
|
| 308 | +$aFiles = jaxon()->upload()->files(); |
|
| 309 | +$this->assertCount(1, $aFiles); |
|
| 310 | +$this->assertCount(1, $aFiles['image']); |
|
| 311 | +$xFile = $aFiles['image'][0]; |
|
| 312 | +$this->assertEquals('white', $xFile->name()); |
|
| 313 | +$this->assertEquals($this->sNameWhite, $xFile->filename()); |
|
| 314 | +} |
|
| 315 | + |
|
| 316 | +/** |
|
| 317 | 317 | * @throws RequestException |
| 318 | 318 | */ |
| 319 | - public function testUploadFileTypeValidationError() |
|
| 320 | - { |
|
| 321 | - jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 322 | - jaxon()->setOption('upload.default.types', ['jpg']); |
|
| 323 | - // Send a request to the registered class |
|
| 324 | - jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 325 | - return $c->g(ServerRequestCreator::class) |
|
| 326 | - ->fromGlobals() |
|
| 327 | - ->withParsedBody([ |
|
| 328 | - 'jxncall' => json_encode([ |
|
| 329 | - 'type' => 'class', |
|
| 330 | - 'name' => 'SampleUpload', |
|
| 331 | - 'method' => 'myMethod', |
|
| 332 | - 'args' => [], |
|
| 333 | - ]), |
|
| 334 | - ]) |
|
| 335 | - ->withUploadedFiles([ |
|
| 336 | - 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 337 | - UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 338 | - ]) |
|
| 339 | - ->withMethod('POST'); |
|
| 340 | - }); |
|
| 341 | - |
|
| 342 | - $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 343 | - $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 344 | - $this->expectException(RequestException::class); |
|
| 345 | - jaxon()->processRequest(); |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - /** |
|
| 319 | +public function testUploadFileTypeValidationError() |
|
| 320 | +{ |
|
| 321 | +jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 322 | +jaxon()->setOption('upload.default.types', ['jpg']); |
|
| 323 | +// Send a request to the registered class |
|
| 324 | +jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 325 | +return $c->g(ServerRequestCreator::class) |
|
| 326 | + ->fromGlobals() |
|
| 327 | + ->withParsedBody([ |
|
| 328 | + 'jxncall' => json_encode([ |
|
| 329 | + 'type' => 'class', |
|
| 330 | + 'name' => 'SampleUpload', |
|
| 331 | + 'method' => 'myMethod', |
|
| 332 | + 'args' => [], |
|
| 333 | + ]), |
|
| 334 | + ]) |
|
| 335 | + ->withUploadedFiles([ |
|
| 336 | + 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 337 | + UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 338 | + ]) |
|
| 339 | + ->withMethod('POST'); |
|
| 340 | +}); |
|
| 341 | + |
|
| 342 | +$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 343 | +$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 344 | +$this->expectException(RequestException::class); |
|
| 345 | +jaxon()->processRequest(); |
|
| 346 | +} |
|
| 347 | + |
|
| 348 | +/** |
|
| 349 | 349 | * @throws RequestException |
| 350 | 350 | */ |
| 351 | - public function testUploadFileExtensionValidationOk() |
|
| 352 | - { |
|
| 353 | - jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 354 | - jaxon()->setOption('upload.default.extensions', ['png']); |
|
| 355 | - // Send a request to the registered class |
|
| 356 | - jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 357 | - return $c->g(ServerRequestCreator::class) |
|
| 358 | - ->fromGlobals() |
|
| 359 | - ->withParsedBody([ |
|
| 360 | - 'jxncall' => json_encode([ |
|
| 361 | - 'type' => 'class', |
|
| 362 | - 'name' => 'SampleUpload', |
|
| 363 | - 'method' => 'myMethod', |
|
| 364 | - 'args' => [], |
|
| 365 | - ]), |
|
| 366 | - ]) |
|
| 367 | - ->withUploadedFiles([ |
|
| 368 | - 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 369 | - UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 370 | - ]) |
|
| 371 | - ->withMethod('POST'); |
|
| 372 | - }); |
|
| 373 | - |
|
| 374 | - $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 375 | - $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 376 | - jaxon()->processRequest(); |
|
| 377 | - |
|
| 378 | - // Return the file name for the next test |
|
| 379 | - $aFiles = jaxon()->upload()->files(); |
|
| 380 | - $this->assertCount(1, $aFiles); |
|
| 381 | - $this->assertCount(1, $aFiles['image']); |
|
| 382 | - $xFile = $aFiles['image'][0]; |
|
| 383 | - $this->assertEquals('white', $xFile->name()); |
|
| 384 | - $this->assertEquals($this->sNameWhite, $xFile->filename()); |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - /** |
|
| 351 | +public function testUploadFileExtensionValidationOk() |
|
| 352 | +{ |
|
| 353 | +jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 354 | +jaxon()->setOption('upload.default.extensions', ['png']); |
|
| 355 | +// Send a request to the registered class |
|
| 356 | +jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 357 | +return $c->g(ServerRequestCreator::class) |
|
| 358 | + ->fromGlobals() |
|
| 359 | + ->withParsedBody([ |
|
| 360 | + 'jxncall' => json_encode([ |
|
| 361 | + 'type' => 'class', |
|
| 362 | + 'name' => 'SampleUpload', |
|
| 363 | + 'method' => 'myMethod', |
|
| 364 | + 'args' => [], |
|
| 365 | + ]), |
|
| 366 | + ]) |
|
| 367 | + ->withUploadedFiles([ |
|
| 368 | + 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 369 | + UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 370 | + ]) |
|
| 371 | + ->withMethod('POST'); |
|
| 372 | +}); |
|
| 373 | + |
|
| 374 | +$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 375 | +$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 376 | +jaxon()->processRequest(); |
|
| 377 | + |
|
| 378 | +// Return the file name for the next test |
|
| 379 | +$aFiles = jaxon()->upload()->files(); |
|
| 380 | +$this->assertCount(1, $aFiles); |
|
| 381 | +$this->assertCount(1, $aFiles['image']); |
|
| 382 | +$xFile = $aFiles['image'][0]; |
|
| 383 | +$this->assertEquals('white', $xFile->name()); |
|
| 384 | +$this->assertEquals($this->sNameWhite, $xFile->filename()); |
|
| 385 | +} |
|
| 386 | + |
|
| 387 | +/** |
|
| 388 | 388 | * @throws RequestException |
| 389 | 389 | */ |
| 390 | - public function testUploadFileExtensionValidationError() |
|
| 391 | - { |
|
| 392 | - jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 393 | - jaxon()->setOption('upload.default.extensions', ['jpg']); |
|
| 394 | - // Send a request to the registered class |
|
| 395 | - jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 396 | - return $c->g(ServerRequestCreator::class) |
|
| 397 | - ->fromGlobals() |
|
| 398 | - ->withParsedBody([ |
|
| 399 | - 'jxncall' => json_encode([ |
|
| 400 | - 'type' => 'class', |
|
| 401 | - 'name' => 'SampleUpload', |
|
| 402 | - 'method' => 'myMethod', |
|
| 403 | - 'args' => [], |
|
| 404 | - ]), |
|
| 405 | - ]) |
|
| 406 | - ->withUploadedFiles([ |
|
| 407 | - 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 408 | - UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 409 | - ]) |
|
| 410 | - ->withMethod('POST'); |
|
| 411 | - }); |
|
| 412 | - |
|
| 413 | - $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 414 | - $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 415 | - $this->expectException(RequestException::class); |
|
| 416 | - jaxon()->processRequest(); |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - /** |
|
| 390 | +public function testUploadFileExtensionValidationError() |
|
| 391 | +{ |
|
| 392 | +jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 393 | +jaxon()->setOption('upload.default.extensions', ['jpg']); |
|
| 394 | +// Send a request to the registered class |
|
| 395 | +jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 396 | +return $c->g(ServerRequestCreator::class) |
|
| 397 | + ->fromGlobals() |
|
| 398 | + ->withParsedBody([ |
|
| 399 | + 'jxncall' => json_encode([ |
|
| 400 | + 'type' => 'class', |
|
| 401 | + 'name' => 'SampleUpload', |
|
| 402 | + 'method' => 'myMethod', |
|
| 403 | + 'args' => [], |
|
| 404 | + ]), |
|
| 405 | + ]) |
|
| 406 | + ->withUploadedFiles([ |
|
| 407 | + 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 408 | + UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 409 | + ]) |
|
| 410 | + ->withMethod('POST'); |
|
| 411 | +}); |
|
| 412 | + |
|
| 413 | +$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 414 | +$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 415 | +$this->expectException(RequestException::class); |
|
| 416 | +jaxon()->processRequest(); |
|
| 417 | +} |
|
| 418 | + |
|
| 419 | +/** |
|
| 420 | 420 | * @throws RequestException |
| 421 | 421 | */ |
| 422 | - public function testUploadFileMaxSizeValidationOk() |
|
| 423 | - { |
|
| 424 | - jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 425 | - jaxon()->setOption('upload.default.max-size', 30000); |
|
| 426 | - // Send a request to the registered class |
|
| 427 | - jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 428 | - return $c->g(ServerRequestCreator::class) |
|
| 429 | - ->fromGlobals() |
|
| 430 | - ->withParsedBody([ |
|
| 431 | - 'jxncall' => json_encode([ |
|
| 432 | - 'type' => 'class', |
|
| 433 | - 'name' => 'SampleUpload', |
|
| 434 | - 'method' => 'myMethod', |
|
| 435 | - 'args' => [], |
|
| 436 | - ]), |
|
| 437 | - ]) |
|
| 438 | - ->withUploadedFiles([ |
|
| 439 | - 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 440 | - UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 441 | - ]) |
|
| 442 | - ->withMethod('POST'); |
|
| 443 | - }); |
|
| 444 | - |
|
| 445 | - $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 446 | - $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 447 | - jaxon()->processRequest(); |
|
| 448 | - |
|
| 449 | - // Return the file name for the next test |
|
| 450 | - $aFiles = jaxon()->upload()->files(); |
|
| 451 | - $this->assertCount(1, $aFiles); |
|
| 452 | - $this->assertCount(1, $aFiles['image']); |
|
| 453 | - $xFile = $aFiles['image'][0]; |
|
| 454 | - $this->assertEquals('white', $xFile->name()); |
|
| 455 | - $this->assertEquals($this->sNameWhite, $xFile->filename()); |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - /** |
|
| 422 | +public function testUploadFileMaxSizeValidationOk() |
|
| 423 | +{ |
|
| 424 | +jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 425 | +jaxon()->setOption('upload.default.max-size', 30000); |
|
| 426 | +// Send a request to the registered class |
|
| 427 | +jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 428 | +return $c->g(ServerRequestCreator::class) |
|
| 429 | + ->fromGlobals() |
|
| 430 | + ->withParsedBody([ |
|
| 431 | + 'jxncall' => json_encode([ |
|
| 432 | + 'type' => 'class', |
|
| 433 | + 'name' => 'SampleUpload', |
|
| 434 | + 'method' => 'myMethod', |
|
| 435 | + 'args' => [], |
|
| 436 | + ]), |
|
| 437 | + ]) |
|
| 438 | + ->withUploadedFiles([ |
|
| 439 | + 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 440 | + UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 441 | + ]) |
|
| 442 | + ->withMethod('POST'); |
|
| 443 | +}); |
|
| 444 | + |
|
| 445 | +$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 446 | +$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 447 | +jaxon()->processRequest(); |
|
| 448 | + |
|
| 449 | +// Return the file name for the next test |
|
| 450 | +$aFiles = jaxon()->upload()->files(); |
|
| 451 | +$this->assertCount(1, $aFiles); |
|
| 452 | +$this->assertCount(1, $aFiles['image']); |
|
| 453 | +$xFile = $aFiles['image'][0]; |
|
| 454 | +$this->assertEquals('white', $xFile->name()); |
|
| 455 | +$this->assertEquals($this->sNameWhite, $xFile->filename()); |
|
| 456 | +} |
|
| 457 | + |
|
| 458 | +/** |
|
| 459 | 459 | * @throws RequestException |
| 460 | 460 | */ |
| 461 | - public function testUploadFileMaxSizeValidationError() |
|
| 462 | - { |
|
| 463 | - jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 464 | - jaxon()->setOption('upload.default.max-size', 25000); |
|
| 465 | - // Send a request to the registered class |
|
| 466 | - jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 467 | - return $c->g(ServerRequestCreator::class) |
|
| 468 | - ->fromGlobals() |
|
| 469 | - ->withParsedBody([ |
|
| 470 | - 'jxncall' => json_encode([ |
|
| 471 | - 'type' => 'class', |
|
| 472 | - 'name' => 'SampleUpload', |
|
| 473 | - 'method' => 'myMethod', |
|
| 474 | - 'args' => [], |
|
| 475 | - ]), |
|
| 476 | - ]) |
|
| 477 | - ->withUploadedFiles([ |
|
| 478 | - 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 479 | - UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 480 | - ]) |
|
| 481 | - ->withMethod('POST'); |
|
| 482 | - }); |
|
| 483 | - |
|
| 484 | - $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 485 | - $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 486 | - $this->expectException(RequestException::class); |
|
| 487 | - jaxon()->processRequest(); |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - /** |
|
| 461 | +public function testUploadFileMaxSizeValidationError() |
|
| 462 | +{ |
|
| 463 | +jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 464 | +jaxon()->setOption('upload.default.max-size', 25000); |
|
| 465 | +// Send a request to the registered class |
|
| 466 | +jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 467 | +return $c->g(ServerRequestCreator::class) |
|
| 468 | + ->fromGlobals() |
|
| 469 | + ->withParsedBody([ |
|
| 470 | + 'jxncall' => json_encode([ |
|
| 471 | + 'type' => 'class', |
|
| 472 | + 'name' => 'SampleUpload', |
|
| 473 | + 'method' => 'myMethod', |
|
| 474 | + 'args' => [], |
|
| 475 | + ]), |
|
| 476 | + ]) |
|
| 477 | + ->withUploadedFiles([ |
|
| 478 | + 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 479 | + UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 480 | + ]) |
|
| 481 | + ->withMethod('POST'); |
|
| 482 | +}); |
|
| 483 | + |
|
| 484 | +$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 485 | +$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 486 | +$this->expectException(RequestException::class); |
|
| 487 | +jaxon()->processRequest(); |
|
| 488 | +} |
|
| 489 | + |
|
| 490 | +/** |
|
| 491 | 491 | * @throws RequestException |
| 492 | 492 | */ |
| 493 | - public function testUploadFileMinSizeValidationOk() |
|
| 494 | - { |
|
| 495 | - jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 496 | - jaxon()->setOption('upload.default.min-size', 25000); |
|
| 497 | - // Send a request to the registered class |
|
| 498 | - jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 499 | - return $c->g(ServerRequestCreator::class) |
|
| 500 | - ->fromGlobals() |
|
| 501 | - ->withParsedBody([ |
|
| 502 | - 'jxncall' => json_encode([ |
|
| 503 | - 'type' => 'class', |
|
| 504 | - 'name' => 'SampleUpload', |
|
| 505 | - 'method' => 'myMethod', |
|
| 506 | - 'args' => [], |
|
| 507 | - ]), |
|
| 508 | - ]) |
|
| 509 | - ->withUploadedFiles([ |
|
| 510 | - 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 511 | - UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 512 | - ]) |
|
| 513 | - ->withMethod('POST'); |
|
| 514 | - }); |
|
| 515 | - |
|
| 516 | - $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 517 | - $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 518 | - jaxon()->processRequest(); |
|
| 519 | - |
|
| 520 | - // Return the file name for the next test |
|
| 521 | - $aFiles = jaxon()->upload()->files(); |
|
| 522 | - $this->assertCount(1, $aFiles); |
|
| 523 | - $this->assertCount(1, $aFiles['image']); |
|
| 524 | - $xFile = $aFiles['image'][0]; |
|
| 525 | - $this->assertEquals('white', $xFile->name()); |
|
| 526 | - $this->assertEquals($this->sNameWhite, $xFile->filename()); |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - /** |
|
| 493 | +public function testUploadFileMinSizeValidationOk() |
|
| 494 | +{ |
|
| 495 | +jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 496 | +jaxon()->setOption('upload.default.min-size', 25000); |
|
| 497 | +// Send a request to the registered class |
|
| 498 | +jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 499 | +return $c->g(ServerRequestCreator::class) |
|
| 500 | + ->fromGlobals() |
|
| 501 | + ->withParsedBody([ |
|
| 502 | + 'jxncall' => json_encode([ |
|
| 503 | + 'type' => 'class', |
|
| 504 | + 'name' => 'SampleUpload', |
|
| 505 | + 'method' => 'myMethod', |
|
| 506 | + 'args' => [], |
|
| 507 | + ]), |
|
| 508 | + ]) |
|
| 509 | + ->withUploadedFiles([ |
|
| 510 | + 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 511 | + UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 512 | + ]) |
|
| 513 | + ->withMethod('POST'); |
|
| 514 | +}); |
|
| 515 | + |
|
| 516 | +$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 517 | +$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 518 | +jaxon()->processRequest(); |
|
| 519 | + |
|
| 520 | +// Return the file name for the next test |
|
| 521 | +$aFiles = jaxon()->upload()->files(); |
|
| 522 | +$this->assertCount(1, $aFiles); |
|
| 523 | +$this->assertCount(1, $aFiles['image']); |
|
| 524 | +$xFile = $aFiles['image'][0]; |
|
| 525 | +$this->assertEquals('white', $xFile->name()); |
|
| 526 | +$this->assertEquals($this->sNameWhite, $xFile->filename()); |
|
| 527 | +} |
|
| 528 | + |
|
| 529 | +/** |
|
| 530 | 530 | * @throws RequestException |
| 531 | 531 | */ |
| 532 | - public function testUploadFileMinSizeValidationError() |
|
| 533 | - { |
|
| 534 | - jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 535 | - jaxon()->setOption('upload.default.min-size', 30000); |
|
| 536 | - // Send a request to the registered class |
|
| 537 | - jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 538 | - return $c->g(ServerRequestCreator::class) |
|
| 539 | - ->fromGlobals() |
|
| 540 | - ->withParsedBody([ |
|
| 541 | - 'jxncall' => json_encode([ |
|
| 542 | - 'type' => 'class', |
|
| 543 | - 'name' => 'SampleUpload', |
|
| 544 | - 'method' => 'myMethod', |
|
| 545 | - 'args' => [], |
|
| 546 | - ]), |
|
| 547 | - ]) |
|
| 548 | - ->withUploadedFiles([ |
|
| 549 | - 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 550 | - UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 551 | - ]) |
|
| 552 | - ->withMethod('POST'); |
|
| 553 | - }); |
|
| 554 | - |
|
| 555 | - $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 556 | - $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 557 | - $this->expectException(RequestException::class); |
|
| 558 | - jaxon()->processRequest(); |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - /** |
|
| 532 | +public function testUploadFileMinSizeValidationError() |
|
| 533 | +{ |
|
| 534 | +jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 535 | +jaxon()->setOption('upload.default.min-size', 30000); |
|
| 536 | +// Send a request to the registered class |
|
| 537 | +jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 538 | +return $c->g(ServerRequestCreator::class) |
|
| 539 | + ->fromGlobals() |
|
| 540 | + ->withParsedBody([ |
|
| 541 | + 'jxncall' => json_encode([ |
|
| 542 | + 'type' => 'class', |
|
| 543 | + 'name' => 'SampleUpload', |
|
| 544 | + 'method' => 'myMethod', |
|
| 545 | + 'args' => [], |
|
| 546 | + ]), |
|
| 547 | + ]) |
|
| 548 | + ->withUploadedFiles([ |
|
| 549 | + 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 550 | + UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 551 | + ]) |
|
| 552 | + ->withMethod('POST'); |
|
| 553 | +}); |
|
| 554 | + |
|
| 555 | +$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 556 | +$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 557 | +$this->expectException(RequestException::class); |
|
| 558 | +jaxon()->processRequest(); |
|
| 559 | +} |
|
| 560 | + |
|
| 561 | +/** |
|
| 562 | 562 | * @throws RequestException |
| 563 | 563 | * @throws SetupException |
| 564 | 564 | */ |
| 565 | - public function testPsrAjaxUpload() |
|
| 566 | - { |
|
| 567 | - _register(); |
|
| 568 | - jaxon()->setOption('core.upload.enabled', true); |
|
| 569 | - jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 570 | - // Send a request to the registered class |
|
| 571 | - $xRequest = jaxon()->di()->g(ServerRequestCreator::class) |
|
| 572 | - ->fromGlobals() |
|
| 573 | - ->withParsedBody([ |
|
| 574 | - 'jxncall' => json_encode([ |
|
| 575 | - 'type' => 'class', |
|
| 576 | - 'name' => 'SampleUpload', |
|
| 577 | - 'method' => 'myMethod', |
|
| 578 | - 'args' => [], |
|
| 579 | - ]), |
|
| 580 | - ]) |
|
| 581 | - ->withUploadedFiles([ |
|
| 582 | - 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 583 | - UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 584 | - ]) |
|
| 585 | - ->withMethod('POST'); |
|
| 586 | - |
|
| 587 | - $xPsrConfigMiddleware = jaxon()->psr()->config(__DIR__ . '/../config/psr.php'); |
|
| 588 | - $xPsrAjaxMiddleware = jaxon()->psr()->ajax(); |
|
| 589 | - // PSR request handler that does nothing, useful to call the config middleware. |
|
| 590 | - $xEmptyRequestHandler = new class implements RequestHandlerInterface |
|
| 591 | - { |
|
| 592 | - private $xPsr17Factory; |
|
| 593 | - |
|
| 594 | - public function __construct() |
|
| 595 | - { |
|
| 596 | - $this->xPsr17Factory = new Psr17Factory(); |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 600 | - { |
|
| 601 | - return $this->xPsr17Factory->createResponse(); |
|
| 602 | - } |
|
| 603 | - }; |
|
| 604 | - // Call the config middleware |
|
| 605 | - $xPsrConfigMiddleware->process($xRequest, $xEmptyRequestHandler); |
|
| 606 | - // Call the ajax middleware |
|
| 607 | - $xPsrResponse = $xPsrAjaxMiddleware->process($xRequest, $xEmptyRequestHandler); |
|
| 608 | - |
|
| 609 | - // Both responses must have the same content and content type |
|
| 610 | - $xJaxonResponse = jaxon()->getResponse(); |
|
| 611 | - $this->assertEquals($xPsrResponse->getBody()->__toString(), $xJaxonResponse->getOutput()); |
|
| 612 | - $this->assertEquals($xPsrResponse->getHeader('content-type')[0], $xJaxonResponse->getContentType()); |
|
| 613 | - |
|
| 614 | - // Uploaded files |
|
| 615 | - $aFiles = jaxon()->upload()->files(); |
|
| 616 | - $this->assertCount(1, $aFiles); |
|
| 617 | - $this->assertCount(1, $aFiles['image']); |
|
| 618 | - $xFile = $aFiles['image'][0]; |
|
| 619 | - $this->assertEquals('white', $xFile->name()); |
|
| 620 | - $this->assertEquals($this->sNameWhite, $xFile->filename()); |
|
| 621 | - $this->assertEquals('png', $xFile->type()); |
|
| 622 | - $this->assertEquals('png', $xFile->extension()); |
|
| 623 | - } |
|
| 565 | +public function testPsrAjaxUpload() |
|
| 566 | +{ |
|
| 567 | +_register(); |
|
| 568 | +jaxon()->setOption('core.upload.enabled', true); |
|
| 569 | +jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 570 | +// Send a request to the registered class |
|
| 571 | +$xRequest = jaxon()->di()->g(ServerRequestCreator::class) |
|
| 572 | +->fromGlobals() |
|
| 573 | +->withParsedBody([ |
|
| 574 | + 'jxncall' => json_encode([ |
|
| 575 | + 'type' => 'class', |
|
| 576 | + 'name' => 'SampleUpload', |
|
| 577 | + 'method' => 'myMethod', |
|
| 578 | + 'args' => [], |
|
| 579 | + ]), |
|
| 580 | +]) |
|
| 581 | +->withUploadedFiles([ |
|
| 582 | + 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 583 | + UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 584 | +]) |
|
| 585 | +->withMethod('POST'); |
|
| 586 | + |
|
| 587 | +$xPsrConfigMiddleware = jaxon()->psr()->config(__DIR__ . '/../config/psr.php'); |
|
| 588 | +$xPsrAjaxMiddleware = jaxon()->psr()->ajax(); |
|
| 589 | +// PSR request handler that does nothing, useful to call the config middleware. |
|
| 590 | +$xEmptyRequestHandler = new class implements RequestHandlerInterface |
|
| 591 | +{ |
|
| 592 | +private $xPsr17Factory; |
|
| 593 | + |
|
| 594 | +public function __construct() |
|
| 595 | +{ |
|
| 596 | + $this->xPsr17Factory = new Psr17Factory(); |
|
| 597 | +} |
|
| 598 | + |
|
| 599 | +public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 600 | +{ |
|
| 601 | + return $this->xPsr17Factory->createResponse(); |
|
| 602 | +} |
|
| 603 | +}; |
|
| 604 | +// Call the config middleware |
|
| 605 | +$xPsrConfigMiddleware->process($xRequest, $xEmptyRequestHandler); |
|
| 606 | +// Call the ajax middleware |
|
| 607 | +$xPsrResponse = $xPsrAjaxMiddleware->process($xRequest, $xEmptyRequestHandler); |
|
| 608 | + |
|
| 609 | +// Both responses must have the same content and content type |
|
| 610 | +$xJaxonResponse = jaxon()->getResponse(); |
|
| 611 | +$this->assertEquals($xPsrResponse->getBody()->__toString(), $xJaxonResponse->getOutput()); |
|
| 612 | +$this->assertEquals($xPsrResponse->getHeader('content-type')[0], $xJaxonResponse->getContentType()); |
|
| 613 | + |
|
| 614 | +// Uploaded files |
|
| 615 | +$aFiles = jaxon()->upload()->files(); |
|
| 616 | +$this->assertCount(1, $aFiles); |
|
| 617 | +$this->assertCount(1, $aFiles['image']); |
|
| 618 | +$xFile = $aFiles['image'][0]; |
|
| 619 | +$this->assertEquals('white', $xFile->name()); |
|
| 620 | +$this->assertEquals($this->sNameWhite, $xFile->filename()); |
|
| 621 | +$this->assertEquals('png', $xFile->type()); |
|
| 622 | +$this->assertEquals('png', $xFile->extension()); |
|
| 623 | +} |
|
| 624 | 624 | } |
@@ -16,560 +16,560 @@ |
||
| 16 | 16 | |
| 17 | 17 | class UploadTest extends TestCase |
| 18 | 18 | { |
| 19 | - /** |
|
| 19 | +/** |
|
| 20 | 20 | * @var string |
| 21 | 21 | */ |
| 22 | - protected $sNameWhite; |
|
| 22 | +protected $sNameWhite; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 24 | +/** |
|
| 25 | 25 | * @var string |
| 26 | 26 | */ |
| 27 | - protected $sPathWhite; |
|
| 27 | +protected $sPathWhite; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 29 | +/** |
|
| 30 | 30 | * @var int |
| 31 | 31 | */ |
| 32 | - protected $sSizeWhite; |
|
| 32 | +protected $sSizeWhite; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 34 | +/** |
|
| 35 | 35 | * @var string |
| 36 | 36 | */ |
| 37 | - protected $sNameBlue; |
|
| 37 | +protected $sNameBlue; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 39 | +/** |
|
| 40 | 40 | * @var string |
| 41 | 41 | */ |
| 42 | - protected $sPathBlue; |
|
| 42 | +protected $sPathBlue; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 44 | +/** |
|
| 45 | 45 | * @var int |
| 46 | 46 | */ |
| 47 | - protected $sSizeBlue; |
|
| 47 | +protected $sSizeBlue; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 49 | +/** |
|
| 50 | 50 | * @throws SetupException |
| 51 | 51 | */ |
| 52 | - public function setUp(): void |
|
| 53 | - { |
|
| 54 | - _register(); |
|
| 55 | - jaxon()->setOption('core.upload.enabled', true); |
|
| 56 | - |
|
| 57 | - jaxon()->setOption('core.response.send', false); |
|
| 58 | - $tmpDir = __DIR__ . '/../upload/tmp'; |
|
| 59 | - @mkdir($tmpDir); |
|
| 60 | - |
|
| 61 | - $sSrcWhite = __DIR__ . '/../upload/src/white.png'; |
|
| 62 | - $this->sNameWhite = 'white.png'; |
|
| 63 | - $this->sPathWhite = "$tmpDir/{$this->sNameWhite}"; |
|
| 64 | - $this->sSizeWhite = filesize($sSrcWhite); |
|
| 65 | - // Copy the file to the temp dir. |
|
| 66 | - @copy($sSrcWhite, $this->sPathWhite); |
|
| 67 | - |
|
| 68 | - $sSrcBlue = __DIR__ . '/../upload/src/blue.png'; |
|
| 69 | - $this->sNameBlue = 'blue.png'; |
|
| 70 | - $this->sPathBlue = "$tmpDir/{$this->sNameBlue}"; |
|
| 71 | - $this->sSizeBlue = filesize($sSrcBlue); |
|
| 72 | - // Copy the file to the temp dir. |
|
| 73 | - @copy($sSrcBlue, $this->sPathBlue); |
|
| 74 | - |
|
| 75 | - jaxon()->register(Jaxon::CALLABLE_CLASS, 'SampleUpload', __DIR__ . '/../src/sample.php'); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 52 | +public function setUp(): void |
|
| 53 | +{ |
|
| 54 | +_register(); |
|
| 55 | +jaxon()->setOption('core.upload.enabled', true); |
|
| 56 | + |
|
| 57 | +jaxon()->setOption('core.response.send', false); |
|
| 58 | +$tmpDir = __DIR__ . '/../upload/tmp'; |
|
| 59 | +@mkdir($tmpDir); |
|
| 60 | + |
|
| 61 | +$sSrcWhite = __DIR__ . '/../upload/src/white.png'; |
|
| 62 | +$this->sNameWhite = 'white.png'; |
|
| 63 | +$this->sPathWhite = "$tmpDir/{$this->sNameWhite}"; |
|
| 64 | +$this->sSizeWhite = filesize($sSrcWhite); |
|
| 65 | +// Copy the file to the temp dir. |
|
| 66 | +@copy($sSrcWhite, $this->sPathWhite); |
|
| 67 | + |
|
| 68 | +$sSrcBlue = __DIR__ . '/../upload/src/blue.png'; |
|
| 69 | +$this->sNameBlue = 'blue.png'; |
|
| 70 | +$this->sPathBlue = "$tmpDir/{$this->sNameBlue}"; |
|
| 71 | +$this->sSizeBlue = filesize($sSrcBlue); |
|
| 72 | +// Copy the file to the temp dir. |
|
| 73 | +@copy($sSrcBlue, $this->sPathBlue); |
|
| 74 | + |
|
| 75 | +jaxon()->register(Jaxon::CALLABLE_CLASS, 'SampleUpload', __DIR__ . '/../src/sample.php'); |
|
| 76 | +} |
|
| 77 | + |
|
| 78 | +/** |
|
| 79 | 79 | * @throws SetupException |
| 80 | 80 | */ |
| 81 | - public function tearDown(): void |
|
| 82 | - { |
|
| 83 | - jaxon()->reset(); |
|
| 84 | - parent::tearDown(); |
|
| 85 | - } |
|
| 81 | +public function tearDown(): void |
|
| 82 | +{ |
|
| 83 | +jaxon()->reset(); |
|
| 84 | +parent::tearDown(); |
|
| 85 | +} |
|
| 86 | 86 | |
| 87 | - /** |
|
| 87 | +/** |
|
| 88 | 88 | * @throws RequestException |
| 89 | 89 | */ |
| 90 | - public function testAjaxUpload() |
|
| 91 | - { |
|
| 92 | - jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 93 | - // Send a request to the registered class |
|
| 94 | - jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 95 | - return $c->g(ServerRequestCreator::class) |
|
| 96 | - ->fromGlobals() |
|
| 97 | - ->withParsedBody([ |
|
| 98 | - 'jxncall' => json_encode([ |
|
| 99 | - 'type' => 'class', |
|
| 100 | - 'name' => 'SampleUpload', |
|
| 101 | - 'method' => 'myMethod', |
|
| 102 | - 'args' => [], |
|
| 103 | - ]), |
|
| 104 | - ]) |
|
| 105 | - ->withUploadedFiles([ |
|
| 106 | - 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 107 | - UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 108 | - ]) |
|
| 109 | - ->withMethod('POST'); |
|
| 110 | - }); |
|
| 111 | - |
|
| 112 | - $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 113 | - $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 114 | - jaxon()->processRequest(); |
|
| 115 | - |
|
| 116 | - // Uploaded files |
|
| 117 | - $aFiles = jaxon()->upload()->files(); |
|
| 118 | - $this->assertCount(1, $aFiles); |
|
| 119 | - $this->assertCount(1, $aFiles['image']); |
|
| 120 | - $xFile = $aFiles['image'][0]; |
|
| 121 | - $this->assertEquals('white', $xFile->name()); |
|
| 122 | - $this->assertEquals($this->sNameWhite, $xFile->filename()); |
|
| 123 | - $this->assertEquals('png', $xFile->type()); |
|
| 124 | - $this->assertEquals('png', $xFile->extension()); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 90 | +public function testAjaxUpload() |
|
| 91 | +{ |
|
| 92 | +jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 93 | +// Send a request to the registered class |
|
| 94 | +jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 95 | +return $c->g(ServerRequestCreator::class) |
|
| 96 | + ->fromGlobals() |
|
| 97 | + ->withParsedBody([ |
|
| 98 | + 'jxncall' => json_encode([ |
|
| 99 | + 'type' => 'class', |
|
| 100 | + 'name' => 'SampleUpload', |
|
| 101 | + 'method' => 'myMethod', |
|
| 102 | + 'args' => [], |
|
| 103 | + ]), |
|
| 104 | + ]) |
|
| 105 | + ->withUploadedFiles([ |
|
| 106 | + 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 107 | + UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 108 | + ]) |
|
| 109 | + ->withMethod('POST'); |
|
| 110 | +}); |
|
| 111 | + |
|
| 112 | +$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 113 | +$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 114 | +jaxon()->processRequest(); |
|
| 115 | + |
|
| 116 | +// Uploaded files |
|
| 117 | +$aFiles = jaxon()->upload()->files(); |
|
| 118 | +$this->assertCount(1, $aFiles); |
|
| 119 | +$this->assertCount(1, $aFiles['image']); |
|
| 120 | +$xFile = $aFiles['image'][0]; |
|
| 121 | +$this->assertEquals('white', $xFile->name()); |
|
| 122 | +$this->assertEquals($this->sNameWhite, $xFile->filename()); |
|
| 123 | +$this->assertEquals('png', $xFile->type()); |
|
| 124 | +$this->assertEquals('png', $xFile->extension()); |
|
| 125 | +} |
|
| 126 | + |
|
| 127 | +/** |
|
| 128 | 128 | * @throws RequestException |
| 129 | 129 | */ |
| 130 | - public function testAjaxUploadMultipleFiles() |
|
| 131 | - { |
|
| 132 | - jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 133 | - // Send a request to the registered class |
|
| 134 | - jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 135 | - return $c->g(ServerRequestCreator::class) |
|
| 136 | - ->fromGlobals() |
|
| 137 | - ->withParsedBody([ |
|
| 138 | - 'jxncall' => json_encode([ |
|
| 139 | - 'type' => 'class', |
|
| 140 | - 'name' => 'SampleUpload', |
|
| 141 | - 'method' => 'myMethod', |
|
| 142 | - 'args' => [], |
|
| 143 | - ]), |
|
| 144 | - ]) |
|
| 145 | - ->withUploadedFiles([ |
|
| 146 | - 'image' => [ |
|
| 147 | - new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 148 | - UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 149 | - new UploadedFile($this->sPathBlue, $this->sSizeBlue, |
|
| 150 | - UPLOAD_ERR_OK, $this->sNameBlue, 'png'), |
|
| 151 | - ], |
|
| 152 | - ]) |
|
| 153 | - ->withMethod('POST'); |
|
| 154 | - }); |
|
| 155 | - |
|
| 156 | - $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 157 | - $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 158 | - jaxon()->processRequest(); |
|
| 159 | - |
|
| 160 | - // Uploaded files |
|
| 161 | - $aFiles = jaxon()->upload()->files(); |
|
| 162 | - $this->assertCount(1, $aFiles); |
|
| 163 | - $this->assertCount(2, $aFiles['image']); |
|
| 164 | - $xFile = $aFiles['image'][0]; |
|
| 165 | - $this->assertEquals('white', $xFile->name()); |
|
| 166 | - $this->assertEquals($this->sNameWhite, $xFile->filename()); |
|
| 167 | - $this->assertEquals('png', $xFile->type()); |
|
| 168 | - $this->assertEquals('png', $xFile->extension()); |
|
| 169 | - $xFile = $aFiles['image'][1]; |
|
| 170 | - $this->assertEquals('blue', $xFile->name()); |
|
| 171 | - $this->assertEquals($this->sNameBlue, $xFile->filename()); |
|
| 172 | - $this->assertEquals('png', $xFile->type()); |
|
| 173 | - $this->assertEquals('png', $xFile->extension()); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 130 | +public function testAjaxUploadMultipleFiles() |
|
| 131 | +{ |
|
| 132 | +jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 133 | +// Send a request to the registered class |
|
| 134 | +jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 135 | +return $c->g(ServerRequestCreator::class) |
|
| 136 | + ->fromGlobals() |
|
| 137 | + ->withParsedBody([ |
|
| 138 | + 'jxncall' => json_encode([ |
|
| 139 | + 'type' => 'class', |
|
| 140 | + 'name' => 'SampleUpload', |
|
| 141 | + 'method' => 'myMethod', |
|
| 142 | + 'args' => [], |
|
| 143 | + ]), |
|
| 144 | + ]) |
|
| 145 | + ->withUploadedFiles([ |
|
| 146 | + 'image' => [ |
|
| 147 | + new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 148 | + UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 149 | + new UploadedFile($this->sPathBlue, $this->sSizeBlue, |
|
| 150 | + UPLOAD_ERR_OK, $this->sNameBlue, 'png'), |
|
| 151 | + ], |
|
| 152 | + ]) |
|
| 153 | + ->withMethod('POST'); |
|
| 154 | +}); |
|
| 155 | + |
|
| 156 | +$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 157 | +$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 158 | +jaxon()->processRequest(); |
|
| 159 | + |
|
| 160 | +// Uploaded files |
|
| 161 | +$aFiles = jaxon()->upload()->files(); |
|
| 162 | +$this->assertCount(1, $aFiles); |
|
| 163 | +$this->assertCount(2, $aFiles['image']); |
|
| 164 | +$xFile = $aFiles['image'][0]; |
|
| 165 | +$this->assertEquals('white', $xFile->name()); |
|
| 166 | +$this->assertEquals($this->sNameWhite, $xFile->filename()); |
|
| 167 | +$this->assertEquals('png', $xFile->type()); |
|
| 168 | +$this->assertEquals('png', $xFile->extension()); |
|
| 169 | +$xFile = $aFiles['image'][1]; |
|
| 170 | +$this->assertEquals('blue', $xFile->name()); |
|
| 171 | +$this->assertEquals($this->sNameBlue, $xFile->filename()); |
|
| 172 | +$this->assertEquals('png', $xFile->type()); |
|
| 173 | +$this->assertEquals('png', $xFile->extension()); |
|
| 174 | +} |
|
| 175 | + |
|
| 176 | +/** |
|
| 177 | 177 | * @throws RequestException |
| 178 | 178 | */ |
| 179 | - public function testAjaxUploadMultipleNames() |
|
| 180 | - { |
|
| 181 | - jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 182 | - // Send a request to the registered class |
|
| 183 | - jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 184 | - return $c->g(ServerRequestCreator::class) |
|
| 185 | - ->fromGlobals() |
|
| 186 | - ->withParsedBody([ |
|
| 187 | - 'jxncall' => json_encode([ |
|
| 188 | - 'type' => 'class', |
|
| 189 | - 'name' => 'SampleUpload', |
|
| 190 | - 'method' => 'myMethod', |
|
| 191 | - 'args' => [], |
|
| 192 | - ]), |
|
| 193 | - ]) |
|
| 194 | - ->withUploadedFiles([ |
|
| 195 | - 'white' => [ |
|
| 196 | - new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 197 | - UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 198 | - ], |
|
| 199 | - 'blue' => [ |
|
| 200 | - new UploadedFile($this->sPathBlue, $this->sSizeBlue, |
|
| 201 | - UPLOAD_ERR_OK, $this->sNameBlue, 'png'), |
|
| 202 | - ], |
|
| 203 | - ]) |
|
| 204 | - ->withMethod('POST'); |
|
| 205 | - }); |
|
| 206 | - |
|
| 207 | - $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 208 | - $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 209 | - jaxon()->processRequest(); |
|
| 210 | - |
|
| 211 | - // Uploaded files |
|
| 212 | - $aFiles = jaxon()->upload()->files(); |
|
| 213 | - $this->assertCount(2, $aFiles); |
|
| 214 | - $this->assertCount(1, $aFiles['white']); |
|
| 215 | - $this->assertCount(1, $aFiles['blue']); |
|
| 216 | - $xFile = $aFiles['white'][0]; |
|
| 217 | - $this->assertEquals('white', $xFile->name()); |
|
| 218 | - $this->assertEquals($this->sNameWhite, $xFile->filename()); |
|
| 219 | - $this->assertEquals('png', $xFile->type()); |
|
| 220 | - $this->assertEquals('png', $xFile->extension()); |
|
| 221 | - $xFile = $aFiles['blue'][0]; |
|
| 222 | - $this->assertEquals('blue', $xFile->name()); |
|
| 223 | - $this->assertEquals($this->sNameBlue, $xFile->filename()); |
|
| 224 | - $this->assertEquals('png', $xFile->type()); |
|
| 225 | - $this->assertEquals('png', $xFile->extension()); |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - /** |
|
| 179 | +public function testAjaxUploadMultipleNames() |
|
| 180 | +{ |
|
| 181 | +jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 182 | +// Send a request to the registered class |
|
| 183 | +jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 184 | +return $c->g(ServerRequestCreator::class) |
|
| 185 | + ->fromGlobals() |
|
| 186 | + ->withParsedBody([ |
|
| 187 | + 'jxncall' => json_encode([ |
|
| 188 | + 'type' => 'class', |
|
| 189 | + 'name' => 'SampleUpload', |
|
| 190 | + 'method' => 'myMethod', |
|
| 191 | + 'args' => [], |
|
| 192 | + ]), |
|
| 193 | + ]) |
|
| 194 | + ->withUploadedFiles([ |
|
| 195 | + 'white' => [ |
|
| 196 | + new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 197 | + UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 198 | + ], |
|
| 199 | + 'blue' => [ |
|
| 200 | + new UploadedFile($this->sPathBlue, $this->sSizeBlue, |
|
| 201 | + UPLOAD_ERR_OK, $this->sNameBlue, 'png'), |
|
| 202 | + ], |
|
| 203 | + ]) |
|
| 204 | + ->withMethod('POST'); |
|
| 205 | +}); |
|
| 206 | + |
|
| 207 | +$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 208 | +$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 209 | +jaxon()->processRequest(); |
|
| 210 | + |
|
| 211 | +// Uploaded files |
|
| 212 | +$aFiles = jaxon()->upload()->files(); |
|
| 213 | +$this->assertCount(2, $aFiles); |
|
| 214 | +$this->assertCount(1, $aFiles['white']); |
|
| 215 | +$this->assertCount(1, $aFiles['blue']); |
|
| 216 | +$xFile = $aFiles['white'][0]; |
|
| 217 | +$this->assertEquals('white', $xFile->name()); |
|
| 218 | +$this->assertEquals($this->sNameWhite, $xFile->filename()); |
|
| 219 | +$this->assertEquals('png', $xFile->type()); |
|
| 220 | +$this->assertEquals('png', $xFile->extension()); |
|
| 221 | +$xFile = $aFiles['blue'][0]; |
|
| 222 | +$this->assertEquals('blue', $xFile->name()); |
|
| 223 | +$this->assertEquals($this->sNameBlue, $xFile->filename()); |
|
| 224 | +$this->assertEquals('png', $xFile->type()); |
|
| 225 | +$this->assertEquals('png', $xFile->extension()); |
|
| 226 | +} |
|
| 227 | + |
|
| 228 | +/** |
|
| 229 | 229 | * @throws RequestException |
| 230 | 230 | */ |
| 231 | - public function testAjaxUploadNameSanitizer() |
|
| 232 | - { |
|
| 233 | - jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 234 | - jaxon()->upload()->sanitizer(function($sFilename, $sVarName) { |
|
| 235 | - return $sVarName === 'image' ? 'img_' . $sFilename : $sFilename; |
|
| 236 | - }); |
|
| 237 | - // Send a request to the registered class |
|
| 238 | - jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 239 | - return $c->g(ServerRequestCreator::class) |
|
| 240 | - ->fromGlobals() |
|
| 241 | - ->withParsedBody([ |
|
| 242 | - 'jxncall' => json_encode([ |
|
| 243 | - 'type' => 'class', |
|
| 244 | - 'name' => 'SampleUpload', |
|
| 245 | - 'method' => 'myMethod', |
|
| 246 | - 'args' => [], |
|
| 247 | - ]), |
|
| 248 | - ]) |
|
| 249 | - ->withUploadedFiles([ |
|
| 250 | - 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 251 | - UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 252 | - ]) |
|
| 253 | - ->withMethod('POST'); |
|
| 254 | - }); |
|
| 255 | - |
|
| 256 | - $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 257 | - $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 258 | - jaxon()->processRequest(); |
|
| 259 | - |
|
| 260 | - // Uploaded files |
|
| 261 | - $aFiles = jaxon()->upload()->files(); |
|
| 262 | - $this->assertCount(1, $aFiles); |
|
| 263 | - $this->assertCount(1, $aFiles['image']); |
|
| 264 | - $xFile = $aFiles['image'][0]; |
|
| 265 | - $this->assertEquals('img_white', $xFile->name()); |
|
| 266 | - $this->assertEquals('png', $xFile->type()); |
|
| 267 | - $this->assertEquals('png', $xFile->extension()); |
|
| 268 | - $this->assertEquals($this->sNameWhite, $xFile->filename()); |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - /** |
|
| 231 | +public function testAjaxUploadNameSanitizer() |
|
| 232 | +{ |
|
| 233 | +jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 234 | +jaxon()->upload()->sanitizer(function($sFilename, $sVarName) { |
|
| 235 | +return $sVarName === 'image' ? 'img_' . $sFilename : $sFilename; |
|
| 236 | +}); |
|
| 237 | +// Send a request to the registered class |
|
| 238 | +jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 239 | +return $c->g(ServerRequestCreator::class) |
|
| 240 | + ->fromGlobals() |
|
| 241 | + ->withParsedBody([ |
|
| 242 | + 'jxncall' => json_encode([ |
|
| 243 | + 'type' => 'class', |
|
| 244 | + 'name' => 'SampleUpload', |
|
| 245 | + 'method' => 'myMethod', |
|
| 246 | + 'args' => [], |
|
| 247 | + ]), |
|
| 248 | + ]) |
|
| 249 | + ->withUploadedFiles([ |
|
| 250 | + 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 251 | + UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 252 | + ]) |
|
| 253 | + ->withMethod('POST'); |
|
| 254 | +}); |
|
| 255 | + |
|
| 256 | +$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 257 | +$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 258 | +jaxon()->processRequest(); |
|
| 259 | + |
|
| 260 | +// Uploaded files |
|
| 261 | +$aFiles = jaxon()->upload()->files(); |
|
| 262 | +$this->assertCount(1, $aFiles); |
|
| 263 | +$this->assertCount(1, $aFiles['image']); |
|
| 264 | +$xFile = $aFiles['image'][0]; |
|
| 265 | +$this->assertEquals('img_white', $xFile->name()); |
|
| 266 | +$this->assertEquals('png', $xFile->type()); |
|
| 267 | +$this->assertEquals('png', $xFile->extension()); |
|
| 268 | +$this->assertEquals($this->sNameWhite, $xFile->filename()); |
|
| 269 | +} |
|
| 270 | + |
|
| 271 | +/** |
|
| 272 | 272 | * @throws RequestException |
| 273 | 273 | */ |
| 274 | - public function testUploadFileTypeValidationOk() |
|
| 275 | - { |
|
| 276 | - jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 277 | - jaxon()->setOption('upload.default.types', ['png']); |
|
| 278 | - // Send a request to the registered class |
|
| 279 | - jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 280 | - return $c->g(ServerRequestCreator::class) |
|
| 281 | - ->fromGlobals() |
|
| 282 | - ->withParsedBody([ |
|
| 283 | - 'jxncall' => json_encode([ |
|
| 284 | - 'type' => 'class', |
|
| 285 | - 'name' => 'SampleUpload', |
|
| 286 | - 'method' => 'myMethod', |
|
| 287 | - 'args' => [], |
|
| 288 | - ]), |
|
| 289 | - ]) |
|
| 290 | - ->withUploadedFiles([ |
|
| 291 | - 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 292 | - UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 293 | - ])->withMethod('POST'); |
|
| 294 | - }); |
|
| 295 | - |
|
| 296 | - $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 297 | - $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 298 | - jaxon()->processRequest(); |
|
| 299 | - |
|
| 300 | - // Return the file name for the next test |
|
| 301 | - $aFiles = jaxon()->upload()->files(); |
|
| 302 | - $this->assertCount(1, $aFiles); |
|
| 303 | - $this->assertCount(1, $aFiles['image']); |
|
| 304 | - $xFile = $aFiles['image'][0]; |
|
| 305 | - $this->assertEquals('white', $xFile->name()); |
|
| 306 | - $this->assertEquals($this->sNameWhite, $xFile->filename()); |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - /** |
|
| 274 | +public function testUploadFileTypeValidationOk() |
|
| 275 | +{ |
|
| 276 | +jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 277 | +jaxon()->setOption('upload.default.types', ['png']); |
|
| 278 | +// Send a request to the registered class |
|
| 279 | +jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 280 | +return $c->g(ServerRequestCreator::class) |
|
| 281 | + ->fromGlobals() |
|
| 282 | + ->withParsedBody([ |
|
| 283 | + 'jxncall' => json_encode([ |
|
| 284 | + 'type' => 'class', |
|
| 285 | + 'name' => 'SampleUpload', |
|
| 286 | + 'method' => 'myMethod', |
|
| 287 | + 'args' => [], |
|
| 288 | + ]), |
|
| 289 | + ]) |
|
| 290 | + ->withUploadedFiles([ |
|
| 291 | + 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 292 | + UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 293 | + ])->withMethod('POST'); |
|
| 294 | +}); |
|
| 295 | + |
|
| 296 | +$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 297 | +$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 298 | +jaxon()->processRequest(); |
|
| 299 | + |
|
| 300 | +// Return the file name for the next test |
|
| 301 | +$aFiles = jaxon()->upload()->files(); |
|
| 302 | +$this->assertCount(1, $aFiles); |
|
| 303 | +$this->assertCount(1, $aFiles['image']); |
|
| 304 | +$xFile = $aFiles['image'][0]; |
|
| 305 | +$this->assertEquals('white', $xFile->name()); |
|
| 306 | +$this->assertEquals($this->sNameWhite, $xFile->filename()); |
|
| 307 | +} |
|
| 308 | + |
|
| 309 | +/** |
|
| 310 | 310 | * @throws RequestException |
| 311 | 311 | */ |
| 312 | - public function testUploadFileTypeValidationError() |
|
| 313 | - { |
|
| 314 | - jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 315 | - jaxon()->setOption('upload.default.types', ['jpg']); |
|
| 316 | - // Send a request to the registered class |
|
| 317 | - jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 318 | - return $c->g(ServerRequestCreator::class) |
|
| 319 | - ->fromGlobals() |
|
| 320 | - ->withParsedBody([ |
|
| 321 | - 'jxncall' => json_encode([ |
|
| 322 | - 'type' => 'class', |
|
| 323 | - 'name' => 'SampleUpload', |
|
| 324 | - 'method' => 'myMethod', |
|
| 325 | - 'args' => [], |
|
| 326 | - ]), |
|
| 327 | - ]) |
|
| 328 | - ->withUploadedFiles([ |
|
| 329 | - 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 330 | - UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 331 | - ]) |
|
| 332 | - ->withMethod('POST'); |
|
| 333 | - }); |
|
| 334 | - |
|
| 335 | - $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 336 | - $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 337 | - $this->expectException(RequestException::class); |
|
| 338 | - jaxon()->processRequest(); |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - /** |
|
| 312 | +public function testUploadFileTypeValidationError() |
|
| 313 | +{ |
|
| 314 | +jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 315 | +jaxon()->setOption('upload.default.types', ['jpg']); |
|
| 316 | +// Send a request to the registered class |
|
| 317 | +jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 318 | +return $c->g(ServerRequestCreator::class) |
|
| 319 | + ->fromGlobals() |
|
| 320 | + ->withParsedBody([ |
|
| 321 | + 'jxncall' => json_encode([ |
|
| 322 | + 'type' => 'class', |
|
| 323 | + 'name' => 'SampleUpload', |
|
| 324 | + 'method' => 'myMethod', |
|
| 325 | + 'args' => [], |
|
| 326 | + ]), |
|
| 327 | + ]) |
|
| 328 | + ->withUploadedFiles([ |
|
| 329 | + 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 330 | + UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 331 | + ]) |
|
| 332 | + ->withMethod('POST'); |
|
| 333 | +}); |
|
| 334 | + |
|
| 335 | +$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 336 | +$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 337 | +$this->expectException(RequestException::class); |
|
| 338 | +jaxon()->processRequest(); |
|
| 339 | +} |
|
| 340 | + |
|
| 341 | +/** |
|
| 342 | 342 | * @throws RequestException |
| 343 | 343 | */ |
| 344 | - public function testUploadFileExtensionValidationOk() |
|
| 345 | - { |
|
| 346 | - jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 347 | - jaxon()->setOption('upload.default.extensions', ['png']); |
|
| 348 | - // Send a request to the registered class |
|
| 349 | - jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 350 | - return $c->g(ServerRequestCreator::class) |
|
| 351 | - ->fromGlobals() |
|
| 352 | - ->withParsedBody([ |
|
| 353 | - 'jxncall' => json_encode([ |
|
| 354 | - 'type' => 'class', |
|
| 355 | - 'name' => 'SampleUpload', |
|
| 356 | - 'method' => 'myMethod', |
|
| 357 | - 'args' => [], |
|
| 358 | - ]), |
|
| 359 | - ]) |
|
| 360 | - ->withUploadedFiles([ |
|
| 361 | - 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 362 | - UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 363 | - ]) |
|
| 364 | - ->withMethod('POST'); |
|
| 365 | - }); |
|
| 366 | - |
|
| 367 | - $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 368 | - $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 369 | - jaxon()->processRequest(); |
|
| 370 | - |
|
| 371 | - // Return the file name for the next test |
|
| 372 | - $aFiles = jaxon()->upload()->files(); |
|
| 373 | - $this->assertCount(1, $aFiles); |
|
| 374 | - $this->assertCount(1, $aFiles['image']); |
|
| 375 | - $xFile = $aFiles['image'][0]; |
|
| 376 | - $this->assertEquals('white', $xFile->name()); |
|
| 377 | - $this->assertEquals($this->sNameWhite, $xFile->filename()); |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - /** |
|
| 344 | +public function testUploadFileExtensionValidationOk() |
|
| 345 | +{ |
|
| 346 | +jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 347 | +jaxon()->setOption('upload.default.extensions', ['png']); |
|
| 348 | +// Send a request to the registered class |
|
| 349 | +jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 350 | +return $c->g(ServerRequestCreator::class) |
|
| 351 | + ->fromGlobals() |
|
| 352 | + ->withParsedBody([ |
|
| 353 | + 'jxncall' => json_encode([ |
|
| 354 | + 'type' => 'class', |
|
| 355 | + 'name' => 'SampleUpload', |
|
| 356 | + 'method' => 'myMethod', |
|
| 357 | + 'args' => [], |
|
| 358 | + ]), |
|
| 359 | + ]) |
|
| 360 | + ->withUploadedFiles([ |
|
| 361 | + 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 362 | + UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 363 | + ]) |
|
| 364 | + ->withMethod('POST'); |
|
| 365 | +}); |
|
| 366 | + |
|
| 367 | +$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 368 | +$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 369 | +jaxon()->processRequest(); |
|
| 370 | + |
|
| 371 | +// Return the file name for the next test |
|
| 372 | +$aFiles = jaxon()->upload()->files(); |
|
| 373 | +$this->assertCount(1, $aFiles); |
|
| 374 | +$this->assertCount(1, $aFiles['image']); |
|
| 375 | +$xFile = $aFiles['image'][0]; |
|
| 376 | +$this->assertEquals('white', $xFile->name()); |
|
| 377 | +$this->assertEquals($this->sNameWhite, $xFile->filename()); |
|
| 378 | +} |
|
| 379 | + |
|
| 380 | +/** |
|
| 381 | 381 | * @throws RequestException |
| 382 | 382 | */ |
| 383 | - public function testUploadFileExtensionValidationError() |
|
| 384 | - { |
|
| 385 | - jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 386 | - jaxon()->setOption('upload.default.extensions', ['jpg']); |
|
| 387 | - // Send a request to the registered class |
|
| 388 | - jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 389 | - return $c->g(ServerRequestCreator::class) |
|
| 390 | - ->fromGlobals() |
|
| 391 | - ->withParsedBody([ |
|
| 392 | - 'jxncall' => json_encode([ |
|
| 393 | - 'type' => 'class', |
|
| 394 | - 'name' => 'SampleUpload', |
|
| 395 | - 'method' => 'myMethod', |
|
| 396 | - 'args' => [], |
|
| 397 | - ]), |
|
| 398 | - ]) |
|
| 399 | - ->withUploadedFiles([ |
|
| 400 | - 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 401 | - UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 402 | - ]) |
|
| 403 | - ->withMethod('POST'); |
|
| 404 | - }); |
|
| 405 | - |
|
| 406 | - $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 407 | - $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 408 | - $this->expectException(RequestException::class); |
|
| 409 | - jaxon()->processRequest(); |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - /** |
|
| 383 | +public function testUploadFileExtensionValidationError() |
|
| 384 | +{ |
|
| 385 | +jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 386 | +jaxon()->setOption('upload.default.extensions', ['jpg']); |
|
| 387 | +// Send a request to the registered class |
|
| 388 | +jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 389 | +return $c->g(ServerRequestCreator::class) |
|
| 390 | + ->fromGlobals() |
|
| 391 | + ->withParsedBody([ |
|
| 392 | + 'jxncall' => json_encode([ |
|
| 393 | + 'type' => 'class', |
|
| 394 | + 'name' => 'SampleUpload', |
|
| 395 | + 'method' => 'myMethod', |
|
| 396 | + 'args' => [], |
|
| 397 | + ]), |
|
| 398 | + ]) |
|
| 399 | + ->withUploadedFiles([ |
|
| 400 | + 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 401 | + UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 402 | + ]) |
|
| 403 | + ->withMethod('POST'); |
|
| 404 | +}); |
|
| 405 | + |
|
| 406 | +$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 407 | +$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 408 | +$this->expectException(RequestException::class); |
|
| 409 | +jaxon()->processRequest(); |
|
| 410 | +} |
|
| 411 | + |
|
| 412 | +/** |
|
| 413 | 413 | * @throws RequestException |
| 414 | 414 | */ |
| 415 | - public function testUploadFileMaxSizeValidationOk() |
|
| 416 | - { |
|
| 417 | - jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 418 | - jaxon()->setOption('upload.default.max-size', 30000); |
|
| 419 | - // Send a request to the registered class |
|
| 420 | - jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 421 | - return $c->g(ServerRequestCreator::class) |
|
| 422 | - ->fromGlobals() |
|
| 423 | - ->withParsedBody([ |
|
| 424 | - 'jxncall' => json_encode([ |
|
| 425 | - 'type' => 'class', |
|
| 426 | - 'name' => 'SampleUpload', |
|
| 427 | - 'method' => 'myMethod', |
|
| 428 | - 'args' => [], |
|
| 429 | - ]), |
|
| 430 | - ]) |
|
| 431 | - ->withUploadedFiles([ |
|
| 432 | - 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 433 | - UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 434 | - ]) |
|
| 435 | - ->withMethod('POST'); |
|
| 436 | - }); |
|
| 437 | - |
|
| 438 | - $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 439 | - $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 440 | - jaxon()->processRequest(); |
|
| 441 | - |
|
| 442 | - // Return the file name for the next test |
|
| 443 | - $aFiles = jaxon()->upload()->files(); |
|
| 444 | - $this->assertCount(1, $aFiles); |
|
| 445 | - $this->assertCount(1, $aFiles['image']); |
|
| 446 | - $xFile = $aFiles['image'][0]; |
|
| 447 | - $this->assertEquals('white', $xFile->name()); |
|
| 448 | - $this->assertEquals($this->sNameWhite, $xFile->filename()); |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - /** |
|
| 415 | +public function testUploadFileMaxSizeValidationOk() |
|
| 416 | +{ |
|
| 417 | +jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 418 | +jaxon()->setOption('upload.default.max-size', 30000); |
|
| 419 | +// Send a request to the registered class |
|
| 420 | +jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 421 | +return $c->g(ServerRequestCreator::class) |
|
| 422 | + ->fromGlobals() |
|
| 423 | + ->withParsedBody([ |
|
| 424 | + 'jxncall' => json_encode([ |
|
| 425 | + 'type' => 'class', |
|
| 426 | + 'name' => 'SampleUpload', |
|
| 427 | + 'method' => 'myMethod', |
|
| 428 | + 'args' => [], |
|
| 429 | + ]), |
|
| 430 | + ]) |
|
| 431 | + ->withUploadedFiles([ |
|
| 432 | + 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 433 | + UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 434 | + ]) |
|
| 435 | + ->withMethod('POST'); |
|
| 436 | +}); |
|
| 437 | + |
|
| 438 | +$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 439 | +$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 440 | +jaxon()->processRequest(); |
|
| 441 | + |
|
| 442 | +// Return the file name for the next test |
|
| 443 | +$aFiles = jaxon()->upload()->files(); |
|
| 444 | +$this->assertCount(1, $aFiles); |
|
| 445 | +$this->assertCount(1, $aFiles['image']); |
|
| 446 | +$xFile = $aFiles['image'][0]; |
|
| 447 | +$this->assertEquals('white', $xFile->name()); |
|
| 448 | +$this->assertEquals($this->sNameWhite, $xFile->filename()); |
|
| 449 | +} |
|
| 450 | + |
|
| 451 | +/** |
|
| 452 | 452 | * @throws RequestException |
| 453 | 453 | */ |
| 454 | - public function testUploadFileMaxSizeValidationError() |
|
| 455 | - { |
|
| 456 | - jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 457 | - jaxon()->setOption('upload.default.max-size', 25000); |
|
| 458 | - // Send a request to the registered class |
|
| 459 | - jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 460 | - return $c->g(ServerRequestCreator::class) |
|
| 461 | - ->fromGlobals() |
|
| 462 | - ->withParsedBody([ |
|
| 463 | - 'jxncall' => json_encode([ |
|
| 464 | - 'type' => 'class', |
|
| 465 | - 'name' => 'SampleUpload', |
|
| 466 | - 'method' => 'myMethod', |
|
| 467 | - 'args' => [], |
|
| 468 | - ]), |
|
| 469 | - ]) |
|
| 470 | - ->withUploadedFiles([ |
|
| 471 | - 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 472 | - UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 473 | - ]) |
|
| 474 | - ->withMethod('POST'); |
|
| 475 | - }); |
|
| 476 | - |
|
| 477 | - $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 478 | - $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 479 | - $this->expectException(RequestException::class); |
|
| 480 | - jaxon()->processRequest(); |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - /** |
|
| 454 | +public function testUploadFileMaxSizeValidationError() |
|
| 455 | +{ |
|
| 456 | +jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 457 | +jaxon()->setOption('upload.default.max-size', 25000); |
|
| 458 | +// Send a request to the registered class |
|
| 459 | +jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 460 | +return $c->g(ServerRequestCreator::class) |
|
| 461 | + ->fromGlobals() |
|
| 462 | + ->withParsedBody([ |
|
| 463 | + 'jxncall' => json_encode([ |
|
| 464 | + 'type' => 'class', |
|
| 465 | + 'name' => 'SampleUpload', |
|
| 466 | + 'method' => 'myMethod', |
|
| 467 | + 'args' => [], |
|
| 468 | + ]), |
|
| 469 | + ]) |
|
| 470 | + ->withUploadedFiles([ |
|
| 471 | + 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 472 | + UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 473 | + ]) |
|
| 474 | + ->withMethod('POST'); |
|
| 475 | +}); |
|
| 476 | + |
|
| 477 | +$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 478 | +$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 479 | +$this->expectException(RequestException::class); |
|
| 480 | +jaxon()->processRequest(); |
|
| 481 | +} |
|
| 482 | + |
|
| 483 | +/** |
|
| 484 | 484 | * @throws RequestException |
| 485 | 485 | */ |
| 486 | - public function testUploadFileMinSizeValidationOk() |
|
| 487 | - { |
|
| 488 | - jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 489 | - jaxon()->setOption('upload.default.min-size', 25000); |
|
| 490 | - // Send a request to the registered class |
|
| 491 | - jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 492 | - return $c->g(ServerRequestCreator::class) |
|
| 493 | - ->fromGlobals() |
|
| 494 | - ->withParsedBody([ |
|
| 495 | - 'jxncall' => json_encode([ |
|
| 496 | - 'type' => 'class', |
|
| 497 | - 'name' => 'SampleUpload', |
|
| 498 | - 'method' => 'myMethod', |
|
| 499 | - 'args' => [], |
|
| 500 | - ]), |
|
| 501 | - ]) |
|
| 502 | - ->withUploadedFiles([ |
|
| 503 | - 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 504 | - UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 505 | - ]) |
|
| 506 | - ->withMethod('POST'); |
|
| 507 | - }); |
|
| 508 | - |
|
| 509 | - $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 510 | - $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 511 | - jaxon()->processRequest(); |
|
| 512 | - |
|
| 513 | - // Return the file name for the next test |
|
| 514 | - $aFiles = jaxon()->upload()->files(); |
|
| 515 | - $this->assertCount(1, $aFiles); |
|
| 516 | - $this->assertCount(1, $aFiles['image']); |
|
| 517 | - $xFile = $aFiles['image'][0]; |
|
| 518 | - $this->assertEquals('white', $xFile->name()); |
|
| 519 | - $this->assertEquals($this->sNameWhite, $xFile->filename()); |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - /** |
|
| 486 | +public function testUploadFileMinSizeValidationOk() |
|
| 487 | +{ |
|
| 488 | +jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 489 | +jaxon()->setOption('upload.default.min-size', 25000); |
|
| 490 | +// Send a request to the registered class |
|
| 491 | +jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 492 | +return $c->g(ServerRequestCreator::class) |
|
| 493 | + ->fromGlobals() |
|
| 494 | + ->withParsedBody([ |
|
| 495 | + 'jxncall' => json_encode([ |
|
| 496 | + 'type' => 'class', |
|
| 497 | + 'name' => 'SampleUpload', |
|
| 498 | + 'method' => 'myMethod', |
|
| 499 | + 'args' => [], |
|
| 500 | + ]), |
|
| 501 | + ]) |
|
| 502 | + ->withUploadedFiles([ |
|
| 503 | + 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 504 | + UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 505 | + ]) |
|
| 506 | + ->withMethod('POST'); |
|
| 507 | +}); |
|
| 508 | + |
|
| 509 | +$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 510 | +$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 511 | +jaxon()->processRequest(); |
|
| 512 | + |
|
| 513 | +// Return the file name for the next test |
|
| 514 | +$aFiles = jaxon()->upload()->files(); |
|
| 515 | +$this->assertCount(1, $aFiles); |
|
| 516 | +$this->assertCount(1, $aFiles['image']); |
|
| 517 | +$xFile = $aFiles['image'][0]; |
|
| 518 | +$this->assertEquals('white', $xFile->name()); |
|
| 519 | +$this->assertEquals($this->sNameWhite, $xFile->filename()); |
|
| 520 | +} |
|
| 521 | + |
|
| 522 | +/** |
|
| 523 | 523 | * @throws RequestException |
| 524 | 524 | */ |
| 525 | - public function testUploadFileMinSizeValidationError() |
|
| 526 | - { |
|
| 527 | - jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 528 | - jaxon()->setOption('upload.default.min-size', 30000); |
|
| 529 | - // Send a request to the registered class |
|
| 530 | - jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 531 | - return $c->g(ServerRequestCreator::class) |
|
| 532 | - ->fromGlobals() |
|
| 533 | - ->withParsedBody([ |
|
| 534 | - 'jxncall' => json_encode([ |
|
| 535 | - 'type' => 'class', |
|
| 536 | - 'name' => 'SampleUpload', |
|
| 537 | - 'method' => 'myMethod', |
|
| 538 | - 'args' => [], |
|
| 539 | - ]), |
|
| 540 | - ]) |
|
| 541 | - ->withUploadedFiles([ |
|
| 542 | - 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 543 | - UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 544 | - ]) |
|
| 545 | - ->withMethod('POST'); |
|
| 546 | - }); |
|
| 547 | - |
|
| 548 | - $this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 549 | - $this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 550 | - $this->expectException(RequestException::class); |
|
| 551 | - jaxon()->processRequest(); |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - /** |
|
| 525 | +public function testUploadFileMinSizeValidationError() |
|
| 526 | +{ |
|
| 527 | +jaxon()->setOption('upload.default.dir', __DIR__ . '/../upload/dst'); |
|
| 528 | +jaxon()->setOption('upload.default.min-size', 30000); |
|
| 529 | +// Send a request to the registered class |
|
| 530 | +jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 531 | +return $c->g(ServerRequestCreator::class) |
|
| 532 | + ->fromGlobals() |
|
| 533 | + ->withParsedBody([ |
|
| 534 | + 'jxncall' => json_encode([ |
|
| 535 | + 'type' => 'class', |
|
| 536 | + 'name' => 'SampleUpload', |
|
| 537 | + 'method' => 'myMethod', |
|
| 538 | + 'args' => [], |
|
| 539 | + ]), |
|
| 540 | + ]) |
|
| 541 | + ->withUploadedFiles([ |
|
| 542 | + 'image' => new UploadedFile($this->sPathWhite, $this->sSizeWhite, |
|
| 543 | + UPLOAD_ERR_OK, $this->sNameWhite, 'png'), |
|
| 544 | + ]) |
|
| 545 | + ->withMethod('POST'); |
|
| 546 | +}); |
|
| 547 | + |
|
| 548 | +$this->assertTrue(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 549 | +$this->assertTrue(jaxon()->di()->getUploadHandler()->canProcessRequest(jaxon()->di()->getRequest())); |
|
| 550 | +$this->expectException(RequestException::class); |
|
| 551 | +jaxon()->processRequest(); |
|
| 552 | +} |
|
| 553 | + |
|
| 554 | +/** |
|
| 555 | 555 | * @throws RequestException |
| 556 | 556 | */ |
| 557 | - public function testRequestWithNoPluginNoUpload() |
|
| 558 | - { |
|
| 559 | - jaxon()->setOption('core.upload.enabled', false); |
|
| 560 | - // Send a request to the registered class |
|
| 561 | - jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 562 | - return $c->g(ServerRequestCreator::class) |
|
| 563 | - ->fromGlobals() |
|
| 564 | - ->withParsedBody([ |
|
| 565 | - 'jxncall' => json_encode([ |
|
| 566 | - 'who' => 'Nobody', |
|
| 567 | - 'args' => [], |
|
| 568 | - ]), |
|
| 569 | - ]) |
|
| 570 | - ->withMethod('POST'); |
|
| 571 | - }); |
|
| 572 | - |
|
| 573 | - $this->assertFalse(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 574 | - } |
|
| 557 | +public function testRequestWithNoPluginNoUpload() |
|
| 558 | +{ |
|
| 559 | +jaxon()->setOption('core.upload.enabled', false); |
|
| 560 | +// Send a request to the registered class |
|
| 561 | +jaxon()->di()->set(ServerRequestInterface::class, function($c) { |
|
| 562 | +return $c->g(ServerRequestCreator::class) |
|
| 563 | + ->fromGlobals() |
|
| 564 | + ->withParsedBody([ |
|
| 565 | + 'jxncall' => json_encode([ |
|
| 566 | + 'who' => 'Nobody', |
|
| 567 | + 'args' => [], |
|
| 568 | + ]), |
|
| 569 | + ]) |
|
| 570 | + ->withMethod('POST'); |
|
| 571 | +}); |
|
| 572 | + |
|
| 573 | +$this->assertFalse(jaxon()->di()->getRequestHandler()->canProcessRequest()); |
|
| 574 | +} |
|
| 575 | 575 | } |
@@ -4,9 +4,9 @@ |
||
| 4 | 4 | |
| 5 | 5 | class SampleUpload |
| 6 | 6 | {
|
| 7 | - public function myMethod() |
|
| 8 | - {
|
|
| 9 | - $xResponse = jaxon()->getResponse(); |
|
| 10 | - $xResponse->alert('This is a response!!');
|
|
| 11 | - } |
|
| 7 | +public function myMethod() |
|
| 8 | +{
|
|
| 9 | +$xResponse = jaxon()->getResponse(); |
|
| 10 | +$xResponse->alert('This is a response!!');
|
|
| 11 | +} |
|
| 12 | 12 | } |
@@ -1,19 +1,19 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | return [ |
| 4 | - 'app' => [ |
|
| 5 | - ], |
|
| 6 | - 'lib' => [ |
|
| 7 | - 'core' => [ |
|
| 8 | - 'debug' => [ |
|
| 9 | - 'on' => false, |
|
| 10 | - ], |
|
| 11 | - 'request' => [ |
|
| 12 | - 'uri' => 'ajax.php', |
|
| 13 | - ], |
|
| 14 | - 'prefix' => [ |
|
| 15 | - 'class' => 'Jxn', |
|
| 16 | - ], |
|
| 17 | - ], |
|
| 18 | - ], |
|
| 4 | +'app' => [ |
|
| 5 | +], |
|
| 6 | +'lib' => [ |
|
| 7 | +'core' => [ |
|
| 8 | +'debug' => [ |
|
| 9 | + 'on' => false, |
|
| 10 | +], |
|
| 11 | +'request' => [ |
|
| 12 | + 'uri' => 'ajax.php', |
|
| 13 | +], |
|
| 14 | +'prefix' => [ |
|
| 15 | + 'class' => 'Jxn', |
|
| 16 | +], |
|
| 17 | +], |
|
| 18 | +], |
|
| 19 | 19 | ]; |
@@ -1,17 +1,17 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | return [ |
| 4 | - 'errors' => [ |
|
| 5 | - 'upload' => [ |
|
| 6 | - 'failed' => "El archivo :name no se ha podido subir.", |
|
| 7 | - 'access' => "No se tiene permiso de escritura el directorio de subida.", |
|
| 8 | - 'type' => "Los archivos de tipo :type no están permitidos.", |
|
| 9 | - 'extension' => "Los archivos con la extensión :extension no estan permitidos.", |
|
| 10 | - 'max-size' => "No se pueden subir archivos con peso :size. Muy grande.", |
|
| 11 | - 'min-size' => "No se pueden subir archivos con peso :size. Muy pequeño.", |
|
| 12 | - 'plugin' => "No se ha encontrado el plugin upload.", |
|
| 13 | - 'request' => "No hay datos de subida en la petición.", |
|
| 14 | - 'invalid' => "Los datos de subida no son válidos.", |
|
| 15 | - ], |
|
| 16 | - ], |
|
| 4 | +'errors' => [ |
|
| 5 | +'upload' => [ |
|
| 6 | +'failed' => "El archivo :name no se ha podido subir.", |
|
| 7 | +'access' => "No se tiene permiso de escritura el directorio de subida.", |
|
| 8 | +'type' => "Los archivos de tipo :type no están permitidos.", |
|
| 9 | +'extension' => "Los archivos con la extensión :extension no estan permitidos.", |
|
| 10 | +'max-size' => "No se pueden subir archivos con peso :size. Muy grande.", |
|
| 11 | +'min-size' => "No se pueden subir archivos con peso :size. Muy pequeño.", |
|
| 12 | +'plugin' => "No se ha encontrado el plugin upload.", |
|
| 13 | +'request' => "No hay datos de subida en la petición.", |
|
| 14 | +'invalid' => "Los datos de subida no son válidos.", |
|
| 15 | +], |
|
| 16 | +], |
|
| 17 | 17 | ]; |
@@ -1,17 +1,17 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | return [ |
| 4 | - 'errors' => [ |
|
| 5 | - 'upload' => [ |
|
| 6 | - 'failed' => "The upload of file :name has failed.", |
|
| 7 | - 'access' => "Cannot get write access to upload directory.", |
|
| 8 | - 'type' => "Upload is not allowed for file of type :type.", |
|
| 9 | - 'extension' => "Upload is not allowed for file with extension :extension.", |
|
| 10 | - 'max-size' => "Upload is not allowed for file of size :size. Too big.", |
|
| 11 | - 'min-size' => "Upload is not allowed for file of size :size. Too small.", |
|
| 12 | - 'plugin' => "Upload plugin not found.", |
|
| 13 | - 'request' => "Upload data not available in the request.", |
|
| 14 | - 'invalid' => "Upload data are invalid.", |
|
| 15 | - ], |
|
| 16 | - ], |
|
| 4 | +'errors' => [ |
|
| 5 | +'upload' => [ |
|
| 6 | +'failed' => "The upload of file :name has failed.", |
|
| 7 | +'access' => "Cannot get write access to upload directory.", |
|
| 8 | +'type' => "Upload is not allowed for file of type :type.", |
|
| 9 | +'extension' => "Upload is not allowed for file with extension :extension.", |
|
| 10 | +'max-size' => "Upload is not allowed for file of size :size. Too big.", |
|
| 11 | +'min-size' => "Upload is not allowed for file of size :size. Too small.", |
|
| 12 | +'plugin' => "Upload plugin not found.", |
|
| 13 | +'request' => "Upload data not available in the request.", |
|
| 14 | +'invalid' => "Upload data are invalid.", |
|
| 15 | +], |
|
| 16 | +], |
|
| 17 | 17 | ]; |