You are here

function MerciUserTestCase::testMerciBucketAvailability in MERCI (Manage Equipment Reservations, Checkout and Inventory) 7.2

Same name and namespace in other branches
  1. 6.2 tests/merci_user.test \MerciUserTestCase::testMerciBucketAvailability()

File

tests/merci_user.test, line 281

Class

MerciUserTestCase

Code

function testMerciBucketAvailability() {

  // Login the merci user.
  $this
    ->drupalLogin($this->merci_user);

  // Test we can reserve our three bucket items all at the same time.
  // Test the fourth reservation at the same time will fail.
  // Create our first reservation
  $node = $this->bucket1;
  $edit = array(
    'title' => $this
      ->randomName(),
    'field_merci_date[und][0][value][date]' => '2011-01-05',
    'field_merci_date[und][0][value][time]' => '09:15',
    'field_merci_date[und][0][value2][date]' => '2011-01-05',
    'field_merci_date[und][0][value2][time]' => '11:15',
    'merci_reservation_items[choice_1][merci_item_nid]' => $node->type,
  );
  $first = $this
    ->merciCreateNode('merci-reservation', $edit);
  $this
    ->assertText(t("@title has been created", array(
    '@title' => $edit['title'],
  )));

  // Assign an item to test issue #1103328
  // Login the admin user.
  $this
    ->drupalLogin($this->admin_user);

  // Cancel the last reservation.  This should Pass
  $edit = array(
    'merci_reservation_items[1][merci_item_nid]' => $node->nid,
  );
  $title = $first->title;
  $first = $this
    ->merciUpdateNode($first->nid, $edit);
  $this
    ->assertText(t("@title has been updated.", array(
    '@title' => $title,
  )));

  // Login the merci user.
  $this
    ->drupalLogin($this->merci_user);

  // Create our second reservation
  $node = $this->bucket2;
  $edit = array(
    'title' => $this
      ->randomName(),
    'field_merci_date[und][0][value][date]' => '2011-01-05',
    'field_merci_date[und][0][value][time]' => '09:15',
    'field_merci_date[und][0][value2][date]' => '2011-01-05',
    'field_merci_date[und][0][value2][time]' => '11:15',
    'merci_reservation_items[choice_1][merci_item_nid]' => $node->type,
  );
  $second = $this
    ->merciCreateNode('merci-reservation', $edit);
  $this
    ->assertText(t("@title has been created", array(
    '@title' => $edit['title'],
  )));

  // Create our third reservation
  $node = $this->bucket3;
  $edit = array(
    'title' => $this
      ->randomName(),
    'field_merci_date[und][0][value][date]' => '2011-01-05',
    'field_merci_date[und][0][value][time]' => '09:15',
    'field_merci_date[und][0][value2][date]' => '2011-01-05',
    'field_merci_date[und][0][value2][time]' => '11:15',
    'merci_reservation_items[choice_1][merci_item_nid]' => $node->type,
  );
  $third = $this
    ->merciCreateNode('merci-reservation', $edit);
  $this
    ->assertText(t("@title has been created", array(
    '@title' => $edit['title'],
  )));

  // Try to create our fourth reservation.  This should FAIL
  $node = $this->bucket3;
  $edit = array(
    'title' => $this
      ->randomName(),
    'field_merci_date[und][0][value][date]' => '2011-01-05',
    'field_merci_date[und][0][value][time]' => '09:15',
    'field_merci_date[und][0][value2][date]' => '2011-01-05',
    'field_merci_date[und][0][value2][time]' => '10:15',
    'merci_reservation_items[choice_1][merci_item_nid]' => $node->type,
  );
  $fail = $this
    ->merciCreateNode('merci-reservation', $edit, FALSE);

  //$this->assertText(t("The dates and times for @title conflict with one or more existing reservations", array('@title' => $node->type)));
  $this
    ->assertText(t("conflict with one or more existing reservations"));

  // Try creating the reservation at a different time.
  $node = $this->bucket3;
  $edit = array(
    'title' => $this
      ->randomName(),
    'field_merci_date[und][0][value][date]' => '2011-01-06',
    'field_merci_date[und][0][value][time]' => '09:15',
    'field_merci_date[und][0][value2][date]' => '2011-01-06',
    'field_merci_date[und][0][value2][time]' => '10:15',
    'merci_reservation_items[choice_1][merci_item_nid]' => $node->type,
  );
  $fourth = $this
    ->merciCreateNode('merci-reservation', $edit);
  $this
    ->assertText(t("@title has been created", array(
    '@title' => $edit['title'],
  )));

  // Test updating current reservations.
  // Also set the times so they will share a bucket item.  Tetris
  // Update second reservation.
  $edit = array(
    'field_merci_date[und][0][value][date]' => '2011-01-05',
    'field_merci_date[und][0][value][time]' => '09:15',
    'field_merci_date[und][0][value2][date]' => '2011-01-05',
    'field_merci_date[und][0][value2][time]' => '09:45',
  );
  $title = $second->title;
  $second = $this
    ->merciUpdateNode($second->nid, $edit);
  $this
    ->assertText(t("@title has been updated.", array(
    '@title' => $title,
  )));

  // Update our third reservation
  $edit = array(
    'field_merci_date[und][0][value][date]' => '2011-01-05',
    'field_merci_date[und][0][value][time]' => '10:15',
    'field_merci_date[und][0][value2][date]' => '2011-01-05',
    'field_merci_date[und][0][value2][time]' => '11:15',
  );
  $title = $third->title;
  $third = $this
    ->merciUpdateNode($third->nid, $edit);
  $this
    ->assertText(t("@title has been updated.", array(
    '@title' => $title,
  )));

  // Now that the above two reservations are sharing an item ....
  // Try to create our fourth reservation.  This should now PASS
  $node = $this->bucket3;
  $edit = array(
    'title' => $this
      ->randomName(),
    'field_merci_date[und][0][value][date]' => '2011-01-05',
    'field_merci_date[und][0][value][time]' => '09:15',
    'field_merci_date[und][0][value2][date]' => '2011-01-05',
    'field_merci_date[und][0][value2][time]' => '10:15',
    'merci_reservation_items[choice_1][merci_item_nid]' => $node->type,
  );
  $pass = $this
    ->merciCreateNode('merci-reservation', $edit);
  $this
    ->assertText(t("@title has been created", array(
    '@title' => $edit['title'],
  )));

  // Login the merci user.
  $this
    ->drupalLogin($this->admin_user);

  // Cancel the last reservation.  This should Pass
  $edit = array(
    'merci_reservation_status' => 5,
  );
  $title = $pass->title;
  $pass = $this
    ->merciUpdateNode($pass->nid, $edit);
  $this
    ->assertText(t("@title has been updated.", array(
    '@title' => $title,
  )));

  // Login the merci user.
  $this
    ->drupalLogin($this->merci_user);

  // Try to create our fifth reservation.  This should Pass
  $node = $this->bucket3;
  $edit = array(
    'title' => $this
      ->randomName(),
    'field_merci_date[und][0][value][date]' => '2011-01-05',
    'field_merci_date[und][0][value][time]' => '09:15',
    'field_merci_date[und][0][value2][date]' => '2011-01-05',
    'field_merci_date[und][0][value2][time]' => '10:15',
    'merci_reservation_items[choice_1][merci_item_nid]' => $node->type,
  );
  $pass = $this
    ->merciCreateNode('merci-reservation', $edit);
  $this
    ->assertText(t("@title has been created", array(
    '@title' => $edit['title'],
  )));
}