I was writing a test for the blog module using SimpleTest when I found the following issue.

$this->own_user = $this->drupalCreateUser(array('create blog content', 'edit own blog content', 'delete own blog content'));
$this->drupalLogin($this->own_user);

// Create test node.
$node1 = $this->drupalCreateNode(array('type' => 'blog'));
$this->drupalGet('node/'. $node1->nid);
  	
var_dump($this->drupalGetContent());

// Edit test node.
$edit = array();
$edit['title'] = 'node/' . $node1->nid;
$edit['body'] = $this->randomName(8);
$this->drupalPost('node/'. $node1->nid .'/edit', $edit, t('Save'));
    
$this->assertWantedRaw(t('Blog entry %title has been updated.', array('%title' => $edit['title'])), t('Node edited successfully.'));

After creating the blog node and dumping the node page, it appears the blog node was successfully created. When attempting to edit the blog node, the test failed.

When I changed the privilege to 'edit any blog content' the test passed.

Comments

boombatower’s picture

Project: Drupal core » SimpleTest
Version: 7.x-dev »
Component: blog.module » Code
Assigned: Unassigned » boombatower

Discovered that this is due to an issue in drupalCreateNode.

This is related to http://drupal.org/node/212304.

beeradb’s picture

@Boombatower: By Discovering this is due to the drupalCreateNode issue I assume you mean because when using drupalCreateNode the node is saved as the user _running_ the tests rather than the test user which is logged in?

boombatower’s picture

@beeradb: Correct. I relize this can be overcome by passing $settings['uid'] to drupalCreateNode, but doesn't make sense that it wouldn't create it as the logged in user.

@all: This could be fixed in two different ways.

  1. Store the user in DrupalTestCase and then simple access it to get the user id.
  2. Convert DrupalTestCase to use internal browser (ie. drupalPost) instead.

This is already be discussed and needs to be decided upon. This issue leads me more towards thinking it should use the second option, although we could provide either, but that could get messy.

boombatower’s picture

Project: SimpleTest » Drupal core
Version: » 7.x-dev
Component: Code » simpletest.module

Once http://drupal.org/node/212304 has been delt with this code will need to be changed.

boombatower’s picture

Component: simpletest.module » tests

Actually this is a test issue.

boombatower’s picture

Status: Active » Postponed
boombatower’s picture

Version: 7.x-dev » 8.x-dev
Component: tests » simpletest.module
Assigned: boombatower » Unassigned

Assume this is fixed, but should be evaluated against 8.x. #4 is no longer a concern.

boombatower’s picture

Status: Postponed » Active
jhedstrom’s picture

Issue summary: View changes
Status: Active » Closed (won't fix)