/* * Copyright (c) 2014 * * This file is licensed under the Affero General Public License version 3 * or later. * * See the COPYING-README file. * */ (function() { /** * Construct a new FileActionsMenu instance * @constructs FileActionsMenu * @memberof OCA.Files */ var FileActionsMenu = OC.Backbone.View.extend({ tagName: 'div', className: 'fileActionsMenu popovermenu bubble hidden open menu', /** * Current context * * @type OCA.Files.FileActionContext */ _context: null, events: { 'click a.action': '_onClickAction' }, template: function(data) { return OCA.Files.Templates['fileactionsmenu'](data); }, /** * Event handler whenever an action has been clicked within the menu * * @param {Object} event event object */ _onClickAction: function(event) { var $target = $(event.target); if (!$target.is('a')) { $target = $target.closest('a'); } var fileActions = this._context.fileActions; var actionName = $target.attr('data-action'); var actions = fileActions.getActions( fileActions.getCurrentMimeType(), fileActions.getCurrentType(), fileActions.getCurrentPermissions() ); var actionSpec = actions[actionName]; var fileName = this._context.$file.attr('data-file'); event.stopPropagation(); event.preventDefault(); OC.hideMenus(); actionSpec.action( fileName, this._context ); }, /** * Renders the menu with the currently set items */ render: function() { var self = this; var fileActions = this._context.fileActions; var actions = fileActions.getActions( fileActions.getCurrentMimeType(), fileActions.getCurrentType(), fileActions.getCurrentPermissions() ); var defaultAction = fileActions.getCurrentDefaultFileAction(); var items = _.filter(actions, function(actionSpec) { return !defaultAction || actionSpec.name !== defaultAction.name; }); items = _.map(items, function(item) { if (_.isFunction(item.displayName)) { item = _.extend({}, item); item.displayName = item.displayName(self._context); } if (_.isFunction(item.iconClass)) { var fileName = self._context.$file.attr('data-file'); item = _.extend({}, item); item.iconClass = item.iconClass(fileName, self._context); } if (_.isFunction(item.icon)) { var fileName = self._context.$file.attr('data-file'); item = _.extend({}, item); item.icon = item.icon(fileName, self._context); } item.inline = item.type === OCA.Files.FileActions.TYPE_INLINE return item; }); items = items.sort(function(actionA, actionB) { var orderA = actionA.order || 0; var orderB = actionB.order || 0; if (orderB === orderA) { return OC.Util.naturalSortCompare(actionA.displayName, actionB.displayName); } return orderA - orderB; }); items = _.map(items, function(item) { item.nameLowerCase = item.name.toLowerCase(); return item; }); this.$el.html(this.template({ items: items })); }, /** * Displays the menu under the given element * * @param {OCA.Files.FileActionContext} context context * @param {Object} $trigger trigger element */ show: function(context) { this._context = context; this.render(); this.$el.removeClass('hidden'); OC.showMenu(null, this.$el); } }); OCA.Files.FileActionsMenu = FileActionsMenu; })(); Nextcloud server, a safe home for all your data: https://github.com/nextcloud/serverwww-data
aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/AppFramework/Utility/TimeFactoryTest.php
blob: 276b2d6da4f64a2bf6699e55011c58f4fa3f6e59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php

declare(strict_types=1);

/**
 * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-only
 */

namespace Test\AppFramework\Utility;

use OC\AppFramework\Utility\TimeFactory;

class TimeFactoryTest extends \Test\TestCase {
	protected TimeFactory $timeFactory;

	protected function setUp(): void {
		$this->timeFactory = new TimeFactory();
	}

	public function testNow(): void {
		$now = $this->timeFactory->now();
		self::assertSame('UTC', $now->getTimezone()->getName());
	}

	public function testNowWithTimeZone(): void {
		$timezone = new \DateTimeZone('Europe/Berlin');
		$withTimeZone = $this->timeFactory->withTimeZone($timezone);

		$now = $withTimeZone->now();
		self::assertSame('Europe/Berlin', $now->getTimezone()->getName());
	}

	public function testGetTimeZone(): void {
		$expected = new \DateTimeZone('Europe/Berlin');
		$actual = $this->timeFactory->getTimeZone('Europe/Berlin');
		self::assertEquals($expected, $actual);
	}

	public function testGetTimeZoneUTC(): void {
		$expected = new \DateTimeZone('UTC');
		$actual = $this->timeFactory->getTimeZone();
		self::assertEquals($expected, $actual);
	}

	public function testGetTimeZoneInvalid(): void {
		$this->expectException(\Exception::class);
		$this->timeFactory->getTimeZone('blubblub');
	}
}