Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SourceUnassignValidatorTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
12 use PHPUnit\Framework\TestCase;
13 
14 class SourceUnassignValidatorTest extends TestCase
15 {
19  private $massUnassignValidator;
20 
21  public function setUp()
22  {
23  parent::setUp();
24  $this->massUnassignValidator = Bootstrap::getObjectManager()->get(BulkSourceUnassignValidatorInterface::class);
25  }
26 
30  public function testSourceValidator()
31  {
32  $skus = ['SKU-1', 'SKU-2'];
33  $sources = ['non-existing-source1', 'non-existing-source2'];
34 
35  $validationResult = $this->massUnassignValidator->validate($skus, $sources);
36 
37  self::assertFalse(
38  $validationResult->isValid(),
39  'Validation did not detect invalid source codes'
40  );
41 
42  $errors = $validationResult->getErrors();
43  self::assertCount(2, $errors, 'Validation did not find all invalid source codes');
44 
45  self::assertEquals(
46  'Source %sourceCode does not exist',
47  $errors[0]->getText(),
48  'Unexpected error message from validator'
49  );
50  self::assertEquals(
51  'Source %sourceCode does not exist',
52  $errors[1]->getText(),
53  'Unexpected error message from validator'
54  );
55  }
56 }
foreach($websiteCodes as $websiteCode) $skus
$errors
Definition: overview.phtml:9