Initial import of space_profiles module
This commit is contained in:
52
tests/codeception/unit/SpaceProfileFormTest.php
Normal file
52
tests/codeception/unit/SpaceProfileFormTest.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace space_profiles;
|
||||
|
||||
use humhub\modules\space\models\Space;
|
||||
use humhub\modules\space_profiles\models\forms\SpaceProfileForm;
|
||||
|
||||
class SpaceProfileFormTest extends UnitTester
|
||||
{
|
||||
public function testValidMinimalDataPassesValidation(): void
|
||||
{
|
||||
$space = Space::findOne(['id' => 2]);
|
||||
$this->assertNotNull($space, 'Expected fixture space with id=2 to exist.');
|
||||
|
||||
$form = new SpaceProfileForm(['contentContainer' => $space]);
|
||||
$form->profile_name = 'Test Rescue Space';
|
||||
$form->city = 'Boston';
|
||||
$form->state = 'MA';
|
||||
$form->zip_code = '02110';
|
||||
$form->contact_email = 'team@example.org';
|
||||
$form->contact_phone = '(617) 555-1212';
|
||||
$form->website_url = 'https://example.org';
|
||||
|
||||
$this->assertTrue($form->validate());
|
||||
}
|
||||
|
||||
public function testStateMustBeTwoCharacters(): void
|
||||
{
|
||||
$space = Space::findOne(['id' => 2]);
|
||||
$this->assertNotNull($space, 'Expected fixture space with id=2 to exist.');
|
||||
|
||||
$form = new SpaceProfileForm(['contentContainer' => $space]);
|
||||
$form->profile_name = 'Invalid State Case';
|
||||
$form->state = 'Massachusetts';
|
||||
|
||||
$this->assertFalse($form->validate(['state']));
|
||||
$this->assertArrayHasKey('state', $form->getErrors());
|
||||
}
|
||||
|
||||
public function testContactEmailMustBeValid(): void
|
||||
{
|
||||
$space = Space::findOne(['id' => 2]);
|
||||
$this->assertNotNull($space, 'Expected fixture space with id=2 to exist.');
|
||||
|
||||
$form = new SpaceProfileForm(['contentContainer' => $space]);
|
||||
$form->profile_name = 'Invalid Email Case';
|
||||
$form->contact_email = 'not-an-email';
|
||||
|
||||
$this->assertFalse($form->validate(['contact_email']));
|
||||
$this->assertArrayHasKey('contact_email', $form->getErrors());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user