Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply more accurate dispensations for the Moodle internal checks #158

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions moodle/Sniffs/Files/MoodleInternalSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Util\Tokens;
use MoodleCodeSniffer\moodle\Util\MoodleUtil;

class MoodleInternalSniff implements Sniff {
/**
Expand All @@ -47,14 +48,28 @@ public function register() {
* @param int $pointer The position in the stack.
*/
public function process(File $file, $pointer) {
// Special dispensation for behat files.
if (basename(dirname($file->getFilename())) === 'behat') {
return;
}

// Special dispensation for lang files.
if (basename(dirname(dirname($file->getFilename()))) === 'lang') {
return;
// Guess moodle root, so we can do better dispensations below.
$moodleRoot = MoodleUtil::getMoodleRoot($file);
if ($moodleRoot) {
$relPath = str_replace('\\', '/', substr($file->path, strlen($moodleRoot)));
// Special dispensation for /tests/behat/ and /lib/behat/ dirs at any level.
if (strpos($relPath, '/tests/behat/') !== false || strpos($relPath, '/lib/behat/') !== false) {
return;
}
// Special dispensation for lang dirs at any level.
if (strpos($relPath, '/lang/') !== false) {
return;
}
} else {
// Falback to simpler dispensations, only looking 1 level.
// Special dispensation for behat files.
if (basename(dirname($file->getFilename())) === 'behat') {
return;
}
// Special dispensation for lang files.
if (basename(dirname(dirname($file->getFilename()))) === 'lang') {
return;
}
}

// We only want to do this once per file.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?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/>.

/**
* Steps definitions related to mod_workshop.
*
* @package mod_workshop
* @category test
* @copyright 2014 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.

require_once(__DIR__ . '/../../../../lib/behat/behat_base.php');

use Behat\Gherkin\Node\TableNode as TableNode;

/**
* Steps definitions related to mod_workshop.
*
* @package mod_workshop
* @category test
* @copyright 2014 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_mod_workshop extends behat_base {}
14 changes: 12 additions & 2 deletions moodle/tests/moodlestandard_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -814,10 +814,20 @@ public function test_moodle_files_moodleinternal_no_moodle_cookie_ok() {
}

public function test_moodle_files_moodleinternal_behat_skipped() {
// Files in behat dirs are ignored.
// Files in /tests/behat/ dirs are ignored.
$this->set_standard('moodle');
$this->set_sniff('moodle.Files.MoodleInternal');
$this->set_fixture(__DIR__ . '/fixtures/moodle_files_moodleinternal/behat/behat_mod_workshop.php');
$this->set_fixture(__DIR__ . '/fixtures/moodle_files_moodleinternal/tests/behat/behat_mod_workshop.php');

$this->set_errors(array());
$this->set_warnings(array());

$this->verify_cs_results();

// Files in /lib/behat/ dirs are ignored.
$this->set_standard('moodle');
$this->set_sniff('moodle.Files.MoodleInternal');
$this->set_fixture(__DIR__ . '/fixtures/moodle_files_moodleinternal/lib/behat/behat_mod_workshop.php');

$this->set_errors(array());
$this->set_warnings(array());
Expand Down