BxBaseServiceProfilesRecommendationsTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * "Recommended friends" on the members' home page: with nothing to suggest (a new or small site) the block shows an
  4. * empty state with a link to find people, instead of rendering nothing and leaving its page column blank.
  5. */
  6. class BxBaseServiceProfilesRecommendationsTest extends BxDolTestCase
  7. {
  8. // No profile has this id, so there is nothing to recommend to it.
  9. private const NO_RECOMMENDATIONS_PROFILE = 2147483000;
  10. private function browse(array $aParams)
  11. {
  12. return BxDolService::call('system', 'browse_recommendations_friends', [self::NO_RECOMMENDATIONS_PROFILE, $aParams], 'TemplServiceProfiles');
  13. }
  14. public function testNothingToRecommendRendersNothingByDefault(): void
  15. {
  16. $this->assertEmpty($this->browse(['per_page' => 3]), 'Blocks without empty_state keep hiding themselves.');
  17. }
  18. public function testEmptyStateExplainsAndLinksToPeople(): void
  19. {
  20. $sHtml = $this->browse(['per_page' => 3, 'empty_state' => true]);
  21. $this->assertStringContainsString('bx-recommendations-empty', $sHtml);
  22. $this->assertStringContainsString(_t('_sys_recom_friends_empty_title'), $sHtml);
  23. $this->assertStringContainsString(_t('_sys_recom_friends_empty_text'), $sHtml);
  24. $oMethod = new ReflectionMethod('BxBaseServiceProfiles', '_getRecommendationsEmptyStateUrl');
  25. $sUrl = $oMethod->invoke(new BxTemplServiceProfiles());
  26. if ($sUrl === '') {
  27. $this->assertStringNotContainsString('bx-btn', $sHtml, 'Without a profile module there is nowhere to send people, so no button.');
  28. return;
  29. }
  30. $this->assertStringStartsWith(BX_DOL_URL_ROOT, $sUrl);
  31. $this->assertStringContainsString('href="' . $sUrl . '"', $sHtml);
  32. $this->assertStringContainsString(_t('_sys_recom_friends_empty_action'), $sHtml);
  33. }
  34. public function testEmptyStateWinsOverTheGenericEmptyMessage(): void
  35. {
  36. $sHtml = $this->browse(['empty_state' => true, 'empty_message' => true]);
  37. $this->assertStringContainsString('bx-recommendations-empty', $sHtml);
  38. $this->assertStringNotContainsString('bx-msg-box', $sHtml);
  39. }
  40. }