diff --git a/app/Models/Foundation/Summit/Events/SummitEvent.php b/app/Models/Foundation/Summit/Events/SummitEvent.php index a60ef1ac..67772050 100644 --- a/app/Models/Foundation/Summit/Events/SummitEvent.php +++ b/app/Models/Foundation/Summit/Events/SummitEvent.php @@ -504,7 +504,7 @@ class SummitEvent extends SilverstripeBaseModel public function getTypeId() { try { - return $this->type->getId(); + return !is_null($this->type) ? $this->type->getId() : 0; } catch(\Exception $ex){ return 0; diff --git a/app/Services/Model/SpeakerService.php b/app/Services/Model/SpeakerService.php index 51e2be75..fa8bbbab 100644 --- a/app/Services/Model/SpeakerService.php +++ b/app/Services/Model/SpeakerService.php @@ -405,6 +405,9 @@ final class SpeakerService implements ISpeakerService public function merge(PresentationSpeaker $speaker_from, PresentationSpeaker $speaker_to, array $data) { return $this->tx_service->transaction(function () use ($speaker_from, $speaker_to, $data) { + + if($speaker_from->getIdentifier() == $speaker_to->getIdentifier()) + throw new ValidationException("You can not merge the same speaker!"); // bio if (!isset($data['bio'])) throw new ValidationException("bio field is required"); $speaker_id = intval($data['bio']); diff --git a/tests/OAuth2SpeakersApiTest.php b/tests/OAuth2SpeakersApiTest.php index 67b324db..a5bbda20 100644 --- a/tests/OAuth2SpeakersApiTest.php +++ b/tests/OAuth2SpeakersApiTest.php @@ -290,7 +290,7 @@ class OAuth2SpeakersApiTest extends ProtectedApiTest public function testGetSpeaker(){ $params = [ - 'speaker_id' => 1 + 'speaker_id' => 2884 ]; $headers = [ @@ -355,4 +355,45 @@ class OAuth2SpeakersApiTest extends ProtectedApiTest $this->assertTrue(!is_null($speaker)); } + public function testMergeSpeakersSame(){ + + $params = [ + 'speaker_from_id' => 1, + 'speaker_to_id' => 1 + ]; + + $headers = [ + "HTTP_Authorization" => " Bearer " . $this->access_token, + "CONTENT_TYPE" => "application/json" + ]; + + $data = [ + 'title' => 1, + 'bio' => 1, + 'first_name' => 1, + 'last_name' => 1, + 'irc' => 1, + 'twitter' => 1, + 'pic' => 1, + 'registration_request' => 1, + 'member' => 1, + ]; + + $response = $this->action( + "PUT", + "OAuth2SummitSpeakersApiController@merge", + $params, + [], + [], + [], + $headers, + json_encode($data) + ); + + $content = $response->getContent(); + $this->assertResponseStatus(412); + $speaker = json_decode($content); + $this->assertTrue(!is_null($speaker)); + } + } \ No newline at end of file