public function StateFlowWebTestCase::testOfPublishedViewsHandler in State Machine 7.3
Test state_flow_handler_field_is_node_revision_published.inc.
Test state_flow_handler_field_is_node_revision_published.inc and some of the other columns used at node/1/revisions-state-flow-states and node/1/state-flow-history
File
- modules/
state_flow/ tests/ state_flow.test, line 354 - state_flow.test
Class
- StateFlowWebTestCase
- Unit tests for the StateFlow revision state machine.
Code
public function testOfPublishedViewsHandler() {
// Add fields to the state_flow_history_entity Field API integration can be
// tested.
$this
->_addtextfield();
// This array holds values added to Field API fields on a
// state_flow_history_entity.
// The 0 index in the array is a dummy value so that the next '1' index
// value syncs up with
// node revision 1.
$field_text = array(
'placeholder_at_zero_key',
);
// Make a dummy node to offset revision ids. This accommodates that Views
// bug in http://drupal.org/node/1862014
debug('Make node 1, vid: 1');
$edit = array();
$new_title = $this
->randomName(8);
$edit['title'] = $new_title;
$edit['event'] = 'keep in draft';
// @todo, test presence of comment.
$edit['event_comment'] = $this
->randomName(8);
$field_text[] = $edit['field_sfhe_text[und][0][value]'] = $this
->randomName(8);
$this
->drupalPost("node/add/article", $edit, t('Save'));
// Then make another revision of the first node.
debug('Create new revision for node 1, vid: 2');
$edit = array();
$new_title = $this
->randomName(8);
$edit['title'] = $new_title;
$edit['event'] = 'keep in draft';
$edit['event_comment'] = $this
->randomName(8);
$field_text[] = $edit['field_sfhe_text[und][0][value]'] = $this
->randomName(8);
$edit['revision'] = TRUE;
$this
->drupalPost("node/1/edit", $edit, t('Save'));
// // Here's the real test.
// Make a new node.
// nid: 2, vid: 3
debug('Create new node 2: vid: 3');
$edit = array();
$new_title = $this
->randomName(8);
$edit['title'] = $new_title;
$edit['event'] = 'keep in draft';
$edit['event_comment'] = $this
->randomName(8);
$field_text[] = $edit['field_sfhe_text[und][0][value]'] = $this
->randomName(8);
$this
->drupalPost("node/add/article", $edit, t('Save'));
// Then make another revision of the second node.
// nid: 2, vid: 4
debug('Create new revision for node 2, vid: 4');
$edit = array();
$new_title = $this
->randomName(8);
$edit['title'] = $new_title;
$edit['event'] = 'keep in draft';
$edit['event_comment'] = $this
->randomName(8);
$field_text[] = $edit['field_sfhe_text[und][0][value]'] = $this
->randomName(8);
$edit['revision'] = 1;
$this
->drupalPost("node/2/edit", $edit, t('Save'));
// Publish revision 4.
// nid: 2, vid: 4
debug('Pubish revision 4 of node 2');
$edit = array();
$edit['event'] = 'publish';
$edit['event_comment'] = $this
->randomName(8);
$field_text[] = $edit['field_sfhe_text[und][0][value]'] = $this
->randomName(8);
$this
->drupalPost("node/2/revisions-state-flow-states", $edit, t('Update State'));
// Make revision 5.
// nid: 2, vid: 5 -> forward rev. nid: 2, vid: 6
debug('Create new revision for node 2, vid: 5');
debug('Forward revision for published vid: 4 of node 2 is created, vid: 6');
$edit = array();
$new_title = $this
->randomName(8);
$edit['title'] = $new_title;
$edit['event'] = 'to draft';
$edit['event_comment'] = $this
->randomName(8);
$field_text[] = $edit['field_sfhe_text[und][0][value]'] = $this
->randomName(8);
$edit['revision'] = 1;
$this
->drupalPost("node/2/edit", $edit, t('Save'));
// Publish revision 5.
// nid: 2 vid: 5
debug('Pubish revision 5 of node 2');
debug('No forward revisioning necessary. vid 5 is just set as active in the node table.');
$edit = array();
$edit['event'] = 'publish';
$edit['event_comment'] = $this
->randomName(8);
$field_text[] = $edit['field_sfhe_text[und][0][value]'] = $this
->randomName(8);
$this
->drupalPost("node/2/revisions-state-flow-states", $edit, t('Update State'));
$this
->drupalGet('node/2/revisions-state-flow-states');
// Make revision 6.
// nid: 2 vid: 7 -> forward rev. nid: 2, vid: 8
debug('Create new revision for node 2, vid: 7');
debug('Forward revision for published vid: 5 of node 2 is created, vid: 8');
$edit = array();
$new_title = $this
->randomName(8);
$edit['title'] = $new_title;
$edit['event'] = 'to draft';
$edit['event_comment'] = $this
->randomName(8);
$field_text[] = $edit['field_sfhe_text[und][0][value]'] = $this
->randomName(8);
$edit['revision'] = 1;
$this
->drupalPost("node/2/edit", $edit, t('Save'));
debug('field_texts: <pre>' . print_r($field_text, TRUE) . '</pre>');
// Check the states page.
$this
->drupalGet('node/2/revisions-state-flow-states');
// Make sure that the list handler is present.
// (state_flow_entity_handler_field_state_flow_states_history_list.inc)
// @todo, shouldn't this be xpath?
$this
->assertRaw('views-field-history-list');
// Verify that CSS was added.
$this
->assertRaw('modules/state_flow_entity/css/state_flow_entity.css', 'CSS has been added');
// Set the testing xpath string and initial replacement patterns.
// @todo, add xpath comments.
$xpath_string = "//tbody/tr[\n\n ./td/a[contains(@href, :revision_url)]\n and ./td[@class=:state_class and contains(., :state_value)]\n and contains(concat(' ', @class), :row_class)\n and ./td/div[@class=:hid_class and contains(., :hid_text)]\n and ./td/div[\n @class=:hid_class\n and ./div[\n @class='state-flow-history-entity-content'\n and ./div[contains(concat(' ', @class, ' '), :field_class)]\n and ./div[contains(., :field_text)]\n ]\n ]\n and ./td[contains(., :published_value)]\n ]";
$xpath_replacements = array(
':row_class' => 'state-flow--is-published--no',
':revision_url' => url('node/2/revisions/3/view'),
':state_value' => 'Draft',
':state_class' => 'views-field views-field-state',
':hid_class' => 'state-flow-history-entity-hid-3',
':published_value' => '',
':hid_text' => 'draft --> draft',
':field_class' => 'field-name-field-sfhe-text',
':field_text' => $field_text[3],
);
// Check revision 3.
$tr = $this
->xpath($xpath_string, $xpath_replacements);
$this
->assertEqual(count($tr), 1, 'There is a table row with for revision 3. It is in a Draft state and not in the node table.');
// Check revision 4.
$xpath_replacements[':revision_url'] = url('node/2/revisions/4/view');
$xpath_replacements[':state_value'] = 'Published';
$xpath_replacements[':hid_class'] = 'state-flow-history-entity-hid-4';
$xpath_replacements[':hid_text'] = 'draft --> draft';
$xpath_replacements[':field_text'] = $field_text[4];
$tr = $this
->xpath($xpath_string, $xpath_replacements);
$this
->assertEqual(count($tr), 1, 'There is a table row with for revision 4. It is in a Published state and not in the node table.');
// Check the other history entity in revision 4.
$xpath_replacements[':hid_text'] = 'draft --> published';
$xpath_replacements[':hid_class'] = 'state-flow-history-entity-hid-5';
$xpath_replacements[':field_text'] = $field_text[5];
$tr = $this
->xpath($xpath_string, $xpath_replacements);
$this
->assertEqual(count($tr), 1, 'Revision 4 contains the correct draft --> published record.');
// Check revision 5.
$xpath_replacements[':revision_url'] = url('node/2/revisions/5/view');
$xpath_replacements[':state_value'] = 'Published';
$xpath_replacements[':published_value'] = '';
$xpath_replacements[':row_class'] = 'state-flow--is-published--no';
$xpath_replacements[':hid_text'] = 'published --> draft';
$xpath_replacements[':hid_class'] = 'state-flow-history-entity-hid-6';
$xpath_replacements[':field_text'] = $field_text[6];
$tr = $this
->xpath($xpath_string, $xpath_replacements);
$this
->verbose($this
->buildXPathQuery($xpath_string, $xpath_replacements));
$this
->assertEqual(count($tr), 1, 'There is a table row with for revision 5. It is in a Draft state and not in the node table.');
// Check other state of revision 5.
$xpath_replacements[':hid_text'] = 'draft --> published';
$xpath_replacements[':hid_class'] = 'state-flow-history-entity-hid-9';
$xpath_replacements[':field_text'] = $field_text[7];
$tr = $this
->xpath($xpath_string, $xpath_replacements);
$this
->verbose($this
->buildXPathQuery($xpath_string, $xpath_replacements));
$this
->assertEqual(count($tr), 1, 'Revision 5 contains the correct draft --> published record.');
// Check the forward revision 8 of revision 5 and the other history entity.
$xpath_replacements[':revision_url'] = url('node/2/revisions/8/view');
$xpath_replacements[':state_value'] = 'Published';
$xpath_replacements[':published_value'] = 'Published';
$xpath_replacements[':row_class'] = 'state-flow--is-published--yes';
$xpath_replacements[':hid_text'] = 'draft --> published';
$xpath_replacements[':hid_class'] = 'state-flow-history-entity-hid-12';
$xpath_replacements[':field_text'] = $field_text[7];
$tr = $this
->xpath($xpath_string, $xpath_replacements);
$this
->verbose($this
->buildXPathQuery($xpath_string, $xpath_replacements));
$this
->assertEqual(count($tr), 1, 'There is a table row with for revision 8. It is in a Published state and in the node table.');
$this
->assertEqual(count($tr), 1, 'Revision 8 contains the correct draft --> published record.');
// Check the other history entity in revision 8.
$xpath_replacements[':hid_text'] = 'published --> draft';
$xpath_replacements[':hid_class'] = 'state-flow-history-entity-hid-11';
$xpath_replacements[':field_text'] = $field_text[6];
$tr = $this
->xpath($xpath_string, $xpath_replacements);
$this
->verbose($this
->buildXPathQuery($xpath_string, $xpath_replacements));
$this
->assertEqual(count($tr), 1, 'Revision 8 contains the correct published --> draft record.');
// Check revision 6.
$xpath_replacements[':revision_url'] = url('node/2/revisions/7/view');
$xpath_replacements[':state_value'] = 'Draft';
$xpath_replacements[':published_value'] = '';
$xpath_replacements[':row_class'] = 'state-flow--is-published--no';
$xpath_replacements[':hid_class'] = 'state-flow-history-entity-hid-10';
$xpath_replacements[':hid_text'] = 'published --> draft';
$xpath_replacements[':field_text'] = $field_text[8];
$tr = $this
->xpath($xpath_string, $xpath_replacements);
$this
->assertEqual(count($tr), 1, 'There is a table row with for revision 6. It is in a Draft state and not in the node table.');
// Test the unpublish step and verify the Views results.
// Unpublish the whole node.
$edit = array();
$edit['event'] = 'unpublish';
$edit['event_comment'] = $this
->randomName(8);
$field_text[] = $edit['field_sfhe_text[und][0][value]'] = $this
->randomName(8);
$this
->drupalPost("node/2/revisions-state-flow-states", $edit, t('Update State'));
// Check the states page.
$this
->drupalGet('node/2/revisions-state-flow-states');
$xpath_replacements[':state_value'] = 'Unpublished';
$xpath_replacements[':hid_class'] = 'state-flow-history-entity-hid-13';
$xpath_replacements[':hid_text'] = 'draft --> unpublished';
$xpath_replacements[':field_text'] = $field_text[9];
$tr = $this
->xpath($xpath_string, $xpath_replacements);
$this
->assertEqual(count($tr), 1);
// Check revision 5.
$xpath_replacements[':revision_url'] = url('node/2/revisions/5/view');
$xpath_replacements[':state_value'] = 'Published';
$xpath_replacements[':published_value'] = '';
$xpath_replacements[':row_class'] = 'state-flow--is-published--no';
$xpath_replacements[':hid_text'] = 'published --> draft';
$xpath_replacements[':hid_class'] = 'state-flow-history-entity-hid-6';
$xpath_replacements[':field_text'] = $field_text[6];
$tr = $this
->xpath($xpath_string, $xpath_replacements);
$this
->assertEqual(count($tr), 1, 'There is a table row with for revision 5. It is in a Published state and in the node table.');
}