@@ -354,7 +354,6 @@ public function testSavesEntityCountsCorrectly($expectedItemCount, $expectedProp
354354
355355 // clean up after the test
356356 $ wiki ->forceDelete ();
357- Schema::dropIfExists ($ tablePage );
358357
359358 $ this ->assertDatabaseHas ('wiki_daily_metrics ' , [
360359 'wiki_id ' => $ wiki ->id ,
@@ -364,4 +363,63 @@ public function testSavesEntityCountsCorrectly($expectedItemCount, $expectedProp
364363 'entity_schema_count ' => $ expectedEntitySchemaCount , // redirects should be ignored
365364 ]);
366365 }
366+
367+ public function testSavesTotalUserCountCorrectly () {
368+ $ wiki = Wiki::factory ()->create ([
369+ 'domain ' => 'usercounttest.wikibase.cloud ' ,
370+ ]);
371+
372+ $ users = [
373+ [
374+ 'user_name ' => 'user1 ' ,
375+ 'user_real_name ' => 'user1 ' ,
376+ 'user_password ' => 'user1 ' ,
377+ 'user_new_password ' => 'user1 ' ,
378+ 'user_email ' => 'user1@email.com ' ,
379+ 'user_touched ' => random_bytes (10 ),
380+ ],
381+ [
382+ 'user_name ' => 'user2 ' ,
383+ 'user_real_name ' => 'user2 ' ,
384+ 'user_password ' => 'user2 ' ,
385+ 'user_new_password ' => 'user2 ' ,
386+ 'user_email ' => 'user2@email.com ' ,
387+ 'user_touched ' => random_bytes (10 ),
388+ ],
389+ ];
390+ $ wikiDb = WikiDb::first ();
391+ $ wikiDb ->update (['wiki_id ' => $ wiki ->id ]);
392+
393+ $ tableUser = $ wikiDb ->name . '. ' . $ wikiDb ->prefix . '_user ' ;
394+ Schema::dropIfExists ($ tableUser );
395+ Schema::create ($ tableUser , function (Blueprint $ table ) {
396+ $ table ->increments ('user_id ' );
397+ $ table ->string ('user_name ' );
398+ $ table ->string ('user_real_name ' )->default (0 );
399+ $ table ->string ('user_password ' , 255 );
400+ $ table ->string ('user_new_password ' );
401+ $ table ->string ('user_email ' );
402+ $ table ->binary ('user_touched ' );
403+ });
404+
405+ // Insert dummy data
406+ DB ::table ($ tableUser )->insert ($ users );
407+ WikiDailyMetrics::create ([
408+ 'id ' => $ wiki ->id . '_ ' . now ()->subDay ()->toDateString (),
409+ 'wiki_id ' => $ wiki ->id ,
410+ 'date ' => now ()->subDay ()->toDateString (),
411+ 'pages ' => 0 ,
412+ 'is_deleted ' => 0 ,
413+ ]);
414+
415+ (new WikiMetrics )->saveMetrics ($ wiki );
416+
417+ // clean up after the test
418+ $ wiki ->forceDelete ();
419+
420+ $ this ->assertDatabaseHas ('wiki_daily_metrics ' , [
421+ 'wiki_id ' => $ wiki ->id ,
422+ 'total_user_count ' => count ($ users ),
423+ ]);
424+ }
367425}
0 commit comments