namespace Galette\Controllers\test\units;
-use atoum;
+use PHPUnit\Framework\TestCase;
use Galette\GaletteTestCase;
use Slim\Psr7\Headers;
use Slim\Psr7\Request;
/**
* Set up tests
*
- * @param string $method Calling method
- *
* @return void
*/
- public function beforeTestMethod($method)
+ public function setUp(): void
{
- parent::beforeTestMethod($method);
+ parent::setUp();
$this->initModels();
$this->initStatus();
*
* @return void
*/
- public function tearDown()
+ public function tearDown(): void
{
$this->zdb = new \Galette\Core\Db();
$this->cleanHistory();
}
+ /**
+ * Cleanup after class
+ *
+ * @return void
+ */
+ public static function tearDownAfterClass(): void
+ {
+ $self = new self(__METHOD__);
+ $self->tearDown();
+ }
+
/**
* Test store models
*
public function testStoreModels()
{
$model = new \Galette\Entity\PdfInvoice($this->zdb, $this->preferences);
- $this->string($model->title)->isIdenticalTo('_T("Invoice") {CONTRIBUTION_YEAR}-{CONTRIBUTION_ID}');
+ $this->assertSame('_T("Invoice") {CONTRIBUTION_YEAR}-{CONTRIBUTION_ID}', $model->title);
$ufactory = new \Slim\Psr7\Factory\UriFactory();
$sfactory = new \Slim\Psr7\Factory\StreamFactory();
$controller = new \Galette\Controllers\PdfController($this->container);
$test_response = $controller->storeModels($request, $response);
- $this->array($this->flash_data['slimFlash'])->isIdenticalTo([
- 'success_detected' => [
- 'Model has been successfully stored!'
- ]
- ]);
+ $this->assertSame(
+ [
+ 'success_detected' => [
+ 'Model has been successfully stored!'
+ ]
+ ],
+ $this->flash_data['slimFlash']
+ );
$model = new \Galette\Entity\PdfInvoice($this->zdb, $this->preferences);
- $this->string($model->title)->isIdenticalTo('DaTitle');
+ $this->assertSame('DaTitle', $model->title);
}
/**
//test with non-logged-in user
$test_response = $controller->membersCards($request, $response, $this->adh->id);
- $this->array($test_response->getHeaders())->isIdenticalTo(['Location' => ['/member/me']]);
- $this->integer($test_response->getStatusCode())->isIdenticalTo(200);
- $this->array($this->flash_data['slimFlash'])->isIdenticalTo([
- 'error_detected' => [
- 'You do not have permission for requested URL.'
- ]
- ]);
+ $this->assertSame(['Location' => ['/member/me']], $test_response->getHeaders());
+ $this->assertSame(200, $test_response->getStatusCode());
+ $this->assertSame(
+ [
+ 'error_detected' => [
+ 'You do not have permission for requested URL.'
+ ]
+ ],
+ $this->flash_data['slimFlash']
+ );
$this->flash_data = [];
//test logged-in as superadmin
$this->logSuperAdmin();
$test_response = null;
- $this
- ->output(
- function () use ($controller, $request, $response, &$test_response) {
- $test_response = $controller->membersCards($request, $response, $this->adh->id);
- }
- )->isNotEmpty();
- $this->integer($test_response->getStatusCode())->isIdenticalTo(200);
- $this->string($test_response->getHeader('Content-type')[0])->isIdenticalTo('application/pdf');
- $this->string($test_response->getHeader('Content-Disposition')[0])->isIdenticalTo('attachment;filename="cards.pdf"');
+ $this->expectOutputRegex('/^%PDF-\d\.\d\.');
+ $test_response = $controller->membersCards($request, $response, $this->adh->id);
+
+ $this->assertSame(200, $test_response->getStatusCode());
+ $this->assertSame('application/pdf', $test_response->getHeader('Content-type')[0]);
+ $this->assertSame('attachment;filename="cards.pdf"', $test_response->getHeader('Content-Disposition')[0]);
//test no selection
- $test_response = null;
$test_response = $controller->membersCards($request, $response);
- $this->array($test_response->getHeaders())->isIdenticalTo(['Location' => ['/members']]);
- $this->integer($test_response->getStatusCode())->isIdenticalTo(301);
- $this->array($this->flash_data['slimFlash'])->isIdenticalTo([
- 'error_detected' => [
- 'No member was selected, please check at least one name.'
- ]
- ]);
+ $this->assertSame(['Location' => ['/members']], $test_response->getHeaders());
+ $this->assertSame(301, $test_response->getStatusCode());
+ $this->assertSame(
+ [
+ 'error_detected' => [
+ 'No member was selected, please check at least one name.'
+ ]
+ ],
+ $this->flash_data['slimFlash']
+ );
$this->flash_data = [];
+ }
- //test again from filters
- $test_response = null;
+ /**
+ * Test filtered membersCards
+ *
+ * @return void
+ */
+ public function testFilteredMembersCards()
+ {
+ $this->getMemberOne();
+
+ $ufactory = new \Slim\Psr7\Factory\UriFactory();
+ $sfactory = new \Slim\Psr7\Factory\StreamFactory();
+
+ $request = new Request(
+ 'POST',
+ $ufactory->createUri('/members/card/' . $this->adh->id),
+ new Headers(['Content-Type' => ['text/html']]),
+ [],
+ [],
+ $sfactory->createStream()
+ );
+
+ $response = new \Slim\Psr7\Response();
+ $controller = new \Galette\Controllers\PdfController($this->container);
+
+ //test logged-in as superadmin
+ $this->logSuperAdmin();
+
+ //test with filters
$filters = new \Galette\Filters\MembersList();
$filters->selected = [$this->adh->id];
$this->session->filter_members = $filters;
- $this
- ->output(
- function () use ($controller, $request, $response, &$test_response) {
- $test_response = $controller->membersCards($request, $response);
- }
- )->isNotEmpty();
+
+ $this->expectOutputRegex('/^%PDF-\d.\d.');
+ $test_response = $controller->membersCards($request, $response);
unset($this->session->filter_members);
- $this->integer($test_response->getStatusCode())->isIdenticalTo(200);
- $this->string($test_response->getHeader('Content-type')[0])->isIdenticalTo('application/pdf');
- $this->string($test_response->getHeader('Content-Disposition')[0])->isIdenticalTo('attachment;filename="cards.pdf"');
+ $this->assertSame(200, $test_response->getStatusCode());
+ $this->assertSame('application/pdf', $test_response->getHeader('Content-type')[0]);
+ $this->assertSame('attachment;filename="cards.pdf"', $test_response->getHeader('Content-Disposition')[0]);
}
/**
//test with non-logged-in user
$test_response = $controller->membersLabels($request, $response, $this->adh->id);
- $this->array($test_response->getHeaders())->isIdenticalTo(['Location' => ['/members']]);
- $this->integer($test_response->getStatusCode())->isIdenticalTo(301);
- $this->array($this->flash_data['slimFlash'])->isIdenticalTo([
- 'error_detected' => [
- 'No member was selected, please check at least one name.'
- ]
- ]);
+ $this->assertSame(['Location' => ['/members']], $test_response->getHeaders());
+ $this->assertSame(301, $test_response->getStatusCode());
+ $this->assertSame(
+ [
+ 'error_detected' => [
+ 'No member was selected, please check at least one name.'
+ ]
+ ],
+ $this->flash_data['slimFlash']
+ );
$this->flash_data = [];
//test again from filters
$filters = new \Galette\Filters\MembersList();
$filters->selected = [$this->adh->id];
$this->session->filter_members = $filters;
- $this
- ->output(
- function () use ($controller, $request, $response, &$test_response) {
- $test_response = $controller->membersLabels($request, $response);
- }
- )->isNotEmpty();
-
- $this->integer($test_response->getStatusCode())->isIdenticalTo(200);
- $this->string($test_response->getHeader('Content-type')[0])->isIdenticalTo('application/pdf');
- $this->string($test_response->getHeader('Content-Disposition')[0])->isIdenticalTo('attachment;filename="labels_print_filename.pdf"');
+
+ $this->expectOutputRegex('/^%PDF-\d\.\d');
+ $test_response = $controller->membersLabels($request, $response);
+
+ $this->assertSame(200, $test_response->getStatusCode());
+ $this->assertSame('application/pdf', $test_response->getHeader('Content-type')[0]);
+ $this->assertSame('attachment;filename="labels_print_filename.pdf"', $test_response->getHeader('Content-Disposition')[0]);
unset($this->session->filter_members);
//test logged-in as superadmin
//test no selection
$test_response = null;
$test_response = $controller->membersCards($request, $response);
- $this->array($test_response->getHeaders())->isIdenticalTo(['Location' => ['/members']]);
- $this->integer($test_response->getStatusCode())->isIdenticalTo(301);
- $this->array($this->flash_data['slimFlash'])->isIdenticalTo([
- 'error_detected' => [
- 'No member was selected, please check at least one name.'
- ]
- ]);
+ $this->assertSame(['Location' => ['/members']], $test_response->getHeaders());
+ $this->assertSame(301, $test_response->getStatusCode());
+ $this->assertSame(
+ [
+ 'error_detected' => [
+ 'No member was selected, please check at least one name.'
+ ]
+ ],
+ $this->flash_data['slimFlash']
+ );
$this->flash_data = [];
+ }
+
+ /**
+ * Test filtered membersLabels
+ *
+ * @return void
+ */
+ public function testFilteredMembersLabels()
+ {
+ unset($this->session->filter_members);
+ $this->getMemberOne();
+
+ $ufactory = new \Slim\Psr7\Factory\UriFactory();
+ $sfactory = new \Slim\Psr7\Factory\StreamFactory();
+
+ $request = new Request(
+ 'POST',
+ $ufactory->createUri('/members/labels'),
+ new Headers(['Content-Type' => ['text/html']]),
+ [],
+ [],
+ $sfactory->createStream()
+ );
+
+ $response = new \Slim\Psr7\Response();
+ $controller = new \Galette\Controllers\PdfController($this->container);
+
+ //test logged-in as superadmin
+ $this->logSuperAdmin();
//test again from filters
- $test_response = null;
$filters = new \Galette\Filters\MembersList();
$filters->selected = [$this->adh->id];
$this->session->filter_members = $filters;
- $this
- ->output(
- function () use ($controller, $request, $response, &$test_response) {
- $test_response = $controller->membersCards($request, $response);
- }
- )->isNotEmpty();
-
- $this->integer($test_response->getStatusCode())->isIdenticalTo(200);
- $this->string($test_response->getHeader('Content-type')[0])->isIdenticalTo('application/pdf');
- $this->string($test_response->getHeader('Content-Disposition')[0])->isIdenticalTo('attachment;filename="cards.pdf"');
+
+ $this->expectOutputRegex('/^%PDF-\d\.\d');
+ $test_response = $controller->membersCards($request, $response);
+
+ $this->assertSame(200, $test_response->getStatusCode());
+ $this->assertSame('application/pdf', $test_response->getHeader('Content-type')[0]);
+ $this->assertSame('attachment;filename="cards.pdf"', $test_response->getHeader('Content-Disposition')[0]);
}
/**
//test with non-logged-in user
$test_response = $controller->adhesionForm($request, $response, $this->adh->id);
- $this->array($test_response->getHeaders())->isIdenticalTo(['Location' => ['/member/me']]);
- $this->integer($test_response->getStatusCode())->isIdenticalTo(200);
- $this->array($this->flash_data['slimFlash'])->isIdenticalTo([
- 'error_detected' => [
- 'You do not have permission for requested URL.'
- ]
- ]);
+ $this->assertSame(['Location' => ['/member/me']], $test_response->getHeaders());
+ $this->assertSame(200, $test_response->getStatusCode());
+ $this->assertSame(
+ [
+ 'error_detected' => [
+ 'You do not have permission for requested URL.'
+ ]
+ ],
+ $this->flash_data['slimFlash']
+ );
$this->flash_data = [];
//test logged-in as superadmin
$this->logSuperAdmin();
$test_response = null;
- $this
- ->output(
- function () use ($controller, $request, $response, &$test_response) {
- $test_response = $controller->adhesionForm($request, $response, $this->adh->id);
- }
- )->isNotEmpty();
-
- $this->integer($test_response->getStatusCode())->isIdenticalTo(200);
- $this->string($test_response->getHeader('Content-type')[0])->isIdenticalTo('application/pdf');
- $this->string($test_response->getHeader('Content-Disposition')[0])->isIdenticalTo('attachment;filename="adherent_form.' . $this->adh->id . '.pdf"');
+
+ $this->expectOutputRegex('/^%PDF-\d\.\d/');
+ $test_response = $controller->adhesionForm($request, $response, $this->adh->id);
+
+ $this->assertSame(200, $test_response->getStatusCode());
+ $this->assertSame('application/pdf', $test_response->getHeader('Content-type')[0]);
+ $this->assertSame('attachment;filename="adherent_form.' . $this->adh->id . '.pdf"', $test_response->getHeader('Content-Disposition')[0]);
}
/**
//test no selection
$test_response = null;
$test_response = $controller->membersCards($request, $response);
- $this->array($test_response->getHeaders())->isIdenticalTo(['Location' => ['/members']]);
- $this->integer($test_response->getStatusCode())->isIdenticalTo(301);
- $this->array($this->flash_data['slimFlash'])->isIdenticalTo([
- 'error_detected' => [
- 'No member was selected, please check at least one name.'
- ]
- ]);
+ $this->assertSame(['Location' => ['/members']], $test_response->getHeaders());
+ $this->assertSame(301, $test_response->getStatusCode());
+ $this->assertSame(
+ [
+ 'error_detected' => [
+ 'No member was selected, please check at least one name.'
+ ]
+ ],
+ $this->flash_data['slimFlash']
+ );
$this->flash_data = [];
//test with selection
);
$test_response = null;
- $this
- ->output(
- function () use ($controller, $request, $response, &$test_response) {
- $test_response = $controller->attendanceSheet($request, $response);
- }
- )->isNotEmpty();
-
- $this->integer($test_response->getStatusCode())->isIdenticalTo(200);
- $this->string($test_response->getHeader('Content-type')[0])->isIdenticalTo('application/pdf');
- $this->string($test_response->getHeader('Content-Disposition')[0])->isIdenticalTo('attachment;filename="attendance_sheet.pdf"');
+
+ $this->expectOutputRegex('/^%PDF-\d\.\d/');
+ $test_response = $controller->attendanceSheet($request, $response);
+
+ $this->assertSame(200, $test_response->getStatusCode());
+ $this->assertSame('application/pdf', $test_response->getHeader('Content-type')[0]);
+ $this->assertSame('attachment;filename="attendance_sheet.pdf"', $test_response->getHeader('Content-Disposition')[0]);
}
/**
//test not logged
$test_response = $controller->contribution($request, $response, $this->contrib->id);
- $this->array($test_response->getHeaders())->isIdenticalTo(['Location' => ['/contributions']]);
- $this->integer($test_response->getStatusCode())->isIdenticalTo(301);
- $this->array($this->flash_data['slimFlash'])->isIdenticalTo([
- 'error_detected' => [
- 'Unable to load contribution #' . $this->contrib->id . '!'
- ]
- ]);
+ $this->assertSame(['Location' => ['/contributions']], $test_response->getHeaders());
+ $this->assertSame(301, $test_response->getStatusCode());
+ $this->assertSame(
+ [
+ 'error_detected' => [
+ 'Unable to load contribution #' . $this->contrib->id . '!'
+ ]
+ ],
+ $this->flash_data['slimFlash']
+ );
$this->flash_data = [];
//test superadmin
$this->logSuperAdmin();
$test_response = null;
- $this
- ->output(
- function () use ($controller, $request, $response, &$test_response) {
- $test_response = $controller->contribution($request, $response, $this->contrib->id);
- }
- )->isNotEmpty();
-
- $this->integer($test_response->getStatusCode())->isIdenticalTo(200);
- $this->string($test_response->getHeader('Content-type')[0])->isIdenticalTo('application/pdf');
- $this->string($test_response->getHeader('Content-Disposition')[0])->isIdenticalTo('attachment;filename="contribution_' . $this->contrib->id . '_invoice.pdf"');
+
+ $this->expectOutputRegex('/^%PDF-\d\.\d\/');
+ $test_response = $controller->contribution($request, $response, $this->contrib->id);
+
+ $this->assertSame(200, $test_response->getStatusCode());
+ $this->assertSame('application/pdf', $test_response->getHeader('Content-type')[0]);
+ $this->assertSame('attachment;filename="contribution_' . $this->contrib->id . '_invoice.pdf"', $test_response->getHeader('Content-Disposition')[0]);
}
}