Skip to content

Commit

Permalink
Merge pull request #31 from Vinelab/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Mulkave committed Sep 24, 2014
2 parents 4359cf7 + cc2ee59 commit 921cdfe
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 13 deletions.
5 changes: 4 additions & 1 deletion src/Vinelab/Cdn/Providers/AwsS3Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
109 changes: 97 additions & 12 deletions tests/Vinelab/Cdn/Providers/AwsS3ProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,21 @@ 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);

$this->m_validator = M::mock('Vinelab\Cdn\Validators\Contracts\ProviderValidatorInterface');
$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');
Expand All @@ -36,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,
Expand All @@ -57,28 +74,96 @@ public function setUp()
],
];

$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'
],
],
],
];

$this->p_awsS3Provider->init($configurations);

$result = $this->p_awsS3Provider->upload(new Collection([$this->m_spl_file]));

assertEquals(true, $result);
}

public function testInitializingObject()
public function testUrlGenerator()
{
$returned = $this->p_awsS3Provider->init($this->configurations);
$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);

assertInstanceOf('Vinelab\Cdn\Providers\AwsS3Provider', $returned);
$result = $this->p_awsS3Provider->urlGenerator($this->path);

assertEquals($this->cdn_url, $result);
}

public function testUploadingAssets()
public function testEmptyUrlGenerator()
{
$this->p_awsS3Provider->init($this->configurations);
$configurations = [
'default' => 'aws.s3',
'url' => 'https://s3.amazonaws.com',
'threshold' => 10,
'providers' => [
'aws' => [
's3' => [
'credentials' => [
'key' => 'XXXXXXX',
'secret' => 'YYYYYYY',
],
'buckets' => [
'' => '*',
],
'acl' => 'public-read'
],
],
],
];

$result = $this->p_awsS3Provider->upload(new Collection([$this->m_spl_file]));
$this->p_awsS3Provider->init($configurations);

assertEquals(true, $result);
$result = $this->p_awsS3Provider->urlGenerator($this->path);

assertEquals($this->path_url, $result);
}

}

0 comments on commit 921cdfe

Please sign in to comment.