Skip to content

Commit

Permalink
Merge pull request #15 from michield/stable
Browse files Browse the repository at this point in the history
add Travis-CI testing
  • Loading branch information
michield committed Oct 21, 2015
2 parents 7270bdd + 36af65e commit f120257
Show file tree
Hide file tree
Showing 33 changed files with 1,438 additions and 956 deletions.
4 changes: 4 additions & 0 deletions .gitignore
@@ -0,0 +1,4 @@
/vendor/
plugins/restapi/output/
/composer.lock
/.php_cs.cache
27 changes: 27 additions & 0 deletions .php_cs
@@ -0,0 +1,27 @@
<?php

// Needed to get styleci-bridge loaded
require_once __DIR__.'/vendor/autoload.php';

use SLLH\StyleCIBridge\ConfigBridge;

return ConfigBridge::create()
->setUsingCache(true)
;

$finder = Symfony\CS\Finder\DefaultFinder::create()
->exclude('admin/help')
->exclude('admin/info')
->exclude('public_html/texts')
->exclude('admin/ui')
->exclude('admin/locale')
->exclude('admin/PHPMailer')
->in(__DIR__)
;

return Symfony\CS\Config\Config::create()
// ->level(Symfony\CS\FixerInterface::PSR0_LEVEL) /* default is symfony */
// ->level(Symfony\CS\FixerInterface::NONE_LEVEL)
->fixers(array('trailing_spaces', 'encoding', 'align_double_arrow', 'newline_after_open_tag', 'ordered_use', 'long_array_syntax'))
->finder($finder)
;
23 changes: 23 additions & 0 deletions .styleci.yml
@@ -0,0 +1,23 @@
preset: symfony

enabled:
- align_double_arrow
- newline_after_open_tag
- ordered_use
- long_array_syntax

disabled:
- unalign_double_arrow
- unalign_equals

finder:
exclude:
- "hostedplugins"
- "public_html/lists/admin/plugins"
- "public_html/lists/admin/PHPMailer"
- "public_html/lists/admin/help"
- "public_html/lists/admin/info"
- "public_html/lists/admin/locale"
- "public_html/lists/admin/ui"


35 changes: 35 additions & 0 deletions .travis.yml
@@ -0,0 +1,35 @@
# Configuration file for running the test suite. Results will be at https://travis-ci.org/phpList/phplist-plugin-restapi
# whitelist
language: php
php:
- 7.0
- 5.6
- 5.5
- 5.4
- 5.3

before_script:
- sudo apt-get update > /dev/null
- sudo apt-get install -y --force-yes apache2 libapache2-mod-php5 php5-curl php5-mysql php5-intl
# Set a custom vhost
- sudo sed -i -e "s,/var/www,$(pwd)/vendor/phpList/phplist3/public_html,g" /etc/apache2/sites-available/default
- sudo sed -i -e "/DocumentRoot/i\ServerName phplist.dev" /etc/apache2/sites-available/default
- sudo sed -i -e "/DocumentRoot/i\SetEnv ConfigFile $(pwd)/tests/travis-ci/config.php" /etc/apache2/sites-available/default
- echo "127.0.0.1 phplist.dev" | sudo tee -a /etc/hosts
- sudo cat /etc/apache2/sites-available/default
- sudo /etc/init.d/apache2 restart
- composer self-update
- composer install --dev --prefer-dist
- sudo cp -f tests/travis-ci/behat.yml behat.yml

# Set MySQL configuration and create the database.
- mysql -e 'SET GLOBAL wait_timeout = 5400;'
- mysql -e 'create database phplisttraviscidb;'

script:
- vendor/bin/behat
- phpunit -c tests/phpunit/phpunit.xml tests/phpunit/restapi.php
after_failure:
- echo "Failures detected. Outputing additional logs:"
- sudo cat /var/log/apache2/error.log
- sudo cat /var/log/mysql/error.log
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -7,11 +7,12 @@ Two plugins inside this repo: "restapi" and "restapi-test"

