Skip to content
Open
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
37 changes: 37 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# This is a basic workflow to help you get started with Actions
name: CI

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches:
- master
- release/*
- feature/*
pull_request:
branches:
- master
- release/*
- feature/*

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

- name: PHPUnit (php-actions)
uses: php-actions/phpunit@master
with:
# Configuration file location
config: forum/phpunit.xml
bootstrap: forum/qa-tests/autoload.php
# Memory limit
memory: 512M
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.idea/
.vagrant/
*.retry

.phpunit.result.cache
/vendor/
27 changes: 27 additions & 0 deletions forum/phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="true"
backupStaticAttributes="false"
bootstrap="qa-tests/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Feature">
<directory suffix="Test.php">./qa-tests</directory>
</testsuite>
</testsuites>
<filter>
<!-- <whitelist processUncoveredFilesFromWhitelist="true">-->
<!-- <directory suffix=".php">./app</directory>-->
<!-- </whitelist>-->
</filter>
<!-- <php>-->
<!-- <env name="APP_ENV" value="testing"/>-->
<!-- <env name="CACHE_DRIVER" value="array"/>-->
<!-- <env name="SESSION_DRIVER" value="array"/>-->
<!-- <env name="QUEUE_DRIVER" value="sync"/>-->
<!-- </php>-->
</phpunit>
34 changes: 19 additions & 15 deletions forum/qa-include/qa-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -898,27 +898,31 @@ function qa_xml($string)
}


function qa_js($value, $forcequotes=false)
function qa_js($value, $forcequotes = false)
/*
Return JavaScript representation of $value, putting in quotes if non-numeric or if $forcequotes is true. In the
case of boolean values they are returned as the appropriate true or false string
*/
{
$boolean = is_bool($value);
if ($boolean)
$value = $value ? 'true' : 'false';
if ((is_numeric($value) || $boolean) && !$forcequotes)
return $value;
else
return "'".strtr($value, array(
"'" => "\\'",
'/' => '\\/',
'\\' => '\\\\',
"\n" => "\\n",
"\r" => "\\n",
))."'";
}
$boolean = is_bool($value);
if ($boolean) {
$value = $value ? 'true' : 'false';
}

if ((is_numeric($value) || $boolean) && !$forcequotes) {
return $value;
}

$map = [
"'" => "\\'",
'/' => '\\/',
'\\' => '\\\\',
"\n" => "\\n",
"\r" => "\\n",
];

return "'" . strtr($value, $map) . "'";
}

// Finding out more about the current request

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ class qa_html_theme_layer extends qa_html_theme_base {
var $plugin_url_warnonleave;

// needed to get the plugin url
function qa_html_theme_layer($template, $content, $rooturl, $request)
public function __construct($template, $content, $rooturl, $request)
{
if(qa_opt('q2apro_warnonleave_enabled')) {
global $qa_layers;
$this->plugin_url_warnonleave = $qa_layers['Warn-On-Leave Layer']['urltoroot'];
}
qa_html_theme_base::qa_html_theme_base($template, $content, $rooturl, $request);
qa_html_theme_base::__construct($template, $content, $rooturl, $request);
}

function head_script(){
Expand Down
5 changes: 4 additions & 1 deletion forum/qa-tests/AppUsersTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?php

require_once QA_INCLUDE_DIR.'app/users.php';
require_once QA_INCLUDE_DIR.'app/options.php';

class AppUsersTest extends PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

class AppUsersTest extends TestCase
{
/**
* Test logic of permissions function.
Expand Down
58 changes: 39 additions & 19 deletions forum/qa-tests/BaseTest.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,45 @@
<?php

class BaseTest extends PHPUnit_Framework_TestCase
{
public function test__qa_js()
{
$test = qa_js('test');
$this->assertSame("'test'", $test);

$test = qa_js('test', true);
$this->assertSame("'test'", $test);
use PHPUnit\Framework\TestCase;

$test = qa_js(123);
$this->assertSame(123, $test);
class BaseTest extends TestCase
{
/**
* @dataProvider qa_js_dataprovider
*/
public function test__qa_js($input, bool $forceQuotes, $expectedResult): void
{
$test = qa_js($input, $forceQuotes);
$this->assertSame($expectedResult, $test);
}

$test = qa_js(123, true);
$this->assertSame("'123'", $test);
/**
* @dataProvider qa_version_to_float_dataprovider
*/
public function test__qa_version_to_float($version, $expectedResult): void
{
$test = qa_version_to_float($version);
$this->assertSame($expectedResult, $test);
}

$test = qa_js(true);
$this->assertSame('true', $test);
public function qa_version_to_float_dataprovider(): array
{
return [
['1.0', 1.0],
['1.6.2.2', 1.006002002],
[1.6, 1.006],
];
}

$test = qa_js(true, true);
$this->assertSame("'true'", $test);
}
}
public function qa_js_dataprovider(): array
{
return [
[ 'test', false, "'test'"],
[ 'test', true, "'test'"],
[ 123, false, 123],
[ 123, true, "'123'"],
[ true, false, 'true'],
[ true, true, "'true'"],
];
}
}
Loading