aboutsummaryrefslogtreecommitdiffstats
path: root/documentation/introduction/intro-walkthrough.asciidoc
blob: 185498f6276317cad4cf9a2eb03e4ee41b341fa0 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
---
title: Example Application Walkthrough
order: 2
layout: page
---

[[intro.walkthrough]]
= Example Application Walkthrough

Let us follow the long tradition of first saying "Hello World!" when learning a
new programming framework.
First, using the primary server-side API.

[source, java]
----
import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.Label;
import com.vaadin.ui.UI;

@Title("My UI")
public class HelloWorld extends UI {
    @Override
    protected void init(VaadinRequest request) {
        // Create the content root layout for the UI
        VerticalLayout content = new VerticalLayout();
        setContent(content);

        // Display the greeting
        content.addComponent(new Label("Hello World!"));

        // Have a clickable button
        content.addComponent(new Button("Push Me!",
            click -> Notification.show("Pushed!")));
    }
}
----

A Vaadin application has one or more __UI__s that extend the
[classname]#com.vaadin.ui.UI# class. A UI is a part of the web page in which the
Vaadin application runs. An application can have multiple UIs in the same page,
especially in portals, or in different windows or tabs. A UI is associated with
a user session, and a session is created for each user who uses the application.
In the context of our Hello World UI, it is sufficient to know that the
underlying session is created when the user first accesses the application by
opening the page, and the [methodname]#init()# method is invoked at that time.

The page title, which is shown in the caption of the browser window or tab, is
defined with an annotation. The example uses a layout component as the root
content of the UI, as that is the case with most Vaadin applications, which
normally have more than one component. It then creates a new [classname]#Label#
user interface component, which displays simple text, and sets the text to
"Hello World!". The label is added to the layout.

The example also shows how to create a button and handle button click events.
Event handling is described in
<<dummy/../../../framework/architecture/architecture-events#architecture.events,"Events and Listeners">> and on the practical side in <<dummy/../../../framework/application/application-events#application.events,"Handling Events with Listeners">>.
In Java 8, you can implement listeners with lambda expressions, which simplifies the handler code significantly.

The result of the Hello World application, when opened in a browser, is shown in
<<figure.intro.walkthrough>>.

[[figure.intro.walkthrough]]
.Hello World Application
image::img/HelloWorld.png[scaledwidth=70%]

To run a program, you need to package it as a web application WAR package and
deploy it to a server, as explained in
<<dummy/../../../framework/application/application-environment#application.environment,"Deploying
an Application">>. During development, you typically deploy to an application
server integrated with the IDE.
4/stable29'>backport/46124/stable29 Nextcloud server, a safe home for all your data: https://github.com/nextcloud/serverwww-data
aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/FilesTest.php
blob: 1d26984ee72189b4eff2c9030e0468bde91f3e5e (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
/**
 * @author Robin McCorkell <rmccorkell@karoshi.org.uk>
 *
 * @copyright Copyright (c) 2015, ownCloud, Inc.
 * @license AGPL-3.0
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

namespace Test;

class FilesTest extends \Test\TestCase {

	const UPLOAD_LIMIT_DEFAULT_STR = '511M';
	const UPLOAD_LIMIT_SETTING_STR = '2M';
	const UPLOAD_LIMIT_SETTING_BYTES = 2097152;

	/** @var array $tmpDirs */
	private $tmpDirs = [];

	/**
	 * @return array
	 */
	private function getUploadLimitTestFiles() {
		$dir = \OC::$server->getTempManager()->getTemporaryFolder();
		$this->tmpDirs[] = $dir;
		$result = [
			'.htaccess' => $dir . '/htaccess',
			'.user.ini' => $dir . '/user.ini'
		];
		copy(\OC::$SERVERROOT . '/tests/data/setUploadLimit/htaccess', $result['.htaccess']);
		copy(\OC::$SERVERROOT . '/tests/data/setUploadLimit/user.ini', $result['.user.ini']);
		return $result;
	}

	protected function tearDown() {
		foreach ($this->tmpDirs as $dir) {
			\OC_Helper::rmdirr($dir);
		}
		parent::tearDown();
	}

	public function testSetUploadLimitSizeSanity() {
		$this->assertFalse(\OC_Files::setUploadLimit(PHP_INT_MAX + 10));
		$this->assertFalse(\OC_Files::setUploadLimit(\OC_Files::UPLOAD_MIN_LIMIT_BYTES - 10));
		$this->assertFalse(\OC_Files::setUploadLimit('foobar'));
	}

	public function setUploadLimitWriteProvider() {
		return [
			[
				// both files writable
				true, true,
				self::UPLOAD_LIMIT_SETTING_BYTES, self::UPLOAD_LIMIT_SETTING_BYTES,
				self::UPLOAD_LIMIT_SETTING_STR, self::UPLOAD_LIMIT_SETTING_STR
			],
			[
				// neither file writable
				false, false,
				self::UPLOAD_LIMIT_SETTING_BYTES, false,
				self::UPLOAD_LIMIT_DEFAULT_STR, self::UPLOAD_LIMIT_DEFAULT_STR
			],
			[
				// only .htaccess writable
				true, false,
				self::UPLOAD_LIMIT_SETTING_BYTES, false,
				self::UPLOAD_LIMIT_SETTING_STR, self::UPLOAD_LIMIT_DEFAULT_STR
			],
			[
				// only .user.ini writable
				false, true,
				self::UPLOAD_LIMIT_SETTING_BYTES, false,
				self::UPLOAD_LIMIT_DEFAULT_STR, self::UPLOAD_LIMIT_SETTING_STR
			],
			[
				// test rounding of values
				true, true,
				self::UPLOAD_LIMIT_SETTING_BYTES + 20, self::UPLOAD_LIMIT_SETTING_BYTES,
				self::UPLOAD_LIMIT_SETTING_STR, self::UPLOAD_LIMIT_SETTING_STR
			]
		];
	}

	/**
	 * @dataProvider setUploadLimitWriteProvider
	 */
	public function testSetUploadLimitWrite(
		$htaccessWritable, $userIniWritable,
		$setSize, $expectedSize,
		$htaccessStr, $userIniStr
	) {
		$this->markTestSkipped('TODO: Disable because fails on drone');

		$files = $this->getUploadLimitTestFiles();
		chmod($files['.htaccess'], ($htaccessWritable ? 0644 : 0444));
		chmod($files['.user.ini'], ($userIniWritable ? 0644 : 0444));

		$htaccessSize = filesize($files['.htaccess']);
		$userIniSize = filesize($files['.user.ini']);
		$htaccessSizeMod = 2*(strlen($htaccessStr) - strlen(self::UPLOAD_LIMIT_DEFAULT_STR));
		$userIniSizeMod = 2*(strlen($userIniStr) - strlen(self::UPLOAD_LIMIT_DEFAULT_STR));

		$this->assertEquals($expectedSize, \OC_Files::setUploadLimit($setSize, $files));

		// check file contents
		$htaccess = file_get_contents($files['.htaccess']);
		$this->assertEquals(1,
			preg_match('/php_value upload_max_filesize '.$htaccessStr.'/', $htaccess)
		);
		$this->assertEquals(1,
			preg_match('/php_value post_max_size '.$htaccessStr.'/', $htaccess)
		);
		$this->assertEquals($htaccessSize + $htaccessSizeMod, filesize($files['.htaccess']));

		$userIni = file_get_contents($files['.user.ini']);
		$this->assertEquals(1,
			preg_match('/upload_max_filesize='.$userIniStr.'/', $userIni)
		);
		$this->assertEquals(1,
			preg_match('/post_max_size='.$userIniStr.'/', $userIni)
		);
		$this->assertEquals($userIniSize + $userIniSizeMod, filesize($files['.user.ini']));
	}
}