-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed image uploading. Both URL and a file #29
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,22 @@ public function __construct(string $filename) | |
{ | ||
$this->validateFile($filename); | ||
$this->imageFormat = self::ALLOWED_FILE_TYPES[exif_imagetype($filename)]; | ||
$this->imageData = iconv('UTF-8', 'UTF-8//IGNORE', utf8_encode(file_get_contents($filename))); | ||
$this->imageData = $this->byteArray($filename); | ||
} | ||
|
||
/** | ||
* Generate byte array similar to the one in C# and Java | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove unnecessary comment. It does not add any value. |
||
*/ | ||
public function byteArray(string $filename): array | ||
{ | ||
$data = file_get_contents($filename); | ||
$array = array(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please make sure the code style is inline with the other files: run |
||
foreach(str_split($data) as $char) | ||
{ | ||
array_push($array, ord($char)); | ||
} | ||
|
||
return $array; | ||
} | ||
|
||
public function getPostBodyData(): string | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -17,12 +17,25 @@ final class ImageUrlUploadTest extends TestCase | |||||
*/ | ||||||
public function productImageUpload_withURL(): void | ||||||
{ | ||||||
$imageUrl = 'https://example.com/image.png'; | ||||||
$allowedImageType = [ | ||||||
'gif' => 'GIF', | ||||||
'jpeg' => 'JPEG', | ||||||
'jpg' => 'JPEG', | ||||||
'png' => 'PNG', | ||||||
'bmp' => 'BMP', | ||||||
]; | ||||||
|
||||||
$imageUrl = 'https://example.com/image.png'; | ||||||
$imageFormat = $allowedImageType[ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please make sure the code style is inline with the other files: run |
||||||
strtolower(array_values(array_slice(explode('.', $imageUrl), -1))[0]) | ||||||
]; | ||||||
|
||||||
$productImageUpload = new ImageUrlUpload($imageUrl); | ||||||
|
||||||
self::assertInstanceOf(ImageUrlUpload::class, $productImageUpload); | ||||||
self::assertAttributeEquals($imageFormat, 'imageFormat', $productImageUpload); | ||||||
self::assertAttributeEquals($imageUrl, 'imageUrl', $productImageUpload); | ||||||
self::assertSame(['imageUrl' => $imageUrl], json_decode($productImageUpload->getPostBodyData(), true)); | ||||||
// self::assertSame(['imageUrl' => $imageUrl], json_decode($productImageUpload->getPostBodyData(), true)); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove dead code
Suggested change
|
||||||
self::assertSame(['imageFormat' => $imageFormat, 'imageData' => $imageData], json_decode($productImageUpload->getPostBodyData(), true)); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should fix this test
Suggested change
|
||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add
ext-exif
to composer.json as a required extension? i've missed this.