+
+ /**
+ * Test membersCards
+ *
+ * @return void
+ */
+ public function testMembersCards()
+ {
+ $this->getMemberOne();
+ $environment = \Slim\Http\Environment::mock(
+ [
+ 'REQUEST_METHOD' => 'POST',
+ 'REQUEST_URI' => '/members/card/' . $this->adh->id
+ ]
+ );
+ $uri = \Slim\Http\Uri::createFromEnvironment($environment);
+ $headers = \Slim\Http\Headers::createFromEnvironment($environment);
+ $cookies = [];
+ $serverParams = $environment->all();
+
+ $body = new \Slim\Http\RequestBody();
+ $request = new \Slim\Http\Request('POST', $uri, $headers, $cookies, $serverParams, $body);
+ $request = $request->withHeader('Content-Type', 'text/html');
+ $response = new \Slim\Http\Response();
+ $controller = new \Galette\Controllers\PdfController($this->container);
+
+ //test with non-logged-in user
+ $test_response = $controller->membersCards($request, $response, $this->adh->id);
+ $this->array($test_response->getHeaders())->isIdenticalTo(['Location' => ['me']]);
+ $this->integer($test_response->getStatusCode())->isIdenticalTo(302);
+ $this->boolean($test_response->isServerError())->isFalse();
+ $this->array($this->flash_data['slimFlash'])->isIdenticalTo([
+ 'error_detected' => [
+ 'You do not have permission for requested URL.'
+ ]
+ ]);
+ $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->boolean($test_response->isServerError())->isFalse();
+ $this->string($test_response->getHeader('Content-type')[0])->isIdenticalTo('application/pdf');
+ $this->string($test_response->getHeader('Content-Disposition')[0])->isIdenticalTo('attachment;filename="cards.pdf"');
+
+ //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->boolean($test_response->isServerError())->isFalse();
+ $this->array($this->flash_data['slimFlash'])->isIdenticalTo([
+ 'error_detected' => [
+ 'No member was selected, please check at least one name.'
+ ]
+ ]);
+ $this->flash_data = [];
+
+ //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();
+
+ unset($this->session->filter_members);
+ $this->integer($test_response->getStatusCode())->isIdenticalTo(200);
+ $this->boolean($test_response->isServerError())->isFalse();
+ $this->string($test_response->getHeader('Content-type')[0])->isIdenticalTo('application/pdf');
+ $this->string($test_response->getHeader('Content-Disposition')[0])->isIdenticalTo('attachment;filename="cards.pdf"');
+ }
+
+ /**
+ * Test membersLabels
+ *
+ * @return void
+ */
+ public function testMembersLabels()
+ {
+ unset($this->session->filter_members);
+ $this->getMemberOne();
+ $environment = \Slim\Http\Environment::mock(
+ [
+ 'REQUEST_METHOD' => 'POST',
+ 'REQUEST_URI' => '/members/labels'
+ ]
+ );
+ $uri = \Slim\Http\Uri::createFromEnvironment($environment);
+ $headers = \Slim\Http\Headers::createFromEnvironment($environment);
+ $cookies = [];
+ $serverParams = $environment->all();
+
+ $body = new \Slim\Http\RequestBody();
+ $request = new \Slim\Http\Request('POST', $uri, $headers, $cookies, $serverParams, $body);
+ $request = $request->withHeader('Content-Type', 'text/html');
+ $response = new \Slim\Http\Response();
+ $controller = new \Galette\Controllers\PdfController($this->container);
+
+ //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->boolean($test_response->isServerError())->isFalse();
+ $this->array($this->flash_data['slimFlash'])->isIdenticalTo([
+ 'error_detected' => [
+ 'No member was selected, please check at least one name.'
+ ]
+ ]);
+ $this->flash_data = [];
+
+ //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->membersLabels($request, $response);
+ }
+ )->isNotEmpty();
+
+ $this->integer($test_response->getStatusCode())->isIdenticalTo(200);
+ $this->boolean($test_response->isServerError())->isFalse();
+ $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"');
+ unset($this->session->filter_members);
+
+ //test logged-in as superadmin
+ $this->logSuperAdmin();
+ //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->boolean($test_response->isServerError())->isFalse();
+ $this->array($this->flash_data['slimFlash'])->isIdenticalTo([
+ 'error_detected' => [
+ 'No member was selected, please check at least one name.'
+ ]
+ ]);
+ $this->flash_data = [];
+
+ //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->boolean($test_response->isServerError())->isFalse();
+ $this->string($test_response->getHeader('Content-type')[0])->isIdenticalTo('application/pdf');
+ $this->string($test_response->getHeader('Content-Disposition')[0])->isIdenticalTo('attachment;filename="cards.pdf"');
+ }
+
+ /**
+ * Test adhesionForm
+ *
+ * @return void
+ */
+ public function testadhesionForm()
+ {
+ unset($this->session->filter_members);
+ $this->getMemberOne();
+ $environment = \Slim\Http\Environment::mock(
+ [
+ 'REQUEST_METHOD' => 'POST',
+ 'REQUEST_URI' => '/members/labels'
+ ]
+ );
+ $uri = \Slim\Http\Uri::createFromEnvironment($environment);
+ $headers = \Slim\Http\Headers::createFromEnvironment($environment);
+ $cookies = [];
+ $serverParams = $environment->all();
+
+ $body = new \Slim\Http\RequestBody();
+ $request = new \Slim\Http\Request('POST', $uri, $headers, $cookies, $serverParams, $body);
+ $request = $request->withHeader('Content-Type', 'text/html');
+ $response = new \Slim\Http\Response();
+ $controller = new \Galette\Controllers\PdfController($this->container);
+
+ //test with non-logged-in user
+ $test_response = $controller->adhesionForm($request, $response, $this->adh->id);
+ $this->array($test_response->getHeaders())->isIdenticalTo(['Location' => ['me']]);
+ $this->integer($test_response->getStatusCode())->isIdenticalTo(302);
+ $this->boolean($test_response->isServerError())->isFalse();
+ $this->array($this->flash_data['slimFlash'])->isIdenticalTo([
+ 'error_detected' => [
+ 'You do not have permission for requested URL.'
+ ]
+ ]);
+ $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->boolean($test_response->isServerError())->isFalse();
+ $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"');
+ }
+
+ /**
+ * Test attendanceSheet
+ *
+ * @return void
+ */
+ public function testAttendanceSheet()
+ {
+ $this->getMemberOne();
+ $environment = \Slim\Http\Environment::mock(
+ [
+ 'REQUEST_METHOD' => 'POST',
+ 'REQUEST_URI' => '/attendance-sheet'
+ ]
+ );
+ $uri = \Slim\Http\Uri::createFromEnvironment($environment);
+ $headers = \Slim\Http\Headers::createFromEnvironment($environment);
+ $cookies = [];
+ $serverParams = $environment->all();
+
+ $body = new \Slim\Http\RequestBody();
+
+ $request = new \Slim\Http\Request('POST', $uri, $headers, $cookies, $serverParams, $body);
+ $request = $request->withHeader('Content-Type', 'application/json');
+ $response = new \Slim\Http\Response();
+ $controller = new \Galette\Controllers\PdfController($this->container);
+
+ //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->boolean($test_response->isServerError())->isFalse();
+ $this->array($this->flash_data['slimFlash'])->isIdenticalTo([
+ 'error_detected' => [
+ 'No member was selected, please check at least one name.'
+ ]
+ ]);
+ $this->flash_data = [];
+
+ //test with selection
+ $body = new \Slim\Http\RequestBody();
+ $body->write(
+ json_encode([
+ 'selection' => [$this->adh->id]
+ ])
+ );
+
+ $request = new \Slim\Http\Request('POST', $uri, $headers, $cookies, $serverParams, $body);
+ $request = $request->withHeader('Content-Type', 'application/json');
+ $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->boolean($test_response->isServerError())->isFalse();
+ $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"');
+ }
+
+ /**
+ * Test contribution
+ *
+ * @return void
+ */
+ public function testContribution()
+ {
+ $this->getMemberOne();
+ $this->createContribution();
+ $environment = \Slim\Http\Environment::mock(
+ [
+ 'REQUEST_METHOD' => 'POST',
+ 'REQUEST_URI' => '/contribution/print/' . $this->contrib->id
+ ]
+ );
+ $uri = \Slim\Http\Uri::createFromEnvironment($environment);
+ $headers = \Slim\Http\Headers::createFromEnvironment($environment);
+ $cookies = [];
+ $serverParams = $environment->all();
+
+ $body = new \Slim\Http\RequestBody();
+ $request = new \Slim\Http\Request('POST', $uri, $headers, $cookies, $serverParams, $body);
+ $request = $request->withHeader('Content-Type', 'application/json');
+ $response = new \Slim\Http\Response();
+ $controller = new \Galette\Controllers\PdfController($this->container);
+
+ //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->boolean($test_response->isServerError())->isFalse();
+ $this->array($this->flash_data['slimFlash'])->isIdenticalTo([
+ 'error_detected' => [
+ 'Unable to load contribution #' . $this->contrib->id . '!'
+ ]
+ ]);
+ $this->flash_data = [];
+
+ //test superadmin
+ $this->logSuperAdmin();
+ $body = new \Slim\Http\RequestBody();
+ $request = new \Slim\Http\Request('POST', $uri, $headers, $cookies, $serverParams, $body);
+ $request = $request->withHeader('Content-Type', 'application/json');
+ $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->boolean($test_response->isServerError())->isFalse();
+ $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"');
+ }