em = self::getContainer()->get(EntityManagerInterface::class); $this->client = static::createClient(); } // public function testGetParameters(): void // { // $this->loginAs($this->user); // $this->assertResponseIsSuccessful(); // $this->get('/api/parameters/6262'); // $this->assertResponseStatusCodeSame(200); // $this->assertJsonContains([ // '@context' => '/api/contexts/Parameters', // '@id' => '/api/parameters/6262', // '@type' => 'Parameters', // 'id' => 6262, // 'organization' => '/api/organizations/616013', // 'financialDate' => '2024-01-23T00:00:00+00:00', // 'musicalDate' => '2024-01-23T00:00:00+00:00', // 'startCourseDate' => '2024-01-23T00:00:00+00:00', // 'endCourseDate' => '2024-01-23T00:00:00+00:00', // 'average' => 20, // 'editCriteriaNotationByAdminOnly'=> true, // 'smsSenderName' => 'MySender', // 'logoDonorsMove' => false, // 'subDomain' => 'subdomain', // 'website' => 'https://www.example.com', // 'otherWebsite' => 'https://www.otherwebsite.com', // 'customDomain' => 'https://www.customdomain.com', // 'desactivateOpentalentSiteWeb' => false, // 'bulletinPeriod' => 'SomePeriod', // 'bulletinWithTeacher' => false, // 'bulletinPrintAddress' => false, // 'bulletinSignatureDirector' => true, // 'bulletinDisplayLevelAcquired' => true, // 'bulletinShowEducationWithoutEvaluation' => false, // 'bulletinViewTestResults' => false, // 'bulletinShowAbsences' => false, // 'bulletinShowAverages' => true, // 'bulletinOutput' => 'SomeOutput', // 'bulletinEditWithoutEvaluation' => true, // 'bulletinReceiver' => 'STUDENTS_AND_THEIR_GUARDIANS', // 'bulletinCriteriaSort' => 'BY_CRITERIA_INSERT', // 'usernameSMS' => 'username', // 'passwordSMS' => 'password', // 'showAdherentList' => true, // 'studentsAreAdherents' => false, // 'timezone' => 'Europe/Paris', // 'educationPeriodicity' => 'ANNUAL', // 'advancedEducationNotationType' => 'BY_EDUCATION', // 'sendAttendanceEmail' => false, // 'sendAttendanceSms' => false, // 'generateAttendanceReport' => true, // 'consultPedagogicResult' => true, // 'consultTeacherListing' => true, // 'periodValidation' => true, // 'notifyAdministrationAbsence' => false, // ]); // } // public function testBadPutBulletinCriteriasort() // { // $this->loginAs($this->user); // $this->put('/api/parameters/6262', [ // 'bulletinCriteriaSort' => 'BAD_CRITERIA_SORT' // ]); // $this->assertResponseStatusCodeSame(400); // } public function testBadadvancedEducationNotationType() { $this->loginAs($this->user); $this->put('/api/parameters/6262', [ 'bulletinCriteriaSort' => 'bad_advancedEducation' ]); $this->assertResponseStatusCodeSame(400); } // public function testDeleteParameters() // { // $this->loginAs($this->user); // $this->delete('/api/parameters/6262'); // $this->assertResponseStatusCodeSame(405); // } // public function testBadTimeZone() // { // $this->loginAs($this->user); // $this->put('/api/parameters/6262', [ // 'timezone' => 'bad_timezone' // ]); // $this->assertResponseStatusCodeSame(500); // } // public function testBadPeridicity() // { // $this->loginAs($this->user); // $this->put('/api/parameters/6262', [ // 'educationPeriodicity' => 'bad_periodicity' // ]); // $this->assertResponseStatusCodeSame(500); // } public function loginAs() { // on récupère l'access qui a l'id 641003 dans l'entity manager $access = $this->em->getRepository(Access::class)->find(642459); $person = $access->getPerson(); $response = $this->post( '/login_check', ['username' => $person->getUsername(), 'password' => $person->getPassword()] ); $content = $response->getContent(); $this->securityToken = json_decode($content)->token; $this->user = $access; } /** * Send a GET request and return the response parsed content * * @param string $route * @param array $headers * @return ResponseInterface */ protected function get(string $route, array $headers = []): ResponseInterface { return $this->request( Request::METHOD_GET, $route, null, $headers ); } /** * Send a POST request and return the response parsed content * * @param string $route * @param array $data * @param array $headers * @return ResponseInterface */ protected function post(string $route, array $data, array $headers = []): ResponseInterface { return $this->request( Request::METHOD_POST, $route, $data, $headers ); } /** * Send a requests, parse the hydra response and return an object or a Collection * * @param string $method * @param string $route * @param array $data * @param array $headers * @return ResponseInterface */ protected function request(string $method, string $route, array | null $data = null, array $headers = []): ResponseInterface { if ($this->user) { $headers = array_merge( ['x-accessid' => $this->user->getId(), 'authorization' => 'BEARER ' . $this->securityToken], $headers ); } $parameters = ['headers' => $headers]; if ($data) { $parameters['json'] = $data; } return $this->client->request( $method, $route, $parameters ); } /** * Send a PUT request and return the response parsed content * * @param string $route * @param array $data * @param array $headers * @return ResponseInterface */ protected function put(string $route, array $data, array $headers = []): ResponseInterface { return $this->request( Request::METHOD_PUT, $route, $data, $headers ); } /** * Send a DELETE request and return the response parsed content * * @param string $route * @param array $headers * @return ResponseInterface */ protected function delete(string $route, array $headers = []): ResponseInterface { return $this->request( Request::METHOD_DELETE, $route, null, $headers ); } /** * Assert that the response has the expected status code and is well formated * * @param string $resourceClass * @param int $expectedStatus * @return void */ protected function validateCollectionSchema(string $resourceClass, int $expectedStatus = 200): void { $this->assertResponseStatusCodeSame($expectedStatus); if ($expectedStatus == 200) { $this->assertResponseIsSuccessful(); } // Asserts that the returned content type is JSON-LD (the default) $this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8'); // Asserts that the returned JSON is validated by the JSON Schema generated for this resource by API Platform // >>> Issue with the json typed PublicStructure::addresses properties // $this->assertMatchesResourceCollectionJsonSchema($resourceClass); } }