vcategories.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Thomas Tanghus
  6. * @copyright 2012 Thomas Tanghus (thomas@tanghus.net)
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. //require_once("../lib/template.php");
  23. class Test_VCategories extends UnitTestCase {
  24. protected $objectType;
  25. protected $user;
  26. protected $backupGlobals = FALSE;
  27. public function setUp() {
  28. OC_User::clearBackends();
  29. OC_User::useBackend('dummy');
  30. $this->user = uniqid('user_');
  31. $this->objectType = uniqid('type_');
  32. OC_User::createUser($this->user, 'pass');
  33. OC_User::setUserId($this->user);
  34. }
  35. public function tearDown() {
  36. //$query = OC_DB::prepare('DELETE FROM `*PREFIX*vcategories` WHERE `item_type` = ?');
  37. //$query->execute(array('test'));
  38. }
  39. public function testInstantiateWithDefaults() {
  40. $defcategories = array('Friends', 'Family', 'Work', 'Other');
  41. $catmgr = new OC_VCategories($this->objectType, $this->user, $defcategories);
  42. $this->assertEqual(4, count($catmgr->categories()));
  43. }
  44. public function testAddCategories() {
  45. $categories = array('Friends', 'Family', 'Work', 'Other');
  46. $catmgr = new OC_VCategories($this->objectType, $this->user);
  47. foreach($categories as $category) {
  48. $result = $catmgr->add($category);
  49. $this->assertTrue($result);
  50. }
  51. $this->assertFalse($catmgr->add('Family'));
  52. $this->assertFalse($catmgr->add('fAMILY'));
  53. $this->assertEqual(4, count($catmgr->categories()));
  54. }
  55. public function testdeleteCategories() {
  56. $defcategories = array('Friends', 'Family', 'Work', 'Other');
  57. $catmgr = new OC_VCategories($this->objectType, $this->user, $defcategories);
  58. $this->assertEqual(4, count($catmgr->categories()));
  59. $catmgr->delete('family');
  60. $this->assertEqual(3, count($catmgr->categories()));
  61. $catmgr->delete(array('Friends', 'Work', 'Other'));
  62. $this->assertEqual(0, count($catmgr->categories()));
  63. }
  64. public function testAddToCategory() {
  65. $objids = array(1, 2, 3, 4, 5, 6, 7, 8, 9);
  66. $catmgr = new OC_VCategories($this->objectType, $this->user);
  67. foreach($objids as $id) {
  68. $catmgr->addToCategory($id, 'Family');
  69. }
  70. $this->assertEqual(1, count($catmgr->categories()));
  71. $this->assertEqual(9, count($catmgr->idsForCategory('Family')));
  72. }
  73. /**
  74. * @depends testAddToCategory
  75. */
  76. public function testRemoveFromCategory() {
  77. $objids = array(1, 2, 3, 4, 5, 6, 7, 8, 9);
  78. // Is this "legal"?
  79. $this->testAddToCategory();
  80. $catmgr = new OC_VCategories($this->objectType, $this->user);
  81. foreach($objids as $id) {
  82. $this->assertTrue(in_array($id, $catmgr->idsForCategory('Family')));
  83. $catmgr->removeFromCategory($id, 'Family');
  84. $this->assertFalse(in_array($id, $catmgr->idsForCategory('Family')));
  85. }
  86. $this->assertEqual(1, count($catmgr->categories()));
  87. $this->assertEqual(0, count($catmgr->idsForCategory('Family')));
  88. }
  89. }