diff --git a/src/Urlbox.php b/src/Urlbox.php index 54ce1f9..89fcefd 100644 --- a/src/Urlbox.php +++ b/src/Urlbox.php @@ -23,10 +23,13 @@ public function generateUrl($options) $format = isset($options['format']) ? $options['format'] : 'png'; unset($options['format']); $_parts = []; - foreach ($options as $key => $value) { - if(!empty($value)){ - $encodedValue = $this->sanitizeValue($value); - $_parts[] = "$key=$encodedValue"; + foreach ($options as $key => $values) { + $values = is_array($values) ? $values : [$values]; + foreach ($values as $value) { + if(!empty($value)){ + $encodedValue = $this->sanitizeValue($value); + $_parts[] = "$key=$encodedValue"; + } } } $query_string = implode("&", $_parts); diff --git a/tests/UrlboxTest.php b/tests/UrlboxTest.php index d2a5ef9..ec92d3f 100644 --- a/tests/UrlboxTest.php +++ b/tests/UrlboxTest.php @@ -61,7 +61,7 @@ public function testKitchenSink() $options['full_page'] = true; $options['width'] = 1280; $options['height'] = '1024'; - $options['cookie'] = 'ckplns=1'; + $options['cookie'] = ['ckplns=1', 'foo=bar']; $options['user_agent'] = 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_0 like Mac OS X) AppleWebKit/602.1.32 (KHTML, like Gecko) Version/10.0 Mobile/14A5261v Safari/602.1'; $options['retina'] = 'true'; $options['thumb_width'] = '400'; @@ -82,7 +82,7 @@ public function testKitchenSink() $options['use_s3'] = 'true'; $this->assertEquals( - "https://api.urlbox.io/v1/API_KEY/9f92cbf2124ec6cf322dfe4967ce17063607966f/png?url=https%3A%2F%2Fapp_staging.example.com%2Fmisc%2Ftemplate_preview.php%3Fdsfdsfsdf%26acc%3D79%26cb%3Dba86b4c1%26regions%3D%255B%257B%2522id%2522%253A%2522dsfds%2522%252C%2522data%2522%253A%257B%2522html%2522%253A%2522It%2520works!%2522%257D%252C%2522type%2522%253A%2522html%2522%257D%255D%26state%3Dpublished%26tid%3D7%26sig%3Da642316f7e0ac9d783c30ef30a89bed3204252000319a2789851bc3de65ea216&delay=5000&selector=%23trynow&full_page=true&width=1280&height=1024&cookie=ckplns%3D1&user_agent=Mozilla%2F5.0%20(iPhone%3B%20CPU%20iPhone%20OS%2010_0%20like%20Mac%20OS%20X)%20AppleWebKit%2F602.1.32%20(KHTML%2C%20like%20Gecko)%20Version%2F10.0%20Mobile%2F14A5261v%20Safari%2F602.1&retina=true&thumb_width=400&crop_width=500&ttl=604800&force=true&wait_for=.someel&click=%23tab-specs-trigger&hover=a%5Bhref%3D%22https%3A%2F%2Fgoogle.com%22%5D&bg_color=%23bbbddd&highlight=trump%7Cinauguration&highlightbg=%2311cc77&highlightfg=green&hide_selector=.modal-backdrop%2C%20%23email-roadblock-topographic-modal&flash=true&timeout=40000&s3_path=%2Fpath%2Fto%2Fimage%20with%20space&use_s3=true", + "https://api.urlbox.io/v1/API_KEY/b891c5fdd5a613eaf42dd7868e9fac1faae2b924/png?url=https%3A%2F%2Fapp_staging.example.com%2Fmisc%2Ftemplate_preview.php%3Fdsfdsfsdf%26acc%3D79%26cb%3Dba86b4c1%26regions%3D%255B%257B%2522id%2522%253A%2522dsfds%2522%252C%2522data%2522%253A%257B%2522html%2522%253A%2522It%2520works!%2522%257D%252C%2522type%2522%253A%2522html%2522%257D%255D%26state%3Dpublished%26tid%3D7%26sig%3Da642316f7e0ac9d783c30ef30a89bed3204252000319a2789851bc3de65ea216&delay=5000&selector=%23trynow&full_page=true&width=1280&height=1024&cookie=ckplns%3D1&cookie=foo%3Dbar&user_agent=Mozilla%2F5.0%20(iPhone%3B%20CPU%20iPhone%20OS%2010_0%20like%20Mac%20OS%20X)%20AppleWebKit%2F602.1.32%20(KHTML%2C%20like%20Gecko)%20Version%2F10.0%20Mobile%2F14A5261v%20Safari%2F602.1&retina=true&thumb_width=400&crop_width=500&ttl=604800&force=true&wait_for=.someel&click=%23tab-specs-trigger&hover=a%5Bhref%3D%22https%3A%2F%2Fgoogle.com%22%5D&bg_color=%23bbbddd&highlight=trump%7Cinauguration&highlightbg=%2311cc77&highlightfg=green&hide_selector=.modal-backdrop%2C%20%23email-roadblock-topographic-modal&flash=true&timeout=40000&s3_path=%2Fpath%2Fto%2Fimage%20with%20space&use_s3=true", $urlbox->generateUrl($options) ); }