Skip to content

Commit

Permalink
New tests for get_option_titles
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasreischmann committed Jan 16, 2015
1 parent 401cd69 commit 6559159
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions tests/locallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,69 @@ public function test_get_ratable_choices(){
$ratingallocate = mod_ratingallocate_generator::get_ratingallocate_for_user($this, $test_module->mod_db, $test_module->teacher);
$this->assertCount(1,$ratingallocate->get_rateable_choices());
}

/**
* Test if option titles are returned according to the default values
*/
public function test_get_option_titles_default(){
$expected_result = array(1 => 'Yes',0 => 'No'); //Depends on language file
$ratings = array(0,1,1,1,0);

$record = mod_ratingallocate_generator::get_default_values();
$test_module = new mod_ratingallocate_generated_module($this,$record);
$ratingallocate = mod_ratingallocate_generator::get_ratingallocate_for_user($this, $test_module->mod_db, $test_module->teacher);

$result = $ratingallocate->get_options_titles($ratings);
$this->assertEquals($expected_result,$result);
}

/**
* Test if option titles are returned according to defined custom values
*/
public function test_get_option_titles_custom(){
$expected_result = array(1 => 'Ja1234', 0 => 'Nein1234'); //Test data
$ratings = array(1,1,1,0,1,1);

$record = mod_ratingallocate_generator::get_default_values();
$record['strategyopt']['strategy_yesno'] = $expected_result;
$test_module = new mod_ratingallocate_generated_module($this,$record);
$ratingallocate = mod_ratingallocate_generator::get_ratingallocate_for_user($this, $test_module->mod_db, $test_module->teacher);

$result = $ratingallocate->get_options_titles($ratings);
$this->assertEquals($expected_result,$result);
}

/**
* Test if option titles are returned according to defined custom values, if ratings consist of just one rating
*/
public function test_get_option_titles_custom1(){
$expected_result = array(1 => 'Ja1234'); //Test data
$ratings = array(1,1,1,1,1);

$record = mod_ratingallocate_generator::get_default_values();
$record['strategyopt']['strategy_yesno'] = $expected_result;
$test_module = new mod_ratingallocate_generated_module($this,$record);
$ratingallocate = mod_ratingallocate_generator::get_ratingallocate_for_user($this, $test_module->mod_db, $test_module->teacher);

$result = $ratingallocate->get_options_titles($ratings);
$this->assertEquals($expected_result,$result);
}

/**
* Test if option titles are returned according to a mixture of defined and custom values,
*/
public function test_get_option_titles_mixed(){
$settings = array(1 => 'Ja1234'); //Test data
$ratings = array(0,1,1,1,1);
$expected_result = $settings;
$expected_result [0] = 'No'; //Depends on language file

$record = mod_ratingallocate_generator::get_default_values();
$record['strategyopt']['strategy_yesno'] = $settings;
$test_module = new mod_ratingallocate_generated_module($this,$record);
$ratingallocate = mod_ratingallocate_generator::get_ratingallocate_for_user($this, $test_module->mod_db, $test_module->teacher);

$result = $ratingallocate->get_options_titles($ratings);
$this->assertEquals($expected_result,$result);
}
}

0 comments on commit 6559159

Please sign in to comment.