/ tests / Services / CertificationRequestValidatorTest.php
CertificationRequestValidatorTest.php
  1  <?php
  2  
  3  namespace Tests\Services;
  4  
  5  use App\Enums\SectorialDimensionsEnum;
  6  use App\Enums\TechnologicalDimensionsEnum;
  7  use App\Enums\UsageDimensionsEnum;
  8  use Tests\TestCase;
  9  use App\Http\Services\CertificationRequestValidator;
 10  use App\Models\Dossier;
 11  use App\Models\NormScope;
 12  use Illuminate\Foundation\Testing\WithFaker;
 13  
 14  class CertificationRequestValidatorTest extends TestCase
 15  {
 16      use WithFaker;
 17  
 18      public string $pdf = 'test_files/certification_request/01. FOR-001/certification_request_v1.0.0.pdf';
 19  
 20      public function testValidatorWithFile()
 21      {
 22          $validator = new CertificationRequestValidator($this->pdf);
 23          $data = $validator->read();
 24          
 25          $this->assertIsArray($data);
 26          $this->assertEquals($validator->validate($data), []);
 27      }
 28  
 29      public function testApplicantValidations() {
 30  
 31          $data = [
 32              'applicant_name' => $this->faker->name,
 33              'applicant_trade_name' => $this->faker->company,
 34              'applicant_nif' => $this->faker->uuid,
 35              'applicant_corporate_identity' => $this->faker->uuid,
 36              'applicant_city_name' => $this->faker->city,
 37              'applicant_zip_code' => $this->faker->postcode,
 38              'applicant_address' => $this->faker->address,
 39              'applicant_phone' => $this->faker->phoneNumber,
 40              'applicant_email' => $this->faker->email,
 41          ];
 42  
 43          $validator = new CertificationRequestValidator($this->pdf);
 44          $got = $validator->validateApplicant($data);
 45  
 46          $this->assertEquals($got, []);
 47      }
 48  
 49      public function testLaboratoryValidations() {
 50  
 51          $data = [
 52              'laboratory_name' => $this->faker->name,
 53              'laboratory_trade_name' => $this->faker->company,
 54              'laboratory_nif' => $this->faker->uuid,
 55              'laboratory_corporate_identity' => $this->faker->uuid,
 56              'laboratory_city_name' => $this->faker->city,
 57              'laboratory_zip_code' => $this->faker->postcode,
 58              'laboratory_address' => $this->faker->address,
 59              'laboratory_phone' => $this->faker->phoneNumber,
 60              'laboratory_email' => $this->faker->email,
 61              'laboratory_notification_number' => $this->faker->uuid,
 62              'laboratory_authorization_number' => $this->faker->uuid,
 63          ];
 64  
 65          $validator = new CertificationRequestValidator($this->pdf);
 66          $got = $validator->validateLaboratory($data);
 67  
 68          $this->assertEquals($got, []);
 69      }
 70  
 71      public function testToeValidations() {
 72  
 73          $data = [
 74              'toe_name' => $this->faker->name,
 75              'toe_alias' => $this->faker->company,
 76              'toe_commercial_name' => $this->faker->company,
 77              'toe_description' => $this->faker->text,
 78              'toe_version' => '1.0.0',
 79              'toe_scope' => $this->faker->text,
 80  
 81              'toe_security_info_link' => $this->faker->url,
 82              'toe_vulnerability_contact_link' => $this->faker->url,
 83              'toe_usage_guide_link' => $this->faker->url,
 84              'toe_public_vulnerabilities' => $this->faker->url,
 85              'toe_vulnerability_notifications_via' => $this->faker->email,
 86  
 87              'toe_support_period' => '1',
 88              'toe_sectorial_dimensions' => implode(';', SectorialDimensionsEnum::toArray()),
 89              'toe_usage_dimensions' => UsageDimensionsEnum::CONTROLACCESS->value,
 90              'toe_technological_dimensions' => implode(';', TechnologicalDimensionsEnum::toArray()),
 91          ];
 92  
 93          $validator = new CertificationRequestValidator($this->pdf);
 94          $got = $validator->validateTOE($data);
 95  
 96          $this->assertEquals($got, []);
 97      }
 98  
 99      public function testDossierValidations() {
100          $scope = NormScope::first();
101          $norm = $scope->norm;
102  
103          $data = [
104              'dossier_norm_version' => $norm->version,
105              'ref_st' => $this->faker->filePath,
106              'ref_strr' => $this->faker->filePath,
107              'ref_previous_dossier' => Dossier::first()->code,
108              'dossier_evaluation_level' => $scope->name,
109              'dossier_type' => 'Acreditación',
110              'dossier_subtype' => 'Nueva',
111              'dossier_modo' => 'Acreditación para Common Criteria',
112          ];
113  
114          $validator = new CertificationRequestValidator($this->pdf);
115          $got = $validator->validateDossier($data);
116  
117          $this->assertEquals($got, []);
118      }
119  }