activitymanager.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <?php
  2. /**
  3. * Copyright (c) 2014 Thomas Müller <deepdiver@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. *
  8. */
  9. class Test_ActivityManager extends PHPUnit_Framework_TestCase {
  10. /** @var \OC\ActivityManager */
  11. private $activityManager;
  12. public function setUp() {
  13. $this->activityManager = new \OC\ActivityManager();
  14. $this->activityManager->registerExtension(function() {
  15. return new NoOpExtension();
  16. });
  17. $this->activityManager->registerExtension(function() {
  18. return new SimpleExtension();
  19. });
  20. }
  21. public function testNotificationTypes() {
  22. $result = $this->activityManager->getNotificationTypes('en');
  23. $this->assertTrue(is_array($result));
  24. $this->assertEquals(2, sizeof($result));
  25. }
  26. public function testFilterNotificationTypes() {
  27. $result = $this->activityManager->filterNotificationTypes(array('NT0', 'NT1', 'NT2', 'NT3'), 'FILTER1');
  28. $this->assertTrue(is_array($result));
  29. $this->assertEquals(3, sizeof($result));
  30. $result = $this->activityManager->filterNotificationTypes(array('NT0', 'NT1', 'NT2', 'NT3'), 'FILTER2');
  31. $this->assertTrue(is_array($result));
  32. $this->assertEquals(4, sizeof($result));
  33. }
  34. public function testDefaultTypes() {
  35. $result = $this->activityManager->getDefaultTypes('stream');
  36. $this->assertTrue(is_array($result));
  37. $this->assertEquals(1, sizeof($result));
  38. $result = $this->activityManager->getDefaultTypes('email');
  39. $this->assertTrue(is_array($result));
  40. $this->assertEquals(0, sizeof($result));
  41. }
  42. public function testTranslate() {
  43. $result = $this->activityManager->translate('APP0', '', '', array(), false, false, 'en');
  44. $this->assertEquals('Stupid translation', $result);
  45. $result = $this->activityManager->translate('APP1', '', '', array(), false, false, 'en');
  46. $this->assertFalse($result);
  47. }
  48. public function testTypeIcon() {
  49. $result = $this->activityManager->getTypeIcon('NT1');
  50. $this->assertEquals('icon-nt-one', $result);
  51. $result = $this->activityManager->getTypeIcon('NT2');
  52. $this->assertEquals('', $result);
  53. }
  54. public function testGroupParameter() {
  55. $result = $this->activityManager->getGroupParameter(array());
  56. $this->assertEquals(5, $result);
  57. }
  58. public function testNavigation() {
  59. $result = $this->activityManager->getNavigation();
  60. $this->assertEquals(4, sizeof($result['apps']));
  61. $this->assertEquals(2, sizeof($result['top']));
  62. }
  63. public function testIsFilterValid() {
  64. $result = $this->activityManager->isFilterValid('fv01');
  65. $this->assertTrue($result);
  66. $result = $this->activityManager->isFilterValid('FV2');
  67. $this->assertFalse($result);
  68. }
  69. public function testQueryForFilter() {
  70. $result = $this->activityManager->getQueryForFilter('filter1');
  71. $this->assertEquals(
  72. array(
  73. '`app` = ? and `message` like ?',
  74. array('mail', 'ownCloud%')
  75. ), $result
  76. );
  77. $result = $this->activityManager->isFilterValid('filter2');
  78. $this->assertFalse($result);
  79. }
  80. }
  81. class SimpleExtension implements \OCP\Activity\IExtension {
  82. public function getNotificationTypes($languageCode) {
  83. return array('NT1', 'NT2');
  84. }
  85. public function filterNotificationTypes($types, $filter) {
  86. if ($filter === 'FILTER1') {
  87. unset($types[0]);
  88. }
  89. return $types;
  90. }
  91. public function getDefaultTypes($method) {
  92. if ($method === 'stream') {
  93. return array('DT0');
  94. }
  95. return array();
  96. }
  97. public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode) {
  98. if ($app === 'APP0') {
  99. return "Stupid translation";
  100. }
  101. return false;
  102. }
  103. public function getTypeIcon($type) {
  104. if ($type === 'NT1') {
  105. return 'icon-nt-one';
  106. }
  107. return '';
  108. }
  109. public function getGroupParameter($activity) {
  110. return 5;
  111. }
  112. public function getNavigation() {
  113. return array(
  114. 'apps' => array('nav1', 'nav2', 'nav3', 'nav4'),
  115. 'top' => array('top1', 'top2')
  116. );
  117. }
  118. public function isFilterValid($filterValue) {
  119. if ($filterValue === 'fv01') {
  120. return true;
  121. }
  122. return false;
  123. }
  124. public function getQueryForFilter($filter) {
  125. if ($filter === 'filter1') {
  126. return array('`app` = ? and `message` like ?', array('mail', 'ownCloud%'));
  127. }
  128. return false;
  129. }
  130. }
  131. class NoOpExtension implements \OCP\Activity\IExtension {
  132. public function getNotificationTypes($languageCode) {
  133. return false;
  134. }
  135. public function filterNotificationTypes($types, $filter) {
  136. return false;
  137. }
  138. public function getDefaultTypes($method) {
  139. return false;
  140. }
  141. public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode) {
  142. return false;
  143. }
  144. public function getTypeIcon($type) {
  145. return false;
  146. }
  147. public function getGroupParameter($activity) {
  148. return false;
  149. }
  150. public function getNavigation() {
  151. return false;
  152. }
  153. public function isFilterValid($filterValue) {
  154. return false;
  155. }
  156. public function getQueryForFilter($filter) {
  157. return false;
  158. }
  159. }