1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47:
48: class SearchProviderTags_Test extends PHPUnit_Framework_TestCase {
49: 50: 51: 52: 53: 54:
55: private $article;
56:
57: 58: 59: 60: 61: 62: 63:
64: protected function setUp() {
65: $tag = new TagObject();
66: $tag->rebuildTable();
67:
68: $denum = new DEnum();
69: $denum->rebuildTable();
70:
71: $item = new DEnumItem();
72: $item->rebuildTable();
73:
74: $article = new ArticleObject();
75: $article->rebuildTable();
76:
77: $denum = new DEnum('ArticleObject::section');
78: $item->set('DEnumID', $denum->getOID());
79: $item->set('value', 'Test');
80: $item->save();
81:
82: $this->article = $this->createArticleObject('unitTestArticle');
83: }
84:
85: 86: 87: 88: 89: 90: 91:
92: protected function tearDown() {
93: $article = new ArticleObject();
94: $article->dropTable();
95:
96: $tag = new TagObject();
97: $tag->dropTable();
98:
99: $denum = new DEnum();
100: $denum->dropTable();
101:
102: $item = new DEnumItem();
103: $item->dropTable();
104:
105: unset($this->article);
106: }
107:
108: 109: 110: 111: 112: 113:
114: private function createArticleObject($name) {
115: $article = new ArticleObject();
116: $article->set('title', $name);
117: $article->set('description', 'A test article called unitTestArticle with some stop words and the unitTestArticle title twice');
118: $article->set('author', 'blah');
119: $article->set('content', 'blah');
120:
121: return $article;
122: }
123:
124: 125: 126: 127: 128:
129: public function testIndex() {
130: $this->article->save();
131:
132: $tag = new TagObject();
133: $tag->dropTable();
134: $tag->rebuildTable();
135:
136: $provider = SearchProviderFactory::getInstance('SearchProviderTags');
137: $provider->index($this->article);
138:
139: $tags = $this->article->getPropObject('tags')->getRelatedObjects();
140:
141: $found = false;
142: foreach($tags as $tag) {
143: if($tag->get('content') == 'unittestarticle') {
144: $found = true;
145: break;
146: }
147: }
148: $this->assertTrue($found, 'Testing that the index method is generating tags as expected');
149: }
150:
151: 152: 153: 154: 155:
156: public function testDelete() {
157: $this->article->save();
158: $tags = $this->article->getPropObject('tags')->getRelatedObjects();
159:
160: $this->assertTrue(count($tags) > 0, 'Confirming that tags exist after saving the article (ArticleObject::after_save_callback())');
161:
162: $provider = SearchProviderFactory::getInstance('SearchProviderTags');
163: $provider->delete($this->article);
164:
165: $tags = $this->article->getPropObject('tags')->getRelatedObjects();
166:
167: $this->assertTrue(count($tags) == 0, 'Testing that tags have been deleted once a DAO has been deleted from the search index');
168: }
169:
170: 171: 172: 173: 174:
175: public function testSearch() {
176: $this->article->save();
177:
178: $provider = SearchProviderFactory::getInstance('SearchProviderTags');
179: $results = $provider->search('unitTestArticle');
180:
181: $this->assertTrue(count($results) == 1, 'Testing the search method for expected results');
182: $this->assertEquals($this->article->getOID(), $results[0]->getOID(), 'Testing the search method for expected results');
183:
184: $results = $provider->search('unitTestArticle', 'PersonObject');
185:
186: $this->assertTrue(count($results) == 0, 'Testing the search method honours returnType filtering');
187: }
188:
189: 190: 191: 192: 193:
194: public function testGetNumberFound() {
195: $this->article->save();
196:
197: $provider = SearchProviderFactory::getInstance('SearchProviderTags');
198: $results = $provider->search('unitTestArticle');
199:
200: $this->assertTrue($provider->getNumberFound() == 1, 'Testing the method for getting the expected number of results');
201:
202: $article2 = $this->createArticleObject('unitTestArticle 2');
203: $article2->save();
204:
205: $article3 = $this->createArticleObject('unitTestArticle 3');
206: $article3->save();
207:
208: $results = $provider->search('unitTestArticle');
209:
210: $this->assertTrue($provider->getNumberFound() == 3, 'Testing the method for getting the expected number of results');
211: }
212:
213: 214: 215: 216: 217:
218: public function testGetRelated() {
219: $this->article->save();
220:
221:
222: $article2 = $this->createArticleObject('unitTestArticle 2');
223: $article2->save();
224:
225: $article3 = $this->createArticleObject('unitTestArticle 3');
226: $article3->save();
227:
228: $provider = SearchProviderFactory::getInstance('SearchProviderTags');
229: $results = $provider->getRelated($this->article);
230:
231: $this->assertTrue(count($results) == 2, 'Testing the method for getting related objects');
232:
233: $results = $provider->getRelated($this->article, 'all', 0, 1);
234:
235: $this->assertTrue(count($results) == 1, 'Testing the method for getting related objects honours limit param');
236:
237: $results = $provider->getRelated($this->article, 'PersonObject');
238:
239: $this->assertTrue(count($results) == 0, 'Testing the get related objects method honours returnType filtering');
240: }
241: }
242:
243: ?>