-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from LemonMind/tests
Tests
- Loading branch information
Showing
8 changed files
with
546 additions
and
1 deletion.
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
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,10 @@ | ||
<?php | ||
|
||
namespace LemonMind\MessageBundle\Tests; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
class ChatterControllerTest extends TestCase | ||
{ | ||
|
||
} |
103 changes: 103 additions & 0 deletions
103
src/MessageBundle/Tests/Model/DiscordMessageModelTest.php
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,103 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LemonMind\MessageBundle\Tests; | ||
|
||
use LemonMind\MessageBundle\Model\DiscordMessageModel; | ||
use Pimcore\Bundle\EcommerceFrameworkBundle\Model\AbstractProduct; | ||
use Pimcore\Model\DataObject\AbstractObject; | ||
use Pimcore\Test\KernelTestCase; | ||
|
||
class DiscordMessageModelTest extends KernelTestCase | ||
{ | ||
/** | ||
* @var AbstractObject | ||
*/ | ||
private $testProduct; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->testProduct = new class() extends AbstractProduct { | ||
public function getId(): int | ||
{ | ||
return 1; | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return 'name'; | ||
} | ||
|
||
public function getPrice(): string | ||
{ | ||
return '20'; | ||
} | ||
}; | ||
} | ||
|
||
public function testTitle(): void | ||
{ | ||
$discordMessage = new DiscordMessageModel($this->testProduct, [], ''); | ||
$options = $discordMessage->create()->getOptions(); | ||
|
||
if (!is_null($options)) { | ||
$options = $options->toArray(); | ||
} else { | ||
throw new \Exception('options is null'); | ||
} | ||
|
||
$this->assertEquals('Object id 1', $options['embeds'][0]['title']); | ||
} | ||
|
||
/** | ||
* @test | ||
* @dataProvider dataProvider | ||
*/ | ||
public function testEmbedFields(array $fields, string $additionalInfo, string $expected): void | ||
{ | ||
$discordMessage = new DiscordMessageModel($this->testProduct, $fields, $additionalInfo); | ||
|
||
if (!$fields) { | ||
$this->assertEquals($expected, $additionalInfo); | ||
|
||
return; | ||
} | ||
|
||
$options = $discordMessage->create()->getOptions(); | ||
|
||
if (!is_null($options)) { | ||
$options = $options->toArray(); | ||
} else { | ||
throw new \Exception('options is null'); | ||
} | ||
|
||
$actualFields = $options['embeds'][0]['fields']; | ||
$actual = ''; | ||
|
||
foreach ($actualFields as $field) { | ||
$actual .= $field['value'] . ';'; | ||
} | ||
|
||
$actual = rtrim($actual, ';'); | ||
|
||
$this->assertEquals($expected, $actual); | ||
} | ||
|
||
public function dataProvider(): array | ||
{ | ||
return [ | ||
[[], '', ''], | ||
[[], 'lorem', 'lorem'], | ||
[['name'], '', 'name'], | ||
[['price'], '', '20'], | ||
[['name'], 'lorem', 'name;lorem'], | ||
[['name', 'price'], 'lorem', 'name;20;lorem'], | ||
]; | ||
} | ||
|
||
// protected function tearDown(): void | ||
// { | ||
// $this->testProduct = null; | ||
// } | ||
} |
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,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LemonMind\MessageBundle\Tests\Model; | ||
|
||
use App\Model\Product\AbstractProduct; | ||
use LemonMind\MessageBundle\Model\EmailMessageModel; | ||
use Pimcore\Test\KernelTestCase; | ||
|
||
class EmailMessageModelTest extends KernelTestCase | ||
{ | ||
private AbstractProduct $testProduct; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->testProduct = new class() extends AbstractProduct { | ||
public function getId(): int | ||
{ | ||
return 1; | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return 'name'; | ||
} | ||
|
||
public function getPrice(): string | ||
{ | ||
return '20'; | ||
} | ||
}; | ||
} | ||
|
||
/** | ||
* @test | ||
* @dataProvider dataProvider | ||
*/ | ||
public function testCreate(array $fields, string $additionalInfo, string $expected): void | ||
{ | ||
$emailMessage = new EmailMessageModel($this->testProduct, $fields, $additionalInfo); | ||
$this->assertEquals($expected, $emailMessage->create()); | ||
} | ||
|
||
public function dataProvider(): array | ||
{ | ||
return [ | ||
[[], '', '<table></table>'], | ||
[[], 'lorem', '<table></table><br>lorem'], | ||
[['name'], '', '<table><tr><td>name</td><td>name</td></tr></table>'], | ||
[['price'], '', '<table><tr><td>price</td><td>20</td></tr></table>'], | ||
[['name', 'price'], '', '<table><tr><td>name</td><td>name</td></tr><tr><td>price</td><td>20</td></tr></table>'], | ||
[['name', 'price'], 'lorem', '<table><tr><td>name</td><td>name</td></tr><tr><td>price</td><td>20</td></tr></table><br>lorem'], | ||
]; | ||
} | ||
} |
130 changes: 130 additions & 0 deletions
130
src/MessageBundle/Tests/Model/GoogleChatMessageModelTest.php
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,130 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LemonMind\MessageBundle\Tests; | ||
|
||
use LemonMind\MessageBundle\Model\GoogleChatMessageModel; | ||
use Pimcore\Bundle\EcommerceFrameworkBundle\Model\AbstractProduct; | ||
use Pimcore\Test\KernelTestCase; | ||
|
||
class GoogleChatMessageModelTest extends KernelTestCase | ||
{ | ||
/** | ||
* @var AbstractProduct | ||
*/ | ||
private $testProduct; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->testProduct = new class() extends AbstractProduct { | ||
public function getId(): int | ||
{ | ||
return 1; | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return 'name'; | ||
} | ||
|
||
public function getPrice(): string | ||
{ | ||
return '20'; | ||
} | ||
}; | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function testHeader(): void | ||
{ | ||
$googleMessage = new GoogleChatMessageModel($this->testProduct, [], ''); | ||
$options = $googleMessage->create()->getOptions(); | ||
|
||
if (!is_null($options)) { | ||
$options = $options->toArray(); | ||
} else { | ||
throw new \Exception('options is null'); | ||
} | ||
|
||
$header = $options['cards'][0]['header']; | ||
$this->assertEquals('Object id 1', $header['title']); | ||
} | ||
|
||
/** | ||
* @test | ||
* @dataProvider dataProvider | ||
*/ | ||
public function testAdditionalInfoWidget(array $fields, string $additionalInfo, array $expected): void | ||
{ | ||
$googleMessage = new GoogleChatMessageModel($this->testProduct, [], $additionalInfo); | ||
$options = $googleMessage->create()->getOptions(); | ||
|
||
if (!is_null($options)) { | ||
$options = $options->toArray(); | ||
} else { | ||
throw new \Exception('options is null'); | ||
} | ||
|
||
if ('' === $additionalInfo) { | ||
$this->assertLessThan(2, count($options['cards'][0]['sections'])); | ||
|
||
return; | ||
} | ||
|
||
$additionalInfoWidget = $options['cards'][0]['sections'][1]['widgets']; | ||
|
||
$expectedWidget = [ | ||
['textParagraph' => ['text' => 'Additional information']], | ||
['textParagraph' => ['text' => $additionalInfo]], | ||
]; | ||
|
||
$this->assertEquals($expectedWidget, $additionalInfoWidget); | ||
} | ||
|
||
/** | ||
* @test | ||
* @dataProvider dataProvider | ||
*/ | ||
public function testDataWidget(array $fields, string $additionalInfo, array $expected): void | ||
{ | ||
$googleMessage = new GoogleChatMessageModel($this->testProduct, $fields, $additionalInfo); | ||
$options = $googleMessage->create()->getOptions(); | ||
|
||
if (!is_null($options)) { | ||
$options = $options->toArray(); | ||
} else { | ||
throw new \Exception('options is null'); | ||
} | ||
|
||
$dataWidget = $options['cards'][0]['sections'][0]['widgets']; | ||
|
||
if (!$fields) { | ||
$this->assertEquals(0, count($dataWidget)); | ||
} | ||
|
||
foreach ($fields as $field) { | ||
$needle = [ | ||
'topLabel' => $field, | ||
'content' => $expected[$field], | ||
]; | ||
|
||
$r = array_search($needle, array_column($dataWidget, 'keyValue'), true); | ||
$this->assertNotFalse($r); | ||
} | ||
} | ||
|
||
public function dataProvider(): array | ||
{ | ||
return [ | ||
[[], '', []], | ||
[[], 'lorem', []], | ||
[['name'], '', ['name' => 'name']], | ||
[['price'], '', ['price' => '20']], | ||
[['name'], 'lorem', ['name' => 'name']], | ||
[['name', 'price'], 'lorem', ['name' => 'name', 'price' => '20']], | ||
]; | ||
} | ||
} |
Oops, something went wrong.