Merge remote-tracking branch 'upstream/release/0.9' into release/0.9

This commit is contained in:
Antonin 2015-05-29 18:59:09 +02:00
commit 4ced550942
19 changed files with 1088 additions and 34 deletions

View File

@ -21,7 +21,6 @@ use Framadate\Services\InputService;
use Framadate\Services\LogService;
use Framadate\Services\PurgeService;
use Framadate\Services\SecurityService;
use Framadate\Utils;
include_once __DIR__ . '/../app/inc/init.php';
include_once __DIR__ . '/../bandeaux.php';

View File

@ -18,8 +18,6 @@
*/
namespace Framadate;
use Framadate\Editable;
class Form
{

View File

@ -5,7 +5,14 @@ class MailService {
private $smtp_allowed;
const DELAY_BEFORE_RESEND = 300;
const MAILSERVICE_KEY = 'mailservice';
private $logService;
function __construct($smtp_allowed) {
$this->logService = new LogService();
$this->smtp_allowed = $smtp_allowed;
}
@ -13,10 +20,12 @@ class MailService {
return filter_var($email, FILTER_VALIDATE_EMAIL);
}
function send($to, $subject, $body, $param = '') {
if ($this->smtp_allowed == true) {
function send($to, $subject, $body, $msgKey = null) {
if ($this->smtp_allowed == true && $this->canSendMsg($msgKey)) {
mb_internal_encoding('UTF-8');
// Build headers
$subject = mb_encode_mimeheader(html_entity_decode($subject, ENT_QUOTES, 'UTF-8'), 'UTF-8', 'B', "\n", 9);
$encoded_app = mb_encode_mimeheader(NOMAPPLICATION, 'UTF-8', 'B', "\n", 6);
@ -39,11 +48,38 @@ class MailService {
$headers .= "Auto-Submitted:auto-generated\n";
$headers .= 'Return-Path: <>';
// Build body
$body = $body . '<br/><br/>' . __('Mail', 'Thanks for your trust.') . '<br/>' . NOMAPPLICATION . '<hr/>' . __('Mail', 'FOOTER');
mail($to, $subject, $body, $headers, $param);
// Send mail
$this->sendMail($to, $subject, $body, $msgKey, $headers);
}
}
function canSendMsg($msgKey) {
if ($msgKey == null) {
return true;
}
if (!isset($_SESSION[self::MAILSERVICE_KEY])) {
$_SESSION[self::MAILSERVICE_KEY] = [];
}
return !isset($_SESSION[self::MAILSERVICE_KEY][$msgKey]) || time() - $_SESSION[self::MAILSERVICE_KEY][$msgKey] > self::DELAY_BEFORE_RESEND;
}
private function sendMail($to, $subject, $body, $msgKey, $headers) {
mail($to, $subject, $body, $headers, '');
// Log
$this->logService->log('MAIL', 'Mail sent to: ' . $to . ', key: ' . $msgKey);
// Store the mail sending date
$_SESSION[self::MAILSERVICE_KEY][$msgKey] = time();
}
}

View File

@ -28,7 +28,7 @@ if (isset($_POST['lang']) && is_string($_POST['lang']) && in_array($_POST['lang'
}
/* <html lang="$locale"> */
$i18n->get('Something, just to load the dictionary');
$i18n->get('', 'Something, just to load the dictionary');
$locale = $i18n->getLoadedLang();
/* Date Format */

View File

@ -0,0 +1,23 @@
<?php
namespace Framadate;
abstract class FramaTestCase extends \PHPUnit_Framework_TestCase {
protected function getTestResourcePath($resourcepath) {
return __DIR__ . '/../resources/'.$resourcepath;
}
protected function readTestResource($resourcepath) {
return file_get_contents($this->getTestResourcePath($resourcepath));
}
protected function invoke(&$object, $methodName) {
$reflectionClass = new \ReflectionClass($object);
$reflectionMethod = $reflectionClass->getMethod($methodName);
$reflectionMethod->setAccessible(true);
$params = array_slice(func_get_args(), 2); // get all the parameters after $methodName
return $reflectionMethod->invokeArgs($object, $params);
}
}

View File

@ -0,0 +1,39 @@
<?php
namespace Framadate\Services;
use Framadate\FramaTestCase;
class MailServiceUnitTest extends FramaTestCase {
const MSG_KEY = '666';
/**
* @test
*/
function should_send_a_2nd_mail_after_a_good_interval() {
// Given
$mailService = new MailService(true);
$_SESSION[MailService::MAILSERVICE_KEY] = [self::MSG_KEY => time() - 1000];
// When
$canSendMsg = $mailService->canSendMsg(self::MSG_KEY);
// Then
$this->assertEquals(true, $canSendMsg);
}
/**
* @test
*/
function should_not_send_2_mails_in_a_short_interval() {
// Given
$mailService = new MailService(true);
$_SESSION[MailService::MAILSERVICE_KEY] = [self::MSG_KEY => time()];
// When
$canSendMsg = $mailService->canSendMsg(self::MSG_KEY);
// Then
$this->assertEquals(false, $canSendMsg);
}
}

3
app/tests/bootstrap.php Normal file
View File

@ -0,0 +1,3 @@
<?php
$loader = require __DIR__ . '/../../vendor/autoload.php';
$loader->addPsr4('Framadate\\', __DIR__.'/Framadate');

View File

@ -14,6 +14,10 @@
"o80/i18n": "dev-develop"
},
"require-dev": {
"phpunit/phpunit": "^4.5"
},
"autoload": {
"psr-4": {
"Framadate\\": "app/classes/Framadate/"

972
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -41,13 +41,13 @@ if (file_exists('bandeaux_local.php')) {
// Step 1/4 : error if $_SESSION from info_sondage are not valid
if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || (($config['use_smtp']) ? empty($_SESSION['form']->admin_mail) : false)) {
Utils::print_header(__("Error!"));
bandeau_titre(__("Error!"));
Utils::print_header(__('Error', 'Error!'));
bandeau_titre(__('Error', 'Error!'));
echo '
<div class="alert alert-danger">
<h3>' . __('You haven\'t filled the first section of the poll creation.') . ' !</h3>
<p>' . __('Back to the homepage of') . ' <a href="' . Utils::get_server_name() . '"> ' . NOMAPPLICATION . '</a></p>
<h3>' . __('Error', 'You haven\'t filled the first section of the poll creation.') . ' !</h3>
<p>' . __('Generic', 'Back to the homepage of') . ' <a href="' . Utils::get_server_name() . '"> ' . NOMAPPLICATION . '</a></p>
</div>' . "\n";
bandeau_pied();
@ -149,7 +149,7 @@ if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || (
// Summary
$summary = '<ol>';
foreach ($_SESSION['form']->getChoices() as $choice) {
foreach ($_SESSION['form']->getChoices() as $i=>$choice) {
preg_match_all('/\[!\[(.*?)\]\((.*?)\)\]\((.*?)\)/', $choice->getName(), $md_a_img); // Markdown [![alt](src)](href)
preg_match_all('/!\[(.*?)\]\((.*?)\)/', $choice->getName(), $md_img); // Markdown ![alt](src)
@ -198,7 +198,7 @@ if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || (
<div class="col-sm-6">
<div class="input-group date">
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar text-info"></i></span>
<input type="text" class="form-control" id="enddate" data-date-format="' . __('Date', 'dd/mm/yyyy') . '" aria-describedby="dateformat" name="enddate" value="' . $end_date_str . '" size="10" maxlength="10" placeholder="' . __("dd/mm/yyyy") . '" />
<input type="text" class="form-control" id="enddate" data-date-format="' . __('Date', 'dd/mm/yyyy') . '" aria-describedby="dateformat" name="enddate" value="' . $end_date_str . '" size="10" maxlength="10" placeholder="' . __('Date', 'dd/mm/yyyy') . '" />
</div>
</div>
<span id="dateformat" class="sr-only">' . __('Date', 'dd/mm/yyyy') . '</span>

View File

@ -194,7 +194,7 @@ if (!isset($_SESSION['form']->title) || !isset($_SESSION['form']->admin_name) ||
<div class="col-sm-6">
<div class="input-group date">
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar text-info"></i></span>
<input type="text" class="form-control" id="enddate" data-date-format="'. __('Date', 'dd/mm/yyyy') .'" aria-describedby="dateformat" name="enddate" value="'.$end_date_str.'" size="10" maxlength="10" placeholder="'. __('dd/mm/yyyy') .'" />
<input type="text" class="form-control" id="enddate" data-date-format="'. __('Date', 'dd/mm/yyyy') .'" aria-describedby="dateformat" name="enddate" value="'.$end_date_str.'" size="10" maxlength="10" placeholder="'. __('Date', 'dd/mm/yyyy') .'" />
</div>
</div>
<span id="dateformat" class="sr-only">('. __('Date', 'dd/mm/yyyy') .')</span>

View File

@ -18,9 +18,6 @@
*/
use Framadate\Services\LogService;
use Framadate\Services\PollService;
use Framadate\Services\InputService;
use Framadate\Services\MailService;
use Framadate\Message;
use Framadate\Utils;
include_once __DIR__ . '/app/inc/init.php';

View File

@ -43,7 +43,7 @@ if (!empty($_POST['mail'])) {
$smarty->assign('polls', $polls);
$body = $smarty->fetch('mail/find_polls.tpl');
$mailService->send($mail, __('Homepage', 'Where are my polls'), $body);
$mailService->send($mail, __('Homepage', 'Where are my polls'), $body, 'SEND_POLLS');
$message = new Message('success', __('FindPolls', 'Polls sent'));
} else {
$message = new Message('warning', __('Error', 'No polls found'));

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.5 KiB

View File

@ -17,9 +17,7 @@
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
*/
use Framadate\Services\LogService;
use Framadate\Services\PollService;
use Framadate\Utils;
include_once __DIR__ . '/app/inc/init.php';

1
phpunit.bat Normal file
View File

@ -0,0 +1 @@
vendor\bin\phpunit.bat --bootstrap app\tests\bootstrap.php app/tests

1
phpunit.sh Normal file
View File

@ -0,0 +1 @@
vendor\bin\phpunit --bootstrap app\tests\bootstrap.php app/tests

View File

@ -64,7 +64,7 @@ function sendUpdateNotification($poll, $mailService, $name, $type) {
$_SESSION['mail_sent'] = [];
}
if ($poll->receiveNewVotes && (!isset($_SESSION['mail_sent'][$poll->id]) || $_SESSION['mail_sent'][$poll->id] !== true)) {
if ($poll->receiveNewVotes) {
$subject = '[' . NOMAPPLICATION . '] ' . __('Mail', 'Poll\'s participation') . ' : ' . $poll->title;
@ -82,9 +82,8 @@ function sendUpdateNotification($poll, $mailService, $name, $type) {
}
$message .= Utils::getUrlSondage($poll->admin_id, true) . "\n\n";
$mailService->send($poll->admin_mail, $subject, $message);
$_SESSION['mail_sent'][$poll->id] = true;
$messageTypeKey = $type . '-' . $poll->id;
$mailService->send($poll->admin_mail, $subject, $message, $messageTypeKey);
}
}
@ -152,7 +151,7 @@ if (!empty($_POST['save'])) { // Save edition of an old vote
$message = new Message('danger', __('Error', 'The name is invalid.'));
}
if (count($choices) != count($_POST['choices'])) {
$message = new Message('danger', __('There is a problem with your choices'));
$message = new Message('danger', __('Error', 'There is a problem with your choices'));
}
if ($message == null) {

View File

@ -29,8 +29,6 @@
<div class="col-md-6 col-md-offset-3 text-center">
<p class="home-choice">
<a href="{$SERVER_URL}find_polls.php" class="opacity" role="button">
<img alt="" class="img-responsive center-block" src="{'images/question.png'|resource}"/>
<br/>
<span class="btn btn-warning btn-lg">
<span class="glyphicon glyphicon-search"></span>
{__('Homepage', 'Where are my polls')}