diff --git a/tests/multiple_value_widget.test b/tests/multiple_value_widget.test index 56ff2eb..bfe2da8 100644 --- a/tests/multiple_value_widget.test +++ b/tests/multiple_value_widget.test @@ -1,12 +1,17 @@ drupalPost('admin/structure/types/manage/page/fields/body', $edit, t('Save settings')); - $this->assertRaw(t('Saved %field configuration.', array('%field' => 'Body')), t('Body field settings have been updated.')); + $this->assertRaw(t('Saved %field configuration.', array('%field' => 'Body')), 'Body field settings have been updated.'); // Check if the setting works. $this->drupalGet('node/add/page'); - $this->assertFieldById('edit-body-und-add-more', t('Add another item'), t('Add another item button found.')); + $this->assertFieldById('edit-body-und-add-more', t('Add another item'), 'Add another item button found.'); // Field with unlimited cardinality and FIELD_BEHAVIOR_CUSTOM. $field_list = array( @@ -148,10 +155,10 @@ class MultipleValueWidgetTestCase extends DrupalWebTestCase { public function testThemeRegistry() { $hooks = theme_get_registry(FALSE); if (isset($hooks['field_multiple_value_form'])) { - $this->assertEqual($hooks['field_multiple_value_form']['function'], 'multiple_value_widget_field_multiple_value_form'); + $this->assertEqual($hooks['field_multiple_value_form']['function'], 'multiple_value_widget_field_multiple_value_form', 'MVW form theme hooks properly registered.'); } if (isset($hooks['file_widget_multiple'])) { - $this->assertEqual($hooks['file_widget_multiple']['function'], 'multiple_value_widget_file_widget_multiple'); + $this->assertEqual($hooks['file_widget_multiple']['function'], 'multiple_value_widget_file_widget_multiple', 'MVW file widget theme hooks properly registered.'); } } @@ -162,8 +169,6 @@ class MultipleValueWidgetTestCase extends DrupalWebTestCase { * @see multiple_value_widget_form_field_ui_field_edit_form_alter() */ public function testFieldManagementInterface() { - $this->drupalGet('admin/structure/types/manage/page/fields/body'); - // Look for the following xpath expressions. $xpaths = array( '//div[@id="edit-instance-widget-settings-multiple-value-widget"]', @@ -172,17 +177,10 @@ class MultipleValueWidgetTestCase extends DrupalWebTestCase { $this->constructFieldXpath('id', 'edit-instance-widget-settings-multiple-value-widget-blocks'), $this->constructFieldXpath('id', 'edit-instance-widget-settings-multiple-value-widget-accordion'), ); + $this->drupalGet('admin/structure/types/manage/page/fields/body'); foreach ($xpaths as $xpath) { $results = count($this->xpath($xpath)); - $this->assertEqual($results, 1); - } - - // Check that the previous xpath expressions don't target anything. - // This is testing the FIELD_BEHAVIOR_DEFAULT vs FIELD_BEHAVIOR_CUSTOM. - $this->drupalGet('admin/structure/types/manage/page/fields/field_list'); - foreach ($xpaths as $xpath) { - $results = count($this->xpath($xpath)); - $this->assertEqual($results, 0); + $this->assertEqual($results, 1, 'Found each of the expected radio elements(table, tabs, blocks, accordion).'); } // Check that the previous xpath expressions target something. @@ -191,7 +189,15 @@ class MultipleValueWidgetTestCase extends DrupalWebTestCase { $this->drupalGet('admin/structure/types/manage/page/fields/field_single_text'); foreach ($xpaths as $xpath) { $results = count($this->xpath($xpath)); - $this->assertEqual($results, 1); + $this->assertEqual($results, 1, 'Found each of the expected radio elements(table, tabs, blocks, accordion).'); + } + + // Check that the previous xpath expressions don't target anything. + // This is testing the FIELD_BEHAVIOR_DEFAULT vs FIELD_BEHAVIOR_CUSTOM. + $this->drupalGet('admin/structure/types/manage/page/fields/field_list'); + foreach ($xpaths as $xpath) { + $results = count($this->xpath($xpath)); + $this->assertEqual($results, 0, 'Found none of the possible MVW options(table, tabs, blocks, accordion)'); } } @@ -208,28 +214,28 @@ class MultipleValueWidgetTestCase extends DrupalWebTestCase { $this->drupalGet('node/add/page'); $xpath = '//ul[contains(@class, "mvw-tabs")]//a[@href="#mvw-group-body-0"]'; $results = count($this->xpath($xpath)); - $this->assertEqual($results, 1); + $this->assertEqual($results, 1, 'Tabs element found, as per field configuration.'); // Check that we get the standard title. $xpath = '//ul[contains(@class, "mvw-tabs")]//a[@href="#mvw-group-body-0"]/text()'; $results = $this->xpath($xpath); $tab_title = (string) reset($results); - $this->assertEqual($tab_title, 'Body (1)'); + $this->assertEqual($tab_title, 'Body (1)', 'Tab has the expected/default title.'); // Check that the tabs specific assets/settings are present. - $this->assertRaw('"mvw-body":"tabs"'); - $this->assertRaw('jquery.ui.tabs'); + $this->assertRaw('"mvw-body":"tabs"', 'Drupal.settings contains the correct mvw parameter.'); + $this->assertRaw('jquery.ui.tabs', 'Correct jQuery UI library loaded in page.'); // Body is set anew to 'blocks'. $edit = array( 'instance[widget][settings][multiple_value_widget]' => 'blocks', ); $this->drupalPost('admin/structure/types/manage/page/fields/body', $edit, t('Save settings')); - $this->assertRaw(t('Saved %field configuration.', array('%field' => 'Body')), t('Body field settings have been updated.')); + $this->assertRaw(t('Saved %field configuration.', array('%field' => 'Body')), 'Body field settings have been updated.'); $this->drupalGet('node/add/page'); $xpath = '//div[contains(@class, "mvw-group")]/div[@class="mvw-group-title ui-widget-header ui-corner-all"]'; $results = count($this->xpath($xpath)); - $this->assertEqual($results, 1); + $this->assertEqual($results, 1, 'Element rendered as Blocks has expected title div structure.'); // Check that the blocks specific settings are present. - $this->assertRaw('"mvw-body":"blocks"'); + $this->assertRaw('"mvw-body":"blocks"', 'Drupal.settings contains the correct mvw parameter.'); // Body is set anew to 'accordion' and cardinality to 2. $edit = array( @@ -237,19 +243,19 @@ class MultipleValueWidgetTestCase extends DrupalWebTestCase { 'field[cardinality]' => 2, ); $this->drupalPost('admin/structure/types/manage/page/fields/body', $edit, t('Save settings')); - $this->assertRaw(t('Saved %field configuration.', array('%field' => 'Body')), t('Body field settings have been updated.')); + $this->assertRaw(t('Saved %field configuration.', array('%field' => 'Body')), 'Body field settings have been updated.'); $this->drupalGet('node/add/page'); $xpath = '//div[contains(@class, "mvw-group")]//span[@class="ui-icon ui-icon-arrowthick-2-n-s"]'; $results = count($this->xpath($xpath)); - $this->assertEqual($results, 2); + $this->assertEqual($results, 2, 'Element correctly rendered as Accordion with cardinality 2.'); // Check that the accordion specific assets/settings are present. - $this->assertRaw('"mvw-body":"accordion"'); - $this->assertRaw('jquery.ui.accordion'); + $this->assertRaw('"mvw-body":"accordion"', 'Drupal.settings contains the correct mvw parameter.'); + $this->assertRaw('jquery.ui.accordion', 'Correct jQuery UI library loaded in page.'); // Check that the rest of the assets are added correctly. $this->assertRaw($module_path . '/multiple_value_widget.js'); $this->assertRaw($module_path . '/multiple_value_widget.css'); - $this->assertRaw('jquery.ui.sortable'); + $this->assertRaw('jquery.ui.sortable', 'Correct jQuery UI library loaded in page.'); } /** @@ -266,7 +272,7 @@ class MultipleValueWidgetTestCase extends DrupalWebTestCase { $xpath = '//ul[contains(@class, "mvw-tabs")]//a[@href="#mvw-group-body-0"]/text()'; $results = $this->xpath($xpath); $tab_title = (string) reset($results); - $this->assertEqual($tab_title, MULTIPLE_VALUE_WIDGET_TEST_MODIFIED_TITLE); + $this->assertEqual($tab_title, MULTIPLE_VALUE_WIDGET_TEST_MODIFIED_TITLE, 'Element title altered as expected.'); } /** @@ -278,10 +284,10 @@ class MultipleValueWidgetTestCase extends DrupalWebTestCase { // Test that validation fails in the simplest case, with AJAX. $this->drupalPostAjax(NULL, array(), array('field_required_multiple_text_add_more' => t('Add another item'))); - $this->assertText('field is required.'); + $this->assertText(t('field is required.'), 'Required field validation failed as expected.'); // Test that validation fails in the simplest case, without AJAX. $this->drupalPost(NULL, array(), t('Save')); - $this->assertText('field is required.'); + $this->assertText(t('field is required.'), 'Required field validation failed as expected.'); // Test that validation succeeds. $this->drupalGet('node/add/page'); @@ -293,10 +299,10 @@ class MultipleValueWidgetTestCase extends DrupalWebTestCase { // With Ajax; we also confirm that a field item is correctly added, // after the form is rebuild. $this->drupalPostAjax(NULL, $edit, array('field_required_multiple_text_add_more' => t('Add another item'))); - $this->assertFieldByName('field_required_multiple_text[und][1][value]', NULL, t('Validation succeeded since we got a new item added.')); + $this->assertFieldByName('field_required_multiple_text[und][1][value]', NULL, 'Validation succeeded since we got a new item added.'); // Without Ajax. $this->drupalPost(NULL, $edit, t('Save')); - $this->assertText('Basic page ' . $edit['title'] . ' has been created.'); + $this->assertText('Basic page ' . $edit['title'] . ' has been created.', 'Created new basic page.'); // Get a reference to the new node. $node = $this->drupalGetNodeByTitle($edit['title']); @@ -311,8 +317,8 @@ class MultipleValueWidgetTestCase extends DrupalWebTestCase { ); $this->drupalPost(NULL, $edit, t('Save')); $node = $this->drupalGetNodeByTitle($node->title, TRUE); - $this->assertEqual($node->field_required_multiple_text[LANGUAGE_NONE][0]['value'], $field_required_multiple_text_value_1); - $this->assertEqual($node->field_required_multiple_text[LANGUAGE_NONE][1]['value'], $field_required_multiple_text_value_0); + $this->assertEqual($node->field_required_multiple_text[LANGUAGE_NONE][0]['value'], $field_required_multiple_text_value_1, 'Reordered trailing element found in correct new position.'); + $this->assertEqual($node->field_required_multiple_text[LANGUAGE_NONE][1]['value'], $field_required_multiple_text_value_0, 'Reordered leading element found in correct new position.'); // Test validation fails after rearranging fields. $this->drupalGet('node/' . $node->nid . '/edit'); @@ -321,10 +327,10 @@ class MultipleValueWidgetTestCase extends DrupalWebTestCase { ); // With Ajax. $this->drupalPostAjax(NULL, $edit, array('field_required_multiple_text_add_more' => t('Add another item'))); - $this->assertText('field is required.'); + $this->assertText(t('field is required.'), 'Required field validation failed as expected.'); // Without Ajax. $this->drupalPost(NULL, $edit, t('Save')); - $this->assertText('field is required.'); + $this->assertText(t('field is required.'), 'Required field validation failed as expected.'); } } diff --git a/tests/multiple_value_widget_test/multiple_value_widget_test.info b/tests/multiple_value_widget_test/multiple_value_widget_test.info index d3366ba..56d3aa8 100644 --- a/tests/multiple_value_widget_test/multiple_value_widget_test.info +++ b/tests/multiple_value_widget_test/multiple_value_widget_test.info @@ -3,6 +3,5 @@ description = Tests Multiple Value Widget module functionality. Do not enable. core = 7.x package = Testing hidden = TRUE -dependencies[] = multiple_value_widget -files[] = multiple_value_widget_test.module +dependencies[] = multiple_value_widget diff --git a/tests/multiple_value_widget_test/multiple_value_widget_test.module b/tests/multiple_value_widget_test/multiple_value_widget_test.module index 27b7e79..3da931a 100644 --- a/tests/multiple_value_widget_test/multiple_value_widget_test.module +++ b/tests/multiple_value_widget_test/multiple_value_widget_test.module @@ -1,6 +1,6 @@