source: trunk/tests/attachment.php @ 1184

Revision 939, 6.2 KB checked in by bogdan2412, 4 years ago (diff)

Make tests work again after previous revision

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1#! /usr/bin/env php
2<?php
3
4require_once(dirname($argv[0]) . "/utilities.php");
5require_once(IA_ROOT_DIR.'www/utilities.php');
6
7test_cleanup();
8test_prepare();
9
10log_print("Dude 1 creates a page");
11$res = curl_test(array(
12        'url' => url_textblock_edit('sandbox/test_page'),
13        'user' => 'test_dude1',
14        'post' => array(
15                'text' => "Test page\nxzx-content1-xzx\n",
16                'title' => "Test xzx-title1-xzx",
17                'last_revision' => "0",
18)));
19
20log_print("Dude 1 attaches a sample file");
21// FIXME: easily borked.
22file_put_contents('/tmp/test_file', 'xzx-file-xzx');
23$res = curl_test(array(
24        'url' => url_attachment_new('sandbox/test_page'),
25        'user' => 'test_dude1',
26        'post' => array(
27                'file_name' => '@/tmp/test_file'),
28));
29log_assert_equal($res['url'],  url_absolute(
30            url_textblock('sandbox/test_page')));
31
32log_print("Anon looks at file");
33$res = curl_test(array(
34        'url' => url_attachment('sandbox/test_page', 'test_file'),
35        'validate_html' => false,
36));
37log_assert_equal($res['content'],  'xzx-file-xzx');
38
39log_print("Anon looks at attachment list");
40$res = curl_test(array(
41        'url' => url_attachment_list('sandbox/test_page'),
42));
43log_assert(strstr($res['content'], html_escape(
44        url_attachment('sandbox/test_page', 'test_file'))));
45// FIXME: this shouldn't be visible
46log_assert(strstr($res['content'], html_escape(
47            url_attachment_delete('sandbox/test_page', 'test_file'))));
48
49log_print("Anon tries to delete attachment, fails");
50$res = curl_test(array(
51        'url' => url_attachment_delete('sandbox/test_page', 'test_file'),
52        'post' => array(),
53));
54log_assert_equal($res['url'],  url_absolute(url_login()));
55
56log_print("Admin looks in list and sees attachment");
57$res = curl_test(array(
58        'url' => url_attachment_list('sandbox/test_page'),
59));
60log_assert(strstr($res['content'], html_escape(
61            url_attachment('sandbox/test_page', 'test_file'))));
62
63log_print("Admin deletes attachment, OK");
64$res = curl_test(array(
65        'url' => url_attachment_delete('sandbox/test_page', 'test_file'),
66        'user' => 'test_admin',
67        'post' => array()
68));
69log_assert_equal($res['url'],  url_absolute(url_textblock('sandbox/test_page')));
70
71log_print("Admin looks in list and attachment is gone");
72$res = curl_test(array(
73        'url' => url_attachment_list('sandbox/test_page', 'test_file'),
74));
75log_assert(!strstr($res['content'], html_escape(
76            url_attachment('sandbox/test_page', 'test_file'))));
77
78log_print("Dude 1 attaches 5 files");
79for ($i = 1; $i <= 5; ++$i) {
80    // FIXME: easily borked.
81    file_put_contents("/tmp/test_file_$i", "xzx-spam-file-$i-xzx");
82    $res = curl_test(array(
83            'url' => url_attachment_new('sandbox/test_page'),
84            'user' => 'test_dude1',
85            'post' => array(
86                    'file_name' => "@/tmp/test_file_$i"),
87    ));
88    log_assert_equal($res['url'],  url_absolute(
89                url_textblock('sandbox/test_page')));
90}
91
92log_print("Dude 1 tries to overwrite file 3");
93file_put_contents('/tmp/test_file_3', 'xzx-spam-file-3-replaced-xzx');
94$res = curl_test(array(
95        'url' => url_attachment_new('sandbox/test_page'),
96        'user' => 'test_dude1',
97        'post' => array(
98                'file_name' => '@/tmp/test_file_3'),
99));
100log_assert_equal($res['url'], url_absolute(url_home()));
101
102log_print("Overwriting failed");
103$res = curl_test(array(
104        'url' => url_attachment('sandbox/test_page', 'test_file_3'),
105        'validate_html' => false,
106));
107log_assert_equal($res['content'],  'xzx-spam-file-3-xzx');
108log_assert($res['content'] != 'xzx-spam-file-3-replaced-xzx');
109
110log_print("Dude 2 tries to overwrites file 1");
111file_put_contents('/tmp/test_file_1', 'xzx-spam-file-1-replaced-xzx');
112$res = curl_test(array(
113        'url' => url_attachment_new('sandbox/test_page'),
114        'user' => 'test_dude2',
115        'post' => array(
116                'file_name' => '@/tmp/test_file_1'),
117));
118log_assert_equal($res['url'],  url_absolute(url_home()));
119
120log_print("Anon sees original file");
121$res = curl_test(array(
122        'url' => url_attachment('sandbox/test_page', 'test_file_1'),
123        'validate_html' => false,
124));
125log_assert_equal($res['content'],  'xzx-spam-file-1-xzx');
126
127log_print("Admin looks at file list and is horrified at the spamming from dude1");
128$res = curl_test(array(
129        'url' => url_attachment_list('sandbox/test_page'),
130        'user' => 'test_admin',
131));
132for ($i = 1; $i <= 5; ++$i) {
133    log_assert(strstr($res['content'], html_escape(
134                url_attachment('sandbox/test_page', "test_file_$i"))));
135}
136log_assert(strstr(strtolower($res['content']), html_escape(
137            url_user_profile('test_dude1'))));
138log_assert(!strstr(strtolower($res['content']), html_escape(
139            url_user_profile('test_dude2'))));
140
141log_print("Admin moves the spammed page.");
142$res = curl_test(array(
143        'url' => url_textblock_move('sandbox/test_page'),
144        'user' => 'test_admin',
145        'post' => array(
146            'new_name' => 'sAnDbox/test_page_2',
147)));
148log_assert_equal($res['url'], url_absolute(url_textblock('sandbox/test_page_2')));
149
150log_print("Anon sees the attachments stayed and he complains");
151$res = curl_test(array(
152        'url' => url_attachment('sandbox/test_page_2', 'test_file_2'),
153        'validate_html' => false,
154));
155log_assert_equal($res['content'],  'xzx-spam-file-2-xzx');
156
157log_print("Admin deletes page");
158$res = curl_test(array(
159        'url' => url_textblock_delete('sandbox/test_page_2'),
160        'user' => 'test_admin',
161        'post' => array()
162));
163log_assert_equal($res['url'], url_absolute(url_home()));
164
165log_print("Anon sees spam is finally gone");
166$res = curl_test(array(
167        'url' => url_attachment('sandbox/test_page_2', 'test_file_2'),
168        'validate_html' => false,
169));
170log_assert($res['content'] != 'xzx-spam-file-2-xzx');
171log_assert_equal($res['http_code'], 404);
172
173log_print("Check files are gone in the db and on disk");
174log_assert_equal(array(), attachment_get_all('sandbox/test_page_2'));
175log_assert_equal(0, attachment_get_count('sandbox/test_page_2'));
176log_assert_equal(array(), glob(IA_ROOT_DIR . "attach/sandbox_test_page*"));
177
178log_print("All tests passed. Warning: incomplete.");
179test_cleanup();
Note: See TracBrowser for help on using the repository browser.