public function ProfileTest::testDefaultProfile in Profile 8
Tests default profile functionality.
File
- tests/
src/ Kernel/ ProfileTest.php, line 263
Class
- ProfileTest
- Tests basic functionality of profiles.
Namespace
Drupal\Tests\profile\KernelCode
public function testDefaultProfile() {
$profile_type = ProfileType::create([
'id' => 'test_defaults',
'label' => 'test_defaults',
]);
$profile_type
->save();
/** @var \Drupal\profile\Entity\ProfileInterface $profile1 */
$profile1 = Profile::create([
'type' => $profile_type
->id(),
'uid' => $this->user1
->id(),
]);
$profile1
->save();
// Confirm that the profile was set as default.
$this
->assertTrue($profile1
->isDefault());
/** @var \Drupal\profile\Entity\ProfileInterface $profile2 */
$profile2 = Profile::create([
'type' => $profile_type
->id(),
'uid' => $this->user1
->id(),
]);
$profile2
->setDefault(TRUE);
$profile2
->save();
// Confirm that setting the second profile as default removed the
// flag from the first profile.
$profile2 = $this
->reloadEntity($profile2);
$profile1 = $this
->reloadEntity($profile1);
$this
->assertTrue($profile2
->isDefault());
$this
->assertFalse($profile1
->isDefault());
// Verify that an unpublished profile cannot be the default.
$profile2
->setUnpublished();
$profile2
->save();
$this
->assertFalse($profile2
->isDefault());
$profile1 = $this
->reloadEntity($profile1);
$this
->assertFalse($profile1
->isDefault());
// Confirm that re-saving the other published profile sets it as default.
$profile1
->save();
$this
->assertTrue($profile1
->isDefault());
}