|
| 1 | +<?php |
| 2 | +/* |
| 3 | + +--------------------------------------------------------------------+ |
| 4 | + | Copyright CiviCRM LLC. All rights reserved. | |
| 5 | + | | |
| 6 | + | This work is published under the GNU AGPLv3 license with some | |
| 7 | + | permitted exceptions and without any warranty. For full license | |
| 8 | + | and copyright information, see https://civicrm.org/licensing | |
| 9 | + +--------------------------------------------------------------------+ |
| 10 | + */ |
| 11 | + |
| 12 | +namespace api\v4\Entity; |
| 13 | + |
| 14 | +use api\v4\Api4TestBase; |
| 15 | +use Civi\Api4\MailingAB; |
| 16 | +use Civi\Test\TransactionalInterface; |
| 17 | + |
| 18 | +/** |
| 19 | + * @group headless |
| 20 | + */ |
| 21 | +class MailingABTest extends Api4TestBase implements TransactionalInterface { |
| 22 | + |
| 23 | + public function setUp(): void { |
| 24 | + parent::setUp(); |
| 25 | + \CRM_Core_BAO_ConfigSetting::enableComponent('CiviMail'); |
| 26 | + } |
| 27 | + |
| 28 | + public function testMailingABCRUD(): void { |
| 29 | + // Create |
| 30 | + $mailingAB = MailingAB::create(FALSE) |
| 31 | + ->addValue('name', 'Test Mailing AB') |
| 32 | + ->addValue('status', 'Draft') |
| 33 | + ->execute() |
| 34 | + ->first(); |
| 35 | + |
| 36 | + $this->assertNotNull($mailingAB['id']); |
| 37 | + $this->assertEquals('Test Mailing AB', $mailingAB['name']); |
| 38 | + $this->assertEquals('Draft', $mailingAB['status']); |
| 39 | + |
| 40 | + // Read |
| 41 | + $read = MailingAB::get(FALSE) |
| 42 | + ->addWhere('id', '=', $mailingAB['id']) |
| 43 | + ->execute() |
| 44 | + ->first(); |
| 45 | + |
| 46 | + $this->assertEquals('Test Mailing AB', $read['name']); |
| 47 | + |
| 48 | + // Update |
| 49 | + MailingAB::update(FALSE) |
| 50 | + ->addWhere('id', '=', $mailingAB['id']) |
| 51 | + ->addValue('name', 'Updated Mailing AB') |
| 52 | + ->execute(); |
| 53 | + |
| 54 | + $updated = MailingAB::get(FALSE) |
| 55 | + ->addWhere('id', '=', $mailingAB['id']) |
| 56 | + ->execute() |
| 57 | + ->first(); |
| 58 | + |
| 59 | + $this->assertEquals('Updated Mailing AB', $updated['name']); |
| 60 | + |
| 61 | + // Delete |
| 62 | + MailingAB::delete(FALSE) |
| 63 | + ->addWhere('id', '=', $mailingAB['id']) |
| 64 | + ->execute(); |
| 65 | + |
| 66 | + $deleted = MailingAB::get(FALSE) |
| 67 | + ->addWhere('id', '=', $mailingAB['id']) |
| 68 | + ->execute(); |
| 69 | + |
| 70 | + $this->assertCount(0, $deleted); |
| 71 | + } |
| 72 | + |
| 73 | +} |
0 commit comments