Skip to content

Commit

Permalink
Merge 0a498c4 into 6d8a56c
Browse files Browse the repository at this point in the history
  • Loading branch information
ackintosh committed Oct 20, 2013
2 parents 6d8a56c + 0a498c4 commit 00f13ea
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 8 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"require": {
"silex/silex": "~1.1",
"monolog/monolog": ">=1.0.0"
"monolog/monolog": ">=1.0.0",
"swiftmailer/swiftmailer": ">=4.1.2"
},
"require-dev": {
"phpunit/phpunit": ">=3.7",
Expand Down
51 changes: 50 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions etc/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\ParameterBag;
use Silex\Provider\MonologServiceProvider;
use Silex\Provider\SwiftmailerServiceProvider;

$app = new Silex\Application();
$app['debug'] = true;
Expand All @@ -40,6 +41,7 @@
'couchdb.couchDBURL' => CouchDBURL,
));

$app->register(new SwiftmailerServiceProvider());

$app->mount('/', new Spika\Controller\InstallerController());
$app->mount('/api/', new Spika\Controller\SendPasswordController());
Expand Down
15 changes: 9 additions & 6 deletions src/Spika/Controller/ReportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\ParameterBag;


class ReportController implements ControllerProviderInterface
{
public function connect(Application $app)
Expand All @@ -26,13 +25,17 @@ public function connect(Application $app)
// check unique controller
$controllers->get('/reportViolation.php', function (Request $request) use ($app) {
$documentId = $request->get('docment_id');
mail(AdministratorEmail, "SpilaViolationReport", $documentId);

$message = \Swift_Message::newInstance()
->setSubject("SpilaViolationReport")
->setFrom(AdministratorEmail)
->setTo(AdministratorEmail)
->setBody($documentId);
$app['mailer']->send($message);

return 'OK';
})->before($app['beforeTokenChecker']);

return $controllers;
}

}

?>
36 changes: 36 additions & 0 deletions tests/Spika/Controller/ReportControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
namespace Spika\Controller;

use Silex\Application;
use Silex\WebTestCase;
use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\ParameterBag;

class ReportControllerTest extends WebTestCase
{
public function createApplication()
{
require SPIKA_ROOT . '/etc/app.php';

$mailer = $this->getMockBuilder('\Silex\Provider\SwiftmailerServiceProvider')
->setMethods(array('send'))
->disableOriginalConstructor()
->getMock();
$mailer->expects(once())
->method('send')
->with(isInstanceOf('Swift_Message'));
$app['mailer'] = $mailer;

return $app;
}

/** @test */
public function reportViolationSendsMailAndReturnsOK()
{
$client = $this->createClient();
$crawler = $client->request('GET', '/api/reportViolation.php', array('docment_id' => 'testid'));
assertSame(true, $client->getResponse()->isOk());
assertSame('OK', $client->getResponse()->getContent());
}
}

0 comments on commit 00f13ea

Please sign in to comment.