Merge branch 'more-tests'
This commit is contained in:
commit
5deccf040c
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,7 +1,9 @@
|
|||
/vendor
|
||||
/composer.phar
|
||||
/runtime
|
||||
|
||||
/app/config.yml
|
||||
/public/assets/vendor
|
||||
|
||||
/public/artifacts
|
||||
!/public/artifacts/.gitkeep
|
||||
|
|
|
@ -56,6 +56,7 @@
|
|||
"symfony/debug": "~3.4.0",
|
||||
"symfony/dependency-injection": "~3.4.0",
|
||||
"symfony/event-dispatcher": "~3.4.0",
|
||||
"symfony/cache": "~3.4.0",
|
||||
"psr/log": "~1.0.0",
|
||||
"monolog/monolog": "~1.22.0",
|
||||
"pimple/pimple": "~3.0.0",
|
||||
|
@ -94,6 +95,9 @@
|
|||
"mremi/flowdock": "For FlowdockNotify plugin"
|
||||
},
|
||||
"extra": {
|
||||
"platform": {
|
||||
"php": "5.6.*"
|
||||
},
|
||||
"installer-paths": {
|
||||
"public/assets/vendor/sprintf-js": ["npm-asset/sprintf-js"],
|
||||
"public/assets/vendor/codemirror": ["npm-asset/codemirror"],
|
||||
|
|
250
composer.lock
generated
250
composer.lock
generated
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "68c69d9aed8a6c9ef73856c6ddc9ab23",
|
||||
"content-hash": "acf206f49431b95f0fadc3a765e6930a",
|
||||
"packages": [
|
||||
{
|
||||
"name": "behat/gherkin",
|
||||
|
@ -1602,16 +1602,16 @@
|
|||
},
|
||||
{
|
||||
"name": "phpunit/phpunit",
|
||||
"version": "5.7.26",
|
||||
"version": "5.7.27",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/sebastianbergmann/phpunit.git",
|
||||
"reference": "7fbc25c13309de0c4c9bb48b7361f1eca34c7fbd"
|
||||
"reference": "b7803aeca3ccb99ad0a506fa80b64cd6a56bbc0c"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/7fbc25c13309de0c4c9bb48b7361f1eca34c7fbd",
|
||||
"reference": "7fbc25c13309de0c4c9bb48b7361f1eca34c7fbd",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/b7803aeca3ccb99ad0a506fa80b64cd6a56bbc0c",
|
||||
"reference": "b7803aeca3ccb99ad0a506fa80b64cd6a56bbc0c",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1635,7 +1635,7 @@
|
|||
"sebastian/global-state": "^1.1",
|
||||
"sebastian/object-enumerator": "~2.0",
|
||||
"sebastian/resource-operations": "~1.0",
|
||||
"sebastian/version": "~1.0.3|~2.0",
|
||||
"sebastian/version": "^1.0.6|^2.0.1",
|
||||
"symfony/yaml": "~2.1|~3.0|~4.0"
|
||||
},
|
||||
"conflict": {
|
||||
|
@ -1680,7 +1680,7 @@
|
|||
"testing",
|
||||
"xunit"
|
||||
],
|
||||
"time": "2017-12-17T06:14:38+00:00"
|
||||
"time": "2018-02-01T05:50:59+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpunit/phpunit-mock-objects",
|
||||
|
@ -1787,6 +1787,52 @@
|
|||
],
|
||||
"time": "2015-09-11T15:10:35+00:00"
|
||||
},
|
||||
{
|
||||
"name": "psr/cache",
|
||||
"version": "1.0.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/php-fig/cache.git",
|
||||
"reference": "d11b50ad223250cf17b86e38383413f5a6764bf8"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/php-fig/cache/zipball/d11b50ad223250cf17b86e38383413f5a6764bf8",
|
||||
"reference": "d11b50ad223250cf17b86e38383413f5a6764bf8",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Psr\\Cache\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "PHP-FIG",
|
||||
"homepage": "http://www.php-fig.org/"
|
||||
}
|
||||
],
|
||||
"description": "Common interface for caching libraries",
|
||||
"keywords": [
|
||||
"cache",
|
||||
"psr",
|
||||
"psr-6"
|
||||
],
|
||||
"time": "2016-08-06T20:24:11+00:00"
|
||||
},
|
||||
{
|
||||
"name": "psr/container",
|
||||
"version": "1.0.0",
|
||||
|
@ -1933,6 +1979,54 @@
|
|||
],
|
||||
"time": "2016-10-10T12:19:37+00:00"
|
||||
},
|
||||
{
|
||||
"name": "psr/simple-cache",
|
||||
"version": "1.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/php-fig/simple-cache.git",
|
||||
"reference": "753fa598e8f3b9966c886fe13f370baa45ef0e24"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/php-fig/simple-cache/zipball/753fa598e8f3b9966c886fe13f370baa45ef0e24",
|
||||
"reference": "753fa598e8f3b9966c886fe13f370baa45ef0e24",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Psr\\SimpleCache\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "PHP-FIG",
|
||||
"homepage": "http://www.php-fig.org/"
|
||||
}
|
||||
],
|
||||
"description": "Common interfaces for simple caching",
|
||||
"keywords": [
|
||||
"cache",
|
||||
"caching",
|
||||
"psr",
|
||||
"psr-16",
|
||||
"simple-cache"
|
||||
],
|
||||
"time": "2017-01-02T13:31:39+00:00"
|
||||
},
|
||||
{
|
||||
"name": "robmorgan/phinx",
|
||||
"version": "v0.8.1",
|
||||
|
@ -2880,6 +2974,76 @@
|
|||
"homepage": "https://symfony.com",
|
||||
"time": "2018-01-03T07:37:34+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/cache",
|
||||
"version": "v3.4.4",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/cache.git",
|
||||
"reference": "8dee9ec2c9824c3f4039960d679a6689ee1cbdc1"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/cache/zipball/8dee9ec2c9824c3f4039960d679a6689ee1cbdc1",
|
||||
"reference": "8dee9ec2c9824c3f4039960d679a6689ee1cbdc1",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^5.5.9|>=7.0.8",
|
||||
"psr/cache": "~1.0",
|
||||
"psr/log": "~1.0",
|
||||
"psr/simple-cache": "^1.0",
|
||||
"symfony/polyfill-apcu": "~1.1"
|
||||
},
|
||||
"conflict": {
|
||||
"symfony/var-dumper": "<3.3"
|
||||
},
|
||||
"provide": {
|
||||
"psr/cache-implementation": "1.0",
|
||||
"psr/simple-cache-implementation": "1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"cache/integration-tests": "dev-master",
|
||||
"doctrine/cache": "~1.6",
|
||||
"doctrine/dbal": "~2.4",
|
||||
"predis/predis": "~1.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "3.4-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Symfony\\Component\\Cache\\": ""
|
||||
},
|
||||
"exclude-from-classmap": [
|
||||
"/Tests/"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Symfony Cache component with PSR-6, PSR-16, and tags",
|
||||
"homepage": "https://symfony.com",
|
||||
"keywords": [
|
||||
"caching",
|
||||
"psr6"
|
||||
],
|
||||
"time": "2018-01-18T22:16:57+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/config",
|
||||
"version": "v3.4.4",
|
||||
|
@ -3409,17 +3573,73 @@
|
|||
"time": "2018-01-03T07:37:34+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-mbstring",
|
||||
"version": "v1.6.0",
|
||||
"name": "symfony/polyfill-apcu",
|
||||
"version": "v1.7.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/polyfill-mbstring.git",
|
||||
"reference": "2ec8b39c38cb16674bbf3fea2b6ce5bf117e1296"
|
||||
"url": "https://github.com/symfony/polyfill-apcu.git",
|
||||
"reference": "e8ae2136ddb53dea314df56fcd88e318ab936c00"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/2ec8b39c38cb16674bbf3fea2b6ce5bf117e1296",
|
||||
"reference": "2ec8b39c38cb16674bbf3fea2b6ce5bf117e1296",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-apcu/zipball/e8ae2136ddb53dea314df56fcd88e318ab936c00",
|
||||
"reference": "e8ae2136ddb53dea314df56fcd88e318ab936c00",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.3"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.7-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Symfony\\Polyfill\\Apcu\\": ""
|
||||
},
|
||||
"files": [
|
||||
"bootstrap.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Symfony polyfill backporting apcu_* functions to lower PHP versions",
|
||||
"homepage": "https://symfony.com",
|
||||
"keywords": [
|
||||
"apcu",
|
||||
"compatibility",
|
||||
"polyfill",
|
||||
"portable",
|
||||
"shim"
|
||||
],
|
||||
"time": "2018-01-30T19:27:44+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-mbstring",
|
||||
"version": "v1.7.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/polyfill-mbstring.git",
|
||||
"reference": "78be803ce01e55d3491c1397cf1c64beb9c1b63b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/78be803ce01e55d3491c1397cf1c64beb9c1b63b",
|
||||
"reference": "78be803ce01e55d3491c1397cf1c64beb9c1b63b",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -3431,7 +3651,7 @@
|
|||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.6-dev"
|
||||
"dev-master": "1.7-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
|
@ -3465,7 +3685,7 @@
|
|||
"portable",
|
||||
"shim"
|
||||
],
|
||||
"time": "2017-10-11T12:05:26+00:00"
|
||||
"time": "2018-01-30T19:27:44+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/process",
|
||||
|
|
0
runtime/cache/.gitkeep
vendored
Normal file
0
runtime/cache/.gitkeep
vendored
Normal file
|
@ -1,31 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace b8;
|
||||
|
||||
class Cache
|
||||
{
|
||||
const TYPE_APC = 'ApcCache';
|
||||
const TYPE_REQUEST = 'RequestCache';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected static $instance = [];
|
||||
|
||||
/**
|
||||
* Get a cache object of a specified type.
|
||||
*
|
||||
* @param string $type
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getCache($type = self::TYPE_REQUEST)
|
||||
{
|
||||
if (!isset(self::$instance[$type])) {
|
||||
$class = '\\b8\\Cache\\' . $type;
|
||||
self::$instance[$type] = new $class();
|
||||
}
|
||||
|
||||
return self::$instance[$type];
|
||||
}
|
||||
}
|
|
@ -1,149 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Cache;
|
||||
|
||||
use b8\Type;
|
||||
|
||||
class ApcCache implements Type\CacheInterface
|
||||
{
|
||||
/**
|
||||
* Check if caching is enabled.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isEnabled()
|
||||
{
|
||||
$rtn = false;
|
||||
$apcCli = ini_get('apc.enable_cli');
|
||||
|
||||
if (function_exists('apc_fetch') && (php_sapi_name() != 'cli' || in_array($apcCli, ['1', 1, true, 'On']))) {
|
||||
$rtn = true;
|
||||
}
|
||||
|
||||
return $rtn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get item from the cache:
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key, $default = null)
|
||||
{
|
||||
if (!$this->isEnabled()) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
$success = false;
|
||||
$rtn = apc_fetch($key, $success);
|
||||
if (!$success) {
|
||||
$rtn = $default;
|
||||
}
|
||||
|
||||
return $rtn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an item to the cache:
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param integer $ttl
|
||||
*
|
||||
* @return array|bool
|
||||
*/
|
||||
public function set($key, $value = null, $ttl = 0)
|
||||
{
|
||||
if (!$this->isEnabled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return apc_store($key, $value, $ttl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an item from the cache:
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return bool|string[]
|
||||
*/
|
||||
public function delete($key)
|
||||
{
|
||||
if (!$this->isEnabled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return apc_delete($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an item is in the cache:
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return bool|string[]
|
||||
*/
|
||||
public function contains($key)
|
||||
{
|
||||
if (!$this->isEnabled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return apc_exists($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Short-hand syntax for get()
|
||||
*
|
||||
* @see Config::get()
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($key)
|
||||
{
|
||||
return $this->get($key, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Short-hand syntax for set()
|
||||
*
|
||||
* @see Config::set()
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return array|bool
|
||||
*/
|
||||
public function __set($key, $value = null)
|
||||
{
|
||||
return $this->set($key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is set
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return bool|string[]
|
||||
*/
|
||||
public function __isset($key)
|
||||
{
|
||||
return $this->contains($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset
|
||||
*
|
||||
* @param string $key
|
||||
*/
|
||||
public function __unset($key)
|
||||
{
|
||||
$this->delete($key);
|
||||
}
|
||||
}
|
|
@ -1,90 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Cache;
|
||||
|
||||
use b8\Type;
|
||||
|
||||
class RequestCache implements Type\CacheInterface
|
||||
{
|
||||
protected $data = [];
|
||||
|
||||
/**
|
||||
* Check if caching is enabled.
|
||||
*/
|
||||
public function isEnabled()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get item from the cache:
|
||||
*/
|
||||
public function get($key, $default = null)
|
||||
{
|
||||
return $this->contains($key) ? $this->data[$key] : $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an item to the cache:
|
||||
*/
|
||||
public function set($key, $value = null, $ttl = 0)
|
||||
{
|
||||
$this->data[$key] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an item from the cache:
|
||||
*/
|
||||
public function delete($key)
|
||||
{
|
||||
if ($this->contains($key)) {
|
||||
unset($this->data[$key]);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an item is in the cache:
|
||||
*/
|
||||
public function contains($key)
|
||||
{
|
||||
return array_key_exists($key, $this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Short-hand syntax for get()
|
||||
* @see Config::get()
|
||||
*/
|
||||
public function __get($key)
|
||||
{
|
||||
return $this->get($key, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Short-hand syntax for set()
|
||||
* @see Config::set()
|
||||
*/
|
||||
public function __set($key, $value = null)
|
||||
{
|
||||
return $this->set($key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is set
|
||||
*/
|
||||
public function __isset($key)
|
||||
{
|
||||
return $this->contains($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset
|
||||
*/
|
||||
public function __unset($key)
|
||||
{
|
||||
$this->delete($key);
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@
|
|||
namespace b8;
|
||||
|
||||
use b8\Form\FieldSet;
|
||||
use PHPCensor\View;
|
||||
|
||||
class Form extends FieldSet
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace b8\Form;
|
||||
|
||||
use b8\View;
|
||||
use PHPCensor\View;
|
||||
use b8\Config;
|
||||
|
||||
abstract class Element
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace b8\Form\Element;
|
||||
|
||||
use b8\Form\Input;
|
||||
use b8\View;
|
||||
use PHPCensor\View;
|
||||
|
||||
class Button extends Input
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace b8\Form\Element;
|
||||
|
||||
use b8\View;
|
||||
use PHPCensor\View;
|
||||
use b8\Form\Input;
|
||||
|
||||
class Checkbox extends Input
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace b8\Form\Element;
|
||||
|
||||
use b8\View;
|
||||
use PHPCensor\View;
|
||||
|
||||
class Csrf extends Hidden
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace b8\Form\Element;
|
||||
|
||||
use b8\View;
|
||||
use PHPCensor\View;
|
||||
|
||||
class Email extends Text
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace b8\Form\Element;
|
||||
|
||||
use b8\View;
|
||||
use PHPCensor\View;
|
||||
|
||||
class Password extends Text
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace b8\Form\Element;
|
||||
|
||||
use b8\View;
|
||||
use PHPCensor\View;
|
||||
use b8\Form\Input;
|
||||
|
||||
class Select extends Input
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace b8\Form\Element;
|
||||
|
||||
use b8\View;
|
||||
use PHPCensor\View;
|
||||
|
||||
class Submit extends Button
|
||||
{
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace b8\Form\Element;
|
||||
|
||||
use b8\Form\Input;
|
||||
use b8\View;
|
||||
use PHPCensor\View;
|
||||
|
||||
class Text extends Input
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace b8\Form\Element;
|
||||
|
||||
use b8\View;
|
||||
use PHPCensor\View;
|
||||
|
||||
class TextArea extends Text
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace b8\Form\Element;
|
||||
|
||||
use b8\View;
|
||||
use PHPCensor\View;
|
||||
|
||||
class Url extends Text
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace b8\Form;
|
||||
|
||||
use b8\View;
|
||||
use PHPCensor\View;
|
||||
|
||||
class FieldSet extends Element
|
||||
{
|
||||
|
|
|
@ -2,24 +2,24 @@
|
|||
|
||||
namespace b8\Form;
|
||||
|
||||
use b8\View;
|
||||
use PHPCensor\View;
|
||||
|
||||
class Input extends Element
|
||||
{
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_required = false;
|
||||
protected $required = false;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_pattern;
|
||||
protected $pattern;
|
||||
|
||||
/**
|
||||
* @var callable
|
||||
*/
|
||||
protected $_validator;
|
||||
protected $validator;
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
|
@ -29,12 +29,12 @@ class Input extends Element
|
|||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_error;
|
||||
protected $error;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_customError = false;
|
||||
protected $customError = false;
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
|
@ -78,7 +78,7 @@ class Input extends Element
|
|||
*/
|
||||
public function getRequired()
|
||||
{
|
||||
return $this->_required;
|
||||
return $this->required;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -88,7 +88,7 @@ class Input extends Element
|
|||
*/
|
||||
public function setRequired($required)
|
||||
{
|
||||
$this->_required = (bool)$required;
|
||||
$this->required = (bool)$required;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ class Input extends Element
|
|||
*/
|
||||
public function getValidator()
|
||||
{
|
||||
return $this->_validator;
|
||||
return $this->validator;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -109,7 +109,7 @@ class Input extends Element
|
|||
public function setValidator($validator)
|
||||
{
|
||||
if (is_callable($validator) || $validator instanceof \Closure) {
|
||||
$this->_validator = $validator;
|
||||
$this->validator = $validator;
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
@ -120,7 +120,7 @@ class Input extends Element
|
|||
*/
|
||||
public function getPattern()
|
||||
{
|
||||
return $this->_pattern;
|
||||
return $this->pattern;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -130,7 +130,7 @@ class Input extends Element
|
|||
*/
|
||||
public function setPattern($pattern)
|
||||
{
|
||||
$this->_pattern = $pattern;
|
||||
$this->pattern = $pattern;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -141,12 +141,12 @@ class Input extends Element
|
|||
public function validate()
|
||||
{
|
||||
if ($this->getRequired() && empty($this->value)) {
|
||||
$this->_error = $this->getLabel() . ' is required.';
|
||||
$this->error = $this->getLabel() . ' is required.';
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->getPattern() && !preg_match('/' . $this->getPattern() . '/', $this->value)) {
|
||||
$this->_error = 'Invalid value entered.';
|
||||
$this->error = 'Invalid value entered.';
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -157,13 +157,13 @@ class Input extends Element
|
|||
try {
|
||||
call_user_func_array($validator, [$this->value]);
|
||||
} catch (\Exception $ex) {
|
||||
$this->_error = $ex->getMessage();
|
||||
$this->error = $ex->getMessage();
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_customError) {
|
||||
if ($this->customError) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -177,8 +177,8 @@ class Input extends Element
|
|||
*/
|
||||
public function setError($message)
|
||||
{
|
||||
$this->_customError = true;
|
||||
$this->_error = $message;
|
||||
$this->customError = true;
|
||||
$this->error = $message;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -189,8 +189,8 @@ class Input extends Element
|
|||
protected function onPreRender(View &$view)
|
||||
{
|
||||
$view->value = $this->getValue();
|
||||
$view->error = $this->_error;
|
||||
$view->pattern = $this->_pattern;
|
||||
$view->required = $this->_required;
|
||||
$view->error = $this->error;
|
||||
$view->pattern = $this->pattern;
|
||||
$view->required = $this->required;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace b8;
|
||||
|
||||
use b8\Exception\HttpException;
|
||||
use Symfony\Component\Cache\Simple\ArrayCache;
|
||||
|
||||
class Model
|
||||
{
|
||||
|
@ -23,7 +24,7 @@ class Model
|
|||
$this->data = array_merge($this->data, $initialData);
|
||||
}
|
||||
|
||||
$this->cache = Cache::getCache(Cache::TYPE_REQUEST);
|
||||
$this->cache = new ArrayCache();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace b8\Type;
|
||||
|
||||
interface CacheInterface
|
||||
{
|
||||
public function get($key, $default = null);
|
||||
|
||||
public function set($key, $value = null, $ttl = 0);
|
||||
|
||||
public function delete($key);
|
||||
|
||||
public function contains($key);
|
||||
|
||||
public function isEnabled();
|
||||
|
||||
public function __get($key);
|
||||
|
||||
public function __set($key, $value = null);
|
||||
|
||||
public function __unset($key);
|
||||
|
||||
public function __isset($key);
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace b8;
|
||||
|
||||
class View
|
||||
{
|
||||
protected $vars = [];
|
||||
protected static $helpers = [];
|
||||
protected static $extension = 'phtml';
|
||||
|
||||
public function __construct($file, $path = null)
|
||||
{
|
||||
if (!self::exists($file, $path)) {
|
||||
throw new \RuntimeException('View file does not exist: ' . $file);
|
||||
}
|
||||
|
||||
$this->viewFile = self::getViewFile($file, $path);
|
||||
}
|
||||
|
||||
protected static function getViewFile($file, $path = null)
|
||||
{
|
||||
$viewPath = is_null($path) ? Config::getInstance()->get('b8.view.path') : $path;
|
||||
$fullPath = $viewPath . $file . '.' . static::$extension;
|
||||
|
||||
return $fullPath;
|
||||
}
|
||||
|
||||
public static function exists($file, $path = null)
|
||||
{
|
||||
if (!file_exists(self::getViewFile($file, $path))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function __isset($var)
|
||||
{
|
||||
return isset($this->vars[$var]);
|
||||
}
|
||||
|
||||
public function __get($var)
|
||||
{
|
||||
return $this->vars[$var];
|
||||
}
|
||||
|
||||
public function __set($var, $val)
|
||||
{
|
||||
$this->vars[$var] = $val;
|
||||
}
|
||||
|
||||
public function __call($method, $params = [])
|
||||
{
|
||||
if (!isset(self::$helpers[$method])) {
|
||||
$class = '\\' . Config::getInstance()->get('b8.app.namespace') . '\\Helper\\' . $method;
|
||||
|
||||
if (!class_exists($class)) {
|
||||
$class = '\\b8\\View\\Helper\\' . $method;
|
||||
}
|
||||
|
||||
if (!class_exists($class)) {
|
||||
throw new \Exception('Helper class does not exist: ' . $class);
|
||||
}
|
||||
|
||||
self::$helpers[$method] = new $class();
|
||||
}
|
||||
|
||||
return self::$helpers[$method];
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
extract($this->vars);
|
||||
|
||||
ob_start();
|
||||
require($this->viewFile);
|
||||
$html = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
|
@ -1,548 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace b8\View;
|
||||
|
||||
use b8\View;
|
||||
|
||||
class Template extends View
|
||||
{
|
||||
public static $templateFunctions = [];
|
||||
|
||||
protected static $extension = 'html';
|
||||
|
||||
public function __construct($viewCode)
|
||||
{
|
||||
$this->viewCode = $viewCode;
|
||||
|
||||
if (!count(self::$templateFunctions)) {
|
||||
self::$templateFunctions = [
|
||||
'include' => [$this, 'includeTemplate'],
|
||||
'call' => [$this, 'callHelperFunction']
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public static function createFromFile($file, $path = null)
|
||||
{
|
||||
if (!static::exists($file, $path)) {
|
||||
throw new \Exception('View file does not exist: ' . $file);
|
||||
}
|
||||
|
||||
$viewFile = static::getViewFile($file, $path);
|
||||
return new static(file_get_contents($viewFile));
|
||||
}
|
||||
|
||||
public static function createFromString($string)
|
||||
{
|
||||
return new static($string);
|
||||
}
|
||||
|
||||
public function addFunction($name, $handler)
|
||||
{
|
||||
self::$templateFunctions[$name] = $handler;
|
||||
}
|
||||
|
||||
public function removeFunction($name)
|
||||
{
|
||||
unset(self::$templateFunctions[$name]);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return $this->parse($this->viewCode);
|
||||
}
|
||||
|
||||
protected function parse($string)
|
||||
{
|
||||
$keywords = ['ifnot', 'if', 'else', 'for', 'loop', '@', '/ifnot', '/if', '/for', '/loop'];
|
||||
|
||||
foreach (self::$templateFunctions as $function => $handler) {
|
||||
$keywords[] = $function;
|
||||
}
|
||||
|
||||
$stack = ['children' => [['type' => 'string', 'body' => '']]];
|
||||
$stack['children'][0]['parent'] =& $stack;
|
||||
$current =& $stack['children'][0];
|
||||
|
||||
while (!empty($string)) {
|
||||
$current['body'] .= $this->readUntil('{', $string);
|
||||
|
||||
if (!empty($string)) {
|
||||
$gotKeyword = false;
|
||||
|
||||
foreach ($keywords as $keyword) {
|
||||
$kwLen = strlen($keyword) + 1;
|
||||
|
||||
if (substr($string, 0, $kwLen) == '{' . $keyword) {
|
||||
$gotKeyword = true;
|
||||
$item = ['type' => $keyword, 'cond' => '', 'children' => ''];
|
||||
$string = substr($string, $kwLen);
|
||||
|
||||
$cond = trim($this->readUntil('}', $string));
|
||||
$item['cond'] = $cond;
|
||||
$string = substr($string, 1);
|
||||
|
||||
if (array_key_exists($keyword, self::$templateFunctions)) {
|
||||
$item['function_name'] = $keyword;
|
||||
$item['type'] = 'function';
|
||||
}
|
||||
|
||||
$str = ['type' => 'string', 'body' => ''];
|
||||
$parent =& $current['parent'];
|
||||
|
||||
if (substr($current['body'], (0 - strlen(PHP_EOL))) === PHP_EOL) {
|
||||
$current['body'] = substr($current['body'], 0, strlen($current['body']) - strlen(PHP_EOL));
|
||||
}
|
||||
|
||||
$item['parent'] =& $parent;
|
||||
|
||||
$parent['children'][] = $item;
|
||||
|
||||
if ($keyword == '@' || $item['type'] == 'function') {
|
||||
// If we're processing a variable, add a string to the parent and move up to that as current.
|
||||
$parent['children'][] = $str;
|
||||
$current =& $parent['children'][count($parent['children']) - 1];
|
||||
$current['parent'] =& $parent;
|
||||
} elseif (substr($keyword, 0, 1) == '/') {
|
||||
// If we're processing the end of a block (if/loop), add a string to the parent's parent and move up to that.
|
||||
$parent =& $parent['parent'];
|
||||
$parent['children'][] = $str;
|
||||
$current =& $parent['children'][count($parent['children']) - 1];
|
||||
$current['parent'] =& $parent;
|
||||
} else {
|
||||
if (!is_array($parent['children'][count($parent['children']) - 1]['children'])) {
|
||||
$parent['children'][count($parent['children']) - 1]['children'] = [];
|
||||
}
|
||||
$parent['children'][count($parent['children']) - 1]['children'][] = $str;
|
||||
$current =& $parent['children'][count($parent['children']) - 1]['children'][0];
|
||||
$current['parent'] =& $parent['children'][count($parent['children']) - 1];
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$gotKeyword) {
|
||||
$current['body'] .= substr($string, 0, 1);
|
||||
$string = substr($string, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->processStack($stack);
|
||||
}
|
||||
|
||||
protected function processStack($stack)
|
||||
{
|
||||
$res = '';
|
||||
|
||||
while (count($stack['children'])) {
|
||||
$current = array_shift($stack['children']);
|
||||
|
||||
switch ($current['type']) {
|
||||
case 'string':
|
||||
$res .= $current['body'];
|
||||
break;
|
||||
|
||||
case '@':
|
||||
$res .= $this->doParseVar($current['cond']);
|
||||
break;
|
||||
|
||||
case 'if':
|
||||
$res .= $this->doParseIf($current['cond'], $current);
|
||||
break;
|
||||
|
||||
case 'ifnot':
|
||||
$res .= $this->doParseIfNot($current['cond'], $current);
|
||||
break;
|
||||
|
||||
case 'loop':
|
||||
$res .= $this->doParseLoop($current['cond'], $current);
|
||||
break;
|
||||
|
||||
case 'for':
|
||||
$res .= $this->doParseFor($current['cond'], $current);
|
||||
break;
|
||||
|
||||
case 'function':
|
||||
$res .= $this->doParseFunction($current);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
protected function readUntil($until, &$string)
|
||||
{
|
||||
$read = '';
|
||||
|
||||
while (!empty($string)) {
|
||||
$char = substr($string, 0, 1);
|
||||
|
||||
if ($char == $until) {
|
||||
break;
|
||||
}
|
||||
|
||||
$read .= $char;
|
||||
$string = substr($string, 1);
|
||||
}
|
||||
|
||||
return $read;
|
||||
}
|
||||
|
||||
protected function doParseVar($var)
|
||||
{
|
||||
if ($var == 'year') {
|
||||
return date('Y');
|
||||
}
|
||||
|
||||
$val = $this->processVariableName($var);
|
||||
return $val;
|
||||
}
|
||||
|
||||
protected function doParseIf($condition, $stack)
|
||||
{
|
||||
if ($this->ifConditionIsTrue($condition)) {
|
||||
return $this->processStack($stack);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
protected function doParseIfNot($condition, $stack)
|
||||
{
|
||||
if (!$this->ifConditionIsTrue($condition)) {
|
||||
return $this->processStack($stack);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
protected function ifConditionIsTrue($condition)
|
||||
{
|
||||
$matches = [];
|
||||
|
||||
if (preg_match(
|
||||
'/([a-zA-Z0-9_\-\(\):\s.\"]+)\s+?([\!\=\<\>]+)?\s+?([a-zA-Z0-9\(\)_\-:\s.\"]+)?/',
|
||||
$condition,
|
||||
$matches
|
||||
)) {
|
||||
$left = is_numeric($matches[1])
|
||||
? intval($matches[1])
|
||||
: $this->processVariableName($matches[1]);
|
||||
|
||||
$right = is_numeric($matches[3])
|
||||
? intval($matches[3])
|
||||
: $this->processVariableName($matches[3]);
|
||||
|
||||
$operator = $matches[2];
|
||||
|
||||
switch ($operator) {
|
||||
case '==':
|
||||
case '=':
|
||||
return ($left == $right);
|
||||
|
||||
case '!=':
|
||||
return ($left != $right);
|
||||
|
||||
case '>=':
|
||||
return ($left >= $right);
|
||||
|
||||
case '<=':
|
||||
return ($left <= $right);
|
||||
|
||||
case '>':
|
||||
return ($left > $right);
|
||||
|
||||
case '<':
|
||||
return ($left < $right);
|
||||
}
|
||||
} elseif (preg_match('/([a-zA-Z0-9_\-\(\):\s.]+)/', $condition, $matches)) {
|
||||
return $this->processVariableName($condition) ? true : false;
|
||||
}
|
||||
}
|
||||
|
||||
protected function doParseLoop($var, $stack)
|
||||
{
|
||||
$working = $this->processVariableName($var);
|
||||
|
||||
if (is_null($working)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (!is_array($working)) {
|
||||
$working = [$working];
|
||||
}
|
||||
|
||||
$rtn = '';
|
||||
foreach ($working as $key => $val) {
|
||||
// Make sure we support nesting loops:
|
||||
$keyWas = isset($this->key) ? $this->key : null;
|
||||
$valWas = isset($this->value) ? $this->value : null;
|
||||
$itemWas = isset($this->item) ? $this->item : null;
|
||||
|
||||
// Set up the necessary variables within the stack:
|
||||
$this->parent = $this;
|
||||
$this->item = $val;
|
||||
$this->key = $key;
|
||||
$this->value = $val;
|
||||
$rtn .= $this->processStack($stack);
|
||||
|
||||
// Restore state for any parent nested loops:
|
||||
$this->item = $itemWas;
|
||||
$this->key = $keyWas;
|
||||
$this->value = $valWas;
|
||||
}
|
||||
|
||||
return $rtn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes loops in templates, of the following styles:
|
||||
*
|
||||
* <code>
|
||||
* {for myarray.items}
|
||||
* {@item.title}
|
||||
* {/for}
|
||||
* </code>
|
||||
*
|
||||
* Or:
|
||||
*
|
||||
* <code>
|
||||
* {for 0:pages.count; i++}
|
||||
* <a href="/item/{@i}">{@i}</a>
|
||||
* {/for}
|
||||
* </code>
|
||||
*
|
||||
* @param $cond string The condition string for the loop, to be parsed (e.g. "myarray.items" or "0:pages.count; i++")
|
||||
* @param $stack string The child stack for this loop, to be processed for each item.
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function doParseFor($cond, $stack)
|
||||
{
|
||||
// If this is a simple foreach loop, jump over to parse loop:
|
||||
if (strpos($cond, ';') === false) {
|
||||
return $this->doParseLoop($cond, $stack);
|
||||
}
|
||||
|
||||
// Otherwise, process as a for loop:
|
||||
$parts = explode(';', $cond);
|
||||
$range = explode(':', trim($parts[0]));
|
||||
|
||||
// Process range:
|
||||
$rangeLeft = $this->getForRangePart($range[0]);
|
||||
$rangeRight = $this->getForRangePart($range[1]);
|
||||
|
||||
// Process variable & incrementor / decrementor:
|
||||
$parts[1] = trim($parts[1]);
|
||||
|
||||
$matches = [];
|
||||
if (preg_match('/([a-zA-Z0-9_]+)(\+\+|\-\-)/', $parts[1], $matches)) {
|
||||
$varName = $matches[1];
|
||||
$direction = $matches[2] == '++' ? 'increment' : 'decrement';
|
||||
} else {
|
||||
throw new \Exception('Syntax error in for loop: ' . $cond);
|
||||
}
|
||||
|
||||
$rtn = '';
|
||||
|
||||
if ($direction == 'increment') {
|
||||
for ($i = $rangeLeft; $i < $rangeRight; $i++) {
|
||||
$this->parent = $this;
|
||||
$this->{$varName} = $i;
|
||||
$rtn .= $this->processStack($stack);
|
||||
}
|
||||
} else {
|
||||
for ($i = $rangeLeft; $i > $rangeRight; $i--) {
|
||||
$this->parent = $this;
|
||||
$this->{$varName} = $i;
|
||||
$rtn .= $this->processStack($stack);
|
||||
}
|
||||
}
|
||||
|
||||
return $rtn;
|
||||
}
|
||||
|
||||
protected function getForRangePart($part)
|
||||
{
|
||||
if (is_numeric($part)) {
|
||||
return intval($part);
|
||||
}
|
||||
|
||||
$varPart = $this->processVariableName($part);
|
||||
|
||||
if (is_numeric($varPart)) {
|
||||
return intval($varPart);
|
||||
}
|
||||
|
||||
throw new \Exception('Invalid range in for loop: ' . $part);
|
||||
}
|
||||
|
||||
public function processVariableName($varName)
|
||||
{
|
||||
// Case one - Test for function calls:
|
||||
if (substr($varName, 0, 1) == '(' && substr($varName, -1) == ')') {
|
||||
$functionCall = substr($varName, 1, -1);
|
||||
$parts = explode(' ', $functionCall, 2);
|
||||
$functionName = $parts[0];
|
||||
$arguments = isset($parts[1]) ? $parts[1] : null;
|
||||
|
||||
return $this->executeTemplateFunction($functionName, $arguments);
|
||||
}
|
||||
|
||||
// Case two - Test if it is just a string:
|
||||
if (substr($varName, 0, 1) == '"' && substr($varName, -1) == '"') {
|
||||
return substr($varName, 1, -1);
|
||||
}
|
||||
|
||||
// Case three - Test if it is just a number:
|
||||
if (is_numeric($varName)) {
|
||||
return $varName;
|
||||
}
|
||||
|
||||
// Case four - Test for helper calls:
|
||||
if (strpos($varName, ':') !== false) {
|
||||
list($helper, $property) = explode(':', $varName);
|
||||
|
||||
$helper = $this->{$helper}();
|
||||
|
||||
if (property_exists($helper, $property) || method_exists($helper, '__get')) {
|
||||
return $helper->{$property};
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// Case five - Process as a variable:
|
||||
$varPart = explode('.', $varName);
|
||||
$thisPart = array_shift($varPart);
|
||||
|
||||
|
||||
if (!array_key_exists($thisPart, $this->vars)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$working = $this->{$thisPart};
|
||||
|
||||
while (count($varPart)) {
|
||||
$thisPart = array_shift($varPart);
|
||||
|
||||
if (is_object($working)) {
|
||||
// Check if we're working with an actual property:
|
||||
if (property_exists($working, $thisPart)) {
|
||||
$working = $working->{$thisPart};
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if the object has a magic __get method:
|
||||
if (method_exists($working, '__get')) {
|
||||
$working = $working->{$thisPart};
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (is_array($working) && array_key_exists($thisPart, $working)) {
|
||||
$working = $working[$thisPart];
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($thisPart == 'toLowerCase') {
|
||||
$working = strtolower($working);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($thisPart == 'toUpperCase') {
|
||||
$working = strtoupper($working);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($thisPart == 'isNumeric') {
|
||||
return is_numeric($working);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return $working;
|
||||
}
|
||||
|
||||
protected function doParseFunction($stack)
|
||||
{
|
||||
return $this->executeTemplateFunction($stack['function_name'], $stack['cond']);
|
||||
}
|
||||
|
||||
protected function executeTemplateFunction($function, $args)
|
||||
{
|
||||
if (array_key_exists($function, self::$templateFunctions)) {
|
||||
$handler = self::$templateFunctions[$function];
|
||||
$args = $this->processFunctionArguments($args);
|
||||
|
||||
return $handler($args, $this);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function processFunctionArguments($args)
|
||||
{
|
||||
$rtn = [];
|
||||
$args = explode(';', $args);
|
||||
|
||||
foreach ($args as $arg) {
|
||||
$arg = explode(':', $arg);
|
||||
|
||||
if (count($arg) == 2) {
|
||||
$key = trim($arg[0]);
|
||||
$val = trim($arg[1]);
|
||||
|
||||
if (strpos($val, ',') !== false) {
|
||||
$val = explode(',', $val);
|
||||
}
|
||||
|
||||
$rtn[$key] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
return $rtn;
|
||||
}
|
||||
|
||||
public function getVariable($variable)
|
||||
{
|
||||
return $this->processVariableName($variable);
|
||||
}
|
||||
|
||||
protected function includeTemplate($args, $view)
|
||||
{
|
||||
$template = static::createFromFile($view->getVariable($args['template']));
|
||||
|
||||
if (isset($args['variables'])) {
|
||||
if (!is_array($args['variables'])) {
|
||||
$args['variables'] = [$args['variables']];
|
||||
}
|
||||
|
||||
foreach ($args['variables'] as $variable) {
|
||||
$variable = explode('=>', $variable);
|
||||
$variable = array_map('trim', $variable);
|
||||
|
||||
if (count($variable) == 1) {
|
||||
$template->{$variable[0]} = $view->getVariable($variable[0]);
|
||||
} else {
|
||||
$template->{$variable[1]} = $view->getVariable($variable[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $template->render();
|
||||
}
|
||||
|
||||
protected function callHelperFunction($args)
|
||||
{
|
||||
$helper = $args['helper'];
|
||||
$function = $args['method'];
|
||||
|
||||
return $this->{$helper}()->{$function}();
|
||||
}
|
||||
}
|
|
@ -6,7 +6,6 @@ use b8;
|
|||
use b8\Exception\HttpException;
|
||||
use b8\Http\Response;
|
||||
use b8\Http\Response\RedirectResponse;
|
||||
use b8\View;
|
||||
|
||||
/**
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
|
@ -33,11 +32,8 @@ class Application extends b8\Application
|
|||
$user = b8\Store\Factory::getStore('User')->getByPrimaryKey($_SESSION['php-censor-user-id']);
|
||||
|
||||
if ($user) {
|
||||
$_SESSION['php-censor-user'] = $user;
|
||||
return true;
|
||||
}
|
||||
|
||||
unset($_SESSION['php-censor-user-id']);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -159,11 +155,9 @@ class Application extends b8\Application
|
|||
$defaultUserId = (integer)$config->get('php-censor.security.default_user_id', 1);
|
||||
|
||||
if ($disableAuth && $defaultUserId) {
|
||||
$user = b8\Store\Factory::getStore('User')
|
||||
->getByPrimaryKey($defaultUserId);
|
||||
$user = b8\Store\Factory::getStore('User')->getByPrimaryKey($defaultUserId);
|
||||
|
||||
if ($user) {
|
||||
$_SESSION['php-censor-user'] = $user;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,22 +6,29 @@ use b8\Config;
|
|||
use b8\Exception\HttpException\ForbiddenException;
|
||||
use b8\Http\Request;
|
||||
use b8\Http\Response;
|
||||
use b8\View;
|
||||
use b8\Store\Factory;
|
||||
use PHPCensor\Model\User;
|
||||
use PHPCensor\Store\UserStore;
|
||||
|
||||
class Controller extends \b8\Controller
|
||||
{
|
||||
/**
|
||||
* @var \b8\View
|
||||
* @var View
|
||||
*/
|
||||
protected $controllerView;
|
||||
|
||||
/**
|
||||
* @var \b8\View
|
||||
* @var View
|
||||
*/
|
||||
protected $view;
|
||||
|
||||
/**
|
||||
* @var \b8\View
|
||||
* @var string
|
||||
*/
|
||||
protected $className;
|
||||
|
||||
/**
|
||||
* @var View
|
||||
*/
|
||||
public $layout;
|
||||
|
||||
|
@ -45,6 +52,8 @@ class Controller extends \b8\Controller
|
|||
$class = explode('\\', get_class($this));
|
||||
$this->className = substr(array_pop($class), 0, -10);
|
||||
$this->setControllerView();
|
||||
|
||||
unset($_SESSION['php-censor-user']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -55,7 +64,7 @@ class Controller extends \b8\Controller
|
|||
if (View::exists($this->className)) {
|
||||
$this->controllerView = new View($this->className);
|
||||
} else {
|
||||
$this->controllerView = new View\Template('{@content}');
|
||||
$this->controllerView = new View('{@content}');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,6 +127,26 @@ class Controller extends \b8\Controller
|
|||
*/
|
||||
protected function currentUserIsAdmin()
|
||||
{
|
||||
return $_SESSION['php-censor-user']->getIsAdmin();
|
||||
$user = $this->getUser();
|
||||
if (!$user) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->getUser()->getIsAdmin();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User|null
|
||||
*/
|
||||
protected function getUser()
|
||||
{
|
||||
if (empty($_SESSION['php-censor-user-id'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var UserStore $userStore */
|
||||
$userStore = Factory::getStore('User');
|
||||
|
||||
return $userStore->getById($_SESSION['php-censor-user-id']);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ use PHPCensor\Model\Project;
|
|||
use PHPCensor\Model\User;
|
||||
use PHPCensor\Service\BuildService;
|
||||
use PHPCensor\Controller;
|
||||
use PHPCensor\View;
|
||||
|
||||
/**
|
||||
* Build Controller - Allows users to run and view builds.
|
||||
|
@ -72,7 +73,7 @@ class BuildController extends Controller
|
|||
}
|
||||
|
||||
/** @var User $user */
|
||||
$user = $_SESSION['php-censor-user'];
|
||||
$user = $this->getUser();
|
||||
$perPage = $user->getFinalPerPage();
|
||||
$data = $this->getBuildData($build, $plugin, $severity, $isNew, (($page - 1) * $perPage), $perPage);
|
||||
$pages = ($data['errors'] === 0)
|
||||
|
@ -189,7 +190,7 @@ class BuildController extends Controller
|
|||
$errorStore = b8\Store\Factory::getStore('BuildError');
|
||||
$errors = $errorStore->getByBuildId($build->getId(), $perPage, $start, $plugin, $severity, $isNew);
|
||||
|
||||
$errorView = new b8\View('Build/errors');
|
||||
$errorView = new View('Build/errors');
|
||||
$errorView->build = $build;
|
||||
$errorView->errors = $errors['items'];
|
||||
|
||||
|
@ -213,7 +214,7 @@ class BuildController extends Controller
|
|||
*/
|
||||
protected function getPaginatorHtml($buildId, $plugin, $severity, $isNew, $total, $perPage, $page)
|
||||
{
|
||||
$view = new b8\View('pagination');
|
||||
$view = new View('pagination');
|
||||
|
||||
$urlPattern = APP_URL . 'build/view/' . $buildId;
|
||||
$params = [];
|
||||
|
@ -306,7 +307,7 @@ class BuildController extends Controller
|
|||
foreach ($builds['items'] as $build) {
|
||||
$item = $build->toArray(1);
|
||||
|
||||
$header = new b8\View('Build/header-row');
|
||||
$header = new View('Build/header-row');
|
||||
$header->build = $build;
|
||||
|
||||
$item['header_row'] = $header->render();
|
||||
|
|
|
@ -74,7 +74,7 @@ class GroupController extends Controller
|
|||
$group->setTitle($this->getParam('title'));
|
||||
if (is_null($groupId)) {
|
||||
/** @var User $user */
|
||||
$user = $_SESSION['php-censor-user'];
|
||||
$user = $this->getUser();
|
||||
|
||||
$group->setCreateDate(new \DateTime());
|
||||
$group->setUserId($user->getId());
|
||||
|
|
|
@ -16,6 +16,7 @@ use PHPCensor\Service\BuildService;
|
|||
use PHPCensor\Service\ProjectService;
|
||||
use PHPCensor\Model\Build;
|
||||
use b8\Http\Response\RedirectResponse;
|
||||
use PHPCensor\View;
|
||||
|
||||
/**
|
||||
* Project Controller - Allows users to create, edit and view projects.
|
||||
|
@ -95,7 +96,7 @@ class ProjectController extends PHPCensor\Controller
|
|||
}
|
||||
|
||||
/** @var PHPCensor\Model\User $user */
|
||||
$user = $_SESSION['php-censor-user'];
|
||||
$user = $this->getUser();
|
||||
$perPage = $user->getFinalPerPage();
|
||||
$builds = $this->getLatestBuildsHtml($projectId, $branch, $environment, (($page - 1) * $perPage), $perPage);
|
||||
$pages = ($builds[1] === 0)
|
||||
|
@ -141,7 +142,7 @@ class ProjectController extends PHPCensor\Controller
|
|||
*/
|
||||
protected function getPaginatorHtml($projectId, $branch, $environment, $total, $perPage, $page)
|
||||
{
|
||||
$view = new b8\View('pagination');
|
||||
$view = new View('pagination');
|
||||
|
||||
$urlPattern = APP_URL . 'project/view/' . $projectId;
|
||||
$params = [];
|
||||
|
@ -178,7 +179,7 @@ class ProjectController extends PHPCensor\Controller
|
|||
if (empty($project) || $project->getArchived()) {
|
||||
throw new NotFoundException(Lang::get('project_x_not_found', $projectId));
|
||||
}
|
||||
|
||||
|
||||
$type = $this->getParam('type', 'branch');
|
||||
$id = $this->getParam('id');
|
||||
$debug = (boolean)$this->getParam('debug', false);
|
||||
|
@ -208,7 +209,7 @@ class ProjectController extends PHPCensor\Controller
|
|||
}
|
||||
|
||||
/** @var PHPCensor\Model\User $user */
|
||||
$user = $_SESSION['php-censor-user'];
|
||||
$user = $this->getUser();
|
||||
$build = $this->buildService->createBuild(
|
||||
$project,
|
||||
$environment,
|
||||
|
@ -273,7 +274,7 @@ class ProjectController extends PHPCensor\Controller
|
|||
|
||||
$order = ['id' => 'DESC'];
|
||||
$builds = $this->buildStore->getWhere($criteria, $perPage, $start, [], $order);
|
||||
$view = new b8\View('Project/ajax-builds');
|
||||
$view = new View('Project/ajax-builds');
|
||||
|
||||
foreach ($builds['items'] as &$build) {
|
||||
$build = BuildFactory::getBuild($build);
|
||||
|
@ -312,7 +313,7 @@ class ProjectController extends PHPCensor\Controller
|
|||
$form = $this->projectForm($values);
|
||||
|
||||
if ($method != 'POST' || ($method == 'POST' && !$form->validate())) {
|
||||
$view = new b8\View('Project/edit');
|
||||
$view = new View('Project/edit');
|
||||
$view->type = 'add';
|
||||
$view->project = null;
|
||||
$view->form = $form;
|
||||
|
@ -336,7 +337,7 @@ class ProjectController extends PHPCensor\Controller
|
|||
];
|
||||
|
||||
/** @var PHPCensor\Model\User $user */
|
||||
$user = $_SESSION['php-censor-user'];
|
||||
$user = $this->getUser();
|
||||
$project = $this->projectService->createProject($title, $type, $reference, $user->getId(), $options);
|
||||
|
||||
$response = new RedirectResponse();
|
||||
|
@ -381,7 +382,7 @@ class ProjectController extends PHPCensor\Controller
|
|||
$form = $this->projectForm($values, 'edit/' . $projectId);
|
||||
|
||||
if ($method != 'POST' || ($method == 'POST' && !$form->validate())) {
|
||||
$view = new b8\View('Project/edit');
|
||||
$view = new View('Project/edit');
|
||||
$view->type = 'edit';
|
||||
$view->project = $project;
|
||||
$view->form = $form;
|
||||
|
|
|
@ -11,7 +11,7 @@ use PHPCensor\Store\UserStore;
|
|||
|
||||
/**
|
||||
* Session Controller - Handles user login / logout.
|
||||
*
|
||||
*
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
*/
|
||||
class SessionController extends Controller
|
||||
|
@ -53,7 +53,7 @@ class SessionController extends Controller
|
|||
return $response;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$isLoginFailure = false;
|
||||
|
||||
if ($this->request->getMethod() == 'POST') {
|
||||
|
@ -92,7 +92,7 @@ class SessionController extends Controller
|
|||
|
||||
if ($rememberMe) {
|
||||
$rememberKey = md5(microtime(true));
|
||||
|
||||
|
||||
$user->setRememberKey($rememberKey);
|
||||
$this->userStore->save($user);
|
||||
|
||||
|
@ -161,7 +161,6 @@ class SessionController extends Controller
|
|||
*/
|
||||
public function logout()
|
||||
{
|
||||
unset($_SESSION['php-censor-user']);
|
||||
unset($_SESSION['php-censor-user-id']);
|
||||
|
||||
session_destroy();
|
||||
|
@ -233,7 +232,8 @@ class SessionController extends Controller
|
|||
$hash = password_hash($this->getParam('password'), PASSWORD_DEFAULT);
|
||||
$user->setHash($hash);
|
||||
|
||||
$_SESSION['php-censor-user'] = $this->userStore->save($user);
|
||||
$this->userStore->save($user);
|
||||
|
||||
$_SESSION['php-censor-user-id'] = $user->getId();
|
||||
|
||||
$response = new b8\Http\Response\RedirectResponse();
|
||||
|
|
|
@ -9,10 +9,11 @@ use PHPCensor\Controller;
|
|||
use PHPCensor\Helper\Lang;
|
||||
use PHPCensor\Model\User;
|
||||
use PHPCensor\Service\UserService;
|
||||
use PHPCensor\View;
|
||||
|
||||
/**
|
||||
* User Controller - Allows an administrator to view, add, edit and delete users.
|
||||
*
|
||||
*
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
*/
|
||||
class UserController extends Controller
|
||||
|
@ -55,13 +56,13 @@ class UserController extends Controller
|
|||
public function profile()
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $_SESSION['php-censor-user'];
|
||||
$user = $this->getUser();
|
||||
|
||||
if ($this->request->getMethod() == 'POST') {
|
||||
$name = $this->getParam('name', null);
|
||||
$email = $this->getParam('email', null);
|
||||
$password = $this->getParam('password', null);
|
||||
|
||||
|
||||
$language = $this->getParam('language', null);
|
||||
if (!$language) {
|
||||
$language = null;
|
||||
|
@ -72,8 +73,7 @@ class UserController extends Controller
|
|||
$perPage = null;
|
||||
}
|
||||
|
||||
$_SESSION['php-censor-user'] = $this->userService->updateUser($user, $name, $email, $password, null, $language, $perPage);
|
||||
$user = $_SESSION['php-censor-user'];
|
||||
$user = $this->userService->updateUser($user, $name, $email, $password, null, $language, $perPage);
|
||||
|
||||
$this->view->updated = 1;
|
||||
}
|
||||
|
@ -166,7 +166,7 @@ class UserController extends Controller
|
|||
$form = $this->userForm($values);
|
||||
|
||||
if ($method != 'POST' || ($method == 'POST' && !$form->validate())) {
|
||||
$view = new b8\View('User/edit');
|
||||
$view = new View('User/edit');
|
||||
$view->type = 'add';
|
||||
$view->user = null;
|
||||
$view->form = $form;
|
||||
|
@ -208,7 +208,7 @@ class UserController extends Controller
|
|||
$form = $this->userForm($values, 'edit/' . $userId);
|
||||
|
||||
if ($method != 'POST' || ($method == 'POST' && !$form->validate())) {
|
||||
$view = new b8\View('User/edit');
|
||||
$view = new View('User/edit');
|
||||
$view->type = 'edit';
|
||||
$view->user = $user;
|
||||
$view->form = $form;
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace PHPCensor\Controller;
|
|||
use PHPCensor\Model\Build;
|
||||
use PHPCensor\Controller;
|
||||
use b8\Store\Factory;
|
||||
use b8\View;
|
||||
use PHPCensor\View;
|
||||
use PHPCensor\Model\Project;
|
||||
use b8\Http\Response;
|
||||
use PHPCensor\Store\BuildStore;
|
||||
|
@ -101,7 +101,7 @@ class WidgetAllProjectsController extends Controller
|
|||
|
||||
/**
|
||||
* Get a summary of the project groups we have, and what projects they have in them.
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getGroupInfo()
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace PHPCensor\Controller;
|
||||
|
||||
use b8\Store\Factory;
|
||||
use b8\View;
|
||||
use PHPCensor\View;
|
||||
use b8\Http\Response;
|
||||
use PHPCensor\Controller;
|
||||
use PHPCensor\Store\BuildStore;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace PHPCensor\Controller;
|
||||
|
||||
use b8\Store\Factory;
|
||||
use b8\View;
|
||||
use PHPCensor\View;
|
||||
use b8\Http\Response;
|
||||
use PHPCensor\BuildFactory;
|
||||
use PHPCensor\Controller;
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
namespace PHPCensor\Helper;
|
||||
|
||||
use b8\Cache;
|
||||
use b8\Config;
|
||||
use GuzzleHttp\Client;
|
||||
use Symfony\Component\Cache\Simple\FilesystemCache;
|
||||
|
||||
/**
|
||||
* The Github Helper class provides some Github API call functionality.
|
||||
|
@ -26,10 +26,10 @@ class Github
|
|||
$response = $client->get(('https://api.github.com' . $url), [
|
||||
'query' => $params,
|
||||
]);
|
||||
|
||||
|
||||
$body = json_decode($response->getBody(), true);
|
||||
$headers = $response->getHeaders();
|
||||
|
||||
|
||||
foreach ($body as $item) {
|
||||
$results[] = $item;
|
||||
}
|
||||
|
@ -62,8 +62,8 @@ class Github
|
|||
return [];
|
||||
}
|
||||
|
||||
$cache = Cache::getCache(Cache::TYPE_APC);
|
||||
$rtn = $cache->get('php-censor-github-repos');
|
||||
$cache = new FilesystemCache('', 0, RUNTIME_DIR . 'cache');
|
||||
$rtn = $cache->get('php-censor.github-repos');
|
||||
|
||||
if (!$rtn) {
|
||||
$client = new Client();
|
||||
|
@ -90,7 +90,7 @@ class Github
|
|||
}
|
||||
}
|
||||
|
||||
$cache->set('php-censor-github-repos', $rtn);
|
||||
$cache->set('php-censor.github-repos', $rtn, 3600);
|
||||
}
|
||||
|
||||
return $rtn;
|
||||
|
|
|
@ -3,7 +3,9 @@
|
|||
namespace PHPCensor\Helper;
|
||||
|
||||
use b8\Config;
|
||||
use b8\Store\Factory;
|
||||
use PHPCensor\Model\User;
|
||||
use PHPCensor\Store\UserStore;
|
||||
|
||||
/**
|
||||
* Languages Helper Class - Handles loading strings files and the strings within them.
|
||||
|
@ -11,7 +13,7 @@ use PHPCensor\Model\User;
|
|||
class Lang
|
||||
{
|
||||
const DEFAULT_LANGUAGE = 'en';
|
||||
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
@ -99,7 +101,7 @@ class Lang
|
|||
$languages = [];
|
||||
foreach (self::$languages as $language) {
|
||||
$strings = include(SRC_DIR . 'Languages' . DIRECTORY_SEPARATOR . 'lang.' . $language . '.php');
|
||||
$languages[$language] = !empty($strings['language_name'])
|
||||
$languages[$language] = !empty($strings['language_name'])
|
||||
? $strings['language_name'] . ' (' . $language . ')'
|
||||
: $language;
|
||||
}
|
||||
|
@ -132,11 +134,11 @@ class Lang
|
|||
return;
|
||||
}
|
||||
|
||||
/** @var User $user */
|
||||
$user = !empty($_SESSION['php-censor-user']) ? $_SESSION['php-censor-user'] : null;
|
||||
|
||||
if ((!is_object($user) || get_class($user) == '__PHP_Incomplete_Class') && gettype($user) == 'object') {
|
||||
$user = unserialize(serialize($_SESSION['php-censor-user']));
|
||||
$user = null;
|
||||
if (!empty($_SESSION['php-censor-user-id'])) {
|
||||
/** @var UserStore $userStore */
|
||||
$userStore = Factory::getStore('User');
|
||||
$user = $userStore->getById($_SESSION['php-censor-user-id']);
|
||||
}
|
||||
|
||||
if ($user) {
|
||||
|
@ -173,7 +175,7 @@ class Lang
|
|||
if (is_null($strings) || !is_array($strings) || !count($strings)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
return $strings;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace PHPCensor\Helper;
|
||||
|
||||
use b8\Config;
|
||||
|
||||
/**
|
||||
* Login Is Disabled Helper - Checks if login is disabled in the view
|
||||
*
|
||||
* @author Stephen Ball <phpci@stephen.rebelinblue.com>
|
||||
*/
|
||||
class LoginIsDisabled
|
||||
{
|
||||
/**
|
||||
* Checks if
|
||||
*
|
||||
* @param $method
|
||||
* @param array $params
|
||||
*
|
||||
* @return mixed|null
|
||||
*/
|
||||
public function __call($method, $params = [])
|
||||
{
|
||||
unset($method, $params);
|
||||
|
||||
$config = Config::getInstance();
|
||||
$disableAuth = (boolean)$config->get('php-censor.security.disable_auth', false);
|
||||
|
||||
return $disableAuth;
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace PHPCensor\Helper;
|
||||
|
||||
/**
|
||||
* User Helper - Provides access to logged in user information in views.
|
||||
*
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
*/
|
||||
class User
|
||||
{
|
||||
/**
|
||||
* Proxies method calls through to the current active user model.
|
||||
* @param $method
|
||||
* @param array $params
|
||||
* @return mixed|null
|
||||
*/
|
||||
public function __call($method, $params = [])
|
||||
{
|
||||
if (empty($_SESSION['php-censor-user'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$user = $_SESSION['php-censor-user'];
|
||||
|
||||
if (!is_object($user)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return call_user_func_array([$user, $method], $params);
|
||||
}
|
||||
}
|
|
@ -397,8 +397,8 @@ class BuildError extends Model
|
|||
return null;
|
||||
}
|
||||
|
||||
$cacheKey = 'Cache.Build.' . $key;
|
||||
$rtn = $this->cache->get($cacheKey, null);
|
||||
$cacheKey = 'php-censor.build-' . $key;
|
||||
$rtn = $this->cache->get($cacheKey);
|
||||
|
||||
if (empty($rtn)) {
|
||||
$rtn = Factory::getStore('Build', 'PHPCensor')->getById($key);
|
||||
|
|
|
@ -181,8 +181,8 @@ class BuildMeta extends Model
|
|||
return null;
|
||||
}
|
||||
|
||||
$cacheKey = 'Cache.Build.' . $key;
|
||||
$rtn = $this->cache->get($cacheKey, null);
|
||||
$cacheKey = 'php-censor.build-' . $key;
|
||||
$rtn = $this->cache->get($cacheKey);
|
||||
|
||||
if (empty($rtn)) {
|
||||
$rtn = Factory::getStore('Build', 'PHPCensor')->getById($key);
|
||||
|
|
|
@ -453,8 +453,8 @@ class Project extends Model
|
|||
return null;
|
||||
}
|
||||
|
||||
$cacheKey = 'Cache.ProjectGroup.' . $key;
|
||||
$rtn = $this->cache->get($cacheKey, null);
|
||||
$cacheKey = 'php-censor.project-group-' . $key;
|
||||
$rtn = $this->cache->get($cacheKey);
|
||||
|
||||
if (empty($rtn)) {
|
||||
$rtn = Factory::getStore('ProjectGroup', 'PHPCensor')->getById($key);
|
||||
|
@ -741,8 +741,8 @@ class Project extends Model
|
|||
return null;
|
||||
}
|
||||
|
||||
$cacheKey = 'Cache.ProjectEnvironments.' . $key;
|
||||
$rtn = $this->cache->get($cacheKey, null);
|
||||
$cacheKey = 'php-censor.project-environments-' . $key;
|
||||
$rtn = $this->cache->get($cacheKey);
|
||||
|
||||
if (empty($rtn)) {
|
||||
$store = $this->getEnvironmentStore();
|
||||
|
|
|
@ -2,14 +2,14 @@
|
|||
|
||||
namespace PHPCensor\Plugin;
|
||||
|
||||
use b8\View;
|
||||
use PHPCensor\View;
|
||||
use PHPCensor\Helper\Email as EmailHelper;
|
||||
use Psr\Log\LogLevel;
|
||||
use PHPCensor\Plugin;
|
||||
|
||||
/**
|
||||
* Email Plugin - Provides simple email capability.
|
||||
*
|
||||
*
|
||||
* @author Steve Brazier <meadsteve@gmail.com>
|
||||
*/
|
||||
class Email extends Plugin
|
||||
|
|
105
src/PHPCensor/View.php
Normal file
105
src/PHPCensor/View.php
Normal file
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
|
||||
namespace PHPCensor;
|
||||
|
||||
use b8\Config;
|
||||
use b8\Store\Factory;
|
||||
use PHPCensor\Model\User;
|
||||
use PHPCensor\Store\UserStore;
|
||||
|
||||
class View
|
||||
{
|
||||
protected $vars = [];
|
||||
protected $isContent = false;
|
||||
|
||||
protected static $extension = 'phtml';
|
||||
|
||||
public function __construct($file, $path = null)
|
||||
{
|
||||
if ('{@content}' === $file) {
|
||||
$this->isContent = true;
|
||||
} else {
|
||||
if (!self::exists($file, $path)) {
|
||||
throw new \RuntimeException('View file does not exist: ' . $file);
|
||||
}
|
||||
|
||||
$this->viewFile = self::getViewFile($file, $path);
|
||||
}
|
||||
}
|
||||
|
||||
protected static function getViewFile($file, $path = null)
|
||||
{
|
||||
$viewPath = is_null($path) ? Config::getInstance()->get('b8.view.path') : $path;
|
||||
$fullPath = $viewPath . $file . '.' . static::$extension;
|
||||
|
||||
return $fullPath;
|
||||
}
|
||||
|
||||
public static function exists($file, $path = null)
|
||||
{
|
||||
if (!file_exists(self::getViewFile($file, $path))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function __isset($var)
|
||||
{
|
||||
return isset($this->vars[$var]);
|
||||
}
|
||||
|
||||
public function __get($var)
|
||||
{
|
||||
return $this->vars[$var];
|
||||
}
|
||||
|
||||
public function __set($var, $val)
|
||||
{
|
||||
$this->vars[$var] = $val;
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
if ($this->isContent) {
|
||||
return $this->vars['content'];
|
||||
} else {
|
||||
extract($this->vars);
|
||||
|
||||
ob_start();
|
||||
|
||||
require($this->viewFile);
|
||||
|
||||
$html = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
protected function LoginIsDisabled()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$disableAuth = (boolean)$config->get('php-censor.security.disable_auth', false);
|
||||
|
||||
return $disableAuth;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User|null
|
||||
*/
|
||||
protected function getUser()
|
||||
{
|
||||
if (empty($_SESSION['php-censor-user-id'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var UserStore $userStore */
|
||||
$userStore = Factory::getStore('User');
|
||||
|
||||
return $userStore->getById($_SESSION['php-censor-user-id']);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,8 @@
|
|||
<?php use PHPCensor\Helper\Lang; ?>
|
||||
<?php
|
||||
|
||||
use PHPCensor\Helper\Lang;
|
||||
|
||||
?>
|
||||
<div class="clearfix" style="margin-bottom: 20px;">
|
||||
<a class="btn btn-success pull-right" href="<?php print APP_URL . 'group/edit'; ?>">
|
||||
<?php Lang::out('group_add'); ?>
|
||||
|
@ -22,7 +26,7 @@
|
|||
<td>
|
||||
<div class="btn-group btn-group-right">
|
||||
<a class="btn btn-default btn-sm" href="<?php echo APP_URL ?>group/edit/<?php print $group['id']; ?>"><?php Lang::out('group_edit'); ?></a>
|
||||
<?php if($this->User()->getIsAdmin() && (!count($group['projects']))): ?>
|
||||
<?php if($this->getUser()->getIsAdmin() && (!count($group['projects']))): ?>
|
||||
<button class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
|
||||
<span class="caret"></span>
|
||||
</button>
|
||||
|
@ -45,4 +49,4 @@
|
|||
confirmDelete(e.target.href).onCloseConfirmed = function () {window.location = window.location.href};
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</script>
|
||||
|
|
|
@ -92,7 +92,7 @@ $branches = $build->getExtra('branches');
|
|||
<td>
|
||||
<div class="btn-group btn-group-right">
|
||||
<a class="btn btn-default btn-sm" href="<?php echo APP_URL ?>build/view/<?php print $build->getId(); ?>"><?php Lang::out('view'); ?></a>
|
||||
<?php if($this->User()->getIsAdmin()): ?>
|
||||
<?php if($this->getUser()->getIsAdmin()): ?>
|
||||
<button class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
|
||||
<span class="caret"></span>
|
||||
</button>
|
||||
|
|
|
@ -29,7 +29,7 @@ use PHPCensor\Helper\Lang;
|
|||
?>
|
||||
<div class="pull-right btn-group">
|
||||
<?php if (!$project->getArchived()): ?>
|
||||
<?php if ($this->User()->getIsAdmin()): ?>
|
||||
<?php if ($this->getUser()->getIsAdmin()): ?>
|
||||
<?php if (!empty($environment)): ?>
|
||||
<a class="btn btn-danger" href="<?= $build_url . '?' . http_build_query(['type' => 'environment', 'id' => $environment, 'debug' => 1]); ?>">
|
||||
<?php Lang::out('build_now_debug'); ?>
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
<?php use PHPCensor\Helper\Lang; ?>
|
||||
<?php
|
||||
|
||||
use PHPCensor\Helper\Lang;
|
||||
|
||||
$user = $this->getUser();
|
||||
|
||||
?>
|
||||
<div class="clearfix" style="margin-bottom: 20px;">
|
||||
<div class="pull-right btn-group">
|
||||
<a class="btn btn-success" href="<?php print APP_URL; ?>user/add"><?php Lang::out('add_user'); ?></a>
|
||||
|
@ -39,7 +45,7 @@
|
|||
<td><?php print htmlspecialchars($user->getName()); ?></td>
|
||||
<td><?php print $status; ?></td>
|
||||
<td>
|
||||
<?php if($this->User()->getIsAdmin()): ?>
|
||||
<?php if($user->getIsAdmin()): ?>
|
||||
<div class="btn-group btn-group-right">
|
||||
<a class="btn btn-default btn-sm" href="<?php echo APP_URL ?>user/edit/<?php print $user->getId(); ?>"><?php Lang::out('edit'); ?></a>
|
||||
<button class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<h2 class="box-title">Sorry, there was a problem</h2>
|
||||
</div>
|
||||
|
||||
<?php if ($this->User()->getIsAdmin()): ?>
|
||||
<?php if ($this->getUser()->getIsAdmin()): ?>
|
||||
<div class="box-body">
|
||||
<strong>Message</strong>: <?= $exception->getMessage(); ?><br />
|
||||
<strong>File</strong>: <?= $exception->getFile(); ?><br />
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
<?php use PHPCensor\Helper\Lang; ?>
|
||||
<?php
|
||||
|
||||
use PHPCensor\Helper\Lang;
|
||||
|
||||
$user = $this->getUser();
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
|
@ -87,19 +93,19 @@
|
|||
</ul>
|
||||
</li>
|
||||
|
||||
<?php if (!$this->LoginIsDisabled()->check()): ?>
|
||||
<?php if (!$this->LoginIsDisabled()): ?>
|
||||
<!-- User Account: style can be found in dropdown.less -->
|
||||
<li class="dropdown user user-menu">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
|
||||
<i class="glyphicon glyphicon-user"></i>
|
||||
<span><?php print $this->User()->getName(); ?> <i class="caret"></i></span>
|
||||
<span><?= $user->getName(); ?> <i class="caret"></i></span>
|
||||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
<!-- User image -->
|
||||
<li class="user-header">
|
||||
<img src="https://www.gravatar.com/avatar/<?php print md5($this->User()->getEmail()); ?>?d=mm" class="img-circle" alt="<?php print $this->User()->getName(); ?>" />
|
||||
<img src="https://www.gravatar.com/avatar/<?php print md5($user->getEmail()); ?>?d=mm" class="img-circle" alt="<?php print $user->getName(); ?>" />
|
||||
<p>
|
||||
<?php print $this->User()->getName(); ?>
|
||||
<?php print $user->getName(); ?>
|
||||
</p>
|
||||
</li>
|
||||
|
||||
|
@ -124,14 +130,14 @@
|
|||
<!-- sidebar: style can be found in sidebar.less -->
|
||||
<section class="sidebar">
|
||||
|
||||
<?php if (!$this->LoginIsDisabled()->check()): ?>
|
||||
<?php if (!$this->LoginIsDisabled()): ?>
|
||||
<!-- Sidebar user panel -->
|
||||
<div class="user-panel">
|
||||
<div class="pull-left image">
|
||||
<img src="https://www.gravatar.com/avatar/<?php print md5($this->User()->getEmail()); ?>?d=mm" class="img-circle" alt="<?php print $this->User()->getName(); ?>" />
|
||||
<img src="https://www.gravatar.com/avatar/<?php print md5($user->getEmail()); ?>?d=mm" class="img-circle" alt="<?php print $user->getName(); ?>" />
|
||||
</div>
|
||||
<div class="pull-left info">
|
||||
<p><?php Lang::out('hello_name', $this->User()->getName()); ?></p>
|
||||
<p><?php Lang::out('hello_name', $user->getName()); ?></p>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
@ -144,7 +150,7 @@
|
|||
</a>
|
||||
</li>
|
||||
|
||||
<?php if ($this->User()->getIsAdmin()): ?>
|
||||
<?php if ($user->getIsAdmin()): ?>
|
||||
<li class="treeview">
|
||||
<a href="#">
|
||||
<i class="fa fa-edit"></i>
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\b8;
|
||||
|
||||
use b8\Config, b8\Cache;
|
||||
|
||||
class CacheTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testCreateSingleton()
|
||||
{
|
||||
$cache = Cache::getCache(Cache::TYPE_APC);
|
||||
self::assertInstanceOf('\b8\Cache\ApcCache', $cache);
|
||||
}
|
||||
|
||||
public function testDisableCaching()
|
||||
{
|
||||
$config = new Config();
|
||||
Config::getInstance()->set('DisableCaching', true);
|
||||
|
||||
$cache = Cache::getCache(Cache::TYPE_APC);
|
||||
$this->assertFalse($cache->isEnabled());
|
||||
$this->assertFalse($cache->set('anything', 10));
|
||||
$this->assertTrue(is_null($cache->get('anything')));
|
||||
|
||||
Config::getInstance()->set('DisableCaching', false);
|
||||
}
|
||||
|
||||
public function testCaching()
|
||||
{
|
||||
$cache = Cache::getCache(Cache::TYPE_APC);
|
||||
|
||||
if ($cache->isEnabled()) {
|
||||
$this->assertTrue($cache->set('anything', 10));
|
||||
$this->assertTrue($cache->get('anything') == 10);
|
||||
$this->assertTrue(is_null($cache->get('invalid')));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -47,7 +47,7 @@ class DatabaseTest extends \PHPUnit\Framework\TestCase
|
|||
$this->checkDatabaseConnection();
|
||||
|
||||
$connection = Database::getConnection('write');
|
||||
$this->assertInstanceOf('\b8\Database', $connection);
|
||||
self::assertInstanceOf('\b8\Database', $connection);
|
||||
}
|
||||
|
||||
public function testGetDetails()
|
||||
|
@ -55,10 +55,10 @@ class DatabaseTest extends \PHPUnit\Framework\TestCase
|
|||
$this->checkDatabaseConnection();
|
||||
|
||||
$details = Database::getConnection('read')->getDetails();
|
||||
$this->assertTrue(is_array($details));
|
||||
$this->assertTrue(($details['db'] == DB_NAME));
|
||||
$this->assertTrue(($details['user'] == DB_USER));
|
||||
$this->assertTrue(($details['pass'] == DB_PASS));
|
||||
self::assertTrue(is_array($details));
|
||||
self::assertTrue(($details['db'] == DB_NAME));
|
||||
self::assertTrue(($details['user'] == DB_USER));
|
||||
self::assertTrue(($details['pass'] == DB_PASS));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,9 +2,11 @@
|
|||
|
||||
namespace Tests\b8;
|
||||
|
||||
use b8\Form, b8\Config;
|
||||
use b8\Form;
|
||||
use b8\Config;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class FormTest extends \PHPUnit\Framework\TestCase
|
||||
class FormTest extends TestCase
|
||||
{
|
||||
public function testFormBasics()
|
||||
{
|
||||
|
@ -12,8 +14,8 @@ class FormTest extends \PHPUnit\Framework\TestCase
|
|||
$f->setAction('/');
|
||||
$f->setMethod('POST');
|
||||
|
||||
$this->assertTrue($f->getAction() == '/');
|
||||
$this->assertTrue($f->getMethod() == 'POST');
|
||||
self::assertTrue($f->getAction() == '/');
|
||||
self::assertTrue($f->getMethod() == 'POST');
|
||||
|
||||
$config = new Config([
|
||||
'b8' => [
|
||||
|
@ -23,10 +25,11 @@ class FormTest extends \PHPUnit\Framework\TestCase
|
|||
]
|
||||
]);
|
||||
|
||||
$this->assertTrue($f->render('form') == '/POST');
|
||||
self::assertTrue($f->render('form') == '/POST');
|
||||
|
||||
Config::getInstance()->set('b8.view.path', '');
|
||||
$this->assertTrue(strpos((string)$f, '<form') !== false);
|
||||
|
||||
self::assertTrue(strpos((string)$f, '<form') !== false);
|
||||
}
|
||||
|
||||
public function testElementBasics()
|
||||
|
@ -37,44 +40,62 @@ class FormTest extends \PHPUnit\Framework\TestCase
|
|||
$f->setClass('element-class');
|
||||
$f->setContainerClass('container-class');
|
||||
|
||||
$this->assertTrue($f->getName() == 'element-name');
|
||||
$this->assertTrue($f->getId() == 'element-id');
|
||||
$this->assertTrue($f->getLabel() == 'element-label');
|
||||
$this->assertTrue($f->getClass() == 'element-class');
|
||||
$this->assertTrue($f->getContainerClass() == 'container-class');
|
||||
self::assertTrue($f->getName() == 'element-name');
|
||||
self::assertTrue($f->getId() == 'element-id');
|
||||
self::assertTrue($f->getLabel() == 'element-label');
|
||||
self::assertTrue($f->getClass() == 'element-class');
|
||||
self::assertTrue($f->getContainerClass() == 'container-class');
|
||||
|
||||
$output = $f->render();
|
||||
$this->assertTrue(is_string($output));
|
||||
$this->assertTrue(!empty($output));
|
||||
$this->assertTrue(strpos($output, 'container-class') !== false);
|
||||
|
||||
self::assertTrue(is_string($output));
|
||||
self::assertTrue(!empty($output));
|
||||
self::assertTrue(strpos($output, 'container-class') !== false);
|
||||
}
|
||||
|
||||
public function testInputBasics()
|
||||
{
|
||||
$f = new Form\Element\Text();
|
||||
|
||||
$f->setValue('input-value');
|
||||
$f->setRequired(true);
|
||||
$f->setValidator(function ($value) {
|
||||
return ($value == 'input-value');
|
||||
});
|
||||
|
||||
$this->assertTrue($f->getValue() == 'input-value');
|
||||
$this->assertTrue($f->getRequired() == true);
|
||||
$this->assertTrue(is_callable($f->getValidator()));
|
||||
self::assertTrue($f->getValue() == 'input-value');
|
||||
self::assertTrue($f->getRequired() == true);
|
||||
self::assertTrue(is_callable($f->getValidator()));
|
||||
}
|
||||
|
||||
public function testInputCreate()
|
||||
{
|
||||
$text = Form\Element\Text::create(
|
||||
'input-name',
|
||||
'input-label',
|
||||
true
|
||||
);
|
||||
|
||||
self::assertEquals('input-name', $text->getName());
|
||||
self::assertEquals('input-label', $text->getLabel());
|
||||
self::assertTrue($text->getRequired());
|
||||
}
|
||||
|
||||
public function testInputValidation()
|
||||
{
|
||||
$f = new Form\Element\Text();
|
||||
$f->setRequired(true);
|
||||
$this->assertFalse($f->validate());
|
||||
|
||||
self::assertFalse($f->validate());
|
||||
|
||||
$f->setRequired(false);
|
||||
$f->setPattern('input\-value');
|
||||
$this->assertFalse($f->validate());
|
||||
|
||||
self::assertFalse($f->validate());
|
||||
|
||||
$f->setValue('input-value');
|
||||
$this->assertTrue($f->validate());
|
||||
|
||||
self::assertTrue($f->validate());
|
||||
|
||||
$f->setValidator(function ($item) {
|
||||
if ($item != 'input-value') {
|
||||
|
@ -82,11 +103,22 @@ class FormTest extends \PHPUnit\Framework\TestCase
|
|||
}
|
||||
});
|
||||
|
||||
$this->assertTrue($f->validate());
|
||||
self::assertTrue($f->validate());
|
||||
|
||||
$f->setValue('fail');
|
||||
$f->setPattern(null);
|
||||
$this->assertFalse($f->validate());
|
||||
|
||||
self::assertFalse($f->validate());
|
||||
}
|
||||
|
||||
public function testInputValidationWithCustomError()
|
||||
{
|
||||
$f = new Form\Element\Text();
|
||||
$f->setRequired(true);
|
||||
$f->setValue('input-value');
|
||||
$f->setError('Error!');
|
||||
|
||||
self::assertFalse($f->validate());
|
||||
}
|
||||
|
||||
public function testFieldSetBasics()
|
||||
|
@ -108,76 +140,79 @@ class FormTest extends \PHPUnit\Framework\TestCase
|
|||
$f->addField($f2);
|
||||
$f->addField($f3);
|
||||
|
||||
$this->assertFalse($f->validate());
|
||||
self::assertFalse($f->validate());
|
||||
|
||||
$f->setValues(['group' => ['one' => 'ONE', 'two' => 'TWO'], 'three' => 'THREE']);
|
||||
|
||||
$values = $f->getValues();
|
||||
$this->assertTrue(is_array($values));
|
||||
$this->assertTrue(array_key_exists('group', $values));
|
||||
$this->assertTrue(array_key_exists('one', $values['group']));
|
||||
$this->assertTrue(array_key_exists('three', $values));
|
||||
$this->assertTrue($values['group']['one'] == 'ONE');
|
||||
$this->assertTrue($values['group']['two'] == 'TWO');
|
||||
$this->assertTrue($values['three'] == 'THREE');
|
||||
$this->assertTrue($f->validate());
|
||||
self::assertTrue(is_array($values));
|
||||
self::assertTrue(array_key_exists('group', $values));
|
||||
self::assertTrue(array_key_exists('one', $values['group']));
|
||||
self::assertTrue(array_key_exists('three', $values));
|
||||
self::assertTrue($values['group']['one'] == 'ONE');
|
||||
self::assertTrue($values['group']['two'] == 'TWO');
|
||||
self::assertTrue($values['three'] == 'THREE');
|
||||
self::assertTrue($f->validate());
|
||||
|
||||
$html = $f->render();
|
||||
$this->assertTrue(strpos($html, 'one') !== false);
|
||||
$this->assertTrue(strpos($html, 'two') !== false);
|
||||
self::assertTrue(strpos($html, 'one') !== false);
|
||||
self::assertTrue(strpos($html, 'two') !== false);
|
||||
}
|
||||
|
||||
public function testElements()
|
||||
{
|
||||
$e = new Form\Element\Button();
|
||||
$this->assertTrue($e->validate());
|
||||
$this->assertTrue(strpos($e->render(), 'button') !== false);
|
||||
self::assertTrue($e->validate());
|
||||
self::assertTrue(strpos($e->render(), 'button') !== false);
|
||||
|
||||
$e = new Form\Element\Checkbox();
|
||||
$e->setCheckedValue('ten');
|
||||
$this->assertTrue($e->getCheckedValue() == 'ten');
|
||||
$this->assertTrue(strpos($e->render(), 'checkbox') !== false);
|
||||
$this->assertTrue(strpos($e->render(), 'checked') === false);
|
||||
self::assertTrue($e->getCheckedValue() == 'ten');
|
||||
self::assertTrue(strpos($e->render(), 'checkbox') !== false);
|
||||
self::assertTrue(strpos($e->render(), 'checked') === false);
|
||||
|
||||
$e->setValue(true);
|
||||
$this->assertTrue(strpos($e->render(), 'checked') !== false);
|
||||
self::assertTrue(strpos($e->render(), 'checked') !== false);
|
||||
|
||||
$e->setValue('ten');
|
||||
$this->assertTrue(strpos($e->render(), 'checked') !== false);
|
||||
self::assertTrue(strpos($e->render(), 'checked') !== false);
|
||||
|
||||
$e->setValue('fail');
|
||||
$this->assertTrue(strpos($e->render(), 'checked') === false);
|
||||
self::assertTrue(strpos($e->render(), 'checked') === false);
|
||||
|
||||
$e = new Form\Element\CheckboxGroup();
|
||||
$this->assertTrue(strpos($e->render(), 'group') !== false);
|
||||
self::assertTrue(strpos($e->render(), 'group') !== false);
|
||||
|
||||
$e = new Form\ControlGroup();
|
||||
$this->assertTrue(strpos($e->render(), 'group') !== false);
|
||||
self::assertTrue(strpos($e->render(), 'group') !== false);
|
||||
|
||||
$e = new Form\Element\Email();
|
||||
$this->assertTrue(strpos($e->render(), 'email') !== false);
|
||||
self::assertTrue(strpos($e->render(), 'email') !== false);
|
||||
|
||||
$e = new Form\Element\Select();
|
||||
$e->setOptions(['key' => 'Val']);
|
||||
$html = $e->render();
|
||||
$this->assertTrue(strpos($html, 'select') !== false);
|
||||
$this->assertTrue(strpos($html, 'option') !== false);
|
||||
$this->assertTrue(strpos($html, 'key') !== false);
|
||||
$this->assertTrue(strpos($html, 'Val') !== false);
|
||||
self::assertTrue(strpos($html, 'select') !== false);
|
||||
self::assertTrue(strpos($html, 'option') !== false);
|
||||
self::assertTrue(strpos($html, 'key') !== false);
|
||||
self::assertTrue(strpos($html, 'Val') !== false);
|
||||
|
||||
$e = new Form\Element\Submit();
|
||||
$this->assertTrue($e->validate());
|
||||
$this->assertTrue(strpos($e->render(), 'submit') !== false);
|
||||
self::assertTrue($e->validate());
|
||||
self::assertTrue(strpos($e->render(), 'submit') !== false);
|
||||
|
||||
$e = new Form\Element\Text();
|
||||
$e->setValue('test');
|
||||
$this->assertTrue(strpos($e->render(), 'test') !== false);
|
||||
self::assertTrue(strpos($e->render(), 'test') !== false);
|
||||
|
||||
$e = new Form\Element\TextArea();
|
||||
$e->setRows(10);
|
||||
$this->assertTrue(strpos($e->render(), '10') !== false);
|
||||
self::assertTrue(strpos($e->render(), '10') !== false);
|
||||
|
||||
$e = new Form\Element\Url();
|
||||
$this->assertTrue(strpos($e->render(), 'url') !== false);
|
||||
self::assertTrue(strpos($e->render(), 'url') !== false);
|
||||
|
||||
$e = new Form\Element\Password();
|
||||
self::assertTrue(strpos($e->render(), 'password') !== false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ class HttpExceptionTest extends \PHPUnit\Framework\TestCase
|
|||
public function testHttpExceptionIsException()
|
||||
{
|
||||
$ex = new HttpException();
|
||||
$this->assertTrue($ex instanceof \Exception);
|
||||
self::assertTrue($ex instanceof \Exception);
|
||||
}
|
||||
|
||||
public function testHttpException()
|
||||
|
@ -17,10 +17,10 @@ class HttpExceptionTest extends \PHPUnit\Framework\TestCase
|
|||
try {
|
||||
throw new HttpException('Test');
|
||||
} catch (HttpException $ex) {
|
||||
$this->assertTrue($ex->getMessage() == 'Test');
|
||||
$this->assertTrue($ex->getErrorCode() == 500);
|
||||
$this->assertTrue($ex->getStatusMessage() == 'Internal Server Error');
|
||||
$this->assertTrue($ex->getHttpHeader() == 'HTTP/1.1 500 Internal Server Error');
|
||||
self::assertTrue($ex->getMessage() == 'Test');
|
||||
self::assertTrue($ex->getErrorCode() == 500);
|
||||
self::assertTrue($ex->getStatusMessage() == 'Internal Server Error');
|
||||
self::assertTrue($ex->getHttpHeader() == 'HTTP/1.1 500 Internal Server Error');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,8 +29,8 @@ class HttpExceptionTest extends \PHPUnit\Framework\TestCase
|
|||
try {
|
||||
throw new HttpException\BadRequestException('Test');
|
||||
} catch (HttpException $ex) {
|
||||
$this->assertTrue($ex->getErrorCode() == 400);
|
||||
$this->assertTrue($ex->getStatusMessage() == 'Bad Request');
|
||||
self::assertTrue($ex->getErrorCode() == 400);
|
||||
self::assertTrue($ex->getStatusMessage() == 'Bad Request');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,8 +39,8 @@ class HttpExceptionTest extends \PHPUnit\Framework\TestCase
|
|||
try {
|
||||
throw new HttpException\ForbiddenException('Test');
|
||||
} catch (HttpException $ex) {
|
||||
$this->assertTrue($ex->getErrorCode() == 403);
|
||||
$this->assertTrue($ex->getStatusMessage() == 'Forbidden');
|
||||
self::assertTrue($ex->getErrorCode() == 403);
|
||||
self::assertTrue($ex->getStatusMessage() == 'Forbidden');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,8 +49,8 @@ class HttpExceptionTest extends \PHPUnit\Framework\TestCase
|
|||
try {
|
||||
throw new HttpException\NotAuthorizedException('Test');
|
||||
} catch (HttpException $ex) {
|
||||
$this->assertTrue($ex->getErrorCode() == 401);
|
||||
$this->assertTrue($ex->getStatusMessage() == 'Not Authorized');
|
||||
self::assertTrue($ex->getErrorCode() == 401);
|
||||
self::assertTrue($ex->getStatusMessage() == 'Not Authorized');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,8 +59,8 @@ class HttpExceptionTest extends \PHPUnit\Framework\TestCase
|
|||
try {
|
||||
throw new HttpException\NotFoundException('Test');
|
||||
} catch (HttpException $ex) {
|
||||
$this->assertTrue($ex->getErrorCode() == 404);
|
||||
$this->assertTrue($ex->getStatusMessage() == 'Not Found');
|
||||
self::assertTrue($ex->getErrorCode() == 404);
|
||||
self::assertTrue($ex->getStatusMessage() == 'Not Found');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,8 +69,8 @@ class HttpExceptionTest extends \PHPUnit\Framework\TestCase
|
|||
try {
|
||||
throw new HttpException\ServerErrorException('Test');
|
||||
} catch (HttpException $ex) {
|
||||
$this->assertTrue($ex->getErrorCode() == 500);
|
||||
$this->assertTrue($ex->getStatusMessage() == 'Internal Server Error');
|
||||
self::assertTrue($ex->getErrorCode() == 500);
|
||||
self::assertTrue($ex->getStatusMessage() == 'Internal Server Error');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,8 +79,8 @@ class HttpExceptionTest extends \PHPUnit\Framework\TestCase
|
|||
try {
|
||||
throw new HttpException\ValidationException('Test');
|
||||
} catch (HttpException $ex) {
|
||||
$this->assertTrue($ex->getErrorCode() == 400);
|
||||
$this->assertTrue($ex->getStatusMessage() == 'Bad Request');
|
||||
self::assertTrue($ex->getErrorCode() == 400);
|
||||
self::assertTrue($ex->getStatusMessage() == 'Bad Request');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,15 +2,15 @@
|
|||
|
||||
namespace Tests\b8;
|
||||
|
||||
use b8\View;
|
||||
use b8\View\Template;
|
||||
use PHPCensor\View;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ViewTest extends \PHPUnit\Framework\TestCase
|
||||
class ViewTest extends TestCase
|
||||
{
|
||||
public function testSimpleView()
|
||||
{
|
||||
$view = new View('simple', __DIR__ . '/data/view/');
|
||||
$this->assertTrue($view->render() == 'Hello');
|
||||
self::assertTrue($view->render() == 'Hello');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,95 +26,15 @@ class ViewTest extends \PHPUnit\Framework\TestCase
|
|||
$view = new View('vars', __DIR__ . '/data/view/');
|
||||
$view->who = 'World';
|
||||
|
||||
$this->assertTrue(isset($view->who));
|
||||
$this->assertFalse(isset($view->what));
|
||||
$this->assertTrue($view->render() == 'Hello World');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Exception
|
||||
*/
|
||||
public function testInvalidHelper()
|
||||
{
|
||||
$view = new Template('{@Invalid:test}');
|
||||
$view->render();
|
||||
}
|
||||
|
||||
public function testSimpleUserView()
|
||||
{
|
||||
$view = new Template('Hello');
|
||||
$this->assertTrue($view->render() == 'Hello');
|
||||
}
|
||||
|
||||
public function testUserViewYear()
|
||||
{
|
||||
$view = new Template('{@year}');
|
||||
$this->assertTrue($view->render() == date('Y'));
|
||||
self::assertTrue(isset($view->who));
|
||||
self::assertFalse(isset($view->what));
|
||||
self::assertTrue($view->render() == 'Hello World');
|
||||
}
|
||||
|
||||
public function testUserViewVars()
|
||||
{
|
||||
$view = new Template('Hello {@who}');
|
||||
$view->who = 'World';
|
||||
$this->assertTrue($view->render() == 'Hello World');
|
||||
|
||||
$view = new Template('Hello {@who}');
|
||||
$this->assertTrue($view->render() == 'Hello ');
|
||||
|
||||
$view = new Template('Hello {@who.name}');
|
||||
$view->who = ['name' => 'Dan'];
|
||||
$this->assertTrue($view->render() == 'Hello Dan');
|
||||
|
||||
$tmp = new Template('Hello');
|
||||
$tmp->who = 'World';
|
||||
$view = new Template('Hello {@tmp.who}');
|
||||
$view->tmp = $tmp;
|
||||
$this->assertTrue($view->render() == 'Hello World');
|
||||
|
||||
try {
|
||||
$tmp = new Template('Hello');
|
||||
$view = new Template('Hello {@tmp.who}');
|
||||
$view->tmp = $tmp;
|
||||
$this->assertTrue($view->render() == 'Hello ');
|
||||
} catch (\Exception $e) {
|
||||
self::assertInstanceOf('\PHPUnit_Framework_Error_Notice', $e);
|
||||
}
|
||||
|
||||
$view = new Template('Hello {@who.toUpperCase}');
|
||||
$view->who = 'World';
|
||||
$this->assertTrue($view->render() == 'Hello WORLD');
|
||||
|
||||
$view = new Template('Hello {@who.toLowerCase}');
|
||||
$view->who = 'World';
|
||||
$this->assertTrue($view->render() == 'Hello world');
|
||||
$view = new View('{@content}');
|
||||
$view->content = 'World';
|
||||
self::assertTrue($view->render() == 'World');
|
||||
}
|
||||
|
||||
public function testUserViewIf()
|
||||
{
|
||||
$view = new Template('Hello{if who} World{/if}');
|
||||
$view->who = true;
|
||||
$this->assertTrue($view->render() == 'Hello World');
|
||||
|
||||
$view = new Template('Hello{if who} World{/if}');
|
||||
$view->who = false;
|
||||
$this->assertTrue($view->render() == 'Hello');
|
||||
|
||||
$view = new Template('Hello{ifnot who} World{/ifnot}');
|
||||
$view->who = true;
|
||||
$this->assertTrue($view->render() == 'Hello');
|
||||
}
|
||||
|
||||
public function testUserViewLoop()
|
||||
{
|
||||
$view = new Template('Hello {loop who}{@item}{/loop}');
|
||||
$view->who = ['W', 'o', 'r', 'l', 'd'];
|
||||
$this->assertTrue($view->render() == 'Hello World');
|
||||
|
||||
$view = new Template('Hello {loop who}{@item}{/loop}');
|
||||
$this->assertTrue($view->render() == 'Hello ');
|
||||
|
||||
$view = new Template('Hello {loop who}{@item}{/loop}');
|
||||
$view->who = 'World';
|
||||
$this->assertTrue($view->render() == 'Hello World');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ class CreateAdminCommandTest extends \PHPUnit\Framework\TestCase
|
|||
parent::setUp();
|
||||
|
||||
$userStoreMock = $this->getMockBuilder('PHPCensor\\Store\\UserStore')->getMock();
|
||||
|
||||
|
||||
$this->command = new CreateAdminCommand($userStoreMock);
|
||||
|
||||
$this->helper = $this
|
||||
|
@ -60,6 +60,6 @@ class CreateAdminCommandTest extends \PHPUnit\Framework\TestCase
|
|||
$commandTester = $this->getCommandTester();
|
||||
$commandTester->execute([]);
|
||||
|
||||
$this->assertEquals('User account created!' . PHP_EOL, $commandTester->getDisplay());
|
||||
self::assertEquals('User account created!' . PHP_EOL, $commandTester->getDisplay());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -140,7 +140,7 @@ class InstallCommandTest extends \PHPUnit\Framework\TestCase
|
|||
$this->executeWithoutParam('--db-type', $dialog);
|
||||
|
||||
// Check that specified arguments are correctly loaded.
|
||||
$this->assertEquals('testedvalue', $this->config['b8']['database']['type']);
|
||||
self::assertEquals('testedvalue', $this->config['b8']['database']['type']);
|
||||
}
|
||||
|
||||
public function testDatabaseHostConfig()
|
||||
|
@ -153,8 +153,8 @@ class InstallCommandTest extends \PHPUnit\Framework\TestCase
|
|||
$this->executeWithoutParam('--db-host', $dialog);
|
||||
|
||||
// Check that specified arguments are correctly loaded.
|
||||
$this->assertEquals('testedvalue', $this->config['b8']['database']['servers']['read'][0]['host']);
|
||||
$this->assertEquals('testedvalue', $this->config['b8']['database']['servers']['write'][0]['host']);
|
||||
self::assertEquals('testedvalue', $this->config['b8']['database']['servers']['read'][0]['host']);
|
||||
self::assertEquals('testedvalue', $this->config['b8']['database']['servers']['write'][0]['host']);
|
||||
}
|
||||
|
||||
public function testDatabaseStringPortConfig()
|
||||
|
@ -167,8 +167,8 @@ class InstallCommandTest extends \PHPUnit\Framework\TestCase
|
|||
$this->executeWithoutParam('--db-port', $dialog);
|
||||
|
||||
// Check that specified arguments are correctly loaded.
|
||||
$this->assertArrayNotHasKey('port', $this->config['b8']['database']['servers']['read'][0]);
|
||||
$this->assertArrayNotHasKey('port', $this->config['b8']['database']['servers']['write'][0]);
|
||||
self::assertArrayNotHasKey('port', $this->config['b8']['database']['servers']['read'][0]);
|
||||
self::assertArrayNotHasKey('port', $this->config['b8']['database']['servers']['write'][0]);
|
||||
}
|
||||
|
||||
public function testDatabasePortConfig()
|
||||
|
@ -181,8 +181,8 @@ class InstallCommandTest extends \PHPUnit\Framework\TestCase
|
|||
$this->executeWithoutParam('--db-port', $dialog);
|
||||
|
||||
// Check that specified arguments are correctly loaded.
|
||||
$this->assertEquals(333, $this->config['b8']['database']['servers']['read'][0]['port']);
|
||||
$this->assertEquals(333, $this->config['b8']['database']['servers']['write'][0]['port']);
|
||||
self::assertEquals(333, $this->config['b8']['database']['servers']['read'][0]['port']);
|
||||
self::assertEquals(333, $this->config['b8']['database']['servers']['write'][0]['port']);
|
||||
}
|
||||
|
||||
public function testDatabaseNameConfig()
|
||||
|
@ -195,7 +195,7 @@ class InstallCommandTest extends \PHPUnit\Framework\TestCase
|
|||
$this->executeWithoutParam('--db-name', $dialog);
|
||||
|
||||
// Check that specified arguments are correctly loaded.
|
||||
$this->assertEquals('testedvalue', $this->config['b8']['database']['name']);
|
||||
self::assertEquals('testedvalue', $this->config['b8']['database']['name']);
|
||||
}
|
||||
|
||||
public function testDatabaseUserConfig()
|
||||
|
@ -208,19 +208,19 @@ class InstallCommandTest extends \PHPUnit\Framework\TestCase
|
|||
$this->executeWithoutParam('--db-user', $dialog);
|
||||
|
||||
// Check that specified arguments are correctly loaded.
|
||||
$this->assertEquals('testedvalue', $this->config['b8']['database']['username']);
|
||||
self::assertEquals('testedvalue', $this->config['b8']['database']['username']);
|
||||
}
|
||||
|
||||
public function testDatabasePasswordConfig()
|
||||
{
|
||||
$dialog = $this->getHelperMock();
|
||||
|
||||
|
||||
$dialog->expects($this->once())->method('ask')->willReturn('testedvalue');
|
||||
|
||||
$this->executeWithoutParam('--db-password', $dialog);
|
||||
|
||||
// Check that specified arguments are correctly loaded.
|
||||
$this->assertEquals('testedvalue', $this->config['b8']['database']['password']);
|
||||
self::assertEquals('testedvalue', $this->config['b8']['database']['password']);
|
||||
}
|
||||
|
||||
public function testUrlConfig()
|
||||
|
@ -233,7 +233,7 @@ class InstallCommandTest extends \PHPUnit\Framework\TestCase
|
|||
$this->executeWithoutParam('--url', $dialog);
|
||||
|
||||
// Check that specified arguments are correctly loaded.
|
||||
$this->assertEquals('http://testedvalue.com', $this->config['php-censor']['url']);
|
||||
self::assertEquals('http://testedvalue.com', $this->config['php-censor']['url']);
|
||||
}
|
||||
|
||||
public function testAdminEmailConfig()
|
||||
|
@ -246,7 +246,7 @@ class InstallCommandTest extends \PHPUnit\Framework\TestCase
|
|||
$this->executeWithoutParam('--admin-email', $dialog);
|
||||
|
||||
// Check that specified arguments are correctly loaded.
|
||||
$this->assertEquals('admin@php-censor.local', $this->admin['email']);
|
||||
self::assertEquals('admin@php-censor.local', $this->admin['email']);
|
||||
}
|
||||
|
||||
public function testAdminNameConfig()
|
||||
|
@ -259,7 +259,7 @@ class InstallCommandTest extends \PHPUnit\Framework\TestCase
|
|||
$this->executeWithoutParam('--admin-name', $dialog);
|
||||
|
||||
// Check that specified arguments are correctly loaded.
|
||||
$this->assertEquals('testedvalue', $this->admin['name']);
|
||||
self::assertEquals('testedvalue', $this->admin['name']);
|
||||
}
|
||||
|
||||
public function testAdminPasswordConfig()
|
||||
|
@ -272,6 +272,6 @@ class InstallCommandTest extends \PHPUnit\Framework\TestCase
|
|||
$this->executeWithoutParam('--admin-password', $dialog);
|
||||
|
||||
// Check that specified arguments are correctly loaded.
|
||||
$this->assertEquals('testedvalue', $this->admin['password']);
|
||||
self::assertEquals('testedvalue', $this->admin['password']);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,17 +16,17 @@ class WebhookControllerTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$error = $webController->handleAction('test', []);
|
||||
|
||||
$this->assertInstanceOf('b8\Http\Response\JsonResponse', $error);
|
||||
self::assertInstanceOf('b8\Http\Response\JsonResponse', $error);
|
||||
|
||||
$responseData = $error->getData();
|
||||
$this->assertEquals(500, $responseData['code']);
|
||||
self::assertEquals(500, $responseData['code']);
|
||||
|
||||
$this->assertEquals('failed', $responseData['body']['status']);
|
||||
self::assertEquals('failed', $responseData['body']['status']);
|
||||
|
||||
$this->assertEquals('application/json', $responseData['headers']['Content-Type']);
|
||||
self::assertEquals('application/json', $responseData['headers']['Content-Type']);
|
||||
|
||||
// @todo: we can't text the result is JSON file with
|
||||
// $this->assertJson((string) $error);
|
||||
// self::assertJson((string) $error);
|
||||
// since the flush method automatically add the header and break the
|
||||
// testing framework.
|
||||
}
|
||||
|
|
|
@ -13,6 +13,6 @@ class AnsiConverterTest extends TestCase
|
|||
$expectedOutput = '<span class="ansi_color_bg_black ansi_color_fg_red">This is red !</span>';
|
||||
$actualOutput = AnsiConverter::convert($input);
|
||||
|
||||
$this->assertEquals($expectedOutput, $actualOutput);
|
||||
self::assertEquals($expectedOutput, $actualOutput);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ class BuildInterpolatorTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$actualOutput = $this->testedInterpolator->interpolate($string);
|
||||
|
||||
$this->assertEquals($expectedOutput, $actualOutput);
|
||||
self::assertEquals($expectedOutput, $actualOutput);
|
||||
}
|
||||
|
||||
public function testInterpolate_LeavesStringsUnchangedWhenBuildIsSet()
|
||||
|
@ -42,7 +42,7 @@ class BuildInterpolatorTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$actualOutput = $this->testedInterpolator->interpolate($string);
|
||||
|
||||
$this->assertEquals($expectedOutput, $actualOutput);
|
||||
self::assertEquals($expectedOutput, $actualOutput);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ class CommandExecutorTest extends \PHPUnit\Framework\TestCase
|
|||
{
|
||||
$this->testedExecutor->executeCommand(['echo "%s"', 'Hello World']);
|
||||
$output = $this->testedExecutor->getLastOutput();
|
||||
$this->assertEquals("Hello World", $output);
|
||||
self::assertEquals("Hello World", $output);
|
||||
}
|
||||
|
||||
public function testGetLastOutput_ForgetsPreviousCommandOutput()
|
||||
|
@ -33,19 +33,19 @@ class CommandExecutorTest extends \PHPUnit\Framework\TestCase
|
|||
$this->testedExecutor->executeCommand(['echo "%s"', 'Hello World']);
|
||||
$this->testedExecutor->executeCommand(['echo "%s"', 'Hello Tester']);
|
||||
$output = $this->testedExecutor->getLastOutput();
|
||||
$this->assertEquals("Hello Tester", $output);
|
||||
self::assertEquals("Hello Tester", $output);
|
||||
}
|
||||
|
||||
public function testExecuteCommand_ReturnsTrueForValidCommands()
|
||||
{
|
||||
$returnValue = $this->testedExecutor->executeCommand(['echo "%s"', 'Hello World']);
|
||||
$this->assertTrue($returnValue);
|
||||
self::assertTrue($returnValue);
|
||||
}
|
||||
|
||||
public function testExecuteCommand_ReturnsFalseForInvalidCommands()
|
||||
{
|
||||
$returnValue = $this->testedExecutor->executeCommand(['eerfdcvcho "%s" > /dev/null 2>&1', 'Hello World']);
|
||||
$this->assertFalse($returnValue);
|
||||
self::assertFalse($returnValue);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -62,9 +62,9 @@ class CommandExecutorTest extends \PHPUnit\Framework\TestCase
|
|||
EOD;
|
||||
$data = str_repeat("-", $length);
|
||||
$returnValue = $this->testedExecutor->executeCommand([$script]);
|
||||
$this->assertTrue($returnValue);
|
||||
$this->assertEquals($data, trim($this->testedExecutor->getLastOutput()));
|
||||
$this->assertEquals($data, trim($this->testedExecutor->getLastError()));
|
||||
self::assertTrue($returnValue);
|
||||
self::assertEquals($data, trim($this->testedExecutor->getLastOutput()));
|
||||
self::assertEquals($data, trim($this->testedExecutor->getLastError()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -80,26 +80,26 @@ EOD;
|
|||
public function testFindBinary_ReturnsNullWihQuietArgument()
|
||||
{
|
||||
$thisFileName = "WorldWidePeace";
|
||||
$this->assertFalse($this->testedExecutor->findBinary($thisFileName, true));
|
||||
self::assertFalse($this->testedExecutor->findBinary($thisFileName, true));
|
||||
}
|
||||
|
||||
public function testReplaceIllegalCharacters()
|
||||
{
|
||||
$this->assertEquals(
|
||||
self::assertEquals(
|
||||
"start <20> end",
|
||||
$this->testedExecutor->replaceIllegalCharacters(
|
||||
"start \xf0\x9c\x83\x96 end"
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
self::assertEquals(
|
||||
"start <20> end",
|
||||
$this->testedExecutor->replaceIllegalCharacters(
|
||||
"start \xF0\x9C\x83\x96 end"
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
self::assertEquals(
|
||||
"start 123_X08<30>_X00<30>_Xa4<61>_5432 end",
|
||||
$this->testedExecutor->replaceIllegalCharacters(
|
||||
"start 123_X08\x08_X00\x00_Xa4\xa4_5432 end"
|
||||
|
|
|
@ -8,9 +8,9 @@ class LangTest extends LocalizationTestCase
|
|||
{
|
||||
public function testSuccess()
|
||||
{
|
||||
$this->assertTrue(true);
|
||||
self::assertTrue(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
|
@ -37,7 +37,7 @@ class LangTest extends LocalizationTestCase
|
|||
$en = include($directory . 'lang.en.php');
|
||||
|
||||
foreach ($en as $enIndex => $enString) {
|
||||
$this->assertArrayHasKey($enIndex, $strings);
|
||||
self::assertArrayHasKey($enIndex, $strings);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
|
|
@ -27,12 +27,12 @@ class MailerFactoryTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$factory = new MailerFactory(['email_settings' => $config]);
|
||||
|
||||
$this->assertEquals($config['smtp_address'], $factory->getMailConfig('smtp_address'));
|
||||
$this->assertEquals($config['smtp_port'], $factory->getMailConfig('smtp_port'));
|
||||
$this->assertEquals($config['smtp_encryption'], $factory->getMailConfig('smtp_encryption'));
|
||||
$this->assertEquals($config['smtp_username'], $factory->getMailConfig('smtp_username'));
|
||||
$this->assertEquals($config['smtp_password'], $factory->getMailConfig('smtp_password'));
|
||||
$this->assertEquals($config['default_mailto_address'], $factory->getMailConfig('default_mailto_address'));
|
||||
self::assertEquals($config['smtp_address'], $factory->getMailConfig('smtp_address'));
|
||||
self::assertEquals($config['smtp_port'], $factory->getMailConfig('smtp_port'));
|
||||
self::assertEquals($config['smtp_encryption'], $factory->getMailConfig('smtp_encryption'));
|
||||
self::assertEquals($config['smtp_username'], $factory->getMailConfig('smtp_username'));
|
||||
self::assertEquals($config['smtp_password'], $factory->getMailConfig('smtp_password'));
|
||||
self::assertEquals($config['default_mailto_address'], $factory->getMailConfig('default_mailto_address'));
|
||||
}
|
||||
|
||||
public function testExecute_TestMailer()
|
||||
|
@ -49,10 +49,10 @@ class MailerFactoryTest extends \PHPUnit\Framework\TestCase
|
|||
$factory = new MailerFactory(['email_settings' => $config]);
|
||||
$mailer = $factory->getSwiftMailerFromConfig();
|
||||
|
||||
$this->assertEquals($config['smtp_address'], $mailer->getTransport()->getHost());
|
||||
$this->assertEquals($config['smtp_port'], $mailer->getTransport()->getPort());
|
||||
$this->assertEquals('tls', $mailer->getTransport()->getEncryption());
|
||||
$this->assertEquals($config['smtp_username'], $mailer->getTransport()->getUsername());
|
||||
$this->assertEquals($config['smtp_password'], $mailer->getTransport()->getPassword());
|
||||
self::assertEquals($config['smtp_address'], $mailer->getTransport()->getHost());
|
||||
self::assertEquals($config['smtp_port'], $mailer->getTransport()->getPort());
|
||||
self::assertEquals('tls', $mailer->getTransport()->getEncryption());
|
||||
self::assertEquals($config['smtp_username'], $mailer->getTransport()->getUsername());
|
||||
self::assertEquals($config['smtp_password'], $mailer->getTransport()->getPassword());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ use PHPCensor\Model;
|
|||
|
||||
/**
|
||||
* Unit tests for the Build model class.
|
||||
*
|
||||
*
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
*/
|
||||
class BuildTest extends \PHPUnit\Framework\TestCase
|
||||
|
@ -19,32 +19,32 @@ class BuildTest extends \PHPUnit\Framework\TestCase
|
|||
public function testExecute_TestIsAValidModel()
|
||||
{
|
||||
$build = new Build();
|
||||
$this->assertTrue($build instanceof \b8\Model);
|
||||
$this->assertTrue($build instanceof Model);
|
||||
self::assertTrue($build instanceof \b8\Model);
|
||||
self::assertTrue($build instanceof Model);
|
||||
}
|
||||
|
||||
public function testExecute_TestBaseBuildDefaults()
|
||||
{
|
||||
$build = new Build();
|
||||
$this->assertEquals('#', $build->getCommitLink());
|
||||
$this->assertEquals('#', $build->getBranchLink());
|
||||
$this->assertEquals(null, $build->getFileLinkTemplate());
|
||||
self::assertEquals('#', $build->getCommitLink());
|
||||
self::assertEquals('#', $build->getBranchLink());
|
||||
self::assertEquals(null, $build->getFileLinkTemplate());
|
||||
}
|
||||
|
||||
public function testExecute_TestIsSuccessful()
|
||||
{
|
||||
$build = new Build();
|
||||
$build->setStatus(Build::STATUS_PENDING);
|
||||
$this->assertFalse($build->isSuccessful());
|
||||
self::assertFalse($build->isSuccessful());
|
||||
|
||||
$build->setStatus(Build::STATUS_RUNNING);
|
||||
$this->assertFalse($build->isSuccessful());
|
||||
self::assertFalse($build->isSuccessful());
|
||||
|
||||
$build->setStatus(Build::STATUS_FAILED);
|
||||
$this->assertFalse($build->isSuccessful());
|
||||
self::assertFalse($build->isSuccessful());
|
||||
|
||||
$build->setStatus(Build::STATUS_SUCCESS);
|
||||
$this->assertTrue($build->isSuccessful());
|
||||
self::assertTrue($build->isSuccessful());
|
||||
}
|
||||
|
||||
public function testExecute_TestBuildExtra()
|
||||
|
@ -57,26 +57,26 @@ class BuildTest extends \PHPUnit\Framework\TestCase
|
|||
$build = new Build();
|
||||
$build->setExtra(json_encode($info));
|
||||
|
||||
$this->assertEquals('Item One', $build->getExtra('item1'));
|
||||
$this->assertEquals(2, $build->getExtra('item2'));
|
||||
$this->assertNull($build->getExtra('item3'));
|
||||
$this->assertEquals($info, $build->getExtra());
|
||||
|
||||
self::assertEquals('Item One', $build->getExtra('item1'));
|
||||
self::assertEquals(2, $build->getExtra('item2'));
|
||||
self::assertNull($build->getExtra('item3'));
|
||||
self::assertEquals($info, $build->getExtra());
|
||||
|
||||
$build->setExtraValue('item3', 'Item Three');
|
||||
|
||||
$this->assertEquals('Item One', $build->getExtra('item1'));
|
||||
$this->assertEquals('Item Three', $build->getExtra('item3'));
|
||||
self::assertEquals('Item One', $build->getExtra('item1'));
|
||||
self::assertEquals('Item Three', $build->getExtra('item3'));
|
||||
|
||||
$build->setExtraValues([
|
||||
'item3' => 'Item Three New',
|
||||
'item4' => 4,
|
||||
]);
|
||||
|
||||
$this->assertEquals('Item One', $build->getExtra('item1'));
|
||||
$this->assertEquals('Item Three New', $build->getExtra('item3'));
|
||||
$this->assertEquals(4, $build->getExtra('item4'));
|
||||
self::assertEquals('Item One', $build->getExtra('item1'));
|
||||
self::assertEquals('Item Three New', $build->getExtra('item3'));
|
||||
self::assertEquals(4, $build->getExtra('item4'));
|
||||
|
||||
$this->assertEquals([
|
||||
self::assertEquals([
|
||||
'item1' => 'Item One',
|
||||
'item2' => 2,
|
||||
'item3' => 'Item Three New',
|
||||
|
|
|
@ -7,7 +7,7 @@ use PHPCensor\Model;
|
|||
|
||||
/**
|
||||
* Unit tests for the Project model class.
|
||||
*
|
||||
*
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
*/
|
||||
class ProjectTest extends \PHPUnit\Framework\TestCase
|
||||
|
@ -15,8 +15,8 @@ class ProjectTest extends \PHPUnit\Framework\TestCase
|
|||
public function testExecute_TestIsAValidModel()
|
||||
{
|
||||
$project = new Project();
|
||||
$this->assertTrue($project instanceof \b8\Model);
|
||||
$this->assertTrue($project instanceof Model);
|
||||
self::assertTrue($project instanceof \b8\Model);
|
||||
self::assertTrue($project instanceof Model);
|
||||
}
|
||||
|
||||
public function testExecute_TestGitDefaultBranch()
|
||||
|
@ -24,7 +24,7 @@ class ProjectTest extends \PHPUnit\Framework\TestCase
|
|||
$project = new Project();
|
||||
$project->setType('git');
|
||||
|
||||
$this->assertEquals('master', $project->getBranch());
|
||||
self::assertEquals('master', $project->getBranch());
|
||||
}
|
||||
|
||||
public function testExecute_TestGithubDefaultBranch()
|
||||
|
@ -32,7 +32,7 @@ class ProjectTest extends \PHPUnit\Framework\TestCase
|
|||
$project = new Project();
|
||||
$project->setType('github');
|
||||
|
||||
$this->assertEquals('master', $project->getBranch());
|
||||
self::assertEquals('master', $project->getBranch());
|
||||
}
|
||||
|
||||
public function testExecute_TestGitlabDefaultBranch()
|
||||
|
@ -40,7 +40,7 @@ class ProjectTest extends \PHPUnit\Framework\TestCase
|
|||
$project = new Project();
|
||||
$project->setType('gitlab');
|
||||
|
||||
$this->assertEquals('master', $project->getBranch());
|
||||
self::assertEquals('master', $project->getBranch());
|
||||
}
|
||||
|
||||
public function testExecute_TestBitbucketDefaultBranch()
|
||||
|
@ -48,7 +48,7 @@ class ProjectTest extends \PHPUnit\Framework\TestCase
|
|||
$project = new Project();
|
||||
$project->setType('bitbucket');
|
||||
|
||||
$this->assertEquals('master', $project->getBranch());
|
||||
self::assertEquals('master', $project->getBranch());
|
||||
}
|
||||
|
||||
public function testExecute_TestMercurialDefaultBranch()
|
||||
|
@ -56,7 +56,7 @@ class ProjectTest extends \PHPUnit\Framework\TestCase
|
|||
$project = new Project();
|
||||
$project->setType('hg');
|
||||
|
||||
$this->assertEquals('default', $project->getBranch());
|
||||
self::assertEquals('default', $project->getBranch());
|
||||
}
|
||||
|
||||
public function testExecute_TestProjectAccessInformation()
|
||||
|
@ -69,9 +69,9 @@ class ProjectTest extends \PHPUnit\Framework\TestCase
|
|||
$project = new Project();
|
||||
$project->setAccessInformation($info);
|
||||
|
||||
$this->assertEquals('Item One', $project->getAccessInformation('item1'));
|
||||
$this->assertEquals(2, $project->getAccessInformation('item2'));
|
||||
$this->assertNull($project->getAccessInformation('item3'));
|
||||
$this->assertEquals($info, $project->getAccessInformation());
|
||||
self::assertEquals('Item One', $project->getAccessInformation('item1'));
|
||||
self::assertEquals(2, $project->getAccessInformation('item2'));
|
||||
self::assertNull($project->getAccessInformation('item3'));
|
||||
self::assertEquals($info, $project->getAccessInformation());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ use PHPCensor\Model\Build;
|
|||
|
||||
/**
|
||||
* Unit test for the PHPUnit plugin.
|
||||
*
|
||||
*
|
||||
* @author meadsteve
|
||||
*/
|
||||
class EmailTest extends \PHPUnit\Framework\TestCase
|
||||
|
@ -156,7 +156,7 @@ class EmailTest extends \PHPUnit\Framework\TestCase
|
|||
// As no addresses will have been mailed as non are configured.
|
||||
$expectedReturn = false;
|
||||
|
||||
$this->assertEquals($expectedReturn, $returnValue);
|
||||
self::assertEquals($expectedReturn, $returnValue);
|
||||
}
|
||||
|
||||
public function testBuildsBasicEmails()
|
||||
|
@ -165,7 +165,7 @@ class EmailTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$this->testedEmailPlugin->execute();
|
||||
|
||||
$this->assertContains('test-receiver@example.com', $this->message['to']);
|
||||
self::assertContains('test-receiver@example.com', $this->message['to']);
|
||||
}
|
||||
|
||||
public function testBuildsDefaultEmails()
|
||||
|
@ -174,7 +174,7 @@ class EmailTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$this->testedEmailPlugin->execute();
|
||||
|
||||
$this->assertContains('default-mailto-address@example.com', $this->message['to']);
|
||||
self::assertContains('default-mailto-address@example.com', $this->message['to']);
|
||||
}
|
||||
|
||||
public function testExecute_UniqueRecipientsFromWithCommitter()
|
||||
|
@ -182,12 +182,12 @@ class EmailTest extends \PHPUnit\Framework\TestCase
|
|||
$this->loadEmailPluginWithOptions(['addresses' => ['test-receiver@example.com', 'test-receiver2@example.com']]);
|
||||
|
||||
$returnValue = $this->testedEmailPlugin->execute();
|
||||
$this->assertTrue($returnValue);
|
||||
self::assertTrue($returnValue);
|
||||
|
||||
$this->assertCount(2, $this->message['to']);
|
||||
self::assertCount(2, $this->message['to']);
|
||||
|
||||
$this->assertContains('test-receiver@example.com', $this->message['to']);
|
||||
$this->assertContains('test-receiver2@example.com', $this->message['to']);
|
||||
self::assertContains('test-receiver@example.com', $this->message['to']);
|
||||
self::assertContains('test-receiver2@example.com', $this->message['to']);
|
||||
}
|
||||
|
||||
public function testExecute_UniqueRecipientsWithCommitter()
|
||||
|
@ -198,10 +198,10 @@ class EmailTest extends \PHPUnit\Framework\TestCase
|
|||
]);
|
||||
|
||||
$returnValue = $this->testedEmailPlugin->execute();
|
||||
$this->assertTrue($returnValue);
|
||||
self::assertTrue($returnValue);
|
||||
|
||||
$this->assertContains('test-receiver@example.com', $this->message['to']);
|
||||
$this->assertContains('committer@test.com', $this->message['to']);
|
||||
self::assertContains('test-receiver@example.com', $this->message['to']);
|
||||
self::assertContains('committer@test.com', $this->message['to']);
|
||||
}
|
||||
|
||||
public function testCcDefaultEmails()
|
||||
|
@ -220,7 +220,7 @@ class EmailTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$this->testedEmailPlugin->execute();
|
||||
|
||||
$this->assertEquals(
|
||||
self::assertEquals(
|
||||
[
|
||||
'cc-email-1@example.com',
|
||||
'cc-email-2@example.com',
|
||||
|
@ -241,7 +241,7 @@ class EmailTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$this->testedEmailPlugin->execute();
|
||||
|
||||
$this->assertContains('committer-email@example.com', $this->message['to']);
|
||||
self::assertContains('committer-email@example.com', $this->message['to']);
|
||||
}
|
||||
|
||||
public function testMailSuccessfulBuildHaveProjectName()
|
||||
|
@ -255,8 +255,8 @@ class EmailTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$this->testedEmailPlugin->execute();
|
||||
|
||||
$this->assertContains('Test-Project', $this->message['subject']);
|
||||
$this->assertContains('Test-Project', $this->message['body']);
|
||||
self::assertContains('Test-Project', $this->message['subject']);
|
||||
self::assertContains('Test-Project', $this->message['body']);
|
||||
}
|
||||
|
||||
public function testMailFailingBuildHaveProjectName()
|
||||
|
@ -270,8 +270,8 @@ class EmailTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$this->testedEmailPlugin->execute();
|
||||
|
||||
$this->assertContains('Test-Project', $this->message['subject']);
|
||||
$this->assertContains('Test-Project', $this->message['body']);
|
||||
self::assertContains('Test-Project', $this->message['subject']);
|
||||
self::assertContains('Test-Project', $this->message['body']);
|
||||
}
|
||||
|
||||
public function testMailSuccessfulBuildHaveStatus()
|
||||
|
@ -285,8 +285,8 @@ class EmailTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$this->testedEmailPlugin->execute();
|
||||
|
||||
$this->assertContains('Passing', $this->message['subject']);
|
||||
$this->assertContains('success', $this->message['body']);
|
||||
self::assertContains('Passing', $this->message['subject']);
|
||||
self::assertContains('success', $this->message['body']);
|
||||
}
|
||||
|
||||
public function testMailFailingBuildHaveStatus()
|
||||
|
@ -300,8 +300,8 @@ class EmailTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$this->testedEmailPlugin->execute();
|
||||
|
||||
$this->assertContains('Failing', $this->message['subject']);
|
||||
$this->assertContains('failed', $this->message['body']);
|
||||
self::assertContains('Failing', $this->message['subject']);
|
||||
self::assertContains('failed', $this->message['body']);
|
||||
}
|
||||
|
||||
public function testMailDeliverySuccess()
|
||||
|
@ -316,7 +316,7 @@ class EmailTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$returnValue = $this->testedEmailPlugin->execute();
|
||||
|
||||
$this->assertEquals(true, $returnValue);
|
||||
self::assertEquals(true, $returnValue);
|
||||
}
|
||||
|
||||
public function testMailDeliveryFail()
|
||||
|
@ -331,6 +331,6 @@ class EmailTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$returnValue = $this->testedEmailPlugin->execute();
|
||||
|
||||
$this->assertEquals(false, $returnValue);
|
||||
self::assertEquals(false, $returnValue);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ class PhpUnitOptionsTest extends \PHPUnit\Framework\TestCase
|
|||
public function testCommandArguments($rawOptions, $parsedArguments)
|
||||
{
|
||||
$options = new PhpUnitOptions($rawOptions, '/location');
|
||||
$this->assertSame($parsedArguments, $options->getCommandArguments());
|
||||
self::assertSame($parsedArguments, $options->getCommandArguments());
|
||||
}
|
||||
|
||||
public function testGetters()
|
||||
|
@ -109,14 +109,14 @@ class PhpUnitOptionsTest extends \PHPUnit\Framework\TestCase
|
|||
'/location'
|
||||
);
|
||||
|
||||
$this->assertEquals('/path/to/run/from', $options->getRunFrom());
|
||||
$this->assertEquals('subTest', $options->getTestsPath());
|
||||
$this->assertNull($options->getOption('random'));
|
||||
$this->assertEmpty($options->getDirectories());
|
||||
$this->assertEmpty($options->getConfigFiles());
|
||||
self::assertEquals('/path/to/run/from', $options->getRunFrom());
|
||||
self::assertEquals('subTest', $options->getTestsPath());
|
||||
self::assertNull($options->getOption('random'));
|
||||
self::assertEmpty($options->getDirectories());
|
||||
self::assertEmpty($options->getConfigFiles());
|
||||
|
||||
$files = $options->getConfigFiles(ROOT_DIR);
|
||||
|
||||
$this->assertFileExists(ROOT_DIR . $files[0]);
|
||||
self::assertFileExists(ROOT_DIR . $files[0]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,46 +85,46 @@ class PharTest extends \PHPUnit\Framework\TestCase
|
|||
public function testPlugin()
|
||||
{
|
||||
$plugin = $this->getPlugin();
|
||||
$this->assertInstanceOf('PHPCensor\Plugin', $plugin);
|
||||
$this->assertInstanceOf('PHPCensor\Model\Build', $plugin->getBuild());
|
||||
$this->assertInstanceOf('PHPCensor\Builder', $plugin->getBuilder());
|
||||
self::assertInstanceOf('PHPCensor\Plugin', $plugin);
|
||||
self::assertInstanceOf('PHPCensor\Model\Build', $plugin->getBuild());
|
||||
self::assertInstanceOf('PHPCensor\Builder', $plugin->getBuilder());
|
||||
}
|
||||
|
||||
public function testDirectory()
|
||||
{
|
||||
$plugin = $this->getPlugin();
|
||||
$plugin->getBuilder()->buildPath = 'foo';
|
||||
$this->assertEquals('foo', $plugin->getDirectory());
|
||||
self::assertEquals('foo', $plugin->getDirectory());
|
||||
|
||||
$plugin = $this->getPlugin(['directory' => 'dirname']);
|
||||
$this->assertEquals('dirname', $plugin->getDirectory());
|
||||
self::assertEquals('dirname', $plugin->getDirectory());
|
||||
}
|
||||
|
||||
public function testFilename()
|
||||
{
|
||||
$plugin = $this->getPlugin();
|
||||
$this->assertEquals('build.phar', $plugin->getFilename());
|
||||
self::assertEquals('build.phar', $plugin->getFilename());
|
||||
|
||||
$plugin = $this->getPlugin(['filename' => 'another.phar']);
|
||||
$this->assertEquals('another.phar', $plugin->getFilename());
|
||||
self::assertEquals('another.phar', $plugin->getFilename());
|
||||
}
|
||||
|
||||
public function testRegExp()
|
||||
{
|
||||
$plugin = $this->getPlugin();
|
||||
$this->assertEquals('/\.php$/', $plugin->getRegExp());
|
||||
self::assertEquals('/\.php$/', $plugin->getRegExp());
|
||||
|
||||
$plugin = $this->getPlugin(['regexp' => '/\.(php|phtml)$/']);
|
||||
$this->assertEquals('/\.(php|phtml)$/', $plugin->getRegExp());
|
||||
self::assertEquals('/\.(php|phtml)$/', $plugin->getRegExp());
|
||||
}
|
||||
|
||||
public function testStub()
|
||||
{
|
||||
$plugin = $this->getPlugin();
|
||||
$this->assertNull($plugin->getStub());
|
||||
self::assertNull($plugin->getStub());
|
||||
|
||||
$plugin = $this->getPlugin(['stub' => 'stub.php']);
|
||||
$this->assertEquals('stub.php', $plugin->getStub());
|
||||
self::assertEquals('stub.php', $plugin->getStub());
|
||||
}
|
||||
|
||||
public function testExecute()
|
||||
|
@ -135,14 +135,14 @@ class PharTest extends \PHPUnit\Framework\TestCase
|
|||
$path = $this->buildSource();
|
||||
$plugin->getBuilder()->buildPath = $path;
|
||||
|
||||
$this->assertTrue($plugin->execute());
|
||||
self::assertTrue($plugin->execute());
|
||||
|
||||
$this->assertFileExists($path . '/build.phar');
|
||||
self::assertFileExists($path . '/build.phar');
|
||||
PHPPhar::loadPhar($path . '/build.phar');
|
||||
$this->assertFileEquals($path . '/one.php', 'phar://build.phar/one.php');
|
||||
$this->assertFileEquals($path . '/two.php', 'phar://build.phar/two.php');
|
||||
$this->assertFileNotExists('phar://build.phar/config/config.ini');
|
||||
$this->assertFileNotExists('phar://build.phar/views/index.phtml');
|
||||
self::assertFileEquals($path . '/one.php', 'phar://build.phar/one.php');
|
||||
self::assertFileEquals($path . '/two.php', 'phar://build.phar/two.php');
|
||||
self::assertFileNotExists('phar://build.phar/config/config.ini');
|
||||
self::assertFileNotExists('phar://build.phar/views/index.phtml');
|
||||
}
|
||||
|
||||
public function testExecuteRegExp()
|
||||
|
@ -153,14 +153,14 @@ class PharTest extends \PHPUnit\Framework\TestCase
|
|||
$path = $this->buildSource();
|
||||
$plugin->getBuilder()->buildPath = $path;
|
||||
|
||||
$this->assertTrue($plugin->execute());
|
||||
self::assertTrue($plugin->execute());
|
||||
|
||||
$this->assertFileExists($path . '/build.phar');
|
||||
self::assertFileExists($path . '/build.phar');
|
||||
PHPPhar::loadPhar($path . '/build.phar');
|
||||
$this->assertFileEquals($path . '/one.php', 'phar://build.phar/one.php');
|
||||
$this->assertFileEquals($path . '/two.php', 'phar://build.phar/two.php');
|
||||
$this->assertFileNotExists('phar://build.phar/config/config.ini');
|
||||
$this->assertFileEquals($path . '/views/index.phtml', 'phar://build.phar/views/index.phtml');
|
||||
self::assertFileEquals($path . '/one.php', 'phar://build.phar/one.php');
|
||||
self::assertFileEquals($path . '/two.php', 'phar://build.phar/two.php');
|
||||
self::assertFileNotExists('phar://build.phar/config/config.ini');
|
||||
self::assertFileEquals($path . '/views/index.phtml', 'phar://build.phar/views/index.phtml');
|
||||
}
|
||||
|
||||
public function testExecuteStub()
|
||||
|
@ -179,11 +179,11 @@ STUB;
|
|||
$plugin = $this->getPlugin(['stub' => 'stub.php']);
|
||||
$plugin->getBuilder()->buildPath = $path;
|
||||
|
||||
$this->assertTrue($plugin->execute());
|
||||
self::assertTrue($plugin->execute());
|
||||
|
||||
$this->assertFileExists($path . '/build.phar');
|
||||
self::assertFileExists($path . '/build.phar');
|
||||
$phar = new PHPPhar($path . '/build.phar');
|
||||
$this->assertEquals($content, trim($phar->getStub())); // + trim because PHP adds newline char
|
||||
self::assertEquals($content, trim($phar->getStub())); // + trim because PHP adds newline char
|
||||
}
|
||||
|
||||
public function testExecuteUnknownDirectory()
|
||||
|
@ -195,6 +195,6 @@ STUB;
|
|||
$plugin = $this->getPlugin(['directory' => $directory]);
|
||||
$plugin->getBuilder()->buildPath = $this->buildSource();
|
||||
|
||||
$this->assertFalse($plugin->execute());
|
||||
self::assertFalse($plugin->execute());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -92,14 +92,14 @@ class ExecutorTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$returnValue = $this->testedExecutor->executePlugin($pluginName, $options);
|
||||
|
||||
$this->assertEquals($expectedReturnValue, $returnValue);
|
||||
self::assertEquals($expectedReturnValue, $returnValue);
|
||||
}
|
||||
|
||||
public function testExecutePlugin_LogsFailureForNonExistentClasses()
|
||||
{
|
||||
$options = [];
|
||||
$pluginName = 'DOESNTEXIST';
|
||||
|
||||
|
||||
$this->mockBuildLogger->logFailure(sprintf('Plugin does not exist: %s', $pluginName))->shouldBeCalledTimes(1);
|
||||
|
||||
$this->testedExecutor->executePlugin($pluginName, $options);
|
||||
|
@ -162,7 +162,7 @@ class ExecutorTest extends \PHPUnit\Framework\TestCase
|
|||
]
|
||||
];
|
||||
|
||||
$this->assertEquals([], $this->testedExecutor->getBranchSpecificConfig($config, 'branch-1'));
|
||||
self::assertEquals([], $this->testedExecutor->getBranchSpecificConfig($config, 'branch-1'));
|
||||
|
||||
$config = [
|
||||
'setup' => [
|
||||
|
@ -173,7 +173,7 @@ class ExecutorTest extends \PHPUnit\Framework\TestCase
|
|||
],
|
||||
];
|
||||
|
||||
$this->assertEquals(['phpunit' => []], $this->testedExecutor->getBranchSpecificConfig($config, 'branch-1'));
|
||||
self::assertEquals(['phpunit' => []], $this->testedExecutor->getBranchSpecificConfig($config, 'branch-1'));
|
||||
|
||||
$config = [
|
||||
'setup' => [
|
||||
|
@ -184,7 +184,7 @@ class ExecutorTest extends \PHPUnit\Framework\TestCase
|
|||
],
|
||||
];
|
||||
|
||||
$this->assertEquals([], $this->testedExecutor->getBranchSpecificConfig($config, 'branch-1'));
|
||||
self::assertEquals([], $this->testedExecutor->getBranchSpecificConfig($config, 'branch-1'));
|
||||
|
||||
$config = [
|
||||
'setup' => [
|
||||
|
@ -197,7 +197,7 @@ class ExecutorTest extends \PHPUnit\Framework\TestCase
|
|||
],
|
||||
];
|
||||
|
||||
$this->assertEquals(['phpunit' => []], $this->testedExecutor->getBranchSpecificConfig($config, 'branch-1'));
|
||||
self::assertEquals(['phpunit' => []], $this->testedExecutor->getBranchSpecificConfig($config, 'branch-1'));
|
||||
|
||||
$config = [
|
||||
'setup' => [
|
||||
|
@ -210,7 +210,7 @@ class ExecutorTest extends \PHPUnit\Framework\TestCase
|
|||
],
|
||||
];
|
||||
|
||||
$this->assertEquals(['phpunit' => []], $this->testedExecutor->getBranchSpecificConfig($config, 'branch-1'));
|
||||
self::assertEquals(['phpunit' => []], $this->testedExecutor->getBranchSpecificConfig($config, 'branch-1'));
|
||||
|
||||
$config = [
|
||||
'setup' => [
|
||||
|
@ -223,7 +223,7 @@ class ExecutorTest extends \PHPUnit\Framework\TestCase
|
|||
],
|
||||
];
|
||||
|
||||
$this->assertEquals([], $this->testedExecutor->getBranchSpecificConfig($config, 'branch-1'));
|
||||
self::assertEquals([], $this->testedExecutor->getBranchSpecificConfig($config, 'branch-1'));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ class FactoryTest extends \PHPUnit\Framework\TestCase {
|
|||
{
|
||||
$pluginClass = $this->getFakePluginClassName('ExamplePluginWithSingleOptionalArg');
|
||||
$plugin = $this->testedFactory->buildPlugin($pluginClass);
|
||||
$this->assertInstanceOf($pluginClass, $plugin);
|
||||
self::assertInstanceOf($pluginClass, $plugin);
|
||||
}
|
||||
|
||||
public function testBuildPluginThrowsExceptionIfMissingResourcesForRequiredArg()
|
||||
|
@ -74,7 +74,7 @@ class FactoryTest extends \PHPUnit\Framework\TestCase {
|
|||
/** @var ExamplePluginWithSingleRequiredArg $plugin */
|
||||
$plugin = $this->testedFactory->buildPlugin($pluginClass);
|
||||
|
||||
$this->assertEquals($this->expectedResource, $plugin->RequiredArgument);
|
||||
self::assertEquals($this->expectedResource, $plugin->RequiredArgument);
|
||||
}
|
||||
|
||||
public function testBuildPluginLoadsArgumentsBasedOnType()
|
||||
|
@ -90,7 +90,7 @@ class FactoryTest extends \PHPUnit\Framework\TestCase {
|
|||
/** @var ExamplePluginWithSingleTypedRequiredArg $plugin */
|
||||
$plugin = $this->testedFactory->buildPlugin($pluginClass);
|
||||
|
||||
$this->assertEquals($this->expectedResource, $plugin->RequiredArgument);
|
||||
self::assertEquals($this->expectedResource, $plugin->RequiredArgument);
|
||||
}
|
||||
|
||||
public function testBuildPluginLoadsFullExample()
|
||||
|
@ -102,7 +102,7 @@ class FactoryTest extends \PHPUnit\Framework\TestCase {
|
|||
/** @var ExamplePluginFull $plugin */
|
||||
$plugin = $this->testedFactory->buildPlugin($pluginClass);
|
||||
|
||||
$this->assertInstanceOf($pluginClass, $plugin);
|
||||
self::assertInstanceOf($pluginClass, $plugin);
|
||||
}
|
||||
|
||||
public function testBuildPluginLoadsFullExampleWithOptions()
|
||||
|
@ -121,8 +121,8 @@ class FactoryTest extends \PHPUnit\Framework\TestCase {
|
|||
$expectedArgs
|
||||
);
|
||||
|
||||
$this->assertInternalType('array', $plugin->options);
|
||||
$this->assertArrayHasKey('thing', $plugin->options);
|
||||
self::assertInternalType('array', $plugin->options);
|
||||
self::assertArrayHasKey('thing', $plugin->options);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -30,31 +30,31 @@ class PhpUnitResultTest extends \PHPUnit\Framework\TestCase
|
|||
$output = $parser->parse()->getResults();
|
||||
$errors = $parser->getErrors();
|
||||
|
||||
$this->assertEquals(7, $parser->getFailures());
|
||||
$this->assertInternalType('array', $output);
|
||||
$this->assertInternalType('array', $errors);
|
||||
$this->assertNotEmpty($output);
|
||||
$this->assertNotEmpty($errors);
|
||||
self::assertEquals(7, $parser->getFailures());
|
||||
self::assertInternalType('array', $output);
|
||||
self::assertInternalType('array', $errors);
|
||||
self::assertNotEmpty($output);
|
||||
self::assertNotEmpty($errors);
|
||||
|
||||
// The trace elements should not include the build path
|
||||
$this->assertStringStartsNotWith($buildPath, $output[3]['trace'][0]);
|
||||
$this->assertStringStartsNotWith($buildPath, $output[3]['trace'][1]);
|
||||
self::assertStringStartsNotWith($buildPath, $output[3]['trace'][0]);
|
||||
self::assertStringStartsNotWith($buildPath, $output[3]['trace'][1]);
|
||||
|
||||
$this->assertEquals("some output\nfrom f4", $output[7]['output']);
|
||||
$this->assertEquals("has output\non lines", $output[15]['output']);
|
||||
self::assertEquals("some output\nfrom f4", $output[7]['output']);
|
||||
self::assertEquals("has output\non lines", $output[15]['output']);
|
||||
|
||||
$this->assertEquals(PhpUnitResult::SEVERITY_SKIPPED, $output[5]['severity']);
|
||||
self::assertEquals(PhpUnitResult::SEVERITY_SKIPPED, $output[5]['severity']);
|
||||
try {
|
||||
$this->assertContains('Incomplete Test:', $output[5]['message']);
|
||||
self::assertContains('Incomplete Test:', $output[5]['message']);
|
||||
} catch (\PHPUnit_Framework_ExpectationFailedException $e) {
|
||||
self::$skipped[] = ['cls' => $resultClass, 'ex' => $e];
|
||||
} catch (\PHPUnit\Framework\ExpectationFailedException $e) {
|
||||
self::$skipped[] = ['cls' => $resultClass, 'ex' => $e];
|
||||
}
|
||||
|
||||
$this->assertEquals(PhpUnitResult::SEVERITY_SKIPPED, $output[11]['severity']);
|
||||
self::assertEquals(PhpUnitResult::SEVERITY_SKIPPED, $output[11]['severity']);
|
||||
try {
|
||||
$this->assertContains('Skipped Test:', $output[11]['message']);
|
||||
self::assertContains('Skipped Test:', $output[11]['message']);
|
||||
} catch (\PHPUnit_Framework_ExpectationFailedException $e) {
|
||||
self::$skipped[] = ['cls' => $resultClass, 'ex' => $e];
|
||||
} catch (\PHPUnit\Framework\ExpectationFailedException $e) {
|
||||
|
|
|
@ -12,6 +12,6 @@ class PosixProcessControlTest extends UnixProcessControlTest
|
|||
|
||||
public function testIsAvailable()
|
||||
{
|
||||
$this->assertEquals(function_exists('posix_kill'), PosixProcessControl::isAvailable());
|
||||
self::assertEquals(function_exists('posix_kill'), PosixProcessControl::isAvailable());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,8 +33,8 @@ abstract class ProcessControlTest extends \PHPUnit\Framework\TestCase
|
|||
$this->process = proc_open($this->getTestCommand(), $desc, $this->pipes);
|
||||
sleep(1);
|
||||
|
||||
$this->assertTrue(is_resource($this->process));
|
||||
$this->assertTrue($this->isRunning());
|
||||
self::assertTrue(is_resource($this->process));
|
||||
self::assertTrue($this->isRunning());
|
||||
|
||||
$status = proc_get_status($this->process);
|
||||
return (integer)$status['pid'];
|
||||
|
@ -51,7 +51,7 @@ abstract class ProcessControlTest extends \PHPUnit\Framework\TestCase
|
|||
}
|
||||
array_map('fclose', $this->pipes);
|
||||
$exitCode = proc_close($this->process);
|
||||
$this->assertFalse($this->isRunning());
|
||||
self::assertFalse($this->isRunning());
|
||||
$this->process = null;
|
||||
return $exitCode;
|
||||
}
|
||||
|
@ -76,14 +76,14 @@ abstract class ProcessControlTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$pid = $this->startProcess();
|
||||
|
||||
$this->assertTrue($this->object->isRunning($pid));
|
||||
self::assertTrue($this->object->isRunning($pid));
|
||||
|
||||
fwrite($this->pipes[0], PHP_EOL);
|
||||
|
||||
$exitCode = $this->endProcess();
|
||||
|
||||
$this->assertEquals(0, $exitCode);
|
||||
$this->assertFalse($this->object->isRunning($pid));
|
||||
self::assertEquals(0, $exitCode);
|
||||
self::assertFalse($this->object->isRunning($pid));
|
||||
}
|
||||
|
||||
public function testSoftKill()
|
||||
|
|
|
@ -17,6 +17,6 @@ class UnixProcessControlTest extends ProcessControlTest
|
|||
|
||||
public function testIsAvailable()
|
||||
{
|
||||
$this->assertEquals(DIRECTORY_SEPARATOR === '/', UnixProcessControl::isAvailable());
|
||||
self::assertEquals(DIRECTORY_SEPARATOR === '/', UnixProcessControl::isAvailable());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,14 +8,14 @@ class ServiceTest extends \PHPUnit\Framework\TestCase
|
|||
{
|
||||
public function testGetInstance()
|
||||
{
|
||||
$this->assertInstanceOf('\PHPCensor\Security\Authentication\Service', Service::getInstance());
|
||||
self::assertInstanceOf('\PHPCensor\Security\Authentication\Service', Service::getInstance());
|
||||
}
|
||||
|
||||
public function testBuildBuiltinProvider()
|
||||
{
|
||||
$provider = Service::buildProvider('test', ['type' => 'internal']);
|
||||
|
||||
$this->assertInstanceOf('\PHPCensor\Security\Authentication\UserProvider\Internal', $provider);
|
||||
self::assertInstanceOf('\PHPCensor\Security\Authentication\UserProvider\Internal', $provider);
|
||||
}
|
||||
|
||||
public function testBuildAnyProvider()
|
||||
|
@ -23,9 +23,9 @@ class ServiceTest extends \PHPUnit\Framework\TestCase
|
|||
$config = ['type' => '\Tests\PHPCensor\Security\Authentication\DummyProvider'];
|
||||
$provider = Service::buildProvider("test", $config);
|
||||
|
||||
$this->assertInstanceOf('\Tests\PHPCensor\Security\Authentication\DummyProvider', $provider);
|
||||
$this->assertEquals('test', $provider->key);
|
||||
$this->assertEquals($config, $provider->config);
|
||||
self::assertInstanceOf('\Tests\PHPCensor\Security\Authentication\DummyProvider', $provider);
|
||||
self::assertEquals('test', $provider->key);
|
||||
self::assertEquals($config, $provider->config);
|
||||
}
|
||||
|
||||
public function testGetProviders()
|
||||
|
@ -36,7 +36,7 @@ class ServiceTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$service = new Service($providers);
|
||||
|
||||
$this->assertEquals($providers, $service->getProviders());
|
||||
self::assertEquals($providers, $service->getProviders());
|
||||
}
|
||||
|
||||
public function testGetLoginPasswordProviders()
|
||||
|
@ -47,7 +47,7 @@ class ServiceTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$service = new Service($providers);
|
||||
|
||||
$this->assertEquals(['b' => $b], $service->getLoginPasswordProviders());
|
||||
self::assertEquals(['b' => $b], $service->getLoginPasswordProviders());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ class InternalTest extends \PHPUnit\Framework\TestCase
|
|||
$password = 'bla';
|
||||
$user->setHash(password_hash($password, PASSWORD_DEFAULT));
|
||||
|
||||
$this->assertTrue($this->provider->verifyPassword($user, $password));
|
||||
self::assertTrue($this->provider->verifyPassword($user, $password));
|
||||
}
|
||||
|
||||
public function testVerifyInvaldPassword()
|
||||
|
@ -34,7 +34,7 @@ class InternalTest extends \PHPUnit\Framework\TestCase
|
|||
$password = 'foo';
|
||||
$user->setHash(password_hash($password, PASSWORD_DEFAULT));
|
||||
|
||||
$this->assertFalse($this->provider->verifyPassword($user, 'bar'));
|
||||
self::assertFalse($this->provider->verifyPassword($user, 'bar'));
|
||||
}
|
||||
|
||||
public function testCheckRequirements()
|
||||
|
@ -44,6 +44,6 @@ class InternalTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
public function testProvisionUser()
|
||||
{
|
||||
$this->assertNull($this->provider->provisionUser('john@doe.com'));
|
||||
self::assertNull($this->provider->provisionUser('john@doe.com'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ use PHPCensor\Service\BuildService;
|
|||
|
||||
/**
|
||||
* Unit tests for the ProjectService class.
|
||||
*
|
||||
*
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
*/
|
||||
class BuildServiceTest extends \PHPUnit\Framework\TestCase
|
||||
|
@ -60,18 +60,18 @@ class BuildServiceTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$returnValue = $this->testedService->createBuild($project, null);
|
||||
|
||||
$this->assertEquals(101, $returnValue->getProjectId());
|
||||
$this->assertEquals(Build::STATUS_PENDING, $returnValue->getStatus());
|
||||
$this->assertNull($returnValue->getStartDate());
|
||||
$this->assertNull($returnValue->getFinishDate());
|
||||
$this->assertNull($returnValue->getLog());
|
||||
$this->assertEquals(null, $returnValue->getCommitMessage());
|
||||
$this->assertNull($returnValue->getCommitterEmail());
|
||||
$this->assertEquals(['branches' => []], $returnValue->getExtra());
|
||||
$this->assertEquals('master', $returnValue->getBranch());
|
||||
$this->assertInstanceOf('DateTime', $returnValue->getCreateDate());
|
||||
$this->assertEquals('', $returnValue->getCommitId());
|
||||
$this->assertEquals(Build::SOURCE_UNKNOWN, $returnValue->getSource());
|
||||
self::assertEquals(101, $returnValue->getProjectId());
|
||||
self::assertEquals(Build::STATUS_PENDING, $returnValue->getStatus());
|
||||
self::assertNull($returnValue->getStartDate());
|
||||
self::assertNull($returnValue->getFinishDate());
|
||||
self::assertNull($returnValue->getLog());
|
||||
self::assertEquals(null, $returnValue->getCommitMessage());
|
||||
self::assertNull($returnValue->getCommitterEmail());
|
||||
self::assertEquals(['branches' => []], $returnValue->getExtra());
|
||||
self::assertEquals('master', $returnValue->getBranch());
|
||||
self::assertInstanceOf('DateTime', $returnValue->getCreateDate());
|
||||
self::assertEquals('', $returnValue->getCommitId());
|
||||
self::assertEquals(Build::SOURCE_UNKNOWN, $returnValue->getSource());
|
||||
}
|
||||
|
||||
public function testExecute_CreateBuildWithOptions()
|
||||
|
@ -98,10 +98,10 @@ class BuildServiceTest extends \PHPUnit\Framework\TestCase
|
|||
'test'
|
||||
);
|
||||
|
||||
$this->assertEquals('testbranch', $returnValue->getBranch());
|
||||
$this->assertEquals('123', $returnValue->getCommitId());
|
||||
$this->assertEquals('test', $returnValue->getCommitMessage());
|
||||
$this->assertEquals('test@example.com', $returnValue->getCommitterEmail());
|
||||
self::assertEquals('testbranch', $returnValue->getBranch());
|
||||
self::assertEquals('123', $returnValue->getCommitId());
|
||||
self::assertEquals('test', $returnValue->getCommitMessage());
|
||||
self::assertEquals('test@example.com', $returnValue->getCommitterEmail());
|
||||
}
|
||||
|
||||
public function testExecute_CreateBuildWithExtra()
|
||||
|
@ -131,7 +131,7 @@ class BuildServiceTest extends \PHPUnit\Framework\TestCase
|
|||
['item1' => 1001]
|
||||
);
|
||||
|
||||
$this->assertEquals(1001, $returnValue->getExtra('item1'));
|
||||
self::assertEquals(1001, $returnValue->getExtra('item1'));
|
||||
}
|
||||
|
||||
public function testExecute_CreateDuplicateBuild()
|
||||
|
@ -151,19 +151,19 @@ class BuildServiceTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$returnValue = $this->testedService->createDuplicateBuild($build);
|
||||
|
||||
$this->assertNotEquals($build->getId(), $returnValue->getId());
|
||||
$this->assertEquals($build->getProjectId(), $returnValue->getProjectId());
|
||||
$this->assertEquals($build->getCommitId(), $returnValue->getCommitId());
|
||||
$this->assertNotEquals($build->getStatus(), $returnValue->getStatus());
|
||||
$this->assertEquals(Build::STATUS_PENDING, $returnValue->getStatus());
|
||||
$this->assertNull($returnValue->getLog());
|
||||
$this->assertEquals($build->getBranch(), $returnValue->getBranch());
|
||||
$this->assertNotEquals($build->getCreateDate(), $returnValue->getCreateDate());
|
||||
$this->assertNull($returnValue->getStartDate());
|
||||
$this->assertNull($returnValue->getFinishDate());
|
||||
$this->assertEquals('test', $returnValue->getCommitMessage());
|
||||
$this->assertEquals('test@example.com', $returnValue->getCommitterEmail());
|
||||
$this->assertEquals($build->getExtra('item1'), $returnValue->getExtra('item1'));
|
||||
self::assertNotEquals($build->getId(), $returnValue->getId());
|
||||
self::assertEquals($build->getProjectId(), $returnValue->getProjectId());
|
||||
self::assertEquals($build->getCommitId(), $returnValue->getCommitId());
|
||||
self::assertNotEquals($build->getStatus(), $returnValue->getStatus());
|
||||
self::assertEquals(Build::STATUS_PENDING, $returnValue->getStatus());
|
||||
self::assertNull($returnValue->getLog());
|
||||
self::assertEquals($build->getBranch(), $returnValue->getBranch());
|
||||
self::assertNotEquals($build->getCreateDate(), $returnValue->getCreateDate());
|
||||
self::assertNull($returnValue->getStartDate());
|
||||
self::assertNull($returnValue->getFinishDate());
|
||||
self::assertEquals('test', $returnValue->getCommitMessage());
|
||||
self::assertEquals('test@example.com', $returnValue->getCommitterEmail());
|
||||
self::assertEquals($build->getExtra('item1'), $returnValue->getExtra('item1'));
|
||||
}
|
||||
|
||||
public function testExecute_DeleteBuild()
|
||||
|
@ -176,6 +176,6 @@ class BuildServiceTest extends \PHPUnit\Framework\TestCase
|
|||
$service = new BuildService($store);
|
||||
$build = new Build();
|
||||
|
||||
$this->assertEquals(true, $service->deleteBuild($build));
|
||||
self::assertEquals(true, $service->deleteBuild($build));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ use PHPCensor\Service\BuildStatusService;
|
|||
|
||||
/**
|
||||
* Unit tests for the ProjectService class.
|
||||
*
|
||||
*
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
*/
|
||||
class BuildStatusServiceTest extends \PHPUnit\Framework\TestCase
|
||||
|
@ -142,7 +142,7 @@ class BuildStatusServiceTest extends \PHPUnit\Framework\TestCase
|
|||
$build = $this->getBuild($buildConfigId);
|
||||
$service = new BuildStatusService(self::BRANCH, $this->project, $build);
|
||||
$service->setUrl('http://php-censor.local/');
|
||||
$this->assertEquals($expectedResult, $service->toArray());
|
||||
self::assertEquals($expectedResult, $service->toArray());
|
||||
}
|
||||
|
||||
public function finishedProvider()
|
||||
|
@ -205,4 +205,4 @@ class BuildStatusServiceTest extends \PHPUnit\Framework\TestCase
|
|||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ use PHPCensor\Service\ProjectService;
|
|||
|
||||
/**
|
||||
* Unit tests for the ProjectService class.
|
||||
*
|
||||
*
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
*/
|
||||
class ProjectServiceTest extends \PHPUnit\Framework\TestCase
|
||||
|
@ -37,10 +37,10 @@ class ProjectServiceTest extends \PHPUnit\Framework\TestCase
|
|||
{
|
||||
$returnValue = $this->testedService->createProject('Test Project', 'github', 'block8/phpci', 0);
|
||||
|
||||
$this->assertEquals('Test Project', $returnValue->getTitle());
|
||||
$this->assertEquals('github', $returnValue->getType());
|
||||
$this->assertEquals('block8/phpci', $returnValue->getReference());
|
||||
$this->assertEquals('master', $returnValue->getBranch());
|
||||
self::assertEquals('Test Project', $returnValue->getTitle());
|
||||
self::assertEquals('github', $returnValue->getType());
|
||||
self::assertEquals('block8/phpci', $returnValue->getReference());
|
||||
self::assertEquals('master', $returnValue->getBranch());
|
||||
}
|
||||
|
||||
public function testExecute_CreateProjectWithOptions()
|
||||
|
@ -55,11 +55,11 @@ class ProjectServiceTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$returnValue = $this->testedService->createProject('Test Project', 'github', 'block8/phpci', 0, $options);
|
||||
|
||||
$this->assertEquals('private', $returnValue->getSshPrivateKey());
|
||||
$this->assertEquals('public', $returnValue->getSshPublicKey());
|
||||
$this->assertEquals('config', $returnValue->getBuildConfig());
|
||||
$this->assertEquals('testbranch', $returnValue->getBranch());
|
||||
$this->assertEquals(1, $returnValue->getAllowPublicStatus());
|
||||
self::assertEquals('private', $returnValue->getSshPrivateKey());
|
||||
self::assertEquals('public', $returnValue->getSshPublicKey());
|
||||
self::assertEquals('config', $returnValue->getBuildConfig());
|
||||
self::assertEquals('testbranch', $returnValue->getBranch());
|
||||
self::assertEquals(1, $returnValue->getAllowPublicStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -70,9 +70,9 @@ class ProjectServiceTest extends \PHPUnit\Framework\TestCase
|
|||
$reference = 'git@gitlab.block8.net:block8/phpci.git';
|
||||
$returnValue = $this->testedService->createProject('Gitlab', 'gitlab', $reference, 0);
|
||||
|
||||
$this->assertEquals('git', $returnValue->getAccessInformation('user'));
|
||||
$this->assertEquals('gitlab.block8.net', $returnValue->getAccessInformation('domain'));
|
||||
$this->assertEquals('block8/phpci', $returnValue->getReference());
|
||||
self::assertEquals('git', $returnValue->getAccessInformation('user'));
|
||||
self::assertEquals('gitlab.block8.net', $returnValue->getAccessInformation('domain'));
|
||||
self::assertEquals('block8/phpci', $returnValue->getReference());
|
||||
}
|
||||
|
||||
public function testExecute_UpdateExistingProject()
|
||||
|
@ -84,9 +84,9 @@ class ProjectServiceTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$returnValue = $this->testedService->updateProject($project, 'After Title', 'bitbucket', 'After Reference');
|
||||
|
||||
$this->assertEquals('After Title', $returnValue->getTitle());
|
||||
$this->assertEquals('After Reference', $returnValue->getReference());
|
||||
$this->assertEquals('bitbucket', $returnValue->getType());
|
||||
self::assertEquals('After Title', $returnValue->getTitle());
|
||||
self::assertEquals('After Reference', $returnValue->getReference());
|
||||
self::assertEquals('bitbucket', $returnValue->getType());
|
||||
}
|
||||
|
||||
public function testExecute_EmptyPublicStatus()
|
||||
|
@ -102,7 +102,7 @@ class ProjectServiceTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$returnValue = $this->testedService->updateProject($project, 'Test Project', 'github', 'block8/phpci', $options);
|
||||
|
||||
$this->assertEquals(0, $returnValue->getAllowPublicStatus());
|
||||
self::assertEquals(0, $returnValue->getAllowPublicStatus());
|
||||
}
|
||||
|
||||
public function testExecute_DeleteProject()
|
||||
|
@ -115,6 +115,6 @@ class ProjectServiceTest extends \PHPUnit\Framework\TestCase
|
|||
$service = new ProjectService($store);
|
||||
$project = new Project();
|
||||
|
||||
$this->assertEquals(true, $service->deleteProject($project));
|
||||
self::assertEquals(true, $service->deleteProject($project));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ use PHPCensor\Service\UserService;
|
|||
|
||||
/**
|
||||
* Unit tests for the ProjectService class.
|
||||
*
|
||||
*
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
*/
|
||||
class UserServiceTest extends \PHPUnit\Framework\TestCase
|
||||
|
@ -44,10 +44,10 @@ class UserServiceTest extends \PHPUnit\Framework\TestCase
|
|||
false
|
||||
);
|
||||
|
||||
$this->assertEquals('Test', $user->getName());
|
||||
$this->assertEquals('test@example.com', $user->getEmail());
|
||||
$this->assertEquals(0, $user->getIsAdmin());
|
||||
$this->assertTrue(password_verify('testing', $user->getHash()));
|
||||
self::assertEquals('Test', $user->getName());
|
||||
self::assertEquals('test@example.com', $user->getEmail());
|
||||
self::assertEquals(0, $user->getIsAdmin());
|
||||
self::assertTrue(password_verify('testing', $user->getHash()));
|
||||
}
|
||||
|
||||
public function testExecute_CreateAdminUser()
|
||||
|
@ -61,7 +61,7 @@ class UserServiceTest extends \PHPUnit\Framework\TestCase
|
|||
true
|
||||
);
|
||||
|
||||
$this->assertEquals(1, $user->getIsAdmin());
|
||||
self::assertEquals(1, $user->getIsAdmin());
|
||||
}
|
||||
|
||||
public function testExecute_RevokeAdminStatus()
|
||||
|
@ -72,7 +72,7 @@ class UserServiceTest extends \PHPUnit\Framework\TestCase
|
|||
$user->setIsAdmin(1);
|
||||
|
||||
$user = $this->testedService->updateUser($user, 'Test', 'test@example.com', 'testing', 0);
|
||||
$this->assertEquals(0, $user->getIsAdmin());
|
||||
self::assertEquals(0, $user->getIsAdmin());
|
||||
}
|
||||
|
||||
public function testExecute_GrantAdminStatus()
|
||||
|
@ -83,7 +83,7 @@ class UserServiceTest extends \PHPUnit\Framework\TestCase
|
|||
$user->setIsAdmin(0);
|
||||
|
||||
$user = $this->testedService->updateUser($user, 'Test', 'test@example.com', 'testing', 1);
|
||||
$this->assertEquals(1, $user->getIsAdmin());
|
||||
self::assertEquals(1, $user->getIsAdmin());
|
||||
}
|
||||
|
||||
public function testExecute_ChangesPasswordIfNotEmpty()
|
||||
|
@ -92,8 +92,8 @@ class UserServiceTest extends \PHPUnit\Framework\TestCase
|
|||
$user->setHash(password_hash('testing', PASSWORD_DEFAULT));
|
||||
|
||||
$user = $this->testedService->updateUser($user, 'Test', 'test@example.com', 'newpassword', 0);
|
||||
$this->assertFalse(password_verify('testing', $user->getHash()));
|
||||
$this->assertTrue(password_verify('newpassword', $user->getHash()));
|
||||
self::assertFalse(password_verify('testing', $user->getHash()));
|
||||
self::assertTrue(password_verify('newpassword', $user->getHash()));
|
||||
}
|
||||
|
||||
public function testExecute_DoesNotChangePasswordIfEmpty()
|
||||
|
@ -102,6 +102,6 @@ class UserServiceTest extends \PHPUnit\Framework\TestCase
|
|||
$user->setHash(password_hash('testing', PASSWORD_DEFAULT));
|
||||
|
||||
$user = $this->testedService->updateUser($user, 'Test', 'test@example.com', '', 0);
|
||||
$this->assertTrue(password_verify('testing', $user->getHash()));
|
||||
self::assertTrue(password_verify('testing', $user->getHash()));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue