View source
<?php
namespace Drupal\profile\Tests;
use Drupal\simpletest\WebTestBase;
use Drupal\Component\Utility\Unicode;
class ProfileTypeCRUDTest extends WebTestBase {
public static $modules = array(
'profile',
'field_ui',
'text',
);
function testCRUDUI() {
$this
->drupalLogin($this->rootUser);
$this
->drupalGet('admin/config/people/profiles/types');
$this
->clickLink(t('Add profile type'));
$this
->assertUrl('admin/config/people/profiles/types/add');
$id = Unicode::strtolower($this
->randomMachineName());
$label = $this
->randomString();
$edit = array(
'id' => $id,
'label' => $label,
);
$this
->drupalPostForm(NULL, $edit, t('Save'));
$this
->assertUrl('admin/config/people/profiles/types');
$this
->assertRaw(format_string('%label profile type has been created.', array(
'%label' => $label,
)));
$this
->assertLinkByHref("admin/config/people/profiles/types/manage/{$id}");
$this
->assertLinkByHref("admin/config/people/profiles/types/manage/{$id}/fields");
$this
->assertLinkByHref("admin/config/people/profiles/types/manage/{$id}/display");
$this
->assertLinkByHref("admin/config/people/profiles/types/manage/{$id}/delete");
$this
->drupalGet("admin/config/people/profiles/types/manage/{$id}");
$this
->assertRaw(format_string('Edit %label profile type', array(
'%label' => $label,
)));
$edit = array(
'registration' => 1,
);
$this
->drupalPostForm(NULL, $edit, t('Save'));
$this
->assertUrl('admin/config/people/profiles/types');
$this
->assertRaw(format_string('%label profile type has been updated.', array(
'%label' => $label,
)));
$this
->drupalGet("admin/config/people/profiles/types/manage/{$id}/fields/add-field");
$field_name = Unicode::strtolower($this
->randomMachineName());
$field_label = $this
->randomString();
$edit = array(
'new_storage_type' => 'string',
'label' => $field_label,
'field_name' => $field_name,
);
$this
->drupalPostForm(NULL, $edit, t('Save and continue'));
$this
->drupalPostForm(NULL, array(), t('Save field settings'));
$this
->drupalPostForm(NULL, array(), t('Save settings'));
$this
->assertUrl("admin/config/people/profiles/types/manage/{$id}/fields", array(
'query' => array(
'field_config' => "profile.{$id}.field_{$field_name}",
'destinations[0]' => "admin/config/people/profiles/types/manage/{$id}/fields/add-field",
),
));
$this
->assertRaw(format_string('Saved %label configuration.', array(
'%label' => $field_label,
)));
$this
->drupalGet("admin/config/people/profiles/types/manage/{$id}");
$new_id = Unicode::strtolower($this
->randomMachineName());
$edit = array(
'id' => $new_id,
);
$this
->drupalPostForm(NULL, $edit, t('Save'));
$this
->assertUrl('admin/config/people/profiles/types');
$this
->assertRaw(format_string('%label profile type has been updated.', array(
'%label' => $label,
)));
$this
->assertLinkByHref("admin/config/people/profiles/types/manage/{$new_id}");
$this
->assertNoLinkByHref("admin/config/people/profiles/types/manage/{$id}");
$id = $new_id;
$this
->drupalGet("admin/config/people/profiles/types/manage/{$id}/fields");
}
}