...
 
Commits (12)
{
"phabricator.uri" : "https://rcm-2.wmflabs.org",
"repository.callsign" : "LBC",
"repository.callsign" : "CYG",
"history.immutable" : false,
"unit.engine": "NoseTestEngine"
}
{
"linters": {
"php": {
"type": "php"
}
}
}
\ No newline at end of file
"linters": {
"format": {
"type": "text",
"text.max-line-length": 180,
"severity": {
"1": "disabled",
"2": "disabled",
"4": "autofix",
"5": "disabled"
}
},
"filename": {
"type": "filename"
},
"mergeconflict": {
"type": "merge-conflict"
},
"php": {
"type": "php",
"include": "(\\.php$)"
},
"json": {
"type": "json",
"include": "(\\.json$)"
}
}
}
Password.php
\ No newline at end of file
Password.php
DBPassword.php
stages:
- lint
- codesniffer
- unit
lint:lint-php5.4:
stage: lint
image: php:5.4
before_script:
- bash ci/docker_install-lint.sh > /dev/null
script:
- bash ci/phplint.sh ./
lint:lint-php5.6:
stage: lint
image: php:5.6
before_script:
- bash ci/docker_install-lint.sh > /dev/null
script:
- bash ci/phplint.sh ./
lint:lint-php7.0:
stage: lint
image: php:7.0
before_script:
- bash ci/docker_install-lint.sh > /dev/null
script:
- bash ci/phplint.sh ./
lint:lint-php7.1:
stage: lint
image: php:7.1
before_script:
- bash ci/docker_install-lint.sh > /dev/null
script:
- bash ci/phplint.sh ./
codesniffer:
stage: codesniffer
image: php:5.6
before_script:
- bash ci/docker_install-cs.sh > /dev/null
script:
- bash ci/phpcs.sh
allow_failure: true
unit:testBasic:
stage: unit
image: php:5.6
before_script:
- bash ci/docker_install-unit.sh > /dev/null
script:
- bash ci/phpunitBasic.sh
unit:testRead:
stage: unit
image: php:5.6
before_script:
- bash ci/docker_install-unit.sh > /dev/null
script:
- bash ci/phpunitRead.sh
unit:testReadAssertFail:
stage: unit
image: php:5.6
before_script:
- bash ci/docker_install-unit.sh > /dev/null
script:
- bash ci/phpunitReadAssert.sh
unit:testUserProperty:
stage: unit
image: php:5.6
before_script:
- bash ci/docker_install-unit.sh > /dev/null
script:
- bash ci/phpunitUserProperty.sh
\ No newline at end of file
This diff is collapsed.
<?php
include "DBPassword.php";
require_once __DIR__ . "/DBPassword.php";
/** DBCore.php
* File for Database-Management of the Cygnus-Framework
* @author Freddy2001 <freddy2001@wikipedia.de>, Luke081515 <luke081515@tools.wmflabs.org>, MGChecker <hgasuser@gmail.com>
*/
class DBCore extends DBPassword {
protected $DBusername;
protected $DBDBpassword;
protected $dbUsername;
protected $dbPassword;
protected $database;
protected $DB;
public function DBCore ($Accountdata, $Database) {
$a=0;
$Found = false;
protected $db;
protected $loginHost;
/** __construct
* Initializes the database connection
* @author Luke081515
* @param $accountdata - name of the accounts in dbPassword.php
* @param $database - name of the database that should get used
*/
public function __construct($accountdata, $database) {
$a = 0;
$found = false;
$this->init();
$LoginName = unserialize($this->getLoginName ());
$LoginAccount = unserialize($this->getLoginAccount());
$LoginDBpassword = unserialize($this->getLoginDBpassword());
while (isset ($LoginName [$a]) === true) {
if ($LoginName [$a] === $Accountdata) {
$this->DBusername = $LoginAccount [$a];
$this->DBpassword = $LoginDBpassword [$a];
$Found = true;
$loginName = unserialize($this->getLoginName ());
$loginAccount = unserialize($this->getLoginAccount());
$loginDbPassword = unserialize($this->getLogindbPassword());
$loginHost = unserialize($this->getLoginHost());
while (isset($loginName [$a]) === true) {
if ($loginName [$a] === $accountdata) {
$this->dbUsername = $loginAccount [$a];
$this->dbPassword = $loginDbPassword [$a];
$this->loginHost = $loginHost [$a];
$found = true;
}
$a++;
}
if (!$Found) {
throw new Exception('Keine passenden DB-Anmeldeinformationen vorhanden.');
die(1); // exit with error
}
$this->DB = new mysqli('127.0.0.1', $this->DBusername, $this->DBpassword, $Database);
if ($this->DB->connect_errno) {
if (!$found)
throw new Exception('No matching credentials available. (DB)');
$this->db = new mysqli($this->loginHost, $this->dbUsername, $this->dbPassword, $database);
if ($this->db->connect_errno) {
echo "Error: Failed to make a MySQL connection, here is why: \n";
echo "Errno: " . $mysqli->connect_errno . "\n";
echo "Error: " . $mysqli->connect_error . "\n";
die (1);
}
}
public function query ($sql, $sensitive = false) {
if(!$result = $this->DB->query($sql)) {
if ($sensitive === false)
die('There was an error running the query [' . $this->DB->error . ']');
else
echo ('\nThere was an error running the query [' . $this->DB->error . ']');
/** query
* Runs a query against the current database
* @author Luke081515
* @param $sql - the query statement
* @param $sensitive - default: false. if false, the function will throw an exception in case that there is an error
* @return Returns the result, or 0 if you fetched an empty set.
*/
public function query($sql, $sensitive = false) {
$result = $this->db->query($sql);
if(!$result) {
$err = $this->db->error;
if ($sensitive === false) {
die("There was an error running the query [" . $err . "]");
} else {
echo ("\nThere was an error running the query [" . $err . "]");
}
} else if ($result->num_rows === 0) {
return 0;
} else {
return $result;
}
}
/** modify
* Executes an sql statement that modifies the current database
* @author Luke081515
* @param $sql - the query statement
* @param $sensitive - default: false. if false, the function will throw an exception in case that there is an error
* @return Returns the result of the exeuction statement.
*/
public function modify ($sql, $sensitive = false) {
if(!$result = $this->DB->query($sql)) {
if ($sensitive === false)
die('There was an error running the command [' . $this->DB->error . ']');
else
echo ('\nThere was an error running the command [' . $this->DB->error . ']');
}
else
$result = $this->db->query($sql);
if (!$result) {
$err = $this->db->error;
if ($sensitive === false) {
die("There was an error running the command [" . $err . "]");
} else {
echo ("\nThere was an error running the command [" . $err . "]");
}
} else {
return $result;
}
}
/** escape
* Espaces and SQL string, used to make sure that there are no injections
* @author MGChecker
*/
public function escape($string) {
return $this->db->real_escape_string($string);
}
/** close
* Closes the connection
*/
public function close() {
mysqli_close($this->db);
}
/** __destruct
* Closes the connection
*/
public function __destruct() {
$this->close();
}
}
?>
\ No newline at end of file
<?php
class DBpassword
{
/** Dies ist eine Example-Datei
* Damit das Programm funktioniert, muessen die Daten angepasst werden!
<?php
class DBpassword {
/** This is only an example
* You need to modify the data to make the program work!
*/
private $LoginName;
private $LoginHost;
private $LoginAccount;
private $LoginPassword;
public function DBpassword()
{}
public function __construct() {}
protected function init()
{
$this->LoginName = array( // Empfohlen: Username@wiki
protected function init() {
$this->LoginName = array( // Recommended: Username@wiki
'root@localhost',
);
# Bitte beachten, Accounts müssen in der selben Reihenfolge genannt werden, wie bei LoginName! #
$this->LoginHost = array( // Internetdomain
// NOTE: Accounts need to follow the same order as at loginname
$this->LoginHost = array( // Domain
'127.0.0.1',
);
$this->LoginAccount = array( // Name das Accounts
$this->LoginAccount = array( // Name of the account
'root',
);
$this->LoginPassword = array( // Passwort des Accounts
$this->LoginPassword = array( // Password of the account
'Password',
);
}
protected function getLoginName ()
{
protected function getLoginName() {
return serialize ($this->LoginName);
}
protected function getLoginHost ()
{
protected function getLoginHost() {
return serialize ($this->LoginHost);
}
protected function getLoginAccount ()
{
protected function getLoginAccount() {
return serialize ($this->LoginAccount);
}
protected function getLoginDBpassword ()
{
protected function getLoginDBpassword() {
return serialize ($this->LoginPassword);
}
}
?>
?>
\ No newline at end of file
<?php
class Database extends mysqli {
public function replicaConnect($database) {
$mycnf = parse_ini_file( "./replica.my.cnf" );
$cluster = ( preg_match( '/[-_]p$/', $database ) ) ? substr( $database, 0, -2 ) : $database;
$mycnf = parse_ini_file("./replica.my.cnf");
$cluster = (preg_match('/[-_]p$/', $database)) ? substr($database, 0, -2) : $database;
parent::connect($cluster . '.labsdb', $mycnf['user'], $mycnf['password']);
unset($mycnf);
if( $this->connect_error ) {
if ($this->connect_error) {
die( '<p><strong>Database server login failed.</strong> '
. ' This is probably a temporary problem with the server and will be fixed soon. '
. ' The server returned error code ' . $this->connect_errno . '.</p>' );
}
$res = $this->select_db(str_replace('-', '_', $database));
if( $res === false ) {
if ($res === false) {
die( '<p><strong>Database selection failed.</strong> '
. ' This is probably a temporary problem with the server and will be fixed soon.</p>' );
}
......@@ -19,12 +19,12 @@ class Database extends mysqli {
public static function getName($lang, $project, $separator = '-') {
if ($project == 'wikipedia') {
$project = 'wiki';
} elseif ($project == 'wikimedia') {
} else if ($project == 'wikimedia') {
$project = 'wiki';
} elseif($project == 'wikidata') {
} else if ($project == 'wikidata') {
$project = 'wiki';
$lang = 'wikidata';
}
return $lang . $project . $separator . 'p';
}
}
\ No newline at end of file
}
This diff is collapsed.
......@@ -652,7 +652,7 @@ Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
{project} Copyright (C) {year} {fullname}
Cygnus Copyright (C) 2015-2017 Luke081515, Freddy2001, Hgzh, MGChecker
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
......@@ -672,4 +672,3 @@ may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
<?php
class Password
{
/** Dies ist eine Example-Datei
* Damit das Programm funktioniert, muessen die Daten angepasst werden!
* chmod 0600 nicht vergessen!
class Password {
/** This is just an example!
* For running any Job properly, the data needs to be adapted!
* Do not forget chmod 0600!
*/
private $LoginName;
private $LoginHost;
private $LoginAccount;
private $LoginPassword;
private $MailAddress;
public function Password() {}
public function __construct() {}
protected function init() {
$this->LoginName = array( // Empfohlen: Username@wiki
$this->LoginName = array( // Recommended: Username@wiki
'User@dewiki',
'Bot@dewikisource',
);
# Bitte beachten, Accounts müssen in der selben Reihenfolge genannt werden, wie bei LoginName! #
$this->LoginHost = array( // Internetdomain
// Please note, that the following settings need to be made in the same order as LoginName!
$this->LoginHost = array( // Domain of the Wiki
'de.wikipedia.org',
'de.wikisource.org',
);
$this->LoginAccount = array( // Name das Accounts
$this->LoginAccount = array( // Name of the account
'User',
'Bot',
);
$this->LoginPassword = array( // Passwort des Accounts
$this->LoginPassword = array( // Password of the account
'Userpassword',
'Botpassword',
);
$this->MailAddress = array( // Mailadresse an die Daten gesendet werden koennen
$this->MailAddress = array( // The script sends triggered mails to this address
'hello@example.org',
'support@example.org',
);
}
protected function getLoginName () {
protected function getLoginName() {
return serialize ($this->LoginName);
}
protected function getLoginHost () {
protected function getLoginHost() {
return serialize ($this->LoginHost);
}
protected function getLoginAccount () {
protected function getLoginAccount() {
return serialize ($this->LoginAccount);
}
protected function getLoginPassword () {
return serialize ($this->LoginPassword);
protected function getLoginPassword() {
return serialize ($this->LoginPassword);
}
protected function getMail () {
return serialize ($this->MailAddress);
protected function getMail() {
return serialize ($this->MailAddress);
}
}
?>
\ No newline at end of file
Cygnus
# Overview
Cygnus is a framework for writing a MediaWiki-Bot. It has no built in scripts that you can already use, you may find these at other repos.
# Features
Cygnus has already a lot of features, however it looks like we won't stop adding new features. Currently, we have a lot of API-functions implemented, like reading, writing, read only a section, edit only a section, move a page, get all pages of a category, get all embeddings of a template and in the new version you will find some sysop functions as well, like blocking a user.
# How to get help
Each function at BotCore and DBCore has a small documentation text, where you can find which params you have to use, or which return values you can except. We are working on writing a tutorial as well.
If you want to ask us, you may find us at ##Cygnus on freenode.
# How to contribute
You've found an issue with Cygnus, or want to request a feature? You can create an issue at [our issuetracker](https://gitlab.wmflabs.org/Cygnus/Cygnus/issues). In case you've found a bug, please also mention which version you are currently using, and if possible a trace would be very useful as well.
We accept merge requests as well, you can simply fork the repo and create a merge request.
\ No newline at end of file
<?php
require_once __DIR__ . '/BotCore.php';
/** TestCore.php
* Allows using Cygnus for testing
* @Author Luke081515 <luke081515@tools.wmflabs.org>
* @Version 1.0
* @Status Beta
*/
class TestCore extends Core {
/** __construct
* @param $loginData (Array)
* $loginData[1] - the site to use
* $loginData[2] - the username to use
* $loginData[3] - the password to use
* $loginData[0] is ignored, since this program is mostly for args
** args[0] is the program name, so useless here
*/
public function __construct($loginData) {
$this->setSite($loginData[1]);
$this->setUsername($loginData[2]);
$this->setPassword($loginData[3]);
$this->initcurlArgs('TestCore', true, "bot", true);
$this->login();
}
/** execute
* @param - $functionData Array
** $functionData[0] is the name of the function to execute
** $functionData - all following values are the params
** Takes up to 10 parameters
* @Author Luke081515
* @returns the return value of the Cygnus function
*/
public function execute($functionData) {
$functionName = $functionData[0];
switch(count($functionData)) {
case 1:
return $this->$functionName();
case 2:
return $this->$functionName($functionData[1]);
case 3:
return $this->$functionName($functionData[1], $functionData[2]);
case 4:
return $this->$functionName($functionData[1], $functionData[2], $functionData[3]);
case 5:
return $this->$functionName($functionData[1], $functionData[2], $functionData[3], $functionData[4]);
case 6:
return $this->$functionName($functionData[1], $functionData[2], $functionData[3], $functionData[4],
$functionData[5]);
case 7:
return $this->$functionName($functionData[1], $functionData[2], $functionData[3], $functionData[4],
$functionData[5], $functionData[6]);
case 8:
return $this->$functionName($functionData[1], $functionData[2], $functionData[3], $functionData[4],
$functionData[5], $functionData[6], $functionData[7]);
case 9:
return $this->$functionName($functionData[1], $functionData[2], $functionData[3], $functionData[4],
$functionData[5], $functionData[6], $functionData[7], $functionData[8]);
case 10:
return $this->$functionName($functionData[1], $functionData[2], $functionData[3], $functionData[4],
$functionData[5], $functionData[6], $functionData[7], $functionData[8], $functionData[9]);
case 11:
return $this->$functionName($functionData[1], $functionData[2], $functionData[3], $functionData[4],
$functionData[5], $functionData[6], $functionData[7], $functionData[8], $functionData[9],
$functionData[10]);
default:
return null;
}
}
}
?>
\ No newline at end of file
#!/bin/bash
# We need to install dependencies only for Docker
[[ ! -e /.dockerenv ]] && exit 0
set -xe
# Install git (the php image doesn't have it) which is required by composer
apt-get update -yqq
apt-get install git -yqq
# Install phpcs
pear install PHP_CodeSniffer
\ No newline at end of file
#!/bin/bash
# We need to install dependencies only for Docker
[[ ! -e /.dockerenv ]] && exit 0
set -xe
# Install git (the php image doesn't have it) which is required by composer
apt-get update -yqq
apt-get install git -yqq
#!/bin/bash
# We need to install dependencies only for Docker
[[ ! -e /.dockerenv ]] && exit 0
set -xe
# Install git (the php image doesn't have it) which is required by composer
apt-get update -yqq
apt-get install git wget -yqq
# Install phpunit
wget https://phar.phpunit.de/phpunit-5.7.phar
chmod +x phpunit-5.7.phar
mv phpunit-5.7.phar /usr/local/bin/phpunit
phpunit --version
\ No newline at end of file
phpcs ./ -p --colors
#!/bin/bash
#Usage: `phplint.sh /path/to/dir` or `phplint.sh /path/to/file.php`
error=false
while test $# -gt 0; do
current=$1
shift
if [ ! -d $current ] && [ ! -f $current ] ; then
echo "Invalid directory or file: $current"
error=true
continue
fi
for file in `find $current -type f -name "*.php"` ; do
RESULTS=`php -l $file`
if [ "$RESULTS" != "No syntax errors detected in $file" ] ; then
echo $RESULTS
error=true
fi
done
done
if [ "$error" = true ] ; then
exit 1
else
exit 0
fi
cp Password.example.php Password.php
phpunit ./tests/BotCoreBasicTest.php $readSite $readUser $readPwd
\ No newline at end of file
cp Password.example.php Password.php
phpunit ./tests/BotCorePagePropertyTest.php $readSite $readUser $readPwd
\ No newline at end of file
cp Password.example.php Password.php
phpunit ./tests/BotCoreReadTest.php $readSite $readUser $readPwd
\ No newline at end of file
cp Password.example.php Password.php
phpunit ./tests/BotCoreReadAssertFailTest.php $AssertWrongSite $AssertWrongUser $AssertWrongPwd
cp Password.example.php Password.php
phpunit ./tests/BotCoreUserPropertyTest.php $readSite $readUser $readPwd
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="Cygnus">
<description>Codestyling rules for Cygnus.
</description>
<rule ref="Generic.Classes.DuplicateClassName"/>
<rule ref="Generic.CodeAnalysis.EmptyStatement"/>
<rule ref="Generic.CodeAnalysis.ForLoopShouldBeWhileLoop"/>
<rule ref="Generic.CodeAnalysis.JumbledIncrementer"/>
<rule ref="Generic.CodeAnalysis.UnconditionalIfStatement"/>
<rule ref="Generic.CodeAnalysis.UnnecessaryFinalModifier"/>
<rule ref="Generic.CodeAnalysis.UnusedFunctionParameter"/>
<rule ref="Generic.CodeAnalysis.UselessOverridingMethod"/>
<rule ref="Generic.Commenting.Fixme"/>
<rule ref="Generic.Files.ByteOrderMark"/>
<rule ref="Generic.Files.LineEndings"/>
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="300"/>
<property name="absoluteLineLimit" value="400"/>
</properties>
</rule>
<rule ref="Generic.Formatting.DisallowMultipleStatements"/>
<rule ref="Generic.Formatting.NoSpaceAfterCast"/>
<rule ref="Generic.Functions.OpeningFunctionBraceKernighanRitchie"/>
<rule ref="Generic.NamingConventions.ConstructorName">
<properties>
<property name="error" value="false"/>
</properties>
</rule>
<rule ref="Generic.PHP.DeprecatedFunctions"/>
<rule ref="Generic.PHP.DisallowShortOpenTag"/>
<rule ref="Generic.PHP.ForbiddenFunctions"/>
<rule ref="Generic.PHP.LowerCaseConstant"/>
<rule ref="Generic.WhiteSpace.DisallowSpaceIndent"/>
<rule ref="MySource.PHP.EvalObjectFactory"/>
<rule ref="PEAR.Commenting.InlineComment"/>
<rule ref="PEAR.Files.IncludingFile"/>
<rule ref="PEAR.Formatting.MultiLineAssignment"/>
<rule ref="PEAR.Functions.ValidDefaultValue"/>
<rule ref="PEAR.NamingConventions.ValidClassName"/>
<rule ref="Squiz.PHP.DisallowMultipleAssignments"/>
<rule ref="Squiz.PHP.EmbeddedPhp"/>
<rule ref="Squiz.PHP.Eval"/>
<rule ref="Squiz.PHP.ForbiddenFunctions"/>
<rule ref="Squiz.PHP.Heredoc"/>
<rule ref="Squiz.PHP.InnerFunctions"/>
<rule ref="Squiz.PHP.LowercasePHPFunctions"/>
<rule ref="Squiz.PHP.NonExecutableCode"/>
<rule ref="Squiz.Scope.MethodScope"/>
<rule ref="Squiz.Scope.StaticThisUsage"/>
<rule ref="Squiz.WhiteSpace.CastSpacing"/>
<rule ref="Squiz.WhiteSpace.LanguageConstructSpacing"/>
<rule ref="Squiz.WhiteSpace.LogicalOperatorSpacing"/>
<rule ref="Squiz.WhiteSpace.ObjectOperatorSpacing"/>
<rule ref="Squiz.WhiteSpace.OperatorSpacing"/>
<rule ref="Squiz.WhiteSpace.PropertyLabelSpacing"/>
<rule ref="Squiz.WhiteSpace.ScopeKeywordSpacing"/>
<rule ref="Squiz.WhiteSpace.SemicolonSpacing"/>
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace"/>
</ruleset>
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="Cygnus">
<arg name="tab-width" value="4" />
<rule ref="Generic.WhiteSpace.DisallowSpaceIndent"/>
<rule ref="Generic.WhiteSpace.ScopeIndent">
<properties>
<property name="tabIndent" value="true"/>
</properties>
</rule>
</ruleset>
<?php
require_once __DIR__ . '/../TestCore.php';
use PHPUnit\Framework\TestCase;
/**
* @author Luke081515
*/
final class BotCoreBasicTest extends TestCase {
public $params;
public $Core;
private function createLogin() {
global $argv;
$i = 0;
for ($j = 1; isset($argv[$j]); $j++) {
$params[$i] = $argv[$j];
$i++;
}
return new TestCore($params);
}
/**
* @covers BotCore::requireToken
* checks that login works as well, otherwise csrf token is +\\
*/
public function testRequireValidToken() {
$Core = $this->createLogin();
$notExpected = "+\\";
$actually = $Core->execute(array("requireToken", "csrf"));
$this->assertNotEquals($notExpected, $actually);
}
/**
* @covers BotCore::allowBots
*/
public function testNoBotsNoBots() {
$Core = $this->createLogin();
$text = $Core->readPage("AllowBots1");
$result = $Core->allowBots($text);
$this->assertFalse($result);
}
/**
* @covers BotCore::allowBots
*/
public function testNoBotsBots() {
$Core = $this->createLogin();
$text = $Core->readPage("AllowBots2");
$result = $Core->allowBots($text);
$this->assertTrue($result);
}
/**
* @covers BotCore::allowBots
*/
public function testNoBotsAllowMe() {
$Core = $this->createLogin();
$text = $Core->readPage("AllowBots3");
$result = $Core->allowBots($text);
$this->assertTrue($result);
}
/**
* @covers BotCore::allowBots
*/
public function testNoBotsDenyMe() {
$Core = $this->createLogin();
$text = $Core->readPage("AllowBots4");
$result = $Core->allowBots($text);
$this->assertFalse($result);
}
/**
* @covers BotCore::allowBots
*/
public function testNoBotsAllowMeList() {
$Core = $this->createLogin();
$text = $Core->readPage("AllowBots5");
$result = $Core->allowBots($text);
$this->assertTrue($result);
}
/**
* @covers BotCore::allowBots
*/
public function testNoBotsDenyMeList() {
$Core = $this->createLogin();
$text = $Core->readPage("AllowBots6");
$result = $Core->allowBots($text);
$this->assertFalse($result);
}
/**
* @covers BotCore::allowBots
*/
public function testNoBotsAllowAll() {
$Core = $this->createLogin();
$text = $Core->readPage("AllowBots7");
$result = $Core->allowBots($text);
$this->assertTrue($result);
}
/**
* @covers BotCore::allowBots
*/
public function testNoBotsAllowNone() {
$Core = $this->createLogin();
$text = $Core->readPage("AllowBots8");
$result = $Core->allowBots($text);
$this->assertFalse($result);
}
/**
* @covers BotCore::allowBots
*/
public function testNoBotsDenyAll() {
$Core = $this->createLogin();
$text = $Core->readPage("AllowBots9");
$result = $Core->allowBots($text);
$this->assertFalse($result);
}
/**
* @covers BotCore::allowBots
*/
public function testNoBotsDenyNone() {
$Core = $this->createLogin();
$text = $Core->readPage("AllowBots10");
$result = $Core->allowBots($text);
$this->assertTrue($result);
}
// ToDo: Add curlRequest
}
?>
<?php
require_once __DIR__ . '/../TestCore.php';
use PHPUnit\Framework\TestCase;
/**
* @covers BotCore
* Tests for all read function
*/
final class BotCorePagePropertyTest extends TestCase {
public $params;
public $Core;
private function createLogin() {
global $argv;
$i = 0;
for ($j = 1; isset($argv[$j]); $j++) {
$params[$i] = $argv[$j];
$i++;
}
return new TestCore($params);
}
public function testGetLinksSuccessful() {
$Core = $this->createLogin();
$expected = "Hauptseite";
$actually = $Core->execute(array("getLinks", "Benutzer:Luke081515Bot/Bluelink"));
$this->assertEquals($expected, $actually[0]);
}
public function testgetLinksFail() {
$Core = $this->createLogin();
$expected = false;
$actually = $Core->execute(array("getLinks", "Benutzer:Luke081515Bot/NoLink"));
$this->assertEquals($expected, $actually);
}
}
?>
<?php
require_once __DIR__ . '/../TestCore.php';
use PHPUnit\Framework\TestCase;
/**
* @covers BotCore::readPage
* Tests for all read function
*/
final class BotCoreReadAssertFailTest extends TestCase {
public function testReadPageAssertFail() {
global $argv;
$i = 0;
for ($j = 1; isset($argv[$j]); $j++) {
$params[$i] = $argv[$j];
$i++;
}
$Core = new TestCore($params);
$this->setExpectedException('Exception');
$Core->execute(array("readPage", "Hauptseite"));
}
}
?>
\ No newline at end of file
<?php
require_once __DIR__ . '/../TestCore.php';
use PHPUnit\Framework\TestCase;
/**
* Tests for all read function
*/
final class BotCoreReadTest extends TestCase {
public $params;
public $Core;
private function createLogin() {
global $argv;
$i = 1;
while ($argv[$j] === "CS") {
$i++;
}
while (isset($argv[$i])) {
$params[] = $argv[$i];
$i++;
}
return new TestCore($params);
}
/**
* @covers BotCore::readPage
*/
public function testReadPageSuccessful() {
$Core = $this->createLogin();
$expected = "DummyContent";
$actually = $Core->execute(array("readPage", "DummyPage"));
$this->assertEquals($expected, $actually);
}
/**
* @covers BotCore::readPage
*/
public function testReadPageMissing() {
$Core = $this->createLogin();
$expected = null;
$actually = $Core->execute(array("readPage", "Sfdfsdf"));
$this->assertEquals($expected, $actually);
}
/**
* @covers BotCore::readPageJs
*/
public function testReadPageJsSuccessful() {
$Core = $this->createLogin();
$expected = "UTTest";
$actually = $Core->execute(array("readPageJs", "User:Luke081515Bot/Testpage.js"));
$this->assertEquals($expected, $actually);
}
/**
* @covers BotCore::readPageCss
*/
public function testReadPageCssSuccessful() {
$Core = $this->createLogin();
$expected = "UTTest";
$actually = $Core->execute(array("readPageCss", "User:Luke081515Bot/Testpage.css"));
$this->assertEquals($expected, $actually);
}
/**
* @covers BotCore::readSection
*/
public function testReadSection0Successful() {
$Core = $this->createLogin();
$expected = "text";
$actually = $Core->execute(array("readSection", "User:Luke081515Bot/SectionTest", 0));
$this->assertEquals($expected, $actually);
}
/**
* @covers BotCore::readSection
*/
public function testReadSection1Successful() {
$Core = $this->createLogin();
$expected = "== Section 1 ==\ntext 2";
$actually = $Core->execute(array("readSection", "User:Luke081515Bot/SectionTest", 1));
$this->assertEquals($expected, $actually);
}
/**
* @covers BotCore::getPageID
*/
public function testgetPageIDSuccessful() {
$Core = $this->createLogin();
$expected = "9";
$actually = $Core->execute(array("getPageID", "DummyPage"));
$this->assertEquals($expected, $actually);
}
/**
* @covers BotCore::getPageID
*/
public function testgetPageIDMissing() {
$Core = $this->createLogin();
$actually = $Core->execute(array("getPageID", "Sfdfsdf"));
$this->assertFalse($actually);
}
}
?>
<?php
require_once __DIR__ . '/../TestCore.php';
use PHPUnit\Framework\TestCase;
/**
* @covers BotCore
* Tests for all read function
*/
final class BotCoreUserPropertyTest extends TestCase {
public $params;
public $Core;
private function createLogin() {
global $argv;
$i = 0;
for ($j = 1; isset($argv[$j]); $j++) {
$params[$i] = $argv[$j];
$i++;
}
return new TestCore($params);
}
/**
* @covers BotCore::checkUserExistence
*/
public function testUserExistsSuccessful() {
$Core = $this->createLogin();
$actually = $Core->execute(array("checkUserExistence", "Luke081515"));
$this->assertTrue($actually);
}
/**
* @covers BotCore::checkUserExistence
*/
public function testUserDoesNotExists() {
$Core = $this->createLogin();
$actually = $Core->execute(array("checkUserExistence", "LukeO81515"));
$this->assertFalse($actually);
}
/**
* @covers BotCore::getUserEditcount
*/
public function testUserEditcountSuccessful() {
$Core = $this->createLogin();
$expected = 1;
$actually = $Core->execute(array("getUserEditcount", "UTDummyUser"));
$this->assertEquals($expected, $actually);
}
/**
* @covers BotCore::getUserEditcount
*/
public function testUserEditcountDoesNotExists() {
$Core = $this->createLogin();
$actually = $Core->execute(array("getUserEditcount", "LukeO81515"));
$this->assertFalse($actually);
}
/**
* @covers BotCore::checkUserBlock
*/
public function testUserBlockBlocked() {
$Core = $this->createLogin();
$actually = $Core->execute(array("checkUserBlock", "ABlockedUser"));
$this->assertTrue($actually);
}
/**
* @covers BotCore::checkUserBlock
*/
public function testUserBlockNotBlocked() {
$Core = $this->createLogin();
$actually = $Core->execute(array("checkUserBlock", "Luke081515"));
$this->assertFalse($actually);
}
/**
* @covers BotCore::checkUserMail
*/
public function testUserMailSuccessful() {
$Core = $this->createLogin();
$actually = $Core->execute(array("checkUserMail", "Luke081515"));
$this->assertTrue($actually);
}
/**
* @covers BotCore::checkUserMail
*/
public function testUserMailMissing() {
$Core = $this->createLogin();
$actually = $Core->execute(array("checkUserMail", "UTDummyUser"));
$this->assertFalse($actually);
}
/**
* @covers BotCore::checkUserMail
*/
public function testUserMailUserMissing() {
$Core = $this->createLogin();
$actually = $Core->execute(array("checkUserMail", "LukeO81515"));
$this->assertFalse($actually);
}
/**
* @covers BotCore::getUserGender
*/
public function testcheckUserGenderMale() {
$Core = $this->createLogin();
$expected = "male";
$actually = $Core->execute(array("getUserGender", "Luke081515"));
$this->assertEquals($expected, $actually);
}
/**
* @covers BotCore::getUserGender
*/
public function testcheckUserGenderFemale() {
$Core = $this->createLogin();
$expected = "female";
$actually = $Core->execute(array("getUserGender", "Freddy2001"));
$this->assertEquals($expected, $actually);
}
/**
* @covers BotCore::getUserGender
*/
public function testcheckUserGenderUnknown() {
$Core = $this->createLogin();
$expected = "unknown";
$actually = $Core->execute(array("getUserGender", "UTAccount"));
$this->assertEquals($expected, $actually);
}
/**
* @covers BotCore::getUserGender
*/
public function testcheckUserGenderNoSuchUser() {
$Core = $this->createLogin();
$actually = $Core->execute(array("getUserGender", "NonExistantUser"));
$this->assertFalse($actually);
}
}
?>