drupalVariableSet('user_register',1); $this->drupalModuleEnable('profile'); $edit = $this->drupalCreateUser('access content, administer users, access user profiles, administer site configuration, access administration pages, access configuration pages, access user profiles'); $this->drupalLogin($edit); } function create_field( $type, $set = FALSE ) { $title = "single_". $this->randomName(10); $form_name = 'profile_'. $title; $explanation = $this->randomName(50); if ( $set == FALSE ) { $edit = array( 'category' => $my_category, 'title' => $title, 'name' => $form_name, 'explanation' => $explanation, ); } $this->drupalPost("admin/user/profile/add/". $type, $edit, t('Save field'), 0); $result['fid'] = db_result(db_query('SELECT fid FROM {profile_fields} WHERE title = "%s"', $title)); $result['single_field'] = array('title' => $title, 'form_name' => $form_name, 'explanation' => $explanation); return $result; } function check_field( ) { // checking simple fields $this->drupalGet("user/". $user->uid."/edit/$my_category"); // checking field $this->assertField($form_name , t('Found form named @name', array('@name' => $form_name))); // checking name $this->assertText($title, "Checking title for ". $title); // checking explanation $this->assertText($explanation, "Checking explanation for ". $title); } function set_field_data( $data = $this->randomName(20) ) { unset($edit); $edit = array(); $checking = array(); $edit[$form_name] = $data; $this->save_field_data( ); } function save_field_data( ) { $this->drupalPost("user/". $user->uid."/edit/$my_category", $edit, t('Save') , 0); $this->drupalGet("user/". $user->uid); } function check_profile_page( ) { // checking profile page $this->assertText($edit[$form_name], "Checking ". $edit[$form_name]); $this->assertText($title, "Checking $title"); } function update_field ( $fid, $new_title = $this->randomName(20) ) { $this->drupalPost("admin/user/profile/edit/$fid", array('title' => $new_title), t('Save field') , 0); $this->drupalGet("admin/user/profile"); $this->assertText($new_title, "Checking updated field"); } function delete_field( $fid ) { $this->drupalPost("admin/user/profile/delete/$fid", array(), t('Delete'), 0); $this->drupalGet("admin/user/profile"); $this->assertNoText($new_title, "Checking deleted field $title"); } function test_simple_field ( $type ) { $result = $this->create_field($type) $this->check_field( ); $this->set_field_data(); $this->check_profile_page(); $this->update_field($result['fid']); $this->delete_field($result['fid']); } } class ProfileTestSingleTestCase extends ProfileTestCase { function getInfo() { return array('name' => 'Test Single field', 'description' => "Testing profile module with add/edit/delete new fields into profile page" , 'group' => 'Profile Module'); } function testProfileSingle() { $this->test_simple_field("textfield"); } } class ProfileTestTextareaTestCase extends ProfileTestCase { function getInfo() { return array('name' => 'Test Textarea field', 'description' => "Testing profile module with add/edit/delete new fields into profile page" , 'group' => 'Profile Module'); } function testProfileSingle() { $this->test_simple_field("textarea") } } class ProfileTestFreelistTestCase extends ProfileTestCase { function getInfo() { return array('name' => 'Test Freelist field', 'description' => "Testing profile module with add/edit/delete new fields into profile page" , 'group' => 'Profile Module'); } function testProfileSingle() { $this->test_simple_field("list"); } } class ProfileTestCheckboxTestCase extends ProfileTestCase { function getInfo() { return array('name' => 'Test Checkbox field', 'description' => "Testing profile module with add/edit/delete new fields into profile page" , 'group' => 'Profile Module'); } function testProfileCheckbox() { $this->test_simple_field("checkbox"); } } class ProfileTestUrlTestCase extends ProfileTestCase { function getInfo() { return array('name' => 'Test Url field', 'description' => "Testing profile module with add/edit/delete new fields into profile page" , 'group' => 'Profile Module'); } function testProfileSingle() { $this->test_simple_field("url"); } } class ProfileTestSelectionTestCase extends ProfileTestCase { function getInfo() { return array('name' => 'Test Selection field', 'description' => "Testing profile module with add/edit/delete new fields into profile page" , 'group' => 'Profile Module'); } function testProfileSingle() { $options = ""; for($i = 0; $i < 3; $i++) { $options .= $this->randomName(8) ."\n"; } $edit = array('category' => $my_category, 'title' => $title, 'name' =>$form_name, 'explanation' => $explanation, 'options' => $options); $result = $this->create_field("selection", TRUE); $this->check_field( ); $element = rand(0,2); $value = rtrim($op_tab[$element]); $this->set_field_data($value); $this->check_profile_page(); $this->update_field($result['fid']); $this->delete_field($result['fid']); } } class ProfileTestDateTestCase extends ProfileTestCase { function getInfo() { return array('name' => 'Test Date field', 'description' => "Testing profile module with add/edit/delete new fields into profile page" , 'group' => 'Profile Module'); } function testProfileSingle() { $result = $this->create_field("date"); $this->check_field( ); //Custom set data for date unset($edit); foreach(array('year' => 1983, 'month' => 'Jan', 'day' => 9) as $field => $v) { $key = $form_name .'['. $field .']'; $edit[$key] = $v; } list($format) = explode(' - ', variable_get('date_format_short', 'm/d/Y'), 2); $replace = array( 'd' => sprintf('%02d', 9), 'j' => 9, 'm' => sprintf('%02d', '1'), 'M' => map_month(1), 'Y' => 1983 ); $data = strtr($format, $replace); $this->save_field_data(); $this->check_profile_page(); $this->update_field(); $this->delete_field(); } } class ProfileTest2TestCase extends ProfileTestCase { function getInfo() { return array('name' => 'Test other fields', 'description' => "Testing weight, title page, required" , 'group' => 'Profile Module'); } function testProfileOtherFields() { $this->my_category = $this->randomName(10); // Field One, a textfield $weight = 3; $edit = array('category' => $my_category, 'title' => $title, 'name' => $form_name, 'weight' => $weight, 'required' => 1); $field_one = $this->create_field("textfield", TRUE); //Field Two, another textfield $weight = -2; $edit = array('category' => $my_category, 'title' => $title, 'name' => $form_name, 'weight' => $weight, 'register' => 1, 'required' => 1); $field_two = $this->create_field("textfield", TRUE); //Checking $this->drupalGet("user/". $user->uid."/edit/$my_category"); $content = $this->drupalGetContent(); $pos1 = strpos($content, $field_one['single_field']['title']); $pos2 = strpos($content, $field_two['single_field']['title']); $this->assertTrue($pos2 < $pos1, 'Checking weight field'); $delete_fields = array(); $delete_fields[] = $field_one['single_field]'['fid']; $delete_fields[] = $field_two['single_field']['fid']; // check if this field is visible in registration form // logout $this->drupalGet("logout"); $this->drupalGet("user/register"); $this->assertNoText($field_one['single_field']['title'], 'Field is not visible in registration form'); $this->assertText($field_two['single_field']['title'], 'Field is visible in registration form'); // try to register // I think this needs to be re-written for the new API - Tistur $fname = $this->randomName(5, 'simpletest_'); $fmail = "$fname@drupaltest.example.com"; $edit = array( 'name' => $fname, 'mail' => $fmail ); $this->drupalPost('user/register', $edit, t('Create new account'), 0); //log in $edit = array('name' => $name, 'pass' => $pass); $this->drupalPost('user', $edit, t('Log in'), 0); // TITLE //selection $title = $this->randomName(10); $form_name = 'profile_'.s $title; $page_title = $this->randomName(5) ." %value"; $options = ""; for($i = 0; $i < 3; $i++) { $options .= $this->randomName(8) ."\n"; } $edit = array('category' => $my_category, 'title' => $title, 'name' => $form_name, 'page' => $page_title, 'options' => $options); $selection_one = $this->create_field("selection", TRUE); $element = rand(0,2); $op_tab = explode("\n", $options,3); $choice = rtrim($op_tab[$element]); // checking $this->drupalGet("profile/". $form_name."/$choice"); $title = str_replace("%value", $choice, $page_title); $delete_fields[] = $selection_one['single_field'['fid']; foreach($delete_fields as $fid) { $this->delete_field($fid); } }