Add check on list type when deleting list
[MAILPOET-4752]
This commit is contained in:
@@ -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 |
|
||||
|
@@ -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(
|
||||
|
@@ -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())
|
||||
|
Reference in New Issue
Block a user