Original development by Flowcom AB, Andreas Ek ([@EkAndreas](https://twitter.com/ekandreas))

License: GPLv2
License: GPLv3 or later

##History
```
v. Date Description
2015-10-21 Added Travis integration
0.3 2014-05-31 Moved to phpList organisation and renamed phplist-plugin-restapi
0.2.7 2013-03-13 Added order and limit to listsGet
0.2.6 2013-03-13 Test script fixed with login and password.
Expand Down
26 changes: 26 additions & 0 deletions composer.json
@@ -0,0 +1,26 @@
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/phpList/phplist3"
}
],
"require": {
"phpList/phplist3": "master"
},
"require-dev": {
"behat/mink": "~1.4",
"behat/mink-goutte-driver": "~1.2",
"behat/mink-selenium2-driver": "~1.3",
"behat/behat": "~2.4",
"behat/mink-extension": "~1.3",
"fabpot/goutte": "1.*@stable",
"sllh/php-cs-fixer-styleci-bridge": "~1.3",
"phpunit/phpunit": "3.7.*"
},
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"bin-dir": "vendor/bin/"
}
}
24 changes: 13 additions & 11 deletions plugins/restapi.php
@@ -1,6 +1,7 @@
<?php

/**
* Plugin that implements a REST API
* Plugin that implements a REST API.
*
* Documentation: http://resources.phplist.com/plugin/restapi
*
Expand All @@ -15,23 +16,24 @@
*/
defined('PHPLISTINIT') || die;

class restapi extends phplistPlugin {

public $name = "RESTAPI";
class restapi extends phplistPlugin
{
public $name = 'RESTAPI';
public $description = 'Implements a REST API interface to phpList';
public $topMenuLinks = array(
'main' => array('category' => 'system'),
);
);

function restapi() {
parent::phplistplugin();
$this->coderoot = dirname(__FILE__) . '/restapi/';
public function restapi()
{
parent::phplistplugin();
$this->coderoot = dirname(__FILE__).'/restapi/';
}

function adminmenu() {
public function adminmenu()
{
return array(
"main" => "RESTAPI"
'main' => 'RESTAPI',
);
}

}
48 changes: 29 additions & 19 deletions plugins/restapi/call.php
Expand Up @@ -8,7 +8,7 @@
ob_end_clean();

//Getting phpList globals for this plugin
$plugin = $GLOBALS["plugins"][$_GET["pi"]];
$plugin = $GLOBALS['plugins'][$_GET['pi']];

include 'includes/response.php';
include 'includes/pdo.php';
Expand All @@ -24,38 +24,48 @@
include 'doc/doc.php';

if (function_exists('api_request_log')) {
api_request_log();
api_request_log();
}

//Check if this is called outside phpList auth, this should never occur!
if ( empty( $plugin->coderoot ) ){
Response::outputErrorMessage( 'Not authorized! Please login with [login] and [password] as admin first!' );
if (empty($plugin->coderoot)) {
Response::outputErrorMessage('Not authorized! Please login with [login] and [password] as admin first!');
}

//If other than POST then assume documentation report
if ( strcmp( $_SERVER['REQUEST_METHOD'], "POST") ) {
if (strcmp($_SERVER['REQUEST_METHOD'], 'POST')) {
$doc = new \phpListRestapiDoc();
$doc->addClass( 'Actions' );
$doc->addClass( 'Lists' );
$doc->addClass( 'Subscribers' );
$doc->addClass( 'Templates' );
$doc->addClass( 'Messages' );
$doc->addClass('Actions');
$doc->addClass('Lists');
$doc->addClass('Subscribers');
$doc->addClass('Templates');
$doc->addClass('Messages');
$doc->output();
}

//Check if command is empty!
$cmd = $_REQUEST['cmd'];
$cmd = preg_replace('/\W/','',$cmd);
if ( empty($cmd) ){
Response::outputMessage('OK! For action, please provide Post Param Key [cmd] !');
$cmd = preg_replace('/\W/', '', $cmd);
if (empty($cmd)) {
Response::outputMessage('OK! For action, please provide Post Param Key [cmd] !');
}

//Now bind the commands with static functions
if ( is_callable( array( 'phpListRestapi\Lists', $cmd ) ) ) Lists::$cmd();
if ( is_callable( array( 'phpListRestapi\Actions', $cmd ) ) ) Actions::$cmd();
if ( is_callable( array( 'phpListRestapi\Subscribers', $cmd ) ) ) Subscribers::$cmd();
if ( is_callable( array( 'phpListRestapi\Templates', $cmd ) ) ) Templates::$cmd();
if ( is_callable( array( 'phpListRestapi\Messages', $cmd ) ) ) Messages::$cmd();
if (is_callable(array('phpListRestapi\Lists', $cmd))) {
Lists::$cmd();
}
if (is_callable(array('phpListRestapi\Actions', $cmd))) {
Actions::$cmd();
}
if (is_callable(array('phpListRestapi\Subscribers', $cmd))) {
Subscribers::$cmd();
}
if (is_callable(array('phpListRestapi\Templates', $cmd))) {
Templates::$cmd();
}
if (is_callable(array('phpListRestapi\Messages', $cmd))) {
Messages::$cmd();
}

//If no command found, return error message!
Response::outputErrorMessage( 'No function for provided [cmd] found!' );
Response::outputErrorMessage('No function for provided [cmd] found!');
57 changes: 25 additions & 32 deletions plugins/restapi/doc/doc.php
@@ -1,46 +1,43 @@
<?php

class phpListRestapiDoc {

class phpListRestapiDoc
{
private $classes;

function __construct()
public function __construct()
{
}

function addClass( $classname ){

public function addClass($classname)
{
$this->classes[] = "phpListRestapi\\$classname";

}

function output(){

public function output()
{
$this->header();

foreach( $this->classes as $class ){

$reflect = new \ReflectionClass( $class );
foreach ($this->classes as $class) {
$reflect = new \ReflectionClass($class);
$methods = $reflect->getMethods();
foreach( $methods as $method ){

foreach ($methods as $method) {
echo '<section>';
echo '<div class="page-header">';
echo '<h2>' . $method->name . '</h2>';
echo '<h2>'.$method->name.'</h2>';
echo '</div>';
echo '<div class="row">';
echo '<div class="span12">';

$comment = $method->getDocComment();

$comment = str_replace( '/**', '', $comment );
$comment = str_replace( '*/', '', $comment );
$comment = str_replace( '[*', '<span class="label label-warning">', $comment );
$comment = str_replace( '[', '<span class="label label-success">', $comment );
$comment = str_replace( ']', '</span>', $comment );
$comment = str_replace( '{', '<span class="badge">', $comment );
$comment = str_replace( '}', '</span>', $comment );
$comment = str_replace( '*', '', $comment );
$comment = str_replace('/**', '', $comment);
$comment = str_replace('*/', '', $comment);
$comment = str_replace('[*', '<span class="label label-warning">', $comment);
$comment = str_replace('[', '<span class="label label-success">', $comment);
$comment = str_replace(']', '</span>', $comment);
$comment = str_replace('{', '<span class="badge">', $comment);
$comment = str_replace('}', '</span>', $comment);
$comment = str_replace('*', '', $comment);
//$comment = str_replace( '<br><br>', '', $comment );

echo trim($comment);
Expand All @@ -50,18 +47,15 @@ function output(){
echo '<br/>';
echo '<section>';
}

}

$this->footer();

exit;

}


function header(){

public function header()
{
?>

<!DOCTYPE html>
Expand All @@ -80,7 +74,8 @@ function header(){
<div class="row">
<div class="span6">
<h1>API Plugin to phpList</h1>
<p class="lead">Documentation generated <?php echo date('Y-m-d H:i:s'); ?></p>
<p class="lead">Documentation generated <?php echo date('Y-m-d H:i:s');
?></p>
</div>
</div>
</header>
Expand All @@ -100,8 +95,8 @@ function header(){

}

function footer(){

public function footer()
{
?>
<footer id="footer">
<p class="pull-right"><a href="#">Back to top</a></p>
Expand All @@ -113,6 +108,4 @@ function footer(){
<?php

}


}

0 comments on commit f120257

Please sign in to comment.