function test_registrations() { $reg = null; $user_id = iclicker_service::require_user(); // try get registration $reg = iclicker_service::get_registration_by_clicker_id($this->clicker_id); $this->assertFalse($reg); // create registration $reg = iclicker_service::create_clicker_registration($this->clicker_id, $user_id); $this->assertTrue($reg); $this->assertEqual($this->clicker_id, $reg->clicker_id); $reg_id = $reg->id; $this->assertTrue($reg_id); $this->assertFalse($reg->from_national); // get registration $reg1 = iclicker_service::get_registration_by_clicker_id($this->clicker_id, $user_id); $this->assertTrue($reg1); $this->assertEqual($this->clicker_id, $reg1->clicker_id); $this->assertEqual($reg_id, $reg1->id); $reg2 = iclicker_service::get_registration_by_id($reg_id); $this->assertTrue($reg2); $this->assertEqual($this->clicker_id, $reg2->clicker_id); $this->assertEqual($reg_id, $reg2->id); // save registration $reg->from_national = 1; $save_id = iclicker_service::save_registration($reg); $this->assertTrue($save_id); $this->assertEqual($reg_id, $save_id); // check it changed $reg3 = iclicker_service::get_registration_by_id($reg_id); $this->assertTrue($reg3); $this->assertEqual($reg_id, $reg3->id); $this->assertTrue($reg3->from_national); // too fast $this->assertNotEqual($reg->timemodified, $reg3->timemodified); // make registration inactive $this->assertTrue($reg->activated); $reg4 = iclicker_service::set_registration_active($reg_id, false); $this->assertTrue($reg4); $this->assertFalse($reg4->activated); // check it changed $reg5 = iclicker_service::get_registration_by_id($reg_id); $this->assertTrue($reg5); $this->assertEqual($reg_id, $reg5->id); $this->assertEqual($reg4->id, $reg5->id); $this->assertFalse($reg5->activated); // get all registration $results = iclicker_service::get_registrations_by_user($user_id); $this->assertTrue($results); $this->assertEqual(1, count($results)); $results = iclicker_service::get_registrations_by_user($user_id, true); $this->assertNotNull($results); $this->assertFalse($results); $this->assertEqual(0, count($results)); $results = iclicker_service::get_all_registrations(); $this->assertTrue($results); $this->assertTrue(count($results) >= 1); // remove registration $result = iclicker_service::remove_registration($reg_id); $this->assertTrue($result); // try get registration $reg = iclicker_service::get_registration_by_id($reg_id); $this->assertFalse($reg); }
function test_registrations() { global $DB; $this->resetAfterTest(true); // reset all changes automatically after this test $this->setUser($this->instructorid); $reg = null; $user_id = iclicker_service::require_user(); // try get registration $reg = iclicker_service::get_registration_by_clicker_id($this->clicker_id); $this->assertFalse($reg); // create registration $reg = iclicker_service::create_clicker_registration($this->clicker_id, $user_id); $this->assertTrue(!empty($reg)); $this->assertEquals($this->clicker_id, $reg->clicker_id); $reg_id = $reg->id; $this->assertTrue(!empty($reg_id)); $this->assertEquals(0, $reg->from_national); // get registration $reg1 = iclicker_service::get_registration_by_clicker_id($this->clicker_id, $user_id); $this->assertTrue(!empty($reg1)); $this->assertEquals($this->clicker_id, $reg1->clicker_id); $this->assertEquals($reg_id, $reg1->id); $reg2 = iclicker_service::get_registration_by_id($reg_id); $this->assertTrue(!empty($reg2)); $this->assertEquals($this->clicker_id, $reg2->clicker_id); $this->assertEquals($reg_id, $reg2->id); // save registration $reg->from_national = 1; $save_id = iclicker_service::save_registration($reg); $this->assertTrue(!empty($save_id)); $this->assertEquals($reg_id, $save_id); // check it changed $reg3 = iclicker_service::get_registration_by_id($reg_id); $this->assertTrue(!empty($reg3)); $this->assertEquals($reg_id, $reg3->id); $this->assertEquals(1, $reg3->from_national); // too fast $this->assertNotEquals($reg->timemodified, $reg3->timemodified); // make registration inactive $this->assertEquals(1, $reg->activated); $reg4 = iclicker_service::set_registration_active($reg_id, false); $this->assertTrue(!empty($reg4)); $this->assertEquals(0, $reg4->activated); // check it changed $reg5 = iclicker_service::get_registration_by_id($reg_id); $this->assertTrue(!empty($reg5)); $this->assertEquals($reg_id, $reg5->id); $this->assertEquals($reg4->id, $reg5->id); $this->assertEquals(0, $reg5->activated); // get all registration $results = iclicker_service::get_registrations_by_user($user_id); $this->assertTrue(!empty($results)); $this->assertEquals(1, count($results)); $results = iclicker_service::get_registrations_by_user($user_id, true); $this->assertNotNull($results); $this->assertFalse(!empty($results)); $this->assertEquals(0, count($results)); $this->setAdminUser(); // MUST be admin $results = iclicker_service::get_all_registrations(); $this->assertTrue(!empty($results)); $this->assertTrue(count($results) >= 1); // remove registration $result = iclicker_service::remove_registration($reg_id); $this->assertTrue(!empty($results)); // try get registration $reg = iclicker_service::get_registration_by_id($reg_id); $this->assertFalse($reg); }