2021-07-09 17:58:25 +04:00
/*
* ADMC - AD Management Center
*
2025-01-09 15:46:38 +04:00
* Copyright ( C ) 2020 - 2025 BaseALT Ltd .
* Copyright ( C ) 2020 - 2025 Dmitry Degtyarev
2021-07-09 17:58:25 +04:00
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* This program 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 General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
# include "admc_test_manager_edit.h"
2021-11-09 16:35:31 +04:00
# include "attribute_edits/manager_edit.h"
# include "attribute_edits/manager_widget.h"
# include "attribute_edits/ui_manager_widget.h"
2021-07-09 17:58:25 +04:00
# include "globals.h"
2024-06-04 13:20:07 +04:00
# include "properties_widgets/properties_dialog.h"
2021-07-09 17:58:25 +04:00
# include <QLineEdit>
2021-11-02 15:54:13 +04:00
# include <QPushButton>
2021-07-09 17:58:25 +04:00
void ADMCTestManagerEdit : : init ( ) {
ADMCTest : : init ( ) ;
2021-10-05 17:01:33 +04:00
auto manager_widget = new ManagerWidget ( parent_widget ) ;
2021-12-22 16:26:03 +04:00
edit = new ManagerEdit ( manager_widget , ATTRIBUTE_MANAGER , parent_widget ) ;
2021-07-09 17:58:25 +04:00
2021-10-18 12:29:43 +04:00
manager_display = manager_widget - > ui - > manager_display ;
change_button = manager_widget - > ui - > change_button ;
clear_button = manager_widget - > ui - > clear_button ;
properties_button = manager_widget - > ui - > properties_button ;
2021-07-09 17:58:25 +04:00
const QString name = TEST_USER ;
dn = test_object_dn ( name , CLASS_USER ) ;
const bool create_success = ad . object_add ( dn , CLASS_USER ) ;
QVERIFY ( create_success ) ;
const QString manager_name = QString ( " %1%2 " ) . arg ( TEST_USER , " -manager " ) ;
manager_dn = test_object_dn ( manager_name , CLASS_USER ) ;
const bool create_manager_success = ad . object_add ( manager_dn , CLASS_USER ) ;
QVERIFY ( create_manager_success ) ;
}
void ADMCTestManagerEdit : : load_empty ( ) {
const AdObject object = ad . search_object ( dn ) ;
edit - > load ( ad , object ) ;
QVERIFY ( manager_display - > text ( ) . isEmpty ( ) ) ;
}
void ADMCTestManagerEdit : : load ( ) {
const bool replace_success = ad . attribute_replace_string ( dn , ATTRIBUTE_MANAGER , manager_dn ) ;
QVERIFY ( replace_success ) ;
const AdObject object = ad . search_object ( dn ) ;
edit - > load ( ad , object ) ;
2022-03-11 16:32:36 +04:00
const QString actual_value = manager_display - > text ( ) ;
const QString expected_value = dn_get_name ( manager_dn ) ;
QCOMPARE ( actual_value , expected_value ) ;
2021-07-09 17:58:25 +04:00
}
2021-07-14 12:35:00 +04:00
void ADMCTestManagerEdit : : apply_unmodified ( ) {
test_edit_apply_unmodified ( edit , dn ) ;
}
2021-07-09 17:58:25 +04:00
void ADMCTestManagerEdit : : apply_after_change ( ) {
const AdObject object = ad . search_object ( dn ) ;
edit - > load ( ad , object ) ;
change_button - > click ( ) ;
select_object_dialog_select ( manager_dn ) ;
const bool apply_success = edit - > apply ( ad , dn ) ;
QVERIFY ( apply_success ) ;
const AdObject updated_object = ad . search_object ( dn ) ;
const QString updated_manager = updated_object . get_string ( ATTRIBUTE_MANAGER ) ;
2021-10-01 14:23:56 +04:00
QCOMPARE ( updated_manager , manager_dn ) ;
2021-07-09 17:58:25 +04:00
}
void ADMCTestManagerEdit : : apply_after_clear ( ) {
load ( ) ;
clear_button - > click ( ) ;
const bool apply_success = edit - > apply ( ad , dn ) ;
QVERIFY ( apply_success ) ;
const AdObject updated_object = ad . search_object ( dn ) ;
const QString updated_manager = updated_object . get_string ( ATTRIBUTE_MANAGER ) ;
QVERIFY ( updated_manager . isEmpty ( ) ) ;
}
void ADMCTestManagerEdit : : properties ( ) {
load ( ) ;
properties_button - > click ( ) ;
const bool properties_open = [ ] ( ) {
const QWidgetList widget_list = QApplication : : topLevelWidgets ( ) ;
for ( QWidget * widget : widget_list ) {
auto properties_dialog = qobject_cast < PropertiesDialog * > ( widget ) ;
if ( properties_dialog ! = nullptr ) {
return true ;
}
}
return false ;
} ( ) ;
QVERIFY ( properties_open ) ;
}
QTEST_MAIN ( ADMCTestManagerEdit )