Skip to content

Commit

Permalink
templates finalizados
Browse files Browse the repository at this point in the history
  • Loading branch information
emanuellimeira committed Oct 31, 2017
1 parent a8bb3de commit dc94480
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
13 changes: 8 additions & 5 deletions src/Element/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
class Product implements ElementInterface
{
private $title;
private $img_url;
private $image_url;
private $subtitle;
private $default_action;
private $buttons;

public function __construct(string $title, ? string $img_url = null, ? string $subtitle = null, Button $default_action, $buttons)
public function __construct(string $title, ? string $image_url = null, ? string $subtitle = null, Button $default_action)
{
$this->title = $title;
$this->img_url = $img_url;
$this->image_url = $image_url;
$this->subtitle = $subtitle;
$this->default_action = $default_action;

Expand All @@ -28,13 +28,16 @@ public function get() :array
if ($this->image_url !== null) {
$result['image_url'] = $this->image_url;
}
if ($this->subtitle !== null) {
$result['subtitle'] = $this->subtitle;
}
if ($this->default_action !== null) {
$default_action = $this->default_action->get();
unset($default_action['title']);
$result['default_action'] = $default_action;
}
if ($this->image_url !== null) {
$result['image_url'] = $this->image_url;
if ($this->buttons !== null) {
$result['buttons'] = $this->buttons;
}
return $result;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Element/ProductOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public function get() :array
$result['subtitle'] = $this->subtitle;
$result['price'] = $this->price;

if ($this->quantity !=== null) {
if ($this->quantity !== null) {
$result['quantity'] = $this->quantity;
}
if ($this->currency !=== null) {
if ($this->currency !== null) {
$result['currency'] = $this->currency;
}
if ($this->image_url !=== null) {
if ($this->image_url !== null) {
$result['image_url'] = $this->image_url;
}
return $result;
Expand Down
7 changes: 7 additions & 0 deletions tests/integration/TemplatesMessage/GenericTemplate.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
<?php

namespace CodeBot\TemplatesMessage;

use CodeBot\Element\Button;
use CodeBot\Element\Product;
use PHPUnit\Framework\TestCase;

class GenericTemplateTest extends TestCase
{
public function testListaComDoisProdutos()
{
$button = new Button('web_url', null, 'https://angular.io/');
$product = new Product('Produto 1', 'https://media.licdn.com/mpr/mpr/AAEAAQAAAAAAAAqfAAAAJDQwZWJiNTdkLThiYjUtNGQ2YS1iMzJjLTRiMmQ5YjZiMDNiNw.png', 'Curso de angular', $button);

$button = new Button('web_url', null, 'http://www.php.net/');
$product2 = new Product('Produto 2', 'https://upload.wikimedia.org/wikipedia/commons/thumb/2/27/PHP-logo.svg/1200px-PHP-logo.svg.png', 'Curso de PHP', $button);

$template = new GenericTemplate(1234);
$template->add($product);
$template->add($product2);
$actual = $template->message('qwe');

$expected = [
'recipient' => [
'id' => 1234
Expand Down Expand Up @@ -48,6 +54,7 @@ public function testListaComDoisProdutos()
]
]
];

$this->assertEquals($expected, $actual);
}
}
7 changes: 7 additions & 0 deletions tests/integration/TemplatesMessage/ListTemplateTest.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
<?php

namespace CodeBot\TemplatesMessage;

use CodeBot\Element\Button;
use CodeBot\Element\Product;
use PHPUnit\Framework\TestCase;

class ListTemplateTest extends TestCase
{
public function testListaComDoisProdutos()
{
$button = new Button('web_url', null, 'https://angular.io/');
$product = new Product('Produto 1', 'https://media.licdn.com/mpr/mpr/AAEAAQAAAAAAAAqfAAAAJDQwZWJiNTdkLThiYjUtNGQ2YS1iMzJjLTRiMmQ5YjZiMDNiNw.png', 'Curso de angular', $button);

$button = new Button('web_url', null, 'http://www.php.net/');
$product2 = new Product('Produto 2', 'https://upload.wikimedia.org/wikipedia/commons/thumb/2/27/PHP-logo.svg/1200px-PHP-logo.svg.png', 'Curso de PHP', $button);

$template = new ListTemplate(1234);
$template->add($product);
$template->add($product2);
$actual = $template->message('qwe');

$expected = [
'recipient' => [
'id' => 1234
Expand Down Expand Up @@ -48,6 +54,7 @@ public function testListaComDoisProdutos()
]
]
];

$this->assertEquals($expected, $actual);
}
}

0 comments on commit dc94480

Please sign in to comment.