diff --git a/doc/api_methods/DeleteList.md b/doc/api_methods/DeleteList.md index f9932220f3..dea26e5061 100644 --- a/doc/api_methods/DeleteList.md +++ b/doc/api_methods/DeleteList.md @@ -4,7 +4,7 @@ ## `bool deleteList(string $list_id)` -This method provides functionality for deleting a new list. +This method provides functionality for deleting a list that is of the type 'default'. It returns a boolean value. @@ -24,3 +24,4 @@ Codes description: | 20 | List cannot be deleted because it’s used for an automatic email | | 21 | List cannot be deleted because it’s used for a form | | 22 | The list couldn’t be deleted from the database | +| 23 | Only lists of the type 'default' can be deleted | diff --git a/mailpoet/lib/API/MP/v1/Segments.php b/mailpoet/lib/API/MP/v1/Segments.php index 8c2aaafd34..7c32fecb85 100644 --- a/mailpoet/lib/API/MP/v1/Segments.php +++ b/mailpoet/lib/API/MP/v1/Segments.php @@ -84,6 +84,9 @@ class Segments { public function deleteList(string $listId): bool { $this->validateSegmentId($listId); + // delete is supported only for default segment type + $this->validateSegmentType($listId); + $activelyUsedNewslettersSubjects = $this->newsletterSegmentRepository->getSubjectsOfActivelyUsedEmailsForSegments([$listId]); if (isset($activelyUsedNewslettersSubjects[$listId])) { throw new APIException( diff --git a/mailpoet/tests/integration/API/MP/SegmentsTest.php b/mailpoet/tests/integration/API/MP/SegmentsTest.php index f551737047..7bfe779e1a 100644 --- a/mailpoet/tests/integration/API/MP/SegmentsTest.php +++ b/mailpoet/tests/integration/API/MP/SegmentsTest.php @@ -229,6 +229,18 @@ class SegmentsTest extends \MailPoetTest { } } + public function testItDoesNotAllowDeletingWPSegment(): void { + $wpSegment = $this->segmentsRepository->getWPUsersSegment(); + $this->assertInstanceOf(SegmentEntity::class, $wpSegment); + try { + $this->getApi()->deleteList((string)$wpSegment->getId()); + $this->fail('WP list cannot be updated.'); + } catch (\Exception $e) { + expect($e->getMessage())->equals('List of the type \'' . $wpSegment->getType() . '\' is not supported for this action.'); + expect($e->getCode())->equals(APIException::LIST_TYPE_IS_NOT_SUPPORTED); + } + } + public function testItDeletesList(): void { $segment = $this->createOrUpdateSegment('Test Segment'); $subscriber = (new Subscriber())