2021-12-19 15:57:24 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Tests\Client;
|
|
|
|
|
|
|
|
|
|
use DOMDocument;
|
|
|
|
|
use Illuminate\Support\Facades\File;
|
|
|
|
|
use Illuminate\Support\Str;
|
2023-09-06 17:24:53 +02:00
|
|
|
use LDC\LDCCRM\CrmApiV4;
|
2021-12-19 15:57:24 +01:00
|
|
|
use LDC\LDCCRM\Enums\ArcadiaOrderType;
|
|
|
|
|
use LDC\LDCCRM\Models\ArcadiaMailDefault;
|
|
|
|
|
use LDC\LDCCRM\Models\ArcadiaMailGame;
|
|
|
|
|
|
2023-09-06 17:24:53 +02:00
|
|
|
class CrmClientArcadiaTest extends CrmClientTester
|
2021-12-19 15:57:24 +01:00
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Send arcadia order default test.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2025-08-28 11:07:31 +02:00
|
|
|
public function testArcadiaSendOrderDefault(): void
|
2021-12-19 15:57:24 +01:00
|
|
|
{
|
2023-09-06 17:24:53 +02:00
|
|
|
$api = new CrmApiV4();
|
2021-12-19 15:57:24 +01:00
|
|
|
$customer = $api->getCustomerOrNew(static::$info->hashcode);
|
|
|
|
|
|
|
|
|
|
$arcadiaOrderMail = new ArcadiaMailDefault([
|
2023-09-04 13:08:34 +02:00
|
|
|
'email' => static::$customer->email,
|
|
|
|
|
'firstname' => static::$info->firstname,
|
|
|
|
|
'lastname' => static::$info->lastname,
|
|
|
|
|
'phone' => static::$info->phone,
|
|
|
|
|
'address' => static::$info->address,
|
|
|
|
|
'address2' => static::$info->address2,
|
|
|
|
|
'city' => static::$info->city,
|
|
|
|
|
'postcode' => static::$info->postcode,
|
|
|
|
|
'operation' => 16,
|
|
|
|
|
'label_type_support' => 'Send Departaimants',
|
|
|
|
|
'order_date' => \date('Y/m/d H:i:s'),
|
2023-09-06 17:24:53 +02:00
|
|
|
'state_order' => ArcadiaOrderType::cb->value(),
|
2023-09-04 13:08:34 +02:00
|
|
|
'support_code' => 1,
|
|
|
|
|
'label_type_support' => 'Fond carte Aimanté',
|
|
|
|
|
'order_num' => 23,
|
2021-12-19 15:57:24 +01:00
|
|
|
'package_unit_weight' => 0,
|
|
|
|
|
]);
|
|
|
|
|
$this->assertTrue($arcadiaOrderMail->send($customer));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-08-28 11:07:31 +02:00
|
|
|
* Test arcadia default mail can serialize to json.
|
2021-12-19 15:57:24 +01:00
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2025-08-28 11:07:31 +02:00
|
|
|
public function testArcadiaOrderDefaultJson(): void
|
2021-12-19 15:57:24 +01:00
|
|
|
{
|
|
|
|
|
$data = [
|
2023-09-04 13:08:34 +02:00
|
|
|
'email' => static::$customer->email,
|
|
|
|
|
'firstname' => static::$info->firstname,
|
|
|
|
|
'lastname' => static::$info->lastname,
|
|
|
|
|
'phone' => static::$info->phone,
|
|
|
|
|
'address' => static::$info->address,
|
|
|
|
|
'address2' => static::$info->address2,
|
|
|
|
|
'city' => static::$info->city,
|
|
|
|
|
'postcode' => static::$info->postcode,
|
|
|
|
|
'operation' => 16,
|
|
|
|
|
'label_type_support' => 'Send Departaimants',
|
|
|
|
|
'order_date' => \date('Y/m/d H:i:s'),
|
2023-09-06 17:24:53 +02:00
|
|
|
'state_order' => ArcadiaOrderType::cb->value(),
|
2023-09-04 13:08:34 +02:00
|
|
|
'support_code' => 1,
|
|
|
|
|
'label_type_support' => 'Fond carte Aimanté',
|
|
|
|
|
'order_num' => 23,
|
2021-12-19 15:57:24 +01:00
|
|
|
'package_unit_weight' => 0,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$arcadiaOrderMail = new ArcadiaMailDefault($data);
|
|
|
|
|
|
|
|
|
|
/** Mutator and accessor tests */
|
|
|
|
|
foreach ($data as $propName => $value) {
|
|
|
|
|
$arcadiaOrderMail->{$propName} = $value;
|
|
|
|
|
$arcadiaOrderMail->{$propName} = $arcadiaOrderMail->{$propName};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$jsonDecoded = \json_decode(\json_encode($arcadiaOrderMail), true);
|
|
|
|
|
$this->assertIsArray($jsonDecoded);
|
|
|
|
|
foreach ($data as $key => $value) {
|
|
|
|
|
if (isset($jsonDecoded['deliver'][$key])) {
|
|
|
|
|
$this->assertArrayHasKey($key, $jsonDecoded['deliver']);
|
|
|
|
|
$this->assertEquals($value, $jsonDecoded['deliver'][$key]);
|
|
|
|
|
} else {
|
|
|
|
|
$this->assertArrayHasKey($key, $jsonDecoded);
|
|
|
|
|
$this->assertEquals($value, $jsonDecoded[$key]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Send arcadia order default game.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2025-08-28 11:07:31 +02:00
|
|
|
public function testArcadiaSendOrderGame(): void
|
2021-12-19 15:57:24 +01:00
|
|
|
{
|
2023-09-06 17:24:53 +02:00
|
|
|
$api = new CrmApiV4();
|
2021-12-19 15:57:24 +01:00
|
|
|
$customer = $api->getCustomerOrNew(static::$info->hashcode);
|
|
|
|
|
$arcadiaOrderMail = new ArcadiaMailGame([
|
2023-09-04 13:08:34 +02:00
|
|
|
'email' => static::$customer->email,
|
|
|
|
|
'firstname' => static::$info->firstname,
|
|
|
|
|
'lastname' => static::$info->lastname,
|
|
|
|
|
'phone' => static::$info->phone,
|
|
|
|
|
'address' => static::$info->address,
|
|
|
|
|
'address2' => static::$info->address2,
|
|
|
|
|
'city' => static::$info->city,
|
|
|
|
|
'postcode' => static::$info->postcode,
|
|
|
|
|
'operation' => 16,
|
|
|
|
|
'order_date' => date('Y/m/d H:i:s'),
|
|
|
|
|
'support_code' => 32,
|
2021-12-19 15:57:24 +01:00
|
|
|
'label_type_support' => 'Jeux Reghalal',
|
2025-08-28 11:07:31 +02:00
|
|
|
'code_unique' => \strtoupper(\str_replace('-', '', (string) Str::uuid())),
|
2023-09-04 13:08:34 +02:00
|
|
|
'code_on_pack' => '12365214587562'
|
2021-12-19 15:57:24 +01:00
|
|
|
]);
|
|
|
|
|
$this->assertTrue($arcadiaOrderMail->send($customer));
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-17 15:13:25 +01:00
|
|
|
/**
|
|
|
|
|
* Send arcadia order default game (empty string does not convert to null).
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2025-08-28 11:07:31 +02:00
|
|
|
public function testArcadiaSendOrderGameNullString(): void
|
2022-03-17 15:13:25 +01:00
|
|
|
{
|
2023-09-06 17:24:53 +02:00
|
|
|
$api = new CrmApiV4();
|
2022-03-17 15:13:25 +01:00
|
|
|
$customer = $api->getCustomerOrNew(static::$info->hashcode);
|
|
|
|
|
$arcadiaOrderMail = new ArcadiaMailGame([
|
2023-09-04 13:08:34 +02:00
|
|
|
'email' => 'toto@gmail.com',
|
|
|
|
|
'firstname' => 'Jean',
|
|
|
|
|
'lastname' => 'Pouet',
|
|
|
|
|
'phone' => '0678142536',
|
|
|
|
|
'address' => '30 rue des totots',
|
|
|
|
|
'address2' => null,
|
|
|
|
|
'city' => 'Le Mans',
|
|
|
|
|
'postcode' => '72000',
|
|
|
|
|
'operation' => 12,
|
|
|
|
|
'order_date' => '2022/03/17 11:24:55',
|
|
|
|
|
'support_code' => 16,
|
2022-03-17 15:13:25 +01:00
|
|
|
'label_type_support' => 'Gain du lot : Lot ',
|
2023-09-04 13:08:34 +02:00
|
|
|
'code_unique' => '11N311A1',
|
|
|
|
|
'code_on_pack' => '12345678'
|
2022-03-17 15:13:25 +01:00
|
|
|
]);
|
|
|
|
|
$this->assertTrue($arcadiaOrderMail->send($customer));
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-19 15:57:24 +01:00
|
|
|
/**
|
2025-08-28 11:07:31 +02:00
|
|
|
* Test arcadia game mail can serialize to json.
|
2021-12-19 15:57:24 +01:00
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2025-08-28 11:07:31 +02:00
|
|
|
public function testArcadiaOrderGameJson(): void
|
2021-12-19 15:57:24 +01:00
|
|
|
{
|
|
|
|
|
$data = [
|
2023-09-04 13:08:34 +02:00
|
|
|
'email' => static::$customer->email,
|
|
|
|
|
'firstname' => static::$info->firstname,
|
|
|
|
|
'lastname' => static::$info->lastname,
|
|
|
|
|
'phone' => static::$info->phone,
|
|
|
|
|
'address' => static::$info->address,
|
|
|
|
|
'address2' => static::$info->address2,
|
|
|
|
|
'city' => static::$info->city,
|
|
|
|
|
'postcode' => static::$info->postcode,
|
|
|
|
|
'operation' => 16,
|
|
|
|
|
'order_date' => date('Y/m/d H:i:s'),
|
|
|
|
|
'support_code' => 32,
|
2021-12-19 15:57:24 +01:00
|
|
|
'label_type_support' => 'Jeux Reghalal',
|
2025-08-28 11:07:31 +02:00
|
|
|
'code_unique' => \strtoupper(\str_replace('-', '', (string) Str::uuid())),
|
2023-09-04 13:08:34 +02:00
|
|
|
'code_on_pack' => '12365214587562'
|
2021-12-19 15:57:24 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$arcadiaGameMail = new ArcadiaMailGame($data);
|
|
|
|
|
|
|
|
|
|
/** Mutator and accessor tests */
|
|
|
|
|
foreach ($data as $propName => $value) {
|
|
|
|
|
$arcadiaGameMail->{$propName} = $value;
|
|
|
|
|
$arcadiaGameMail->{$propName} = $arcadiaGameMail->{$propName};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$jsonDecoded = \json_decode(\json_encode($arcadiaGameMail), true);
|
|
|
|
|
$this->assertIsArray($jsonDecoded);
|
|
|
|
|
foreach ($data as $key => $value) {
|
|
|
|
|
if (isset($jsonDecoded['deliver'][$key])) {
|
|
|
|
|
$this->assertArrayHasKey($key, $jsonDecoded['deliver']);
|
|
|
|
|
$this->assertEquals($value, $jsonDecoded['deliver'][$key]);
|
|
|
|
|
} else {
|
|
|
|
|
$this->assertArrayHasKey($key, $jsonDecoded);
|
|
|
|
|
$this->assertEquals($value, $jsonDecoded[$key]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Valdate xml generated files default.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2025-08-28 11:07:31 +02:00
|
|
|
public function testValidateGeneratedXmlDefault(): void
|
2021-12-19 15:57:24 +01:00
|
|
|
{
|
|
|
|
|
$fileFound = false;
|
|
|
|
|
|
|
|
|
|
$files = File::allFiles(\storage_path('export/arcadia'));
|
|
|
|
|
|
|
|
|
|
/** @var \Symfony\Component\Finder\SplFileInfo $file */
|
|
|
|
|
foreach ($files as $file) {
|
2023-09-06 17:24:53 +02:00
|
|
|
if (\strpos($file->getFilename(), 'v4-order-000000023-default-') === 0) {
|
2021-12-19 15:57:24 +01:00
|
|
|
$fileFound = true;
|
|
|
|
|
|
|
|
|
|
// Enable user error handling.
|
|
|
|
|
\libxml_use_internal_errors(true);
|
|
|
|
|
|
|
|
|
|
$xml = new DOMDocument();
|
|
|
|
|
$xml->load($file->getRealPath());
|
|
|
|
|
|
|
|
|
|
$this->assertTrue($xml->schemaValidate(\resource_path('documents/arcadia_default.xsd')));
|
|
|
|
|
$this->libxmlDisplayErrors();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$this->assertTrue($fileFound, 'Should have found a xml file to validate and pass validation');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Valdate xml generated files game.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2025-08-28 11:07:31 +02:00
|
|
|
public function testValidateGeneratedXmlGame(): void
|
2021-12-19 15:57:24 +01:00
|
|
|
{
|
|
|
|
|
$fileFound = false;
|
|
|
|
|
|
|
|
|
|
$files = File::allFiles(\storage_path('export/arcadia'));
|
|
|
|
|
|
|
|
|
|
/** @var \Symfony\Component\Finder\SplFileInfo $file */
|
|
|
|
|
foreach ($files as $file) {
|
2023-09-06 17:24:53 +02:00
|
|
|
if (\strpos($file->getFilename(), 'v4-order-000000000-game') === 0) {
|
2021-12-19 15:57:24 +01:00
|
|
|
$fileFound = true;
|
|
|
|
|
|
|
|
|
|
// Enable user error handling.
|
|
|
|
|
\libxml_use_internal_errors(true);
|
|
|
|
|
|
|
|
|
|
$xml = new DOMDocument();
|
|
|
|
|
$xml->load($file->getRealPath());
|
|
|
|
|
|
|
|
|
|
$this->assertTrue($xml->schemaValidate(\resource_path('documents/arcadia_game.xsd')));
|
|
|
|
|
$this->libxmlDisplayErrors();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$this->assertTrue($fileFound, 'Should have found a xml file to validate and pass validation');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-08-28 11:07:31 +02:00
|
|
|
* Render a \LibXMLError.
|
2021-12-19 15:57:24 +01:00
|
|
|
*
|
|
|
|
|
* @param \LibXMLError $error
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
private function libxmlDisplayError(\LibXMLError $error): string
|
|
|
|
|
{
|
|
|
|
|
$return = "<br/>\n";
|
|
|
|
|
switch ($error->level) {
|
|
|
|
|
case LIBXML_ERR_WARNING:
|
|
|
|
|
$return .= "<b>Warning $error->code</b>: ";
|
|
|
|
|
break;
|
|
|
|
|
case LIBXML_ERR_ERROR:
|
|
|
|
|
$return .= "<b>Error $error->code</b>: ";
|
|
|
|
|
break;
|
|
|
|
|
case LIBXML_ERR_FATAL:
|
|
|
|
|
$return .= "<b>Fatal Error $error->code</b>: ";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
$return .= trim($error->message);
|
|
|
|
|
if ($error->file) {
|
|
|
|
|
$return .= " in <b>$error->file</b>";
|
|
|
|
|
}
|
|
|
|
|
$return .= " on line <b>$error->line</b>\n";
|
|
|
|
|
|
|
|
|
|
return $return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Display xml errors.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2025-08-28 11:07:31 +02:00
|
|
|
private function libxmlDisplayErrors(): void
|
2021-12-19 15:57:24 +01:00
|
|
|
{
|
|
|
|
|
$errors = libxml_get_errors();
|
|
|
|
|
foreach ($errors as $error) {
|
|
|
|
|
print $this->libxmlDisplayError($error);
|
|
|
|
|
}
|
|
|
|
|
libxml_clear_errors();
|
|
|
|
|
}
|
|
|
|
|
}
|