Spaces:
No application file
No application file
File size: 2,673 Bytes
d2897cd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
<?php
declare(strict_types=1);
namespace Mautic\FormBundle\Tests\Entity;
use Mautic\FormBundle\Entity\Field;
use Mautic\FormBundle\Entity\Form;
use PHPUnit\Framework\Assert;
final class FormTest extends \PHPUnit\Framework\TestCase
{
/**
* @dataProvider setNoIndexDataProvider
*/
public function testSetNoIndex($value, $expected, array $changes): void
{
$form = new Form();
$form->setNoIndex($value);
Assert::assertSame($expected, $form->getNoIndex());
Assert::assertSame($changes, $form->getChanges());
}
public static function setNoIndexDataProvider(): iterable
{
yield [null, null, []];
yield [true, true, ['noIndex' => [null, true]]];
yield [false, false, ['noIndex' => [null, false]]];
yield ['', false, ['noIndex' => [null, false]]];
yield [0, false, ['noIndex' => [null, false]]];
yield ['string', true, ['noIndex' => [null, true]]];
}
public function testGetMappedFieldValues(): void
{
$form = $this->createForm();
$result = [
[
'formFieldId' => null,
'mappedObject' => 'contact',
'mappedField' => 'email',
],
[
'formFieldId' => null,
'mappedObject' => 'company',
'mappedField' => 'companyemail',
],
[
'formFieldId' => null,
'mappedObject' => 'company',
'mappedField' => 'companyname',
],
];
Assert::assertSame($result, $form->getMappedFieldValues());
}
public function testGetMappedFieldObjects(): void
{
$form = $this->createForm();
Assert::assertSame(['contact', 'company'], $form->getMappedFieldObjects());
}
private function createForm(): Form
{
$form = new Form();
$contactField = new Field();
$companyFieldA = new Field();
$companyFieldB = new Field();
$notMappedField = new Field();
$contactField->setMappedObject('contact');
$contactField->setMappedField('email');
$companyFieldA->setMappedObject('company');
$companyFieldA->setMappedField('companyemail');
$companyFieldB->setMappedObject('company');
$companyFieldB->setMappedField('companyname');
$form->addField('contact_field_a', $contactField);
$form->addField('company_field_a', $companyFieldA);
$form->addField('company_field_b', $companyFieldB);
$form->addField('not_mapped_field_a', $notMappedField);
return $form;
}
}
|