Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"require": {
"php": ">=7.0",
"botman/botman": "~2.0",
"botman/driver-facebook": "^1.0",
"guzzlehttp/guzzle": "~6.0",
"illuminate/support": "~5.5.0",
"illuminate/contracts": "~5.5.0",
Expand Down
19 changes: 12 additions & 7 deletions src/Testing/BotManTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,10 @@ public function assertReplyNothing()

/**
* @param null $text
* @param null $closure
* @return $this
*/
public function assertQuestion($text = null)
public function assertQuestion($text = null, $closure = null)
{
/** @var Question $question */
$question = $this->getReply();
Expand All @@ -332,22 +333,26 @@ public function assertQuestion($text = null)
PHPUnit::assertSame($text, $question->getText());
}

if (! is_null($closure)) {
call_user_func($closure, new QuestionTester($question));
}

return $this;
}

/**
* @param string $template
* @param bool $strict
* @param null $closure
* @return $this
*/
public function assertTemplate($template, $strict = false)
public function assertTemplate($template, $closure = null)
{
$message = $this->getReply();

if ($strict) {
PHPUnit::assertEquals($template, $message);
} else {
PHPUnit::assertInstanceOf($template, $message);
PHPUnit::assertInstanceOf($template, $message);

if (is_callable($closure)) {
call_user_func($closure, new TemplateTester($message));
}

return $this;
Expand Down
102 changes: 102 additions & 0 deletions src/Testing/ButtonTester.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php

namespace BotMan\Studio\Testing;

use PHPUnit\Framework\Assert as PHPUnit;

/**
* Class ButtonTester.
*/
class ButtonTester
{
protected $button;

public function __construct(array $button)
{
$this->button = $button;
}

public function assertText($text)
{
PHPUnit::assertSame($text, $this->button['text']);

return $this;
}

public function assertTextIsNot($text)
{
PHPUnit::assertNotSame($text, $this->button['text']);

return $this;
}

public function assertTextIn(array $haystack)
{
PHPUnit::assertTrue(in_array($this->button['text'], $haystack));

return $this;
}

public function assertTextNotIn(array $haystack)
{
PHPUnit::assertFalse(in_array($this->button['text'], $haystack));

return $this;
}

public function assertName($name)
{
PHPUnit::assertSame($name, $this->button['name']);

return $this;
}

public function assertNameIsNot($name)
{
PHPUnit::assertNotSame($name, $this->button['name']);

return $this;
}

public function assertValue($value)
{
PHPUnit::assertSame($value, $this->button['value']);

return $this;
}

public function assertValueIsNot($value)
{
PHPUnit::assertNotSame($value, $this->button['value']);

return $this;
}

public function assertImage($image_url)
{
PHPUnit::assertSame($image_url, $this->button['image_url']);

return $this;
}

public function assertImageIsNot($image_url)
{
PHPUnit::assertNotSame($image_url, $this->button['image_url']);

return $this;
}

public function assertAdditional($additional)
{
PHPUnit::assertEqual($additional, $this->button['additional']);

return $this;
}

public function assertAdditionalIsNot($additional)
{
PHPUnit::assertNotEqual($additional, $this->button['additional']);

return $this;
}
}
119 changes: 119 additions & 0 deletions src/Testing/ElementButtonTester.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?php

namespace BotMan\Studio\Testing;

use PHPUnit\Framework\Assert as PHPUnit;

/**
* Class ElementButtonTester.
*/
class ElementButtonTester
{
protected $button;

public function __construct(array $button)
{
$this->button = $button;

return $this;
}

public function assertTitle($title)
{
PHPUnit::assertSame($title, $this->button['title']);

return $this;
}

public function assertTitleIsNot($title)
{
PHPUnit::assertNotSame($title, $this->button['title']);

return $this;
}

public function assertTitleIn(array $haystack)
{
PHPUnit::assertTrue(in_array($this->button['title'], $haystack));

return $this;
}

public function assertTitleNotIn(array $haystack)
{
PHPUnit::assertFalse(in_array($this->button['title'], $haystack));

return $this;
}

public function assertType($type)
{
PHPUnit::assertSame($type, $this->button['type']);

return $this;
}

public function assertTypeIsNot($type)
{
PHPUnit::assertNotSame($type, $this->button['type']);

return $this;
}

public function assertUrl($url)
{
PHPUnit::assertSame($url, $this->button['url']);

return $this;
}

public function assertUrlIsNot($url)
{
PHPUnit::assertNotSame($url, $this->button['url']);

return $this;
}

public function assertPayload($payload)
{
PHPUnit::assertSame($payload, $this->button['payload']);

return $this;
}

public function assertPayloadIsNot($payload)
{
PHPUnit::assertNotSame($payload, $this->button['payload']);

return $this;
}

public function assertHeightRatio($webview_height_ratio)
{
PHPUnit::assertSame($webview_height_ratio, $this->button['webview_height_ratio']);

return $this;
}

public function assertMessengerExtension($messenger_extensions = true)
{
PHPUnit::assertSame($messenger_extensions, $this->button['messenger_extensions']);

return $this;
}

public function assertFallbackUrl($fallback_url)
{
PHPUnit::assertSame($fallback_url, $this->button['fallback_url']);

return $this;
}

public function assertShareContents($closure)
{
$share_content = $this->button['share_contents'];
call_user_func($closure, new TemplateTester($share_content));

return $this;
}
}
115 changes: 115 additions & 0 deletions src/Testing/ElementTester.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?php

namespace BotMan\Studio\Testing;

use PHPUnit\Framework\Assert as PHPUnit;

/**
* Class ElementTester.
*/
class ElementTester
{
protected $element;

public function __construct(array $element)
{
$this->element = $element;
}

public function assertTitle($title)
{
PHPUnit::assertSame($title, $this->element['title']);

return $this;
}

public function assertTitleIsNot($title)
{
PHPUnit::assertNotSame($title, $this->element['title']);

return $this;
}

public function assertTitleIn(array $haystack)
{
PHPUnit::assertTrue(in_array($this->element['title'], $haystack));

return $this;
}

public function assertTitleNotIn(array $haystack)
{
PHPUnit::assertFalse(in_array($this->element['title'], $haystack));

return $this;
}

public function assertSubtitle($subtitle)
{
PHPUnit::assertSame($subtitle, $this->element['subtitle']);

return $this;
}

public function assertSubtitleIsNot($subtitle)
{
PHPUnit::assertNotSame($subtitle, $this->element['subtitle']);

return $this;
}

public function assertSubtitleIn(array $haystack)
{
PHPUnit::assertTrue(in_array($this->element['subtitle'], $haystack));

return $this;
}

public function assertSubtitleNotIn(array $haystack)
{
PHPUnit::assertFalse(in_array($this->element['subtitle'], $haystack));

return $this;
}

public function assertImage($image_url)
{
PHPUnit::assertSame($image_url, $this->element['image_url']);

return $this;
}

public function assertImageIsNot($image_url)
{
PHPUnit::assertNotSame($image_url, $this->element['image_url']);

return $this;
}

public function assertButtonCount($count)
{
PHPUnit::assertCount($count, $this->element['buttons']);

return $this;
}

public function assertButton($index, $closure)
{
$button = $this->element['buttons'][$index];
call_user_func($closure, new ElementButtonTester($button));

return $this;
}

public function assertFirstButton($closure)
{
return $this->assertButton(0, $closure);
}

public function assertLastButton($closure)
{
$last_index = count($this->element['buttons']) - 1;

return $this->assertButton($last_index, $closure);
}
}
Loading