ldc-crm/tests/Unit/CrmClientV2ArcadiaTest.php
2021-10-19 17:15:34 +02:00

122 lines
4.2 KiB
PHP

<?php
namespace Tests\Unit;
use DOMDocument;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
use LDC\LDCCRM\CrmApiV2;
use LDC\LDCCRM\Enums\ArcadiaOrderType;
use LDC\LDCCRM\Models\ArcadiaMailDefault;
use LDC\LDCCRM\Models\ArcadiaMailGame;
class CrmClientV2ArcadiaTest extends CrmClientTester
{
public function testArcadiaSendOrderDefault()
{
$api = new CrmApiV2();
$customer = $api->getCustomerOrNew(static::$info->hashcode);
$arcadiaOrderMail = new ArcadiaMailDefault([
'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'),
'state_order' => ArcadiaOrderType::cb()->value,
'support_code' => 1,
'label_type_support' => 'Fond carte Aimanté',
'order_num' => 23,
'package_unit_weight' => 0,
]);
$this->assertTrue($arcadiaOrderMail->send($customer));
}
public function testArcadiaSendOrderGame()
{
$api = new CrmApiV2();
$customer = $api->getCustomerOrNew(static::$info->hashcode);
$arcadiaOrderMail = new ArcadiaMailGame([
'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,
'label_type_support' => 'Jeux Reghalal',
'code_unique' => \strtoupper(\str_replace('-', '', (string)Str::uuid())),
'code_on_pack' => '12365214587562'
]);
$this->assertTrue($arcadiaOrderMail->send($customer));
}
public function testValidateGeneratedXmlGame()
{
$fileFound = false;
$files = File::allFiles(\storage_path('export/arcadia'));
/** @var \Symfony\Component\Finder\SplFileInfo $file */
foreach ($files as $file) {
if (\strpos($file->getFilename(), 'v2-game') === 0) {
$fileFound = true;
// Enable user error handling
\libxml_use_internal_errors(true);
$xml = new DOMDocument();
$xml->load($file->getRealPath());
if (!$xml->schemaValidate(\resource_path('documents/arcadia_game.xsd'))) {
print '<b>DOMDocument::schemaValidate() Generated Errors!</b>';
$this->libxmlDisplayErrors();
throw new \Exception('Could not validate xml file against xsd');
}
}
}
$this->assertTrue($fileFound, 'Should have found a xml file to validate and pass validation');
}
private function libxmlDisplayError($error)
{
$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;
}
private function libxmlDisplayErrors()
{
$errors = libxml_get_errors();
foreach ($errors as $error) {
print $this->libxmlDisplayError($error);
}
libxml_clear_errors();
}
}