You are here

page_view.test in SimpleTest 5

Same filename and directory in other branches
  1. 6 tests/page_view.test

File

tests/page_view.test
View source
<?php

class PageViewTest extends DrupalTestCase {

  /**
   * Implementation of get_info() for information
   */
  function get_info() {
    return array(
      'name' => t('Unauthorized node view'),
      'desc' => t('Creates a node of type page and then an unpermissioned user attempts to edit the node, ' . 'before tries with an anonymous user. Asserts failure.' . '</ br>WARNING: This is based on default registered user permuissions (no administer nodes).'),
      'group' => 'Node Tests',
    );
  }
  function testPageView() {

    /* Prepare a node to view */
    global $user;
    $node = new stdClass();
    $node->body = $this
      ->randomName(32);
    $node->title = $this
      ->randomName(8);
    $node->teaser = $node->body;
    $node->comment = '2';
    $node->created = time();
    $node->date = format_date($node->created, 'custom', 'Y-m-d H:i:s O');
    $node->format = '1';
    $node->moderate = 0;
    $node->name = $user->name;
    $node->uid = $user->uid;
    $node->promote = 0;
    $node->revision = 0;
    $node->status = '1';
    $node->sticky = 0;
    $node->type = 'page';
    $node->revisions = NULL;
    $node->changed = $node->created;
    $node->taxonomy = NULL;
    node_save($node);
    $this
      ->assertNotNull(node_load($node->nid), 'Node created');

    /* Tries to edit with anonymous user */
    $html = $this
      ->drupalGet(url("node/{$node->nid}/edit", NULL, NULL, TRUE));
    $this
      ->assertResponse(403);

    /* Prepare a user to request the node view */
    $test_user = $this
      ->drupalCreateUserRolePerm(array(
      'access content',
    ));
    $this
      ->drupalLoginUser($test_user);
    $html = $this
      ->drupalGet(url("node/{$node->nid}/edit", NULL, NULL, TRUE));
    $this
      ->assertResponse(403);
    $test_user = $this
      ->drupalCreateUserRolePerm(array(
      'administer nodes',
    ));
    node_delete(array(
      'nid' => $node->nid,
    ));
  }

}

Classes

Namesort descending Description
PageViewTest