@@ -91,9 +91,6 @@ protected function setUp(): void
91
91
92
92
global $ db , $ config , $ user , $ auth , $ cache , $ phpbb_container , $ phpbb_dispatcher ;
93
93
94
- // $avatar_helper = $this->getMockBuilder('\phpbb\avatar\helper')
95
- // ->disableOriginalConstructor()
96
- // ->getMock();
97
94
$ db = $ this ->db = $ this ->new_dbal ();
98
95
$ config = $ this ->config = new \phpbb \config \config ([
99
96
'allow_privmsg ' => true ,
@@ -438,4 +435,97 @@ protected function get_messages_for_subscription($client_hash): array
438
435
439
436
return $ response_data ['data ' ]['messages ' ];
440
437
}
438
+
439
+ /**
440
+ * @depends test_get_subscription
441
+ */
442
+ public function test_export_data_with_migration (): void
443
+ {
444
+ global $ phpbb_root_path , $ phpEx ;
445
+
446
+ require_once __DIR__ . '/../../migrations/handle_subscriptions.php ' ; // load the extension migration
447
+
448
+ $ this ->config ['wpn_webpush_enable ' ] = '1 ' ;
449
+ $ this ->config ['webpush_enable ' ] = '' ;
450
+ $ this ->config ['webpush_vapid_public ' ] = '' ;
451
+ $ this ->config ['webpush_vapid_private ' ] = '' ;
452
+
453
+ $ config_db = new \phpbb \config \db ($ this ->container ->get ('dbal.conn ' ), $ this ->container ->get ('cache.driver ' ), 'phpbb_config ' );
454
+ foreach ($ this ->config as $ config_name => $ config_value )
455
+ {
456
+ $ config_db ->set ($ config_name , $ config_value );
457
+ }
458
+
459
+ $ factory = new \phpbb \db \tools \factory ();
460
+ $ db_tools = $ factory ->get ($ this ->db );
461
+
462
+ $ phpbb_notification_push_data = [
463
+ 'COLUMNS ' => [
464
+ 'notification_type_id ' => ['USINT ' , 0 ],
465
+ 'item_id ' => ['ULINT ' , 0 ],
466
+ 'item_parent_id ' => ['ULINT ' , 0 ],
467
+ 'user_id ' => ['ULINT ' , 0 ],
468
+ 'push_data ' => ['MTEXT ' , '' ],
469
+ 'notification_time ' => ['TIMESTAMP ' , 0 ]
470
+ ],
471
+ 'PRIMARY_KEY ' => ['notification_type_id ' , 'item_id ' , 'item_parent_id ' , 'user_id ' ],
472
+ ];
473
+ $ db_tools ->sql_create_table ('phpbb_notification_push ' , $ phpbb_notification_push_data );
474
+
475
+ $ phpbb_push_subscriptions_data = [
476
+ 'COLUMNS ' => [
477
+ 'subscription_id ' => ['ULINT ' , null , 'auto_increment ' ],
478
+ 'user_id ' => ['ULINT ' , 0 ],
479
+ 'endpoint ' => ['TEXT ' , '' ],
480
+ 'expiration_time ' => ['TIMESTAMP ' , 0 ],
481
+ 'p256dh ' => ['VCHAR ' , '' ],
482
+ 'auth ' => ['VCHAR ' , '' ],
483
+ ],
484
+ 'PRIMARY_KEY ' => ['subscription_id ' , 'user_id ' ],
485
+ ];
486
+ $ db_tools ->sql_create_table ('phpbb_push_subscriptions ' , $ phpbb_push_subscriptions_data );
487
+
488
+ $ config_tool = new \phpbb \db \migration \tool \config ($ config_db );
489
+ $ this ->container ->set ('migrator.tool.config ' , $ config_tool );
490
+ $ tools_collection = new \phpbb \di \service_collection ($ this ->container );
491
+ $ tools_collection ->add ('migrator.tool.config ' );
492
+
493
+ $ migrator = new \phpbb \db \migrator (
494
+ $ this ->container ,
495
+ $ config_db ,
496
+ $ this ->db ,
497
+ $ db_tools ,
498
+ 'phpbb_migrations ' ,
499
+ $ phpbb_root_path ,
500
+ $ phpEx ,
501
+ 'phpbb_ ' ,
502
+ $ tools_collection ,
503
+ new \phpbb \db \migration \helper ()
504
+ );
505
+ $ migrator ->create_migrations_table ();
506
+
507
+ $ migration_class = '\phpbb\webpushnotifications\migrations\handle_subscriptions ' ;
508
+ $ migrator ->populate_migrations ([$ migration_class ]);
509
+
510
+ while ($ migrator ->migration_state ($ migration_class ) !== false )
511
+ {
512
+ $ migrator ->revert ($ migration_class );
513
+ }
514
+
515
+ $ sql = 'SELECT config_name, config_value FROM ' . CONFIG_TABLE . "
516
+ WHERE config_name IN('webpush_enable', 'webpush_vapid_public', 'webpush_vapid_private') " ;
517
+ $ result = $ this ->db ->sql_query ($ sql );
518
+ $ data = $ this ->db ->sql_fetchrowset ($ result );
519
+ $ this ->db ->sql_freeresult ($ result );
520
+
521
+ $ exported_config_data = [];
522
+ foreach ($ data as $ row )
523
+ {
524
+ $ exported_config_data [$ row ['config_name ' ]] = $ row ['config_value ' ];
525
+ }
526
+
527
+ $ this ->assertEquals ($ this ->config ['wpn_webpush_enable ' ], $ exported_config_data ['webpush_enable ' ]);
528
+ $ this ->assertEquals ($ this ->config ['wpn_webpush_vapid_public ' ], $ exported_config_data ['webpush_vapid_public ' ]);
529
+ $ this ->assertEquals ($ this ->config ['wpn_webpush_vapid_private ' ], $ exported_config_data ['webpush_vapid_private ' ]);
530
+ }
441
531
}
0 commit comments