Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Commit

Permalink
Merge branch '2018.11-develop'
Browse files Browse the repository at this point in the history
Change-Id: I8a885732e2b239b6e01eb3ff9ed90f371db13628
  • Loading branch information
pschuele committed Jul 19, 2018
2 parents 5f3f5b3 + 5208eeb commit f364f62
Show file tree
Hide file tree
Showing 122 changed files with 2,489 additions and 1,577 deletions.
15 changes: 15 additions & 0 deletions tests/tine20/ActiveSync/TestCase.php
Expand Up @@ -48,6 +48,7 @@ abstract class ActiveSync_TestCase extends TestCase
const TYPE_ANDROID_5 = 'android5';
const TYPE_ANDROID_6 = 'android6';
const TYPE_ANDROID_7 = 'android7';
const TYPE_IOS_11 = 'iOS11';

/**
* (non-PHPdoc)
Expand Down Expand Up @@ -359,6 +360,20 @@ public static function getTestDevice($_type = null)
'remotewipe' => 0
));
break;

case self::TYPE_IOS_11:
$device = new Syncroton_Model_Device(array(
'deviceid' => 'iphone9c1',
'devicetype' => Syncroton_Model_Device::TYPE_IPHONE,
'policykey' => null,
'policyId' => null,
'ownerId' => Tinebase_Core::getUser()->getId(),
'useragent' => 'Apple-iPhone9C1/1501.530400009',
'acsversion' => '12.1',
'remotewipe' => 0
));
break;


case Syncroton_Model_Device::TYPE_IPHONE:
default:
Expand Down
5 changes: 5 additions & 0 deletions tests/tine20/Admin/JsonTest.php
Expand Up @@ -1446,6 +1446,11 @@ public function testResourceContainerGet()
'description' => 'Our main meeting room',
'email' => 'room@example.com',
'is_location' => TRUE,
'grants' => [[
'account_id' => Tinebase_Core::getUser()->getId(),
'account_type' => Tinebase_Acl_Rights::ACCOUNT_TYPE_USER,
Calendar_Model_ResourceGrants::RESOURCE_ADMIN => true,
]]
]));

$container = $this->_json->getContainer($resource->container_id);
Expand Down
13 changes: 12 additions & 1 deletion tests/tine20/Calendar/Controller/EventNotificationsTests.php
Expand Up @@ -1391,7 +1391,7 @@ public function testResourceNotificationForGrantedUsers($userIsAttendee = true,
if ($suppress_notification) {
$this->assertEquals(1, count($messages), 'one mail should be send to current user (attender)');
} else {
$this->assertEquals(3, count($messages), 'four mails should be send to current user (resource + attender + everybody who is allowed to edit this resource)');
$this->assertEquals(4, count($messages), 'four mails should be send to current user (resource + attender + everybody who is allowed to edit this resource)');
$this->assertEquals(count($event->attendee), count($persistentEvent->attendee));
$this->assertContains('Resource "' . $persistentResource->name . '" was booked', print_r($messages, true));
$this->assertContains('Meeting Room (Required, No response)', print_r($messages, true));
Expand Down Expand Up @@ -1457,6 +1457,17 @@ public function testResourceNotificationMuteForEditors()
$this->testResourceNotification(/* $suppress_notification = */ true);
$this->testResourceNotificationForGrantedUsers(/* $userIsAttendee = */ false, /* $suppress_notification = */ true);
}

/**
* testResourceNotificationMute without editors config
*
*/
public function testResourceNotificationMute()
{
Calendar_Config::getInstance()->set(Calendar_Config::RESOURCE_MAIL_FOR_EDITORS, false);
$this->testResourceNotification(/* $suppress_notification = */ true);
$this->testResourceNotificationForGrantedUsers(/* $userIsAttendee = */ false, /* $suppress_notification = */ true);
}

/**
* testGroupInvitation
Expand Down
40 changes: 40 additions & 0 deletions tests/tine20/Calendar/Controller/RecurTest.php
Expand Up @@ -560,6 +560,46 @@ public function testCreateRecurExceptionAllFollowingGeneral()
)), 'dtstart of new series');
}

public function testCreateRecurExceptionAllFollowingRruleChange()
{
// Wednesday
$from = new Tinebase_DateTime('2015-07-01 00:00:00');
$until = new Tinebase_DateTime('2015-09-29 23:59:59');

$event = new Calendar_Model_Event(array(
'summary' => 'Mettwoch',
'dtstart' => '2015-02-10 12:00:00',
'dtend' => '2015-02-10 13:00:00',
'description' => '2 Pfund Mett. 15 Brotchen. 1ne Zwiebel',
'rrule' => 'FREQ=WEEKLY;INTERVAL=1;WKST=MO;BYDAY=TU,FR',
'container_id' => method_exists($this, '_getTestCalendar') ?
$this->_getTestCalendar()->getId() :
$this->_testCalendar->getId(),
'attendee' => $this->_getAttendee(),
));

$persistentEvent = $this->_controller->create($event);

$exceptions = new Tinebase_Record_RecordSet('Calendar_Model_Event');
// Friday, 03. 07. 2015 - Tuesday, 07. 07. 2015
$recurSet = Calendar_Model_Rrule::computeRecurrenceSet($persistentEvent, $exceptions, $from, $until);
static::assertEquals('2015-07-03 11:00:00', $recurSet->getFirstRecord()->dtstart);

$recurSet[1]->dtstart->addDay(1);
$recurSet[1]->dtend->addDay(1);
$newBaseEvent = $this->_controller->createRecurException($recurSet[1], FALSE, TRUE);
static::assertEquals('2015-07-08 11:00:00', $newBaseEvent->dtstart);
static::assertEquals('WE,FR', $newBaseEvent->rrule->byday);

$oldBaseEvent = $this->_controller->get($persistentEvent->getId());
static::assertEquals('2015-07-07 10:59:59', $oldBaseEvent->rrule->until);
$exceptions = new Tinebase_Record_RecordSet('Calendar_Model_Event');
$oldRecurSet = Calendar_Model_Rrule::computeRecurrenceSet($oldBaseEvent, $exceptions, $from, $until);

$this->assertCount(1, $oldRecurSet, 'one event should be left in given period ');
$this->assertEquals('2015-07-03 11:00:00', $oldRecurSet[0]->dtstart);
}

public function testCreateRecurExceptionAllFollowingAllDay()
{
$from = new Tinebase_DateTime('2015-07-01 00:00:00');
Expand Down
179 changes: 55 additions & 124 deletions tests/tine20/Calendar/Controller/ResourceTest.php
Expand Up @@ -15,9 +15,9 @@
*/
class Calendar_Controller_ResourceTest extends Calendar_TestCase
{
public function testCreateResource()
public function testCreateResource($grants = null)
{
$resource = $this->_getResource();
$resource = $this->_getResource($grants);

$persistentResource = Calendar_Controller_Resource::getInstance()->create($resource);

Expand Down Expand Up @@ -85,23 +85,29 @@ public function testDeleteContainer()
Calendar_Controller_Resource::getInstance()->get((string)$createResource->container_id);
}

public function testManageResourceRight()
public function testManageResourceRightCreate()
{
$role = Tinebase_Acl_Roles::getInstance()->getRoleByName('admin role');
$roleRights = Tinebase_Acl_Roles::getInstance()->getRoleRights($role->getId());
$roleRights = array_filter($roleRights, function($right) {
return $right['right'] != Calendar_Acl_Rights::MANAGE_RESOURCES && $right['right'] != Calendar_Acl_Rights::ADMIN;
});
Tinebase_Acl_Roles::getInstance()->setRoleRights($role->getId(), $roleRights);
Tinebase_Acl_Roles::getInstance()->resetClassCache();

$this->setExpectedException('Tinebase_Exception_AccessDenied', 'You don\'t have the right to manage resources');
$this->testRenameContainer();
$this->_removeRoleRight('Calendar', Calendar_Acl_Rights::MANAGE_RESOURCES);

$this->setExpectedException('Tinebase_Exception_AccessDenied', 'No Permission.');
$this->testCreateResource();
}

public function testResourceConflict()
public function testManageResourceRightDelete()
{
$resource = $this->testCreateResource();
$this->_removeRoleRight('Calendar', Calendar_Acl_Rights::MANAGE_RESOURCES);

$this->setExpectedException('Tinebase_Exception_AccessDenied', 'No Permission.');
Calendar_Controller_Resource::getInstance()->delete($resource);
}

public function testResourceConflict()
{
$resource = $this->testCreateResource([
Calendar_Model_ResourceGrants::RESOURCE_ADMIN => true,
Calendar_Model_ResourceGrants::EVENTS_READ => true,
]);

$event = $this->_getEvent();
$event->attendee = new Tinebase_Record_RecordSet('Calendar_Model_Attender', array(
Expand Down Expand Up @@ -160,7 +166,32 @@ public function testDeleteResource($resource = null)
$this->setExpectedException('Tinebase_Exception_NotFound');
Tinebase_Container::getInstance()->getContainerById($resource->container_id);
}


/**
* testDeleteResourceAttendee
*
* @see https://github.com/tine20/tine20/issues/48
*/
public function testDeleteResourceAttendee()
{
$resource = $this->testCreateResource();

// add resource to an event
$event = $this->_getEvent();
$event->attendee->addRecord(new Calendar_Model_Attender([
'user_type' => Calendar_Model_Attender::USERTYPE_RESOURCE,
'user_id' => $resource->id
]));
$newEvent = Calendar_Controller_Event::getInstance()->create($event);

Calendar_Controller_Resource::getInstance()->delete($resource->getId());

// check if resource attendee is removed
$updatedEvent = Calendar_Controller_Event::getInstance()->get($newEvent->getId());
self::assertEquals(2, count($updatedEvent->attendee), 'resource attender should be removed! '
. print_r($updatedEvent->toArray(), true));
}

/**
* testDeleteResourceWithmissingContainer
*
Expand All @@ -182,18 +213,17 @@ public function testDeleteResourceMissingContainer()
protected function _prepareTestResourceAcl($_removeRoleRight = true)
{
// create resource with acl for sclever
$resource = $this->_getResource();
$resource = $this->_getResource([Calendar_Model_ResourceGrants::RESOURCE_ADMIN => true]);
$sclever = $this->_getPersona('sclever');
$grants = array($this->_getAllCalendarGrants($sclever));
$grants[0] = array_merge($grants[0], array_fill_keys(Calendar_Model_ResourceGrants::getAllGrants(), true));
$grants = $resource->grants;
$grants[1] = $this->_getAllCalendarGrants($sclever);
$grants[1] = array_merge($grants[1], array_fill_keys(Calendar_Model_ResourceGrants::getAllGrants(), true));
$resource->grants = $grants;
$persistentResource = Calendar_Controller_Resource::getInstance()->create($resource);

if (true === $_removeRoleRight) {
// remove manage_resource right
$this->_removeRoleRight('Calendar', Calendar_Acl_Rights::MANAGE_RESOURCES);
// reset class cache
Calendar_Controller_Resource::getInstance()->doContainerACLChecks(true);
}

return $persistentResource;
Expand All @@ -206,6 +236,7 @@ public function testResourceAclUpdateName()
{
$persistentResource = $this->_prepareTestResourceAcl();

Tinebase_Core::set(Tinebase_Core::USER, $this->_personas['pwulf']);
// we will get a AccessDenied when we try to update the containers name
$persistentResource->name = 'try to overwrite name';
try {
Expand All @@ -217,117 +248,14 @@ public function testResourceAclUpdateName()
// attention we created a roll back! so _prepareTestResourceAcl data is gone now! that is why the test ends here
}

/**
* @see 0013348: improve resource permission handling
*/
public function testResourceAclWithManageResources()
{
$persistentResource = $this->_prepareTestResourceAcl(false);

// test WebDav
$calendarShared = \Sabre\CalDAV\Plugin::CALENDAR_ROOT . '/shared';
if (isset($_SERVER['REQUEST_URI'])) {
$oldRequestUri = $_SERVER['REQUEST_URI'];
} else {
$oldRequestUri = null;
}
$_SERVER['REQUEST_URI'] = '/tine20/' . $calendarShared;
$collection = new Calendar_Frontend_WebDAV($calendarShared);
$children = $collection->getChildren();

$this->assertTrue(is_array($children));
$this->assertTrue(count($children) > 0);
$this->assertTrue($children[0] instanceof Calendar_Frontend_WebDAV_Container);

$found = false;
/** @var Calendar_Frontend_WebDAV $child */
foreach ($children as $child) {
if ($persistentResource->name === $child->getName()) {
$found = true;
}
}
static::assertTrue($found, 'did not find resource in WebDav');

if (null === $oldRequestUri) {
unset($_SERVER['REQUEST_URI']);
} else {
$_SERVER['REQUEST_URI'] = $oldRequestUri;
}

// test calendar json search
$filter = array(array(
'field' => 'type',
'operator' => 'equals',
'value' => array(Calendar_Model_Attender::USERTYPE_RESOURCE)
), array(
'field' => 'query',
'operator' => 'contains',
'value' => 'Meeting'
));
$json = new Calendar_Frontend_Json();
$result = $json->searchAttenders($filter);
self::assertEquals(1, $result['resource']['totalcount'], 'resource not found');

// test tinebase container search
$filter = array(array(
'field' => 'type',
'operator' => 'equals',
'value' => Tinebase_Model_Container::TYPE_SHARED,
), array(
'field' => 'name',
'operator' => 'contains',
'value' => 'Meeting'
), array(
'field' => 'application_id',
'operator' => 'equals',
'value' => Tinebase_Application::getInstance()->getApplicationByName('Calendar')->getId()
));
$json = new Tinebase_Frontend_Json_Container();

$containers = $json->searchContainers($filter, null);

$this->assertTrue(is_array($containers) && isset($containers['results']) && is_array($containers['results']));
$this->assertTrue(count($containers['results']) > 0, 'did not find resource in shared containers!');

$found = false;
foreach ($containers['results'] as $container) {
if ($persistentResource->name === $container['name']) {
$found = true;
}
}
static::assertTrue($found, 'did not find resource in shared containers!');

// test tinebase get container
$containers = $json->getContainer('Calendar', Tinebase_Model_Container::TYPE_SHARED, null);

$this->assertTrue(is_array($containers));
$this->assertTrue(count($containers) > 0);

$found = false;
/** @var Tinebase_Model_Container $child */
foreach ($containers as $container) {
if ($persistentResource->name === $container['name']) {
$found = true;
}
}
static::assertTrue($found, 'did not find resource in shared containers!');

// test name change
$persistentResource->name = 'try to overwrite name';
$persistentResourceUpdated = Calendar_Controller_Resource::getInstance()->update($persistentResource);

static::assertEquals($persistentResource->name, $persistentResourceUpdated->name, 'update did not work');
static::assertEquals($persistentResource->name, Tinebase_Container::getInstance()->
get($persistentResourceUpdated->container_id)->name);
}

/**
* @see 0013348: improve resource permission handling
*/
public function testResourceAclUpdateDescription()
{
$persistentResource = $this->_prepareTestResourceAcl();

Tinebase_Core::set(Tinebase_Core::USER, $this->_personas['pwulf']);
// now we will not update the container, but go into abstract update, which will do a get => Tinebase_Exception_AccessDenied
$persistentResource->description = 'shalalala';
try {
Expand Down Expand Up @@ -395,6 +323,7 @@ public function testResourceAclSearchAttenders()
{
$resource = $this->_prepareTestResourceAcl();

Tinebase_Core::set(Tinebase_Core::USER, $this->_personas['pwulf']);
$filter = array(array(
'field' => 'type',
'operator' => 'equals',
Expand Down Expand Up @@ -437,6 +366,7 @@ public function testResourceAclSearchTinebase()
{
$this->_prepareTestResourceAcl();

Tinebase_Core::set(Tinebase_Core::USER, $this->_personas['pwulf']);
$filter = array(array(
'field' => 'type',
'operator' => 'equals',
Expand Down Expand Up @@ -485,6 +415,7 @@ public function testResourceAclGetTinebase()
{
$resource = $this->_prepareTestResourceAcl();

Tinebase_Core::set(Tinebase_Core::USER, $this->_personas['pwulf']);
$json = new Tinebase_Frontend_Json_Container();
$containers = $json->getContainer('Calendar', Tinebase_Model_Container::TYPE_SHARED, null);

Expand Down

0 comments on commit f364f62

Please sign in to comment.