Skip to content

Commit

Permalink
feature/Unit-tests were refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdodonov committed Oct 23, 2021
1 parent 7aa904b commit 662637e
Showing 1 changed file with 50 additions and 21 deletions.
71 changes: 50 additions & 21 deletions Mezon/Gui/FormBuilder/Tests/FormBuilderUnitTest.php
Expand Up @@ -8,7 +8,7 @@

class FormBuilderUnitTest extends TestCase
{

/**
* Method returns testing data
*
Expand All @@ -20,7 +20,7 @@ protected function getJson(string $name): array
{
return json_decode(file_get_contents(__DIR__ . '/conf/' . $name . '.json'), true);
}

/**
* Method constructs FieldsAlgorithms object
*
Expand All @@ -30,21 +30,21 @@ protected function getFieldsAlgorithms()
{
return new FieldsAlgorithms($this->getJson('form-builder-setup'), 'entity');
}

/**
* Setting on and off the form title flag.
*
* @param bool $flag
*/
protected function formHeader(bool $flag)
private function formHeader(bool $flag)
{
if (! $flag) {
$_GET['no-header'] = 1;
} else {
unset($_GET['no-header']);
}
}

/**
* Testing data for creation form tests
*
Expand All @@ -61,7 +61,7 @@ public function creationFormWidthDataProvider(): array
]
];
}

/**
* Testing creation form
*
Expand All @@ -76,12 +76,12 @@ public function testCreationFormWith(array $layout): void
unset($_GET['form-width']);
}
$formBuilder = new FormBuilder($this->getFieldsAlgorithms(), SESSION_ID, 'test-record', $layout);

$this->formHeader(true);

// test body
$content = $formBuilder->creationForm();

// assertions
$this->assertStringContainsString('<div class="page-title">', $content, 'No form title was found');
$this->assertStringContainsString('<form', $content, 'No form tag was found');
Expand All @@ -91,32 +91,61 @@ public function testCreationFormWith(array $layout): void
$this->assertStringContainsString('<option', $content, 'No option tag was found');
$this->assertStringContainsString('type="file"', $content, 'No file field was found');
}

/**
* Testing creation form
* Common part of the tests testUpdatingFormWithNoHeader and testUpdatingFormWithHeader
*
* @return string form content
*/
public function testUpdatingForm(): void
private function updatingFormTestCommonPart(): string
{
// setup
$formBuilder = new FormBuilder($this->getFieldsAlgorithms(), SESSION_ID, 'test-record', $this->getJson('layout'));

$this->formHeader(true);


// test body
$content = $formBuilder->updatingForm('session-id', [
'id' => '23'
]);

// assertions
$this->assertStringContainsString('<div class="page-title">', $content, 'No form title was found');
$this->assertStringContainsString('<form', $content, 'No form tag was found');
$this->assertStringContainsString('<textarea', $content, 'No textarea tag was found');
$this->assertStringContainsString('<input', $content, 'No input tag was found');
$this->assertStringContainsString('<select', $content, 'No select tag was found');
$this->assertStringContainsString('<option', $content, 'No option tag was found');
$this->assertStringContainsString('type="file"', $content, 'No file field was found');

return $content;
}


/**
* Testing updating form with no header
*/
public function testUpdatingFormWithNoHeader(): void
{
// setup
$_GET['no-header'] = 1;

$content = $this->updatingFormTestCommonPart();

$this->assertStringNotContainsString('<div class="page-title">', $content, 'No form title was found');
}

/**
* Testing updating form with header
*/
public function testUpdatingFormWithHeader(): void
{
// setup
if (isset($_GET['no-header'])) {
unset($_GET['no-header']);
}

$content = $this->updatingFormTestCommonPart();

$this->assertStringContainsString('<div class="page-title">', $content, 'No form title was found');
}

/**
* Testing constructor with no form title
*/
Expand All @@ -125,12 +154,12 @@ public function testConstructorNoFormTitle(): void
// setup
$_GET['form-width'] = 7;
$formBuilder = new FormBuilder($this->getFieldsAlgorithms(), SESSION_ID, 'test-record', []);

$this->formHeader(false);

// test body
$content = $formBuilder->creationForm();

// assertions
$this->assertStringNotContainsStringIgnoringCase('<div class="page-title"', $content, 'Form title was found');
}
Expand Down

0 comments on commit 662637e

Please sign in to comment.