2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Unit tests for setuplib.php
20 * @package core_phpunit
21 * @copyright 2012 The Open University
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') || die();
29 * Unit tests for setuplib.php
31 * @copyright 2012 The Open University
32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34 class core_setuplib_testcase extends basic_testcase {
37 * Test get_docs_url_standard in the normal case when we should link to Moodle docs.
39 public function test_get_docs_url_standard() {
41 if (empty($CFG->docroot)) {
42 $docroot = 'http://docs.moodle.org/';
44 $docroot = $CFG->docroot;
46 $this->assertRegExp('~^' . preg_quote($docroot, '') . '/2\d/' . current_language() . '/course/editing$~',
47 get_docs_url('course/editing'));
51 * Test get_docs_url_standard in the special case of an absolute HTTP URL.
53 public function test_get_docs_url_http() {
54 $url = 'http://moodle.org/';
55 $this->assertEquals($url, get_docs_url($url));
59 * Test get_docs_url_standard in the special case of an absolute HTTPS URL.
61 public function test_get_docs_url_https() {
62 $url = 'https://moodle.org/';
63 $this->assertEquals($url, get_docs_url($url));
67 * Test get_docs_url_standard in the special case of a link relative to wwwroot.
69 public function test_get_docs_url_wwwroot() {
71 $this->assertEquals($CFG->wwwroot . '/lib/tests/setuplib_test.php',
72 get_docs_url('%%WWWROOT%%/lib/tests/setuplib_test.php'));
75 public function test_is_web_crawler() {
77 'Mozilla/5.0 (Windows; U; MSIE 9.0; WIndows NT 9.0; en-US))',
78 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:18.0) Gecko/18.0 Firefox/18.0',
79 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/412 (KHTML, like Gecko) Safari/412',
80 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_5; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.215 Safari/534.10',
81 'Opera/9.0 (Windows NT 5.1; U; en)',
82 'Mozilla/5.0 (Linux; U; Android 2.1; en-us; Nexus One Build/ERD62) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17 –Nexus',
83 'Mozilla/5.0 (iPad; U; CPU OS 4_2_1 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 Safari/6533.18.5',
87 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)',
88 'Googlebot/2.1 (+http://www.googlebot.com/bot.html)',
89 'Googlebot-Image/1.0',
91 'Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)',
93 'Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)',
94 'Mozilla/5.0 (compatible; bingbot/2.0 +http://www.bing.com/bingbot.htm)',
98 'Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)',
99 'Mozilla/5.0 (compatible; YandexImages/3.0; +http://yandex.com/bots)',
101 'AltaVista V2.0B crawler@evreka.com',
103 'ZoomSpider - wrensoft.com [ZSEBOT]',
105 'Baiduspider+(+http://www.baidu.com/search/spider_jp.html)',
106 'Baiduspider+(+http://www.baidu.com/search/spider.htm)',
109 'User-Agent: Mozilla/2.0 (compatible; Ask Jeeves/Teoma)',
112 foreach ($browsers as $agent) {
113 $_SERVER['HTTP_USER_AGENT'] = $agent;
114 $this->assertFalse(is_web_crawler());
116 foreach ($crawlers as $agent) {
117 $_SERVER['HTTP_USER_AGENT'] = $agent;
118 $this->assertTrue(is_web_crawler(), "$agent should be considered a search engine");