Commit c2001dde authored by Luke081515's avatar Luke081515

// Experimental

parent ce7fafe4
Pipeline #1304 passed with stages
in 6 minutes and 2 seconds
......@@ -2,6 +2,7 @@ stages:
- lint
- codesniffer
- unit
- codecov
lint:lint-php5.4:
stage: lint
......@@ -74,4 +75,16 @@ unit:testUserProperty:
before_script:
- bash ci/docker_install-unit.sh > /dev/null
script:
- bash ci/phpunitUserProperty.sh
\ No newline at end of file
- bash ci/phpunitUserProperty.sh
codecov:generateReport:
stage: codecov
image: php:7.1
before_script:
- bash ci/docker_install-codecov.sh > /dev/null
script:
- bash ci/phpunitCodecov.sh
artifacts:
paths:
- codecov.html
expire_in: 1 week
\ 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 -yqq git wget libmcrypt-dev libpq-dev libcurl4-gnutls-dev libicu-dev libvpx-dev libjpeg-dev libpng-dev libxpm-dev zlib1g-dev libfreetype6-dev libxml2-dev libexpat1-dev libbz2-dev libgmp3-dev libldap2-dev unixodbc-dev libsqlite3-dev libaspell-dev libsnmp-dev libpcre3-dev libtidy-dev
# Install PHP extensions
docker-php-ext-install mcrypt pdo_pgsql intl gd zip bz2 opcache
# Install & enable Xdebug for code coverage reports
pecl install xdebug
docker-php-ext-enable xdebug
# 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
#!/bin/bash
#Usage: `phplint.sh /path/to/dir` or `phplint.sh /path/to/file.php`
error=false
while test $# -gt 0; do
......
cp Password.example.php Password.php
phpunit --colors=always --whitelist BotCore.php --coverage-html codecov ./tests/BotCoreUserPropertyTest.php $readSite $readUser $readPwd
\ No newline at end of file
<?php
require_once __DIR__ . '/../TestCore.php';
use PHPUnit\Framework\TestCase;
/**
* @covers BotCore
* Tests for all read function
*/
final class BotCoreCodeCov 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);
}
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);
}
/**
* @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);
}
/**
* @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);
}
}
?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment