shouldIgnoreMissing(); $fileUploaderMock->shouldReceive('build')->andReturn(new \models\main\File()); $app->instance(\App\Http\Utils\IFileUploader::class, $fileUploaderMock); return $app; } protected function setUp():void { parent::setUp(); self::insertTestData(); } protected function tearDown():void { self::clearTestData(); parent::tearDown(); } public function testAddBadgeFeatureType(){ return $this->_testAddBadgeFeatureType(); } /** * @param int $summit_id * @return mixed */ protected function _testAddBadgeFeatureType(){ $params = [ 'id' => self::$summit->getId(), ]; $name = str_random(16).'_feature_type'; $template = << image/svg+xml HTML; $data = [ 'name' => $name, 'description' => "this is a description", 'template_content' => $template, 'tag_name' => "vegan", ]; $headers = [ "HTTP_Authorization" => " Bearer " . $this->access_token, "CONTENT_TYPE" => "application/json" ]; $response = $this->action( "POST", "OAuth2SummitBadgeFeatureTypeApiController@add", $params, [], [], [], $headers, json_encode($data) ); $content = $response->getContent(); $this->assertResponseStatus(201); $feature = json_decode($content); $this->assertTrue(!is_null($feature)); $this->assertTrue($feature->name == $name); return $feature; } public function testUpdateBadgeFeatureType(){ $feature_old = $this->_testAddBadgeFeatureType(); $params = [ 'id' => self::$summit->getId(), "feature_id" => $feature_old->id ]; $data = [ 'description' => "this is a description update", 'is_default' => false, ]; $headers = [ "HTTP_Authorization" => " Bearer " . $this->access_token, "CONTENT_TYPE" => "application/json" ]; $response = $this->action( "PUT", "OAuth2SummitBadgeFeatureTypeApiController@update", $params, [], [], [], $headers, json_encode($data) ); $content = $response->getContent(); $this->assertResponseStatus(201); $feature = json_decode($content); $this->assertTrue(!is_null($feature)); $this->assertTrue($feature->name == $feature_old->name); return $feature; } public function testGetAllBySummit(){ $this->_testAddBadgeFeatureType(); $this->_testAddBadgeFeatureType(); $this->_testAddBadgeFeatureType(); $params = [ 'id' => self::$summit->getId(), ]; $headers = [ "HTTP_Authorization" => " Bearer " . $this->access_token, "CONTENT_TYPE" => "application/json" ]; $response = $this->action( "GET", "OAuth2SummitBadgeFeatureTypeApiController@getAllBySummit", $params, [], [], [], $headers ); $content = $response->getContent(); $this->assertResponseStatus(200); $data = json_decode($content); $this->assertTrue(!is_null($data)); $this->assertTrue($data->total == 3); return $data; } /** * @param int $summit_id */ public function testDeleteFeature(){ $feature_old = $this->_testAddBadgeFeatureType(); $params = [ 'id' => self::$summit->getId(), "feature_id" => $feature_old->id ]; $headers = [ "HTTP_Authorization" => " Bearer " . $this->access_token, "CONTENT_TYPE" => "application/json" ]; $response = $this->action( "DELETE", "OAuth2SummitBadgeFeatureTypeApiController@delete", $params, [], [], [], $headers ); $content = $response->getContent(); $this->assertResponseStatus(204); } public function testAddFeatureImage(){ $feature_old = $this->_testAddBadgeFeatureType(); $params = [ 'id' => self::$summit->getId(), "feature_id" => $feature_old->id ]; $headers = [ "HTTP_Authorization" => " Bearer " . $this->access_token, "CONTENT_TYPE" => "application/json" ]; $response = $this->action( "POST", "OAuth2SummitBadgeFeatureTypeApiController@addFeatureImage", $params, [], [], [ 'file' => UploadedFile::fake()->image('feat.svg'), ], $headers ); $content = $response->getContent(); $this->assertResponseStatus(201); $file = json_decode($content); $this->assertTrue(!is_null($file)); } public function testDeleteFeatureImage(){ $feature_old = $this->_testAddBadgeFeatureType(); $params = [ 'id' => self::$summit->getId(), "feature_id" => $feature_old->id ]; $headers = [ "HTTP_Authorization" => " Bearer " . $this->access_token, "CONTENT_TYPE" => "application/json" ]; $response = $this->action( "POST", "OAuth2SummitBadgeFeatureTypeApiController@addFeatureImage", $params, [], [], [ 'file' => UploadedFile::fake()->image('feat.svg'), ], $headers ); $content = $response->getContent(); $this->assertResponseStatus(201); $file = json_decode($content); $this->assertTrue(!is_null($file)); $response = $this->action( "DELETE", "OAuth2SummitBadgeFeatureTypeApiController@deleteFeatureImage", $params, [], [], [], $headers ); $content = $response->getContent(); $this->assertResponseStatus(204); } }