| Línea 41... | 
            Línea 41... | 
          
          
            | 41 | 
             * @package   core_grades
  | 
            41 | 
             * @package   core_grades
  | 
          
          
            | 42 | 
             * @category  test
  | 
            42 | 
             * @category  test
  | 
          
          
            | 43 | 
             * @copyright 2016 Jun Pataleta <jun@moodle.com>
  | 
            43 | 
             * @copyright 2016 Jun Pataleta <jun@moodle.com>
  | 
          
          
            | 44 | 
             * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  | 
            44 | 
             * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  | 
          
          
            | 45 | 
             */
  | 
            45 | 
             */
  | 
          
          
            | 46 | 
            class lib_test extends \advanced_testcase {
  | 
            46 | 
            final class lib_test extends \advanced_testcase {
  | 
          
          
            | Línea 47... | 
            Línea 47... | 
          
          
            | 47 | 
             
  | 
            47 | 
             
  | 
          
          
            | 48 | 
                /**
  | 
            48 | 
                /**
  | 
          
          
            | 49 | 
                 * Test can_output_item.
  | 
            49 | 
                 * Test can_output_item.
  | 
          
          
            | 50 | 
                 */
  | 
            50 | 
                 */
  | 
          
          
            | Línea 368... | 
            Línea 368... | 
          
          
            | 368 | 
                    }
  | 
            368 | 
                    }
  | 
          
          
            | 369 | 
                }
  | 
            369 | 
                }
  | 
          
          
            | Línea 370... | 
            Línea 370... | 
          
          
            | 370 | 
             
  | 
            370 | 
             
  | 
          
          
            | 371 | 
                /**
  | 
            371 | 
                /**
  | 
          
          
            | 372 | 
                 * Tests that ungraded_counts calculates count and sum of grades correctly when there are hidden grades.
  | 
            372 | 
                 * Tests that ungraded_counts calculates count and sum of grades correctly when there are hidden grades.
  | 
          
          
            | 373 | 
                 * @dataProvider ungraded_counts_hidden_grades_data()
  | 
            373 | 
                 * @dataProvider ungraded_counts_hidden_grades_data
  | 
          
          
            | 374 | 
                 * @param bool $hidden Whether to inlcude hidden grades or not.
  | 
            374 | 
                 * @param bool $hidden Whether to inlcude hidden grades or not.
  | 
          
          
            | 375 | 
                 * @param array $expectedcount expected count value (i.e. number of ugraded grades)
  | 
            375 | 
                 * @param array $expectedcount expected count value (i.e. number of ugraded grades)
  | 
          
          
            | 376 | 
                 * @param array $expectedsumarray expceted sum of grades
  | 
            376 | 
                 * @param array $expectedsumarray expceted sum of grades
  | 
          
          
            | 377 | 
                 *
  | 
            377 | 
                 *
  | 
          
          
            | Línea 455... | 
            Línea 455... | 
          
          
            | 455 | 
                /**
  | 
            455 | 
                /**
  | 
          
          
            | 456 | 
                 * Data provider for test_ungraded_counts_hidden_grades
  | 
            456 | 
                 * Data provider for test_ungraded_counts_hidden_grades
  | 
          
          
            | 457 | 
                 *
  | 
            457 | 
                 *
  | 
          
          
            | 458 | 
                 * @return array of testing scenarios
  | 
            458 | 
                 * @return array of testing scenarios
  | 
          
          
            | 459 | 
                 */
  | 
            459 | 
                 */
  | 
          
          
            | 460 | 
                public function ungraded_counts_hidden_grades_data(): array {
  | 
            460 | 
                public static function ungraded_counts_hidden_grades_data(): array {
  | 
          
          
            | 461 | 
                    return [
  | 
            461 | 
                    return [
  | 
          
          
            | 462 | 
                        'nohidden' => [
  | 
            462 | 
                        'nohidden' => [
  | 
          
          
            | 463 | 
                            'hidden' => false,
  | 
            463 | 
                            'hidden' => false,
  | 
          
          
            | 464 | 
                            'count' => ['course' => 1, 'Grade item1' => 1],
  | 
            464 | 
                            'expectedcount' => ['course' => 1, 'Grade item1' => 1],
  | 
          
          
            | 465 | 
                            'sumarray' => ['course' => 6.00000, 'Grade item1' => 3.00000],
  | 
            465 | 
                            'expectedsumarray' => ['course' => 6.00000, 'Grade item1' => 3.00000],
  | 
          
          
            | 466 | 
                        ],
  | 
            466 | 
                        ],
  | 
          
          
            | 467 | 
                        'includehidden' => [
  | 
            467 | 
                        'includehidden' => [
  | 
          
          
            | 468 | 
                            'hidden' => true,
  | 
            468 | 
                            'hidden' => true,
  | 
          
          
            | 469 | 
                            'count' => ['course' => 1, 'Grade item1' => 2],
  | 
            469 | 
                            'expectedcount' => ['course' => 1, 'Grade item1' => 2],
  | 
          
          
            | 470 | 
                            'sumarray' => ['course' => 6.00000, 'Grade item1' => 6.00000],
  | 
            470 | 
                            'expectedsumarray' => ['course' => 6.00000, 'Grade item1' => 6.00000],
  | 
          
          
            | 471 | 
                        ],
  | 
            471 | 
                        ],
  | 
          
          
            | 472 | 
                    ];
  | 
            472 | 
                    ];
  | 
          
          
            | 473 | 
                }
  | 
            473 | 
                }
  | 
          
          
            | Línea 474... | 
            Línea 474... | 
          
          
            | 474 | 
             
  | 
            474 | 
             
  | 
          
          
            | Línea 628... | 
            Línea 628... | 
          
          
            | 628 | 
                    }
  | 
            628 | 
                    }
  | 
          
          
            | 629 | 
                }
  | 
            629 | 
                }
  | 
          
          
            | Línea 630... | 
            Línea 630... | 
          
          
            | 630 | 
             
  | 
            630 | 
             
  | 
          
          
            | 631 | 
                /**
  | 
            631 | 
                /**
  | 
          
          
            | 632 | 
                 * Tests that ungraded_counts calculates count and sum of grades correctly when there are hidden grades.
  | 
            632 | 
                 * Tests that ungraded_counts calculates count and sum of grades correctly when there are hidden grades.
  | 
          
          
            | 633 | 
                 * @dataProvider ungraded_counts_only_active_enrol_data()
  | 
            633 | 
                 * @dataProvider ungraded_counts_only_active_enrol_data
  | 
          
          
            | 634 | 
                 * @param bool $onlyactive Site setting to show only active users.
  | 
            634 | 
                 * @param bool $onlyactive Site setting to show only active users.
  | 
          
          
            | 635 | 
                 * @param int $hascapability Capability constant
  | 
            635 | 
                 * @param int $hascapability Capability constant
  | 
          
          
            | 636 | 
                 * @param bool|null $showonlyactiveenrolpref Show only active user preference.
  | 
            636 | 
                 * @param bool|null $showonlyactiveenrolpref Show only active user preference.
  | 
          
          
            | 637 | 
                 * @param array $expectedcount expected count value (i.e. number of ugraded grades)
  | 
            637 | 
                 * @param array $expectedcount expected count value (i.e. number of ugraded grades)
  | 
          
          
            | Línea 728... | 
            Línea 728... | 
          
          
            | 728 | 
                /**
  | 
            728 | 
                /**
  | 
          
          
            | 729 | 
                 * Data provider for test_ungraded_counts_hidden_grades
  | 
            729 | 
                 * Data provider for test_ungraded_counts_hidden_grades
  | 
          
          
            | 730 | 
                 *
  | 
            730 | 
                 *
  | 
          
          
            | 731 | 
                 * @return array of testing scenarios
  | 
            731 | 
                 * @return array of testing scenarios
  | 
          
          
            | 732 | 
                 */
  | 
            732 | 
                 */
  | 
          
          
            | 733 | 
                public function ungraded_counts_only_active_enrol_data(): array {
  | 
            733 | 
                public static function ungraded_counts_only_active_enrol_data(): array {
  | 
          
          
            | 734 | 
                    return [
  | 
            734 | 
                    return [
  | 
          
          
            | 735 | 
                        'Show only active and no user preference' => [
  | 
            735 | 
                        'Show only active and no user preference' => [
  | 
          
          
            | 736 | 
                            'onlyactive' => true,
  | 
            736 | 
                            'onlyactive' => true,
  | 
          
          
            | 737 | 
                            'hascapability' => 1,
  | 
            737 | 
                            'hascapability' => 1,
  | 
          
          
            | 738 | 
                            'showonlyactiveenrolpref' => null,
  | 
            738 | 
                            'showonlyactiveenrolpref' => null,
  | 
          
          
            | 739 | 
                            'count' => ['course' => 1, 'Grade item1' => 1],
  | 
            739 | 
                            'expectedcount' => ['course' => 1, 'Grade item1' => 1],
  | 
          
          
            | 740 | 
                            'sumarray' => ['course' => 1, 'Grade item1' => 1.00000],
  | 
            740 | 
                            'expectedsumarray' => ['course' => 1, 'Grade item1' => 1.00000],
  | 
          
          
            | 741 | 
                        ],
  | 
            741 | 
                        ],
  | 
          
          
            | 742 | 
                        'Show only active and user preference set to true' => [
  | 
            742 | 
                        'Show only active and user preference set to true' => [
  | 
          
          
            | 743 | 
                            'onlyactive' => true,
  | 
            743 | 
                            'onlyactive' => true,
  | 
          
          
            | 744 | 
                            'hascapability' => 1,
  | 
            744 | 
                            'hascapability' => 1,
  | 
          
          
            | 745 | 
                            'showonlyactiveenrolpref' => true,
  | 
            745 | 
                            'showonlyactiveenrolpref' => true,
  | 
          
          
            | 746 | 
                            'count' => ['course' => 1, 'Grade item1' => 1],
  | 
            746 | 
                            'expectedcount' => ['course' => 1, 'Grade item1' => 1],
  | 
          
          
            | 747 | 
                            'sumarray' => ['course' => 1, 'Grade item1' => 1.00000],
  | 
            747 | 
                            'expectedsumarray' => ['course' => 1, 'Grade item1' => 1.00000],
  | 
          
          
            | 748 | 
                        ],
  | 
            748 | 
                        ],
  | 
          
          
            | 749 | 
                        'Show only active and user preference set to false' => [
  | 
            749 | 
                        'Show only active and user preference set to false' => [
  | 
          
          
            | 750 | 
                            'onlyactive' => true,
  | 
            750 | 
                            'onlyactive' => true,
  | 
          
          
            | 751 | 
                            'hascapability' => 1,
  | 
            751 | 
                            'hascapability' => 1,
  | 
          
          
            | 752 | 
                            'showonlyactiveenrolpref' => false,
  | 
            752 | 
                            'showonlyactiveenrolpref' => false,
  | 
          
          
            | 753 | 
                            'count' => ['course' => 1, 'Grade item1' => 1],
  | 
            753 | 
                            'expectedcount' => ['course' => 1, 'Grade item1' => 1],
  | 
          
          
            | 754 | 
                            'sumarray' => ['course' => 3.00000, 'Grade item1' => 3.00000],
  | 
            754 | 
                            'expectedsumarray' => ['course' => 3.00000, 'Grade item1' => 3.00000],
  | 
          
          
            | 755 | 
                        ],
  | 
            755 | 
                        ],
  | 
          
          
            | 756 | 
                        'Include suspended with capability and user preference set to true' => [
  | 
            756 | 
                        'Include suspended with capability and user preference set to true' => [
  | 
          
          
            | 757 | 
                            'onlyactive' => false,
  | 
            757 | 
                            'onlyactive' => false,
  | 
          
          
            | 758 | 
                            'hascapability' => 1,
  | 
            758 | 
                            'hascapability' => 1,
  | 
          
          
            | 759 | 
                            'showonlyactiveenrolpref' => true,
  | 
            759 | 
                            'showonlyactiveenrolpref' => true,
  | 
          
          
            | 760 | 
                            'count' => ['course' => 1, 'Grade item1' => 1],
  | 
            760 | 
                            'expectedcount' => ['course' => 1, 'Grade item1' => 1],
  | 
          
          
            | 761 | 
                            'sumarray' => ['course' => 1.00000, 'Grade item1' => 1.00000],
  | 
            761 | 
                            'expectedsumarray' => ['course' => 1.00000, 'Grade item1' => 1.00000],
  | 
          
          
            | 762 | 
                        ],
  | 
            762 | 
                        ],
  | 
          
          
            | 763 | 
                        'Include suspended with capability and user preference set to false' => [
  | 
            763 | 
                        'Include suspended with capability and user preference set to false' => [
  | 
          
          
            | 764 | 
                            'onlyactive' => false,
  | 
            764 | 
                            'onlyactive' => false,
  | 
          
          
            | 765 | 
                            'hascapability' => 1,
  | 
            765 | 
                            'hascapability' => 1,
  | 
          
          
            | 766 | 
                            'showonlyactiveenrolpref' => false,
  | 
            766 | 
                            'showonlyactiveenrolpref' => false,
  | 
          
          
            | 767 | 
                            'count' => ['course' => 1, 'Grade item1' => 1],
  | 
            767 | 
                            'expectedcount' => ['course' => 1, 'Grade item1' => 1],
  | 
          
          
            | 768 | 
                            'sumarray' => ['course' => 3.00000, 'Grade item1' => 3.00000],
  | 
            768 | 
                            'expectedsumarray' => ['course' => 3.00000, 'Grade item1' => 3.00000],
  | 
          
          
            | 769 | 
                        ],
  | 
            769 | 
                        ],
  | 
          
          
            | 770 | 
                        'Include suspended with capability and no user preference' => [
  | 
            770 | 
                        'Include suspended with capability and no user preference' => [
  | 
          
          
            | 771 | 
                            'onlyactive' => false,
  | 
            771 | 
                            'onlyactive' => false,
  | 
          
          
            | 772 | 
                            'hascapability' => 1,
  | 
            772 | 
                            'hascapability' => 1,
  | 
          
          
            | 773 | 
                            'showonlyactiveenrolpref' => null,
  | 
            773 | 
                            'showonlyactiveenrolpref' => null,
  | 
          
          
            | 774 | 
                            'count' => ['course' => 1, 'Grade item1' => 1],
  | 
            774 | 
                            'expectedcount' => ['course' => 1, 'Grade item1' => 1],
  | 
          
          
            | 775 | 
                            'sumarray' => ['course' => 3.00000, 'Grade item1' => 3.00000],
  | 
            775 | 
                            'expectedsumarray' => ['course' => 3.00000, 'Grade item1' => 3.00000],
  | 
          
          
            | 776 | 
                        ],
  | 
            776 | 
                        ],
  | 
          
          
            | 777 | 
                        'Include suspended without capability' => [
  | 
            777 | 
                        'Include suspended without capability' => [
  | 
          
          
            | 778 | 
                            'onlyactive' => false,
  | 
            778 | 
                            'onlyactive' => false,
  | 
          
          
            | 779 | 
                            'hascapability' => -1,
  | 
            779 | 
                            'hascapability' => -1,
  | 
          
          
            | 780 | 
                            'showonlyactiveenrolpref' => null,
  | 
            780 | 
                            'showonlyactiveenrolpref' => null,
  | 
          
          
            | 781 | 
                            'count' => ['course' => 1, 'Grade item1' => 1],
  | 
            781 | 
                            'expectedcount' => ['course' => 1, 'Grade item1' => 1],
  | 
          
          
            | 782 | 
                            'sumarray' => ['course' => 1.00000, 'Grade item1' => 1.00000],
  | 
            782 | 
                            'expectedsumarray' => ['course' => 1.00000, 'Grade item1' => 1.00000],
  | 
          
          
            | 783 | 
                        ],
  | 
            783 | 
                        ],
  | 
          
          
            | 784 | 
                    ];
  | 
            784 | 
                    ];
  | 
          
          
            | 785 | 
                }
  | 
            785 | 
                }
  | 
          
          
            | Línea 786... | 
            Línea 786... | 
          
          
            | 786 | 
             
  | 
            786 | 
             
  | 
          
          
            | 787 | 
                /**
  | 
            787 | 
                /**
  | 
          
          
            | 788 | 
                 * Tests for calculate_average.
  | 
            788 | 
                 * Tests for calculate_average.
  | 
          
          
            | 789 | 
                 * @dataProvider calculate_average_data()
  | 
            789 | 
                 * @dataProvider calculate_average_data
  | 
          
          
            | 790 | 
                 * @param int $meanselection Whether to inlcude all grades or non-empty grades in aggregation.
  | 
            790 | 
                 * @param int $meanselection Whether to inlcude all grades or non-empty grades in aggregation.
  | 
          
          
            | 791 | 
                 * @param array $expectedmeancount expected meancount value
  | 
            791 | 
                 * @param array $expectedmeancount expected meancount value
  | 
          
          
            | 792 | 
                 * @param array $expectedaverage expceted average value
  | 
            792 | 
                 * @param array $expectedaverage expceted average value
  | 
          
          
            | 793 | 
                 *
  | 
            793 | 
                 *
  | 
          
          
            | Línea 876... | 
            Línea 876... | 
          
          
            | 876 | 
                /**
  | 
            876 | 
                /**
  | 
          
          
            | 877 | 
                 * Data provider for test_calculate_average
  | 
            877 | 
                 * Data provider for test_calculate_average
  | 
          
          
            | 878 | 
                 *
  | 
            878 | 
                 *
  | 
          
          
            | 879 | 
                 * @return array of testing scenarios
  | 
            879 | 
                 * @return array of testing scenarios
  | 
          
          
            | 880 | 
                 */
  | 
            880 | 
                 */
  | 
          
          
            | 881 | 
                public function calculate_average_data(): array {
  | 
            881 | 
                public static function calculate_average_data(): array {
  | 
          
          
            | 882 | 
                    return [
  | 
            882 | 
                    return [
  | 
          
          
            | 883 | 
                        'Non-empty grades' => [
  | 
            883 | 
                        'Non-empty grades' => [
  | 
          
          
            | 884 | 
                            'meanselection' => 1,
  | 
            884 | 
                            'meanselection' => 1,
  | 
          
          
            | 885 | 
                            'expectedmeancount' => [' course' => 3, 'Assignment 1 mod' => 2, 'Assignment 2 mod' => 2,
  | 
            885 | 
                            'expectedmeancount' => [' course' => 3, 'Assignment 1 mod' => 2, 'Assignment 2 mod' => 2,
  | 
          
          
            | 886 | 
                                'Quiz 1 mod' => 0, 'Grade item1 manual' => 2],
  | 
            886 | 
                                'Quiz 1 mod' => 0, 'Grade item1 manual' => 2],
  |