-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial feature set with bulletins groups and media
- Loading branch information
1 parent
ccd0979
commit f9ec20d
Showing
43 changed files
with
1,558 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
/vendor | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This package is under development and will evolve. Documentation is soon to come so bear with us. Feel free to reach out to me directly in the meantime if you want to use the package and have questions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
use TRMS\Carousel\Server\API; | ||
use TRMS\Carousel\Exceptions\CarouselAPIException; | ||
use TRMS\Carousel\Models\Bulletin; | ||
|
||
use CarouselTests\MockData\MockResponder; | ||
|
||
use GuzzleHttp\Handler\MockHandler; | ||
use GuzzleHttp\HandlerStack; | ||
use GuzzleHttp\Psr7\Response; | ||
use GuzzleHttp\Psr7\Request; | ||
use GuzzleHttp\Exception\RequestException; | ||
|
||
class DeleteModelTest extends PHPUnit_Framework_TestCase | ||
{ | ||
function test_you_can_delete_a_bulletin() | ||
{ | ||
$mock = new MockHandler([ | ||
new Response(200,[],json_encode(['IsDeleted'=>true])) | ||
]); | ||
$handler = HandlerStack::create($mock); | ||
|
||
$mockResponder = new MockResponder; | ||
$bulletinProps = json_decode($mockResponder->bulletin(),true); | ||
$bulletin = new Bulletin($bulletinProps); | ||
|
||
$server = new API(); | ||
$server | ||
->addMockHandler($handler) | ||
->connect('server','username','password') | ||
->delete($bulletin); | ||
|
||
$this->assertTrue($bulletin->IsDeleted); | ||
$this->assertEquals("server/carouselapi/v1/bulletins/$bulletin->id", (string) $mock->getLastRequest()->getUri()); | ||
$this->assertEquals('DELETE', (string) $mock->getLastRequest()->getMethod()); | ||
} | ||
|
||
function test_failed_deletions_throw_an_exception() | ||
{ | ||
$mock = new MockHandler([ | ||
new Response(500), | ||
new Response(404), | ||
new Response(401) | ||
]); | ||
$handler = HandlerStack::create($mock); | ||
|
||
$mockResponder = new MockResponder; | ||
$bulletinProps = json_decode($mockResponder->bulletin(),true); | ||
$bulletin = new Bulletin($bulletinProps); | ||
|
||
$server = new API(); | ||
$server | ||
->addMockHandler($handler) | ||
->connect('server','username','password'); | ||
|
||
|
||
try{ | ||
$server->delete($bulletin); | ||
} catch (CarouselAPIException $e){ | ||
$this->assertTrue(true,"500 exception caught"); | ||
} | ||
|
||
try{ | ||
$server->delete($bulletin); | ||
} catch (CarouselAPIException $e){ | ||
$this->assertTrue(true,"404 exception caught"); | ||
} | ||
|
||
try{ | ||
$server->delete($bulletin); | ||
} catch (CarouselAPIException $e){ | ||
$this->assertTrue(true,"401 exception caught"); | ||
return; | ||
} | ||
|
||
$this->fail('the exceptions did not throw'); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php | ||
|
||
use TRMS\Carousel\Server\API; | ||
use TRMS\Carousel\Requests\FileUploadRequest; | ||
use TRMS\Carousel\Models\Bulletin; | ||
|
||
use TRMS\Carousel\Exceptions\CarouselAPIException; | ||
|
||
use CarouselTests\MockData\MockResponder; | ||
|
||
use GuzzleHttp\Handler\MockHandler; | ||
use GuzzleHttp\HandlerStack; | ||
use GuzzleHttp\Psr7\Response; | ||
use GuzzleHttp\Psr7\Request; | ||
use GuzzleHttp\Exception\RequestException; | ||
|
||
class TestCase extends PHPUnit_Framework_TestCase | ||
{ | ||
function test_you_can_upload_a_bulletin_from_a_file() | ||
{ | ||
$mockResponder = new MockResponder; | ||
$mock = new MockHandler([ | ||
new Response(200,[],json_encode([ | ||
'Bulletins'=>[['id'=>'1']] | ||
])), | ||
]); | ||
|
||
$handler = HandlerStack::create($mock); | ||
|
||
$filepath = 'Tests/MockData/mock_file.png'; | ||
$fileUpload = new FileUploadRequest(Bulletin::class,['ZoneID'=>1]); | ||
$fileUpload->addFile($filepath); | ||
|
||
$server = new API(); | ||
$server | ||
->addMockHandler($handler) | ||
->connect('server','username','password'); | ||
|
||
$bulletins = $server->upload($fileUpload); | ||
|
||
$this->assertInstanceOf(Bulletin::class, $bulletins->first()); | ||
$this->assertEquals($bulletins->first()->id, '1'); | ||
$this->assertEquals('server/carouselapi/v1/bulletins', (string) $mock->getLastRequest()->getUri()); | ||
$this->assertEquals('POST', (string) $mock->getLastRequest()->getMethod()); | ||
$this->assertGreaterThan(150000,$mock->getLastRequest()->getBody()->stream->getSize(), 'the file is big'); | ||
} | ||
|
||
function test_you_can_upload_multiple_bulletins_at_once() | ||
{ | ||
$mockResponder = new MockResponder; | ||
$mock = new MockHandler([ | ||
new Response(200,[],json_encode([ | ||
'Bulletins'=>[['id'=>'1']] | ||
])), | ||
new Response(200,[],json_encode([ | ||
'Bulletins'=>[['id'=>'2']] | ||
])), | ||
]); | ||
|
||
$handler = HandlerStack::create($mock); | ||
|
||
$filepath = 'Tests/MockData/mock_file.png'; | ||
$fileUpload = new FileUploadRequest(Bulletin::class,['ZoneID'=>1]); | ||
$fileUpload->addFile($filepath)->addFile($filepath); | ||
|
||
$server = new API(); | ||
$server | ||
->addMockHandler($handler) | ||
->connect('server','username','password'); | ||
|
||
$bulletins = $server->upload($fileUpload); | ||
|
||
$this->assertInstanceOf(Bulletin::class, $bulletins[0]); | ||
$this->assertInstanceOf(Bulletin::class, $bulletins[1]); | ||
$this->assertEquals($bulletins[0]->id, '1'); | ||
$this->assertEquals($bulletins[1]->id, '2'); | ||
} | ||
|
||
function test_failed_uploads_will_return_an_exception() | ||
{ | ||
$mockResponder = new MockResponder; | ||
$mock = new MockHandler([ | ||
new Response(500,[],json_encode(['Message'=>'File Upload Failed'])), | ||
]); | ||
|
||
$handler = HandlerStack::create($mock); | ||
|
||
$filepath = 'Tests/MockData/mock_file.png'; | ||
$fileUpload = new FileUploadRequest(Bulletin::class,['ZoneID'=>1]); | ||
$fileUpload->addFile($filepath); | ||
|
||
$server = new API(); | ||
$server | ||
->addMockHandler($handler) | ||
->connect('server','username','password'); | ||
|
||
$bulletins = $server->upload($fileUpload); | ||
|
||
$this->assertInstanceOf('TRMS\Carousel\Exceptions\CarouselAPIException', $bulletins->first()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
use TRMS\Carousel\Models\Bulletin; | ||
use TRMS\Carousel\Models\Media; | ||
use TRMS\Carousel\Models\Template; | ||
|
||
use TRMS\Carousel\Server\API; | ||
|
||
use GuzzleHttp\Handler\MockHandler; | ||
use GuzzleHttp\HandlerStack; | ||
use GuzzleHttp\Psr7\Response; | ||
use GuzzleHttp\Psr7\Request; | ||
|
||
class HasBackgroundTraitTest extends PHPUnit_Framework_TestCase | ||
{ | ||
function test_you_can_add_a_background_to_a_bulletin() | ||
{ | ||
$bulletin = new Bulletin(); | ||
$background = new Media(['id'=>'1']); | ||
$bulletin->setBackground($background); | ||
|
||
$this->assertEquals($background->id, $bulletin->BackgroundID); | ||
} | ||
|
||
function test_you_can_add_a_background_to_a_template() | ||
{ | ||
$template = new Template(); | ||
$background = new Media(['id'=>'1']); | ||
$template->setBackground($background); | ||
|
||
$this->assertEquals($background->id, $template->BackgroundID); | ||
} | ||
|
||
function test_if_the_background_object_has_not_been_resolved_an_api_request_will_be_made() | ||
{ | ||
$mock = new MockHandler([ | ||
new Response(200,[],json_encode(['id'=>'12'])), | ||
]); | ||
$handler = HandlerStack::create($mock); | ||
|
||
$api = new API(); | ||
$api->addMockHandler($handler); | ||
|
||
$bulletin = new Bulletin(['BackgroundID'=>'12']); | ||
$bulletin->setApi($api); | ||
$background = $bulletin->getBackground(); | ||
|
||
$this->assertInstanceOf(Media::class, $background); | ||
$this->assertEquals('12',$background->id); | ||
} | ||
} |
Oops, something went wrong.