2013-09-14 23:57:21 +02:00
|
|
|
<?php
|
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
MDL-75111 phpunit: Move tests to use correct names and ns (take#4)
Applied the following changes to various testcase classes:
- Namespaced with component[\level2-API]
- Moved to level2-API subdirectory when required.
- Fixed incorrect use statements with leading backslash.
- Remove file phpdoc block
- Remove MOODLE_INTERNAL if not needed.
- Changed code to point to global scope when needed.
- Fix some relative paths and comments here and there.
- All them passing individually.
- Complete runs passing too.
Special mention to:
- The following task tests have been moved within the level2 directory:
- \core\adhoc_task_test => \core\task\adhoc_task_test
- \core\scheduled_task_test => \core\task\scheduled_task_test
- \core\calendar_cron_task_test => \core\task\calendar_cron_task_test
- \core\h5p_get_content_types_task_test => \core\task\h5p_get_content_types_task_test
- \core\task_database_logger_test => \core\task\database_logger_test
- \core\task_logging_test => \core\task\logging_test
- The following event tests have been moved within level2 directory:
- \core\event_context_locked_test => \core\event\context_locked_test
- \core\event_deprecated_test => \core\event\deprecated_test
- \core\event_grade_deleted_test => \core\event\grade_deleted_test
- \core\event_profile_field_test => \core\event\profile_field_test
- \core\event_unknown_logged_test => \core\event\unknown_logged_test
- \core\event_user_graded_test => \core\event\user_graded_test
- \core\event_user_password_updated_test => \core\event\user_password_updated_test
- The following output tests have been moved within level2 directory:
- \core\mustache_template_finder_test => \core\output\mustache_template_finder_test
- \core\mustache_template_source_loader_test => \core\output\mustache_template_source_loader_test
- \core\output_mustache_helper_collection_test => \core\output\mustache_helper_collection_test
- The following tests have been moved to their correct tests directories:
- lib/tests/time_splittings_test.php => analytics/tests/time_splittings_test.php
- All the classes and tests under lib/filebrowser and lib/filestorage
belong to core, not to core_files. Some day we should move
them to their correct subsystem.
- All the classes and tests under lib/grade belong to core, not
to core_grades. Some day we should move them to their correct
subsystem.
- The core_grades_external class and its \core\grades_external_test
unit test should belong to the grades subsystem or, alternatively,
to \core\external, they both should be moved together.
- The core_grading_external class and its \core\grading_external_test
unit test should belong to the grading subsystem or, alternatively,
to \core\external, they both should be moved together.
- The \core\message\message and \core\message\inbound (may be others)
classes, and their associated tests should go to the core_message
subsystem.
- The core_user class, and its associated tests should go to the
core_user subsystem.
- The \core\update namespace is plain wrong (update is not valid API)
and needs action 1) create it or 2) move elsewhere.
2022-07-01 16:43:34 +02:00
|
|
|
namespace core;
|
2013-09-14 23:57:21 +02:00
|
|
|
|
|
|
|
defined('MOODLE_INTERNAL') || die();
|
|
|
|
|
2015-10-05 15:19:09 +02:00
|
|
|
use core\update\testable_checker;
|
|
|
|
use core\update\testable_checker_cron_executed;
|
2013-09-14 23:57:21 +02:00
|
|
|
|
2015-10-05 15:19:09 +02:00
|
|
|
global $CFG;
|
|
|
|
require_once(__DIR__.'/fixtures/testable_update_checker.php');
|
2013-09-14 23:57:21 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests of the basic API of the available update checker.
|
MDL-75111 phpunit: Move tests to use correct names and ns (take#4)
Applied the following changes to various testcase classes:
- Namespaced with component[\level2-API]
- Moved to level2-API subdirectory when required.
- Fixed incorrect use statements with leading backslash.
- Remove file phpdoc block
- Remove MOODLE_INTERNAL if not needed.
- Changed code to point to global scope when needed.
- Fix some relative paths and comments here and there.
- All them passing individually.
- Complete runs passing too.
Special mention to:
- The following task tests have been moved within the level2 directory:
- \core\adhoc_task_test => \core\task\adhoc_task_test
- \core\scheduled_task_test => \core\task\scheduled_task_test
- \core\calendar_cron_task_test => \core\task\calendar_cron_task_test
- \core\h5p_get_content_types_task_test => \core\task\h5p_get_content_types_task_test
- \core\task_database_logger_test => \core\task\database_logger_test
- \core\task_logging_test => \core\task\logging_test
- The following event tests have been moved within level2 directory:
- \core\event_context_locked_test => \core\event\context_locked_test
- \core\event_deprecated_test => \core\event\deprecated_test
- \core\event_grade_deleted_test => \core\event\grade_deleted_test
- \core\event_profile_field_test => \core\event\profile_field_test
- \core\event_unknown_logged_test => \core\event\unknown_logged_test
- \core\event_user_graded_test => \core\event\user_graded_test
- \core\event_user_password_updated_test => \core\event\user_password_updated_test
- The following output tests have been moved within level2 directory:
- \core\mustache_template_finder_test => \core\output\mustache_template_finder_test
- \core\mustache_template_source_loader_test => \core\output\mustache_template_source_loader_test
- \core\output_mustache_helper_collection_test => \core\output\mustache_helper_collection_test
- The following tests have been moved to their correct tests directories:
- lib/tests/time_splittings_test.php => analytics/tests/time_splittings_test.php
- All the classes and tests under lib/filebrowser and lib/filestorage
belong to core, not to core_files. Some day we should move
them to their correct subsystem.
- All the classes and tests under lib/grade belong to core, not
to core_grades. Some day we should move them to their correct
subsystem.
- The core_grades_external class and its \core\grades_external_test
unit test should belong to the grades subsystem or, alternatively,
to \core\external, they both should be moved together.
- The core_grading_external class and its \core\grading_external_test
unit test should belong to the grading subsystem or, alternatively,
to \core\external, they both should be moved together.
- The \core\message\message and \core\message\inbound (may be others)
classes, and their associated tests should go to the core_message
subsystem.
- The core_user class, and its associated tests should go to the
core_user subsystem.
- The \core\update namespace is plain wrong (update is not valid API)
and needs action 1) create it or 2) move elsewhere.
2022-07-01 16:43:34 +02:00
|
|
|
*
|
|
|
|
* @package core
|
|
|
|
* @category test
|
|
|
|
* @copyright 2012, 2015 David Mudrak <david@moodle.com>
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
2013-09-14 23:57:21 +02:00
|
|
|
*/
|
MDL-75111 phpunit: Move tests to use correct names and ns (take#4)
Applied the following changes to various testcase classes:
- Namespaced with component[\level2-API]
- Moved to level2-API subdirectory when required.
- Fixed incorrect use statements with leading backslash.
- Remove file phpdoc block
- Remove MOODLE_INTERNAL if not needed.
- Changed code to point to global scope when needed.
- Fix some relative paths and comments here and there.
- All them passing individually.
- Complete runs passing too.
Special mention to:
- The following task tests have been moved within the level2 directory:
- \core\adhoc_task_test => \core\task\adhoc_task_test
- \core\scheduled_task_test => \core\task\scheduled_task_test
- \core\calendar_cron_task_test => \core\task\calendar_cron_task_test
- \core\h5p_get_content_types_task_test => \core\task\h5p_get_content_types_task_test
- \core\task_database_logger_test => \core\task\database_logger_test
- \core\task_logging_test => \core\task\logging_test
- The following event tests have been moved within level2 directory:
- \core\event_context_locked_test => \core\event\context_locked_test
- \core\event_deprecated_test => \core\event\deprecated_test
- \core\event_grade_deleted_test => \core\event\grade_deleted_test
- \core\event_profile_field_test => \core\event\profile_field_test
- \core\event_unknown_logged_test => \core\event\unknown_logged_test
- \core\event_user_graded_test => \core\event\user_graded_test
- \core\event_user_password_updated_test => \core\event\user_password_updated_test
- The following output tests have been moved within level2 directory:
- \core\mustache_template_finder_test => \core\output\mustache_template_finder_test
- \core\mustache_template_source_loader_test => \core\output\mustache_template_source_loader_test
- \core\output_mustache_helper_collection_test => \core\output\mustache_helper_collection_test
- The following tests have been moved to their correct tests directories:
- lib/tests/time_splittings_test.php => analytics/tests/time_splittings_test.php
- All the classes and tests under lib/filebrowser and lib/filestorage
belong to core, not to core_files. Some day we should move
them to their correct subsystem.
- All the classes and tests under lib/grade belong to core, not
to core_grades. Some day we should move them to their correct
subsystem.
- The core_grades_external class and its \core\grades_external_test
unit test should belong to the grades subsystem or, alternatively,
to \core\external, they both should be moved together.
- The core_grading_external class and its \core\grading_external_test
unit test should belong to the grading subsystem or, alternatively,
to \core\external, they both should be moved together.
- The \core\message\message and \core\message\inbound (may be others)
classes, and their associated tests should go to the core_message
subsystem.
- The core_user class, and its associated tests should go to the
core_user subsystem.
- The \core\update namespace is plain wrong (update is not valid API)
and needs action 1) create it or 2) move elsewhere.
2022-07-01 16:43:34 +02:00
|
|
|
class update_checker_test extends \advanced_testcase {
|
2013-09-14 23:57:21 +02:00
|
|
|
|
|
|
|
public function test_core_available_update() {
|
2015-10-05 15:19:09 +02:00
|
|
|
$provider = testable_checker::instance();
|
2013-10-04 22:40:44 +02:00
|
|
|
$this->assertInstanceOf('\core\update\checker', $provider);
|
2013-09-14 23:57:21 +02:00
|
|
|
|
|
|
|
$provider->fake_current_environment(2012060102.00, '2.3.2 (Build: 20121012)', '2.3', array());
|
|
|
|
$updates = $provider->get_update_info('core');
|
|
|
|
$this->assertCount(2, $updates);
|
|
|
|
|
|
|
|
$provider->fake_current_environment(2012060103.00, '2.3.3 (Build: 20121212)', '2.3', array());
|
|
|
|
$updates = $provider->get_update_info('core');
|
|
|
|
$this->assertCount(1, $updates);
|
|
|
|
|
|
|
|
$provider->fake_current_environment(2012060103.00, '2.3.3 (Build: 20121212)', '2.3', array());
|
|
|
|
$updates = $provider->get_update_info('core', array('minmaturity' => MATURITY_STABLE));
|
|
|
|
$this->assertNull($updates);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If there are no fetched data yet, the first cron should fetch them.
|
|
|
|
*/
|
|
|
|
public function test_cron_initial_fetch() {
|
2015-10-05 15:19:09 +02:00
|
|
|
$provider = testable_checker::instance();
|
2013-09-14 23:57:21 +02:00
|
|
|
$provider->fakerecentfetch = null;
|
|
|
|
$provider->fakecurrenttimestamp = -1;
|
2020-08-03 01:19:50 +02:00
|
|
|
$this->expectException(\core\update\testable_checker_cron_executed::class);
|
2013-09-14 23:57:21 +02:00
|
|
|
$provider->cron();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If there is a fresh fetch available, no cron execution is expected.
|
|
|
|
*/
|
|
|
|
public function test_cron_has_fresh_fetch() {
|
2015-10-05 15:19:09 +02:00
|
|
|
$provider = testable_checker::instance();
|
2013-09-14 23:57:21 +02:00
|
|
|
$provider->fakerecentfetch = time() - 23 * HOURSECS; // Fetched 23 hours ago.
|
|
|
|
$provider->fakecurrenttimestamp = -1;
|
|
|
|
$provider->cron();
|
|
|
|
$this->assertTrue(true); // We should get here with no exception thrown.
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If there is an outdated fetch, the cron execution is expected.
|
|
|
|
*/
|
|
|
|
public function test_cron_has_outdated_fetch() {
|
2015-10-05 15:19:09 +02:00
|
|
|
$provider = testable_checker::instance();
|
2013-09-14 23:57:21 +02:00
|
|
|
$provider->fakerecentfetch = time() - 49 * HOURSECS; // Fetched 49 hours ago.
|
|
|
|
$provider->fakecurrenttimestamp = -1;
|
2020-08-03 01:19:50 +02:00
|
|
|
$this->expectException(\core\update\testable_checker_cron_executed::class);
|
2013-09-14 23:57:21 +02:00
|
|
|
$provider->cron();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The first cron after 01:42 AM today should fetch the data.
|
|
|
|
*
|
2015-10-05 15:19:09 +02:00
|
|
|
* @see testable_checker::cron_execution_offset()
|
2013-09-14 23:57:21 +02:00
|
|
|
*/
|
|
|
|
public function test_cron_offset_execution_not_yet() {
|
2015-10-05 15:19:09 +02:00
|
|
|
$provider = testable_checker::instance();
|
2013-09-14 23:57:21 +02:00
|
|
|
$provider->fakecurrenttimestamp = mktime(1, 40, 02); // 01:40:02 AM today
|
|
|
|
$provider->fakerecentfetch = $provider->fakecurrenttimestamp - 24 * HOURSECS;
|
|
|
|
$provider->cron();
|
|
|
|
$this->assertTrue(true); // We should get here with no exception thrown.
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The first cron after 01:42 AM today should fetch the data and then
|
|
|
|
* it is supposed to wait next 24 hours.
|
|
|
|
*
|
2015-10-05 15:19:09 +02:00
|
|
|
* @see testable_checker::cron_execution_offset()
|
2013-09-14 23:57:21 +02:00
|
|
|
*/
|
|
|
|
public function test_cron_offset_execution() {
|
2015-10-05 15:19:09 +02:00
|
|
|
$provider = testable_checker::instance();
|
2013-09-14 23:57:21 +02:00
|
|
|
|
|
|
|
// The cron at 01:45 should fetch the data.
|
|
|
|
$provider->fakecurrenttimestamp = mktime(1, 45, 02); // 01:45:02 AM today
|
|
|
|
$provider->fakerecentfetch = $provider->fakecurrenttimestamp - 24 * HOURSECS - 1;
|
|
|
|
$executed = false;
|
|
|
|
try {
|
|
|
|
$provider->cron();
|
2015-10-05 15:19:09 +02:00
|
|
|
} catch (testable_checker_cron_executed $e) {
|
2013-09-14 23:57:21 +02:00
|
|
|
$executed = true;
|
|
|
|
}
|
|
|
|
$this->assertTrue($executed, 'Cron should be executed at 01:45:02 but it was not.');
|
|
|
|
|
|
|
|
// Another cron at 06:45 should still consider data as fresh enough.
|
|
|
|
$provider->fakerecentfetch = $provider->fakecurrenttimestamp;
|
|
|
|
$provider->fakecurrenttimestamp = mktime(6, 45, 03); // 06:45:03 AM
|
|
|
|
$executed = false;
|
|
|
|
try {
|
|
|
|
$provider->cron();
|
2015-10-05 15:19:09 +02:00
|
|
|
} catch (testable_checker_cron_executed $e) {
|
2013-09-14 23:57:21 +02:00
|
|
|
$executed = true;
|
|
|
|
}
|
|
|
|
$this->assertFalse($executed, 'Cron should not be executed at 06:45:03 but it was.');
|
|
|
|
|
|
|
|
// The next scheduled execution should happen the next day.
|
|
|
|
$provider->fakecurrenttimestamp = $provider->fakerecentfetch + 24 * HOURSECS + 1;
|
|
|
|
$executed = false;
|
|
|
|
try {
|
|
|
|
$provider->cron();
|
2015-10-05 15:19:09 +02:00
|
|
|
} catch (testable_checker_cron_executed $e) {
|
2013-09-14 23:57:21 +02:00
|
|
|
$executed = true;
|
|
|
|
}
|
|
|
|
$this->assertTrue($executed, 'Cron should be executed the next night but it was not.');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_compare_responses_both_empty() {
|
2015-10-05 15:19:09 +02:00
|
|
|
$provider = testable_checker::instance();
|
2013-09-14 23:57:21 +02:00
|
|
|
$old = array();
|
|
|
|
$new = array();
|
|
|
|
$cmp = $provider->compare_responses($old, $new);
|
MDL-67673 phpunit: Remove deprecated assertInternalType()
While this is not strictly required, because removal will
happen in PHPUnit 9.0, we are already getting rid of all
uses in core.
From release notes:https://phpunit.de/announcements/phpunit-8.html
assertInternalType() is deprecated and will be removed in
PHPUnit 9. Refactor your test to use assertIsArray(), assertIsBool(),
assertIsFloat(), assertIsInt(), assertIsNumeric(), assertIsObject(),
assertIsResource(), assertIsString(), assertIsScalar(),
assertIsCallable(), or assertIsIterable() instead.
2020-08-02 13:08:42 +02:00
|
|
|
$this->assertIsArray($cmp);
|
2013-09-14 23:57:21 +02:00
|
|
|
$this->assertEmpty($cmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_compare_responses_old_empty() {
|
2015-10-05 15:19:09 +02:00
|
|
|
$provider = testable_checker::instance();
|
2013-09-14 23:57:21 +02:00
|
|
|
$old = array();
|
|
|
|
$new = array(
|
|
|
|
'updates' => array(
|
|
|
|
'core' => array(
|
|
|
|
array(
|
|
|
|
'version' => 2012060103
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$cmp = $provider->compare_responses($old, $new);
|
MDL-67673 phpunit: Remove deprecated assertInternalType()
While this is not strictly required, because removal will
happen in PHPUnit 9.0, we are already getting rid of all
uses in core.
From release notes:https://phpunit.de/announcements/phpunit-8.html
assertInternalType() is deprecated and will be removed in
PHPUnit 9. Refactor your test to use assertIsArray(), assertIsBool(),
assertIsFloat(), assertIsInt(), assertIsNumeric(), assertIsObject(),
assertIsResource(), assertIsString(), assertIsScalar(),
assertIsCallable(), or assertIsIterable() instead.
2020-08-02 13:08:42 +02:00
|
|
|
$this->assertIsArray($cmp);
|
2013-09-14 23:57:21 +02:00
|
|
|
$this->assertNotEmpty($cmp);
|
|
|
|
$this->assertTrue(isset($cmp['core'][0]['version']));
|
|
|
|
$this->assertEquals(2012060103, $cmp['core'][0]['version']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_compare_responses_no_change() {
|
2015-10-05 15:19:09 +02:00
|
|
|
$provider = testable_checker::instance();
|
2013-09-14 23:57:21 +02:00
|
|
|
$old = $new = array(
|
|
|
|
'updates' => array(
|
|
|
|
'core' => array(
|
|
|
|
array(
|
|
|
|
'version' => 2012060104
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'version' => 2012120100
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'mod_foo' => array(
|
|
|
|
array(
|
|
|
|
'version' => 2011010101
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$cmp = $provider->compare_responses($old, $new);
|
MDL-67673 phpunit: Remove deprecated assertInternalType()
While this is not strictly required, because removal will
happen in PHPUnit 9.0, we are already getting rid of all
uses in core.
From release notes:https://phpunit.de/announcements/phpunit-8.html
assertInternalType() is deprecated and will be removed in
PHPUnit 9. Refactor your test to use assertIsArray(), assertIsBool(),
assertIsFloat(), assertIsInt(), assertIsNumeric(), assertIsObject(),
assertIsResource(), assertIsString(), assertIsScalar(),
assertIsCallable(), or assertIsIterable() instead.
2020-08-02 13:08:42 +02:00
|
|
|
$this->assertIsArray($cmp);
|
2013-09-14 23:57:21 +02:00
|
|
|
$this->assertEmpty($cmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_compare_responses_new_and_missing_update() {
|
2015-10-05 15:19:09 +02:00
|
|
|
$provider = testable_checker::instance();
|
2013-09-14 23:57:21 +02:00
|
|
|
$old = array(
|
|
|
|
'updates' => array(
|
|
|
|
'core' => array(
|
|
|
|
array(
|
|
|
|
'version' => 2012060104
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'mod_foo' => array(
|
|
|
|
array(
|
|
|
|
'version' => 2011010101
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$new = array(
|
|
|
|
'updates' => array(
|
|
|
|
'core' => array(
|
|
|
|
array(
|
|
|
|
'version' => 2012060104
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'version' => 2012120100
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$cmp = $provider->compare_responses($old, $new);
|
MDL-67673 phpunit: Remove deprecated assertInternalType()
While this is not strictly required, because removal will
happen in PHPUnit 9.0, we are already getting rid of all
uses in core.
From release notes:https://phpunit.de/announcements/phpunit-8.html
assertInternalType() is deprecated and will be removed in
PHPUnit 9. Refactor your test to use assertIsArray(), assertIsBool(),
assertIsFloat(), assertIsInt(), assertIsNumeric(), assertIsObject(),
assertIsResource(), assertIsString(), assertIsScalar(),
assertIsCallable(), or assertIsIterable() instead.
2020-08-02 13:08:42 +02:00
|
|
|
$this->assertIsArray($cmp);
|
2013-09-14 23:57:21 +02:00
|
|
|
$this->assertNotEmpty($cmp);
|
|
|
|
$this->assertCount(1, $cmp);
|
|
|
|
$this->assertCount(1, $cmp['core']);
|
|
|
|
$this->assertEquals(2012120100, $cmp['core'][0]['version']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_compare_responses_modified_update() {
|
2015-10-05 15:19:09 +02:00
|
|
|
$provider = testable_checker::instance();
|
2013-09-14 23:57:21 +02:00
|
|
|
$old = array(
|
|
|
|
'updates' => array(
|
|
|
|
'mod_foo' => array(
|
|
|
|
array(
|
|
|
|
'version' => 2011010101
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$new = array(
|
|
|
|
'updates' => array(
|
|
|
|
'mod_foo' => array(
|
|
|
|
array(
|
|
|
|
'version' => 2011010102
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$cmp = $provider->compare_responses($old, $new);
|
MDL-67673 phpunit: Remove deprecated assertInternalType()
While this is not strictly required, because removal will
happen in PHPUnit 9.0, we are already getting rid of all
uses in core.
From release notes:https://phpunit.de/announcements/phpunit-8.html
assertInternalType() is deprecated and will be removed in
PHPUnit 9. Refactor your test to use assertIsArray(), assertIsBool(),
assertIsFloat(), assertIsInt(), assertIsNumeric(), assertIsObject(),
assertIsResource(), assertIsString(), assertIsScalar(),
assertIsCallable(), or assertIsIterable() instead.
2020-08-02 13:08:42 +02:00
|
|
|
$this->assertIsArray($cmp);
|
2013-09-14 23:57:21 +02:00
|
|
|
$this->assertNotEmpty($cmp);
|
|
|
|
$this->assertCount(1, $cmp);
|
|
|
|
$this->assertCount(1, $cmp['mod_foo']);
|
|
|
|
$this->assertEquals(2011010102, $cmp['mod_foo'][0]['version']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_compare_responses_invalid_format() {
|
2015-10-05 15:19:09 +02:00
|
|
|
$provider = testable_checker::instance();
|
2013-09-14 23:57:21 +02:00
|
|
|
$broken = array(
|
|
|
|
'status' => 'ERROR' // No 'updates' key here.
|
|
|
|
);
|
2020-08-03 01:19:50 +02:00
|
|
|
$this->expectException(\core\update\checker_exception::class);
|
2013-09-14 23:57:21 +02:00
|
|
|
$cmp = $provider->compare_responses($broken, $broken);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_is_same_release_explicit() {
|
2015-10-05 15:19:09 +02:00
|
|
|
$provider = testable_checker::instance();
|
2013-09-14 23:57:21 +02:00
|
|
|
$this->assertTrue($provider->is_same_release('2.3dev (Build: 20120323)', '2.3dev (Build: 20120323)'));
|
|
|
|
$this->assertTrue($provider->is_same_release('2.3dev (Build: 20120323)', '2.3dev (Build: 20120330)'));
|
|
|
|
$this->assertFalse($provider->is_same_release('2.3dev (Build: 20120529)', '2.3 (Build: 20120601)'));
|
|
|
|
$this->assertFalse($provider->is_same_release('2.3dev', '2.3 dev'));
|
|
|
|
$this->assertFalse($provider->is_same_release('2.3.1', '2.3'));
|
|
|
|
$this->assertFalse($provider->is_same_release('2.3.1', '2.3.2'));
|
|
|
|
$this->assertTrue($provider->is_same_release('2.3.2+', '2.3.2')); // Yes, really!
|
|
|
|
$this->assertTrue($provider->is_same_release('2.3.2 (Build: 123456)', '2.3.2+ (Build: 123457)'));
|
|
|
|
$this->assertFalse($provider->is_same_release('3.0 Community Edition', '3.0 Enterprise Edition'));
|
|
|
|
$this->assertTrue($provider->is_same_release('3.0 Community Edition', '3.0 Community Edition (Build: 20290101)'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_is_same_release_implicit() {
|
2015-10-05 15:19:09 +02:00
|
|
|
$provider = testable_checker::instance();
|
2013-09-14 23:57:21 +02:00
|
|
|
$provider->fake_current_environment(2012060102.00, '2.3.2 (Build: 20121012)', '2.3', array());
|
|
|
|
$this->assertTrue($provider->is_same_release('2.3.2'));
|
|
|
|
$this->assertTrue($provider->is_same_release('2.3.2+'));
|
|
|
|
$this->assertTrue($provider->is_same_release('2.3.2+ (Build: 20121013)'));
|
|
|
|
$this->assertFalse($provider->is_same_release('2.4dev (Build: 20121012)'));
|
|
|
|
}
|
|
|
|
}
|