You are here

public function ClassifiedTestTestBasicTest::test1432606 in Classified Ads 7.3

Bug 1432606: Ads can be viewed when not published.

File

tests/classified_test_basic.test, line 386

Class

ClassifiedTestTestBasicTest
Basic test for known bugs in previous versions.

Code

public function test1432606() {
  $this->group = __FUNCTION__;
  $accounts = array(
    'admin',
    'basic',
    'creator',
  );
  $this
    ->createUsers($accounts);

  // 1. Get the Classified vocabulary id and field name.
  $vid = _classified_get('vid');
  $category_field_name = _classified_get('field-category');

  // 2a. Create a term in it, do not assign a specific lifetime.
  $term = (object) array(
    'name' => $this
      ->randomName(8),
    'description' => $this
      ->randomString(20),
    'vid' => $vid,
  );
  $status = taxonomy_term_save($term);
  $tid = $term->tid;
  $this
    ->assertEqual($status, SAVED_NEW, t('Term @tid created in default vocabulary.', array(
    '@tid' => $tid,
  )), 'setup');

  // 2b. Create a published node bearing that term, belonging to "creator".
  $node = $this
    ->createNode(array(
    $category_field_name => array(
      LANGUAGE_NONE => array(
        0 => array(
          'tid' => $tid,
        ),
      ),
    ),
    'uid' => $this->creatorUser->uid,
    'status' => 1,
  ));
  $path = 'node/' . $node->nid;

  // 3. All four profiles should see published node.
  $this
    ->drupalLogout();
  $this
    ->drupalGet($path);
  $this
    ->assertResponse(200, t('Anonymous user sees published ad.'));
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalGet($path);
  $this
    ->assertResponse(200, t('Ads administrator sees published ad.'));
  $this
    ->drupalLogin($this->basicUser);
  $this
    ->drupalGet($path);
  $this
    ->assertResponse(200, t('Non-author user sees published ad.'));
  $this
    ->drupalLogin($this->creatorUser);
  $this
    ->drupalGet($path);
  $this
    ->assertResponse(200, t('Author sees his published ad.'));

  // 4a. Unpublish the ad.
  $node->status = 0;
  node_save($node);

  // 4b. Ad is unpublished: only admin and creator should be able to see it.
  $this
    ->drupalLogout();
  $this
    ->drupalGet($path);
  $this
    ->assertResponse(403, t('Anonymous user does not see unpublished ad.'));
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalGet($path);
  $this
    ->assertResponse(200, t('Ads administrator sees unpublished ad.'));
  $this
    ->drupalLogin($this->basicUser);
  $this
    ->drupalGet($path);
  $this
    ->assertResponse(403, t('Non-author user does not see unpublished ad.'));
  $this
    ->drupalLogin($this->creatorUser);
  $this
    ->drupalGet($path);
  $this
    ->assertResponse(200, t('Author sees his unpublished ad.'));
}