You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

activitymanager.php 5.0KB

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