3 #include "stg/user_property.h"
6 #include "testsettings.h"
7 #include "testtariffs.h"
11 #include "testusers.h"
12 #include "testservices.h"
17 class TEST_STORE_LOCAL : public TEST_STORE {
23 int WriteUserChgLog(const std::string & /*login*/,
24 const std::string & /*admLogin*/,
26 const std::string & /*paramName*/,
27 const std::string & /*oldValue*/,
28 const std::string & /*newValue*/,
29 const std::string & /*message*/) const override { ++entries; return 0; }
31 size_t GetEntries() const { return entries; }
34 mutable size_t entries;
37 class TEST_SETTINGS_LOCAL : public TEST_SETTINGS {
39 void addFilter(const std::string& field) { filter.push_back(field); }
41 const std::vector<std::string>& GetFilterParamsLog() const { return filter; }
44 std::vector<std::string> filter;
51 struct filter_params_log_data {
54 typedef test_group<filter_params_log_data> tg;
55 tg filter_params_log_test_group("Filter params log tests group");
57 typedef tg::object testobject;
61 void testobject::test<1>()
63 set_test_name("Check normal behaviour");
65 TEST_SETTINGS_LOCAL settings;
66 settings.addFilter("*"); // Allow everything by default.
69 TEST_STORE_LOCAL store;
72 TEST_SERVICES services;
73 STG::UserImpl user(&settings, &store, &tariffs, &admin, &users, services);
75 auto & address = user.GetProperties().address;
76 auto & note = user.GetProperties().note;
77 auto & group = user.GetProperties().group;
79 address.Set("address", admin, "", store, "");
80 note.Set("note", admin, "", store, "");
81 group.Set("group", admin, "", store, "");
83 ensure_equals("entries = 3", store.GetEntries(), 3);
85 note.Set("another note", admin, "", store, "");
87 ensure_equals("entries = 4", store.GetEntries(), 4);
89 address.Set("new address", admin, "", store, "");
91 ensure_equals("entries = 5", store.GetEntries(), 5);
93 group.Set("administrative group", admin, "", store, "");
95 ensure_equals("entries = 6", store.GetEntries(), 6);
101 void testobject::test<2>()
103 set_test_name("Check single filter entry.");
105 TEST_SETTINGS_LOCAL settings;
106 settings.addFilter("address"); // Allow everything by default.
107 TEST_TARIFFS tariffs;
109 TEST_STORE_LOCAL store;
112 TEST_SERVICES services;
113 STG::UserImpl user(&settings, &store, &tariffs, &admin, &users, services);
115 auto & address = user.GetProperties().address;
116 auto & note = user.GetProperties().note;
117 auto & group = user.GetProperties().group;
119 address.Set("address", admin, "", store, "");
120 note.Set("note", admin, "", store, "");
121 group.Set("group", admin, "", store, "");
123 ensure_equals("entries = 1", store.GetEntries(), 1);
125 note.Set("another note", admin, "", store, "");
127 ensure_equals("entries = 1", store.GetEntries(), 1);
129 address.Set("new address", admin, "", store, "");
131 ensure_equals("entries = 2", store.GetEntries(), 2);
133 group.Set("administrative group", admin, "", store, "");
135 ensure_equals("entries = 2", store.GetEntries(), 2);
140 void testobject::test<3>()
142 set_test_name("Check multiple filter entries.");
144 TEST_SETTINGS_LOCAL settings;
145 settings.addFilter("address"); // Allow everything by default.
146 settings.addFilter("group"); // Allow everything by default.
147 TEST_TARIFFS tariffs;
149 TEST_STORE_LOCAL store;
152 TEST_SERVICES services;
153 STG::UserImpl user(&settings, &store, &tariffs, &admin, &users, services);
155 auto & address = user.GetProperties().address;
156 auto & note = user.GetProperties().note;
157 auto & group = user.GetProperties().group;
159 address.Set("address", admin, "", store, "");
160 note.Set("note", admin, "", store, "");
161 group.Set("group", admin, "", store, "");
163 ensure_equals("entries = 2", store.GetEntries(), 2);
165 note.Set("another note", admin, "", store, "");
167 ensure_equals("entries = 2", store.GetEntries(), 2);
169 address.Set("new address", admin, "", store, "");
171 ensure_equals("entries = 3", store.GetEntries(), 3);
173 group.Set("administrative group", admin, "", store, "");
175 ensure_equals("entries = 4", store.GetEntries(), 4);
180 void testobject::test<4>()
182 set_test_name("Check empty filter.");
184 TEST_SETTINGS_LOCAL settings;
185 TEST_TARIFFS tariffs;
187 TEST_STORE_LOCAL store;
190 TEST_SERVICES services;
191 STG::UserImpl user(&settings, &store, &tariffs, &admin, &users, services);
193 auto & address = user.GetProperties().address;
194 auto & note = user.GetProperties().note;
195 auto & group = user.GetProperties().group;
197 address.Set("address", admin, "", store, "");
198 note.Set("note", admin, "", store, "");
199 group.Set("group", admin, "", store, "");
201 ensure_equals("entries = 0", store.GetEntries(), 0);
203 note.Set("another note", admin, "", store, "");
205 ensure_equals("entries = 0", store.GetEntries(), 0);
207 address.Set("new address", admin, "", store, "");
209 ensure_equals("entries = 0", store.GetEntries(), 0);
211 group.Set("administrative group", admin, "", store, "");
213 ensure_equals("entries = 0", store.GetEntries(), 0);