/** * Set up tests. * * @since 2.0 */ protected function setUp() { $config = ConfigProvider::getInstance(); $config->set('session.provider.name', 'Alpha\\Util\\Http\\Session\\SessionProviderArray'); $standardGroup = new Rights(); $standardGroup->rebuildTable(); $standardGroup->set('name', 'Standard'); $standardGroup->save(); $person = new Person(); $person->set('displayName', 'unittestuser'); $person->set('email', '*****@*****.**'); $person->set('password', 'password'); $person->rebuildTable(); $person->save(); $article = new Article(); $article->set('title', 'unit test'); $article->set('description', 'unit test'); $article->set('content', 'unit test'); $article->set('author', 'unit test'); $article->rebuildTable(); $article->save(); $comment = new ArticleComment(); $comment->set('content', 'unit test'); $comment->getPropObject('articleOID')->setValue($article->getOID()); $comment->rebuildTable(); $comment->save(); }
/** * Testing the loadTags() method for accessing the tags on a given object type directly. * * @since 1.0 */ public function testLoadTags() { $this->article->save(); $tagsA = $this->article->getPropObject('tags')->getRelatedObjects(); $tag = new Tag(); $tagsB = $tag->loadTags('Alpha\\Model\\Article', $this->article->getOID()); $this->assertEquals(count($tagsA), count($tagsB), 'testing the loadTags() method for accessing the tags on a given object type directly'); }
/** * Testing the method for getting related objects. * * @since 1.2.3 */ public function testGetRelated() { $this->article->save(); $article2 = $this->createArticle('unitTestArticle 2'); $article2->save(); $article3 = $this->createArticle('unitTestArticle 3'); $article3->save(); $provider = SearchProviderFactory::getInstance('Alpha\\Util\\Search\\SearchProviderTags'); $results = $provider->getRelated($this->article); $this->assertTrue(count($results) == 2, 'Testing the method for getting related objects'); $results = $provider->getRelated($this->article, 'all', 0, 1); $this->assertTrue(count($results) == 1, 'Testing the method for getting related objects honours limit param'); $results = $provider->getRelated($this->article, 'PersonObject'); $this->assertTrue(count($results) == 0, 'Testing the get related objects method honours returnType filtering'); }
/** * Testing that a BO attached to a controller that contains tags will have those tags mapped to the controller's keywords. * * @since 1.0 */ public function testTagsMapToMetaKeywords() { ActiveRecord::begin(); $this->article->save(); ActiveRecord::commit(); $tags = $this->article->getPropObject('tags')->getRelatedObjects(); $found = false; foreach ($tags as $tag) { if ($tag->get('content') == 'unittestarticle') { $found = true; break; } } $this->assertTrue($found, 'Testing the Tag::tokenize method returns a tag called "unittestarticle"'); $this->controller->setRecord($this->article); $this->assertEquals('unittestarticle,unittestarticletagone,unittestarticletagtwo', $this->controller->getKeywords(), 'Testing that a BO attached to a controller that contains tags will have those tags mapped to the controller\'s keywords'); }
/** * Testing the getRelatedObjects method with a ONE-TO-MANY and MANY-TO-MANY relation. * * @since 1.2.1 */ public function testGetRelatedObjects() { $group = new Rights(); $group->set('name', 'unittestgroup'); $group->save(); $person1 = new Person(); $person1->set('displayName', 'user1'); $person1->set('email', '*****@*****.**'); $person1->set('password', 'password'); $person1->save(); $lookup = $person1->getPropObject('rights')->getLookup(); $lookup->setValue(array($person1->getOID(), $group->getOID())); $lookup->save(); $person2 = new Person(); $person2->set('displayName', 'user2'); $person2->set('email', '*****@*****.**'); $person2->set('password', 'password'); $person2->save(); $lookup = $person2->getPropObject('rights')->getLookup(); $lookup->setValue(array($person2->getOID(), $group->getOID())); $lookup->save(); $person2->getPropObject('rights')->setValue($group->getOID()); $this->assertEquals(2, count($group->getPropObject('members')->getRelatedObjects('Alpha\\Model\\Rights')), 'testing the getRelatedObjects method with a MANY-TO-MANY relation'); $this->assertTrue($group->getPropObject('members')->getRelatedObjects('Alpha\\Model\\Rights')[0] instanceof Person, 'testing the getRelatedObjects method with a MANY-TO-MANY relation'); $article = new Article(); $article->set('title', 'unit test'); $article->set('description', 'unit test'); $article->set('content', 'unit test'); $article->set('author', 'unit test'); $article->save(); $comment1 = new ArticleComment(); $comment1->set('content', 'unit test'); $comment1->getPropObject('articleOID')->setValue($article->getOID()); $comment1->save(); $comment2 = new ArticleComment(); $comment2->set('content', 'unit test'); $comment2->getPropObject('articleOID')->setValue($article->getOID()); $comment2->save(); $this->assertEquals(2, count($article->getPropObject('comments')->getRelatedObjects()), 'testing the getRelatedObjects method with a ONE-TO-MANY relation'); $this->assertTrue($article->getPropObject('comments')->getRelatedObjects()[0] instanceof ArticleComment, 'testing the getRelatedObjects method with a ONE-TO-MANY relation'); }
/** * Testing the delete method also removes Tags related to the deleted record. * * @since 2.0.1 * @dataProvider getActiveRecordProviders */ public function testDeleteRelatedTags($provider) { $article = new Article(); $tag = new Tag(); $this->assertEquals(0, $tag->getCount(), 'Testing the delete method also removes Tags related to the deleted record.'); $article->set('title', 'Unit test'); $article->set('description', 'Unit test'); $article->set('author', 'Unit test'); $article->set('content', 'jupiter neptune venus'); $article->save(); $this->assertEquals(3, $tag->getCount(), 'Testing the delete method also removes Tags related to the deleted record.'); $article->delete(); $this->assertEquals(0, $article->getCount(), 'Testing the delete method also removes Tags related to the deleted record.'); $this->assertEquals(0, $tag->getCount(), 'Testing the delete method also removes Tags related to the deleted record.'); }