/** * Set up tests. * * @since 2.0 */ protected function setUp() { $config = ConfigProvider::getInstance(); $config->set('session.provider.name', 'Alpha\\Util\\Http\\Session\\SessionProviderArray'); $tag = new Tag(); $tag->rebuildTable(); $denum = new DEnum(); $denum->rebuildTable(); $item = new DEnumItem(); $item->rebuildTable(); $article = new Article(); $article->rebuildTable(); $articleVote = new ArticleVote(); $articleVote->rebuildTable(); $articleComment = new ArticleComment(); $articleComment->rebuildTable(); $person = new Person(); $person->rebuildTable(); $rights = new Rights(); $rights->rebuildTable(); $rights->set('name', 'Standard'); $rights->save(); $rights = new Rights(); $rights->set('name', 'Admin'); $rights->save(); }
/** * Set up tests. * * @since 2.0 */ protected function setUp() { $config = ConfigProvider::getInstance(); $config->set('session.provider.name', 'Alpha\\Util\\Http\\Session\\SessionProviderArray'); $action = new ActionLog(); $action->rebuildTable(); $tag = new Tag(); $tag->rebuildTable(); $denum = new DEnum(); $denum->rebuildTable(); $item = new DEnumItem(); $item->rebuildTable(); // create a default article DEnum category $denum = new DEnum('Alpha\\Model\\Article::section'); $item->set('value', 'Main'); $item->set('DEnumID', $denum->getID()); $item->save(); $article = new Article(); $article->rebuildTable(); $articleVote = new ArticleVote(); $articleVote->rebuildTable(); $articleComment = new ArticleComment(); $articleComment->rebuildTable(); $person = new Person(); $person->rebuildTable(); $rights = new Rights(); $rights->rebuildTable(); $rights->set('name', 'Standard'); $rights->save(); $rights = new Rights(); $rights->set('name', 'Admin'); $rights->save(); }
/** * Set up tests. * * @since 2.0 */ protected function setUp() { parent::setUp(); $config = ConfigProvider::getInstance(); $config->set('session.provider.name', 'Alpha\\Util\\Http\\Session\\SessionProviderArray'); $tag = new Tag(); $tag->rebuildTable(); $article = new Article(); $article->rebuildTable(); }
/** * Set up tests. * * @since 2.0 */ protected function setUp() { parent::setUp(); $tag = new Tag(); $tag->rebuildTable(); $denum = new DEnum(); $denum->rebuildTable(); $item = new DEnumItem(); $item->rebuildTable(); $article = new Article(); $article->rebuildTable(); $denum = new DEnum('Alpha\\Model\\Article::section'); $item->set('DEnumID', $denum->getOID()); $item->set('value', 'Test'); $item->save(); $this->DEnumID = $denum->getOID(); $this->article = $this->createArticle('unitTestArticle'); }
/** * Set up tests. * * @since 2.0 */ protected function setUp() { $config = ConfigProvider::getInstance(); $config->set('session.provider.name', 'Alpha\\Util\\Http\\Session\\SessionProviderArray'); $tag = new Tag(); $tag->rebuildTable(); $denum = new DEnum(); $denum->rebuildTable(); $item = new DEnumItem(); $item->rebuildTable(); $article = new Article(); $article->rebuildTable(); $denum = new DEnum('Alpha\\Model\\Article::section'); $item->set('DEnumID', $denum->getOID()); $item->set('value', 'Test'); $item->save(); $this->DEnumID = $denum->getOID(); $this->article = $this->createArticle('unitTestArticle'); }
/** * After creating a new Article, tokenize the description field to form a set * of automated tags and save them. * * @since 1.0 */ protected function after_save_callback() { if ($this->getVersion() == 1 && $this->tags instanceof \Alpha\Model\Type\Relation) { // update the empty tags values to reference this OID $this->tags->setValue($this->OID); foreach ($this->taggedAttributes as $tagged) { $tags = Tag::tokenize($this->get($tagged), 'Alpha\\Model\\Article', $this->getOID()); foreach ($tags as $tag) { try { $tag->save(); } catch (ValidationException $e) { /* * The unique key has most-likely been violated because this BO is already tagged with this * value, so we can ignore in this case. */ } } } } $this->setupRels(); }
/** * {@inheritdoc} */ public function index($sourceObject) { $taggedAttributes = $sourceObject->getTaggedAttributes(); foreach ($taggedAttributes as $tagged) { $tags = Tag::tokenize($sourceObject->get($tagged), get_class($sourceObject), $sourceObject->getOID()); foreach ($tags as $tag) { try { $tag->save(); } catch (ValidationException $e) { /* * The unique key has most-likely been violated because this BO is already tagged with this * value, so we can ignore in this case. */ } } } }
/** * 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 that the index method is generating tags as expected. * * @since 1.2.3 */ public function testIndex() { $this->article->save(); $tag = new Tag(); $tag->dropTable(); $tag->rebuildTable(); $provider = SearchProviderFactory::getInstance('Alpha\\Util\\Search\\SearchProviderTags'); $provider->index($this->article); $tags = $this->article->getPropObject('tags')->getRelatedObjects(); $found = false; foreach ($tags as $tag) { if ($tag->get('content') == 'unittestarticle') { $found = true; break; } } $this->assertTrue($found, 'Testing that the index method is generating tags as expected'); }
/** * 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.'); }
/** * Constructor. * * @param $limit The maximum amount of tags to include in the cloud. * @param $cacheKey Set this optional value to attempt to store the tag cloud array in the available cache for 24hrs (cache.provider.name). * * @since 1.0 */ public function __construct($limit, $cacheKey = '') { $config = ConfigProvider::getInstance(); self::$logger = new Logger('TagCloud'); if ($cacheKey != '' && $config->get('cache.provider.name') != '') { $cache = CacheProviderFactory::getInstance($config->get('cache.provider.name')); $this->popTags = $cache->get($cacheKey); // cache look-up failed, so add it for the next time if (!$this->popTags) { self::$logger->debug('Cache lookup on the key [' . $cacheKey . '] failed, regenerating popular tags...'); $this->popTags = Tag::getPopularTagsArray($limit); $cache->set($cacheKey, $this->popTags, 86400); } else { $this->popTags = array_slice($this->popTags, 0, $limit); self::$logger->debug('Cache lookup on the key [' . $cacheKey . '] succeeded'); } } else { $this->popTags = Tag::getPopularTagsArray($limit); } }
/** * Regenerates the tags on the supplied list of active records. * * @param array $records * * @since 1.0 */ private function regenerateTagsOnRecords($records) { foreach ($records as $record) { foreach ($record->get('taggedAttributes') as $tagged) { $tags = Tag::tokenize($record->get($tagged), get_class($record), $record->getOID()); foreach ($tags as $tag) { try { $tag->save(); } catch (ValidationException $e) { /* * The unique key has most-likely been violated because this record is already tagged with this * value, so we can ignore in this case. */ } } } } }
/** * (non-PHPdoc). * * @see alpha/lib/PEAR/PHPUnit-3.2.9/PHPUnit/Framework/PHPUnit_Framework_TestCase::tearDown() * @since 1.0 */ protected function tearDown() { $config = ConfigProvider::getInstance(); $config->set('session.provider.name', 'Alpha\\Util\\Http\\Session\\SessionProviderArray'); $this->controller->abort(); $this->article->dropTable(); unset($this->article); unset($this->controller); $this->person->dropTable(); unset($this->person); $this->group->dropTable(); $this->group->dropTable('Person2Rights'); unset($this->group); $article = new Article(); $article->dropTable(); $tag = new Tag(); $tag->dropTable(); $denum = new DEnum(); $denum->dropTable(); $item = new DEnumItem(); $item->dropTable(); }