Files
roundcubemail/tests/Actions/Contacts/GroupAddmembersTest.php
Michael Voříšek 736795326c Fix plugins composer.json format (#9405)
* Check plugins composer.json using CI

* Add "require-dev" and "config.allow-plugins" to plugins

* fix composer.json format - rm invalid email

* fix composer.json format - fix ext require

* fix composer.json format - fix plugin name

* tmp

* Revert "tmp"

* fix ext in ext install

* disable plugin in plugin install until Roundcube is fully autoloadable

* fix composer.json format - fix non-canonical license name

* Revert "Add "require-dev" and "config.allow-plugins" to plugins"

* no composer install for plugins needed

* Revert "fix ext in ext install"

* add standard "Test" suffix to phpunit files

* rm unneeded "suffix" in phpunit config

* simplify phpunit config

* fix default "xhtml" doctype in unit testing

* fix test_format_date test to not rely on other tests

* even more phpunit config simplify

* stricter/unify phpunit params for E2E tests

* run E2E tests on maximal php version too with lowest deps

* "repositories" in bundled plugins are useless as for root package only

* add/unify missing plugin test
2024-04-05 17:55:46 +02:00

78 lines
2.9 KiB
PHP

<?php
/**
* Test class to test rcmail_action_contacts_group_addmembers
*/
class Actions_Contacts_Group_Addmembers extends ActionTestCase
{
/**
* Test error handling
*/
public function test_group_addmembers_errors()
{
$action = new rcmail_action_contacts_group_addmembers();
$output = $this->initOutput(rcmail_action::MODE_AJAX, 'contacts', 'add-members');
$this->assertInstanceOf('rcmail_action', $action);
$this->assertTrue($action->checks());
// Invalid group id
$_POST = ['_source' => '0', '_gid' => 'unknown'];
$this->runAndAssert($action, OutputJsonMock::E_EXIT);
$result = $output->getOutput();
$this->assertSame(['Content-Type: application/json; charset=UTF-8'], $output->headers);
$this->assertSame('add-members', $result['action']);
$this->assertSame('this.display_message("No group assignments changed.","notice",0);', trim($result['exec']));
// Readonly addressbook
$_POST = ['_source' => rcube_addressbook::TYPE_RECIPIENT, '_gid' => 'test'];
$this->runAndAssert($action, OutputJsonMock::E_EXIT);
$result = $output->getOutput();
$this->assertSame(['Content-Type: application/json; charset=UTF-8'], $output->headers);
$this->assertSame('add-members', $result['action']);
$this->assertSame('this.display_message("This address source is read only.","warning",0);', trim($result['exec']));
}
/**
* Test adding a group member
*/
public function test_group_addmembers_success()
{
$action = new rcmail_action_contacts_group_addmembers();
$output = $this->initOutput(rcmail_action::MODE_AJAX, 'contacts', 'add-members');
$this->assertTrue($action->checks());
self::initDB('contacts');
$db = rcmail::get_instance()->get_dbh();
$query = $db->query('SELECT * FROM `contactgroups` WHERE `user_id` = 1 AND `name` = \'test-group\'');
$result = $db->fetch_assoc($query);
$gid = $result['contactgroup_id'];
$query = $db->query('SELECT * FROM `contacts` WHERE `user_id` = 1 LIMIT 1');
$result = $db->fetch_assoc($query);
$cid = $result['contact_id'];
$_POST = ['_source' => '0', '_gid' => $gid, '_cid' => $cid];
$this->runAndAssert($action, OutputJsonMock::E_EXIT);
$result = $output->getOutput();
$this->assertSame(['Content-Type: application/json; charset=UTF-8'], $output->headers);
$this->assertSame('add-members', $result['action']);
$this->assertSame('this.display_message("Successfully added the contacts to this group.","confirmation",0);', trim($result['exec']));
$query = $db->query('SELECT * FROM `contactgroupmembers` WHERE `contactgroup_id` = ? AND `contact_id` = ?', $gid, $cid);
$result = $db->fetch_assoc($query);
$this->assertTrue(!empty($result));
}
}