From a99400c7bb04b88b6a88597e29aa5189fdc16568 Mon Sep 17 00:00:00 2001 From: mahmoud Date: Tue, 23 Sep 2014 16:32:58 +0300 Subject: [PATCH 1/3] fix URL when bucket is empty close #27 --- src/Vinelab/Cdn/Providers/AwsS3Provider.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Vinelab/Cdn/Providers/AwsS3Provider.php b/src/Vinelab/Cdn/Providers/AwsS3Provider.php index 3a72c06..6075a5c 100755 --- a/src/Vinelab/Cdn/Providers/AwsS3Provider.php +++ b/src/Vinelab/Cdn/Providers/AwsS3Provider.php @@ -227,7 +227,10 @@ public function urlGenerator($path) { $url = $this->cdn_helper->parseUrl($this->getUrl()); - return $url['scheme'] . '://' . $this->getBucket() . '.' . $url['host'] . '/' . $path; + $bucket = $this->getBucket(); + $bucket = ( ! empty($bucket) ) ? $bucket . '.' : ''; + + return $url['scheme'] . '://' . $bucket . $url['host'] . '/' . $path; } /** From 84eee4c73462359db50a0dd562a26c41b936e2fe Mon Sep 17 00:00:00 2001 From: mahmoud Date: Tue, 23 Sep 2014 18:19:52 +0300 Subject: [PATCH 2/3] add the tests for the commit a99400c7bb04b88b6a88597e29aa5189fdc16568 close #27 --- .../Cdn/Providers/AwsS3ProviderTest.php | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/tests/Vinelab/Cdn/Providers/AwsS3ProviderTest.php b/tests/Vinelab/Cdn/Providers/AwsS3ProviderTest.php index ace97df..35678fa 100755 --- a/tests/Vinelab/Cdn/Providers/AwsS3ProviderTest.php +++ b/tests/Vinelab/Cdn/Providers/AwsS3ProviderTest.php @@ -9,6 +9,12 @@ public function setUp() { parent::setUp(); + $this->url = 'http://www.google.com'; + $this->cdn_url = 'http://ZZZZZZZ.www.google.com/public/css/cool/style.css'; + $this->path = 'public/css/cool/style.css'; + $this->path_url = 'http://www.google.com/public/css/cool/style.css'; + $this->pased_url = parse_url($this->url); + $this->m_console = M::mock('Symfony\Component\Console\Output\ConsoleOutput'); $this->m_console->shouldReceive('writeln')->atLeast(2); @@ -16,6 +22,8 @@ public function setUp() $this->m_validator->shouldReceive('validate'); $this->m_helper = M::mock('Vinelab\Cdn\CdnHelper'); + $this->m_helper->shouldReceive('parseUrl') + ->andReturn($this->pased_url); $this->m_spl_file = M::mock('Symfony\Component\Finder\SplFileInfo'); $this->m_spl_file->shouldReceive('getPathname')->andReturn('vinelab/cdn/tests/Vinelab/Cdn/AwsS3ProviderTest.php'); @@ -36,7 +44,7 @@ public function setUp() $this->p_awsS3Provider->setBatchBuilder($this->m_batch); $this->p_awsS3Provider->shouldReceive('connect')->andReturn(true); - + $this->configurations = [ 'default' => 'aws.s3', 'url' => 'https://s3.amazonaws.com', @@ -57,6 +65,8 @@ public function setUp() ], ]; + $this->awsS3Provider_obj = $this->p_awsS3Provider->init($this->configurations); + } public function tearDown() @@ -67,18 +77,21 @@ public function tearDown() public function testInitializingObject() { - $returned = $this->p_awsS3Provider->init($this->configurations); - - assertInstanceOf('Vinelab\Cdn\Providers\AwsS3Provider', $returned); + assertInstanceOf('Vinelab\Cdn\Providers\AwsS3Provider', $this->awsS3Provider_obj); } public function testUploadingAssets() { - $this->p_awsS3Provider->init($this->configurations); - $result = $this->p_awsS3Provider->upload(new Collection([$this->m_spl_file])); assertEquals(true, $result); } + public function testUrlGenerator() + { + $result = $this->p_awsS3Provider->urlGenerator($this->path); + + assertEquals($this->cdn_url, $result); + } + } From 78db8d08e1bf62c9853983bdcb5ced8d5d4c825b Mon Sep 17 00:00:00 2001 From: mahmoud Date: Wed, 24 Sep 2014 14:04:24 +0300 Subject: [PATCH 3/3] add testEmptyUrlGenerator to test empty bucket with url generator --- .../Cdn/Providers/AwsS3ProviderTest.php | 96 ++++++++++++++++--- 1 file changed, 84 insertions(+), 12 deletions(-) diff --git a/tests/Vinelab/Cdn/Providers/AwsS3ProviderTest.php b/tests/Vinelab/Cdn/Providers/AwsS3ProviderTest.php index 35678fa..d743a49 100755 --- a/tests/Vinelab/Cdn/Providers/AwsS3ProviderTest.php +++ b/tests/Vinelab/Cdn/Providers/AwsS3ProviderTest.php @@ -44,8 +44,17 @@ public function setUp() $this->p_awsS3Provider->setBatchBuilder($this->m_batch); $this->p_awsS3Provider->shouldReceive('connect')->andReturn(true); + } - $this->configurations = [ + public function tearDown() + { + M::close(); + parent::tearDown(); + } + + public function testInitializingObject() + { + $configurations = [ 'default' => 'aws.s3', 'url' => 'https://s3.amazonaws.com', 'threshold' => 10, @@ -65,23 +74,35 @@ public function setUp() ], ]; - $this->awsS3Provider_obj = $this->p_awsS3Provider->init($this->configurations); + $awsS3Provider_obj = $this->p_awsS3Provider->init($configurations); + assertInstanceOf('Vinelab\Cdn\Providers\AwsS3Provider', $awsS3Provider_obj); } - public function tearDown() + public function testUploadingAssets() { - M::close(); - parent::tearDown(); - } + $configurations = [ + 'default' => 'aws.s3', + 'url' => 'https://s3.amazonaws.com', + 'threshold' => 10, + 'providers' => [ + 'aws' => [ + 's3' => [ + 'credentials' => [ + 'key' => 'XXXXXXX', + 'secret' => 'YYYYYYY', + ], + 'buckets' => [ + 'ZZZZZZZ' => '*', + ], + 'acl' => 'public-read' + ], + ], + ], + ]; - public function testInitializingObject() - { - assertInstanceOf('Vinelab\Cdn\Providers\AwsS3Provider', $this->awsS3Provider_obj); - } + $this->p_awsS3Provider->init($configurations); - public function testUploadingAssets() - { $result = $this->p_awsS3Provider->upload(new Collection([$this->m_spl_file])); assertEquals(true, $result); @@ -89,9 +110,60 @@ public function testUploadingAssets() public function testUrlGenerator() { + $configurations = [ + 'default' => 'aws.s3', + 'url' => 'https://s3.amazonaws.com', + 'threshold' => 10, + 'providers' => [ + 'aws' => [ + 's3' => [ + 'credentials' => [ + 'key' => 'XXXXXXX', + 'secret' => 'YYYYYYY', + ], + 'buckets' => [ + 'ZZZZZZZ' => '*', + ], + 'acl' => 'public-read' + ], + ], + ], + ]; + + $this->p_awsS3Provider->init($configurations); + $result = $this->p_awsS3Provider->urlGenerator($this->path); assertEquals($this->cdn_url, $result); } + public function testEmptyUrlGenerator() + { + $configurations = [ + 'default' => 'aws.s3', + 'url' => 'https://s3.amazonaws.com', + 'threshold' => 10, + 'providers' => [ + 'aws' => [ + 's3' => [ + 'credentials' => [ + 'key' => 'XXXXXXX', + 'secret' => 'YYYYYYY', + ], + 'buckets' => [ + '' => '*', + ], + 'acl' => 'public-read' + ], + ], + ], + ]; + + $this->p_awsS3Provider->init($configurations); + + $result = $this->p_awsS3Provider->urlGenerator($this->path); + + assertEquals($this->path_url, $result); + } + }