/** * @group Model * @group run */ public function testValidateValue() { /** @var TagModel $tagModel */ $tagModel = TagModel::getInstance(); $id = "12 баксов"; $this->assertTrue($tagModel->validateValue($id, 'id')); }
/** * @group Model */ public function testManyToManyLink() { $topicId = 98; $topicModel = TopicModel::getInstance(); $topicModel->truncate(); $this->assertInstanceOf('Model\\TopicModel', $topicModel); $tagId = 89; $secondTagId = 890; $tagModel = TagModel::getInstance(); $tagModel->truncate(); $this->assertInstanceOf('Model\\TagModel', $tagModel); $topicData = array('id' => $topicId, 'title' => 'link_test'); $topicModel->import($topicData); $topic = $topicModel->getById($topicId); $this->assertEquals($topicId, $topic->getId()); $tagData = array('id' => $tagId, 'name' => 'link_test'); $tagModel->import($tagData); $tag = $tagModel->getById($tagId); $this->assertEquals($tagId, $tag->getId()); $tagData = array('id' => $secondTagId, 'name' => 'link_test2'); $tagModel->import($tagData); $tag = $tagModel->getById($secondTagId); $this->assertEquals($secondTagId, $tag->getId()); $topicModel->linkTopicToTag($topicId, $tagId); $topic = $topicModel->getById($topicId, TopicCond::init()->with(TopicCond::WITH_TAG_COLLECTION)); $this->assertEquals(1, $topic->getTagCollection()->count()); $topicModel->linkTopicToTag($topicId, $secondTagId); $topic = $topicModel->getById($topicId, TopicCond::init()->with(TopicCond::WITH_TAG_COLLECTION)); $this->assertEquals(2, $topic->getTagCollection()->count()); $topicModel->linkTopicToTag($topicId, $secondTagId, false); $topic = $topicModel->getById($topicId, TopicCond::init()->with(TopicCond::WITH_TAG_COLLECTION)); $this->assertEquals(1, $topic->getTagCollection()->count()); }
/** * @group run */ public function testGetMethodWhenOneFieldEntity() { TagModel::getInstance()->delete(array('name' => 'testGetMethodWhenOneFieldEntity')); $importResult = TagModel::getInstance()->import(array('name' => 'testGetMethodWhenOneFieldEntity', '_tag_alias' => array('name' => 'testGetMethodWhenOneFieldEntity_alias'))); $tag = TagModel::getInstance()->getByName('testGetMethodWhenOneFieldEntity'); $this->assertTrue($tag->exists()); $tagAlias = TagAliasModel::getInstance()->getByTagAndName($tag, 'testGetMethodWhenOneFieldEntity_alias'); $this->assertTrue($tagAlias->exists()); }
/** * @group Model */ public function testApplyDefaultValues() { $input = array('id' => '1', '_inner' => array()); $default = array('id' => 100, 'name' => 'test'); $result = array(); TagModel::getInstance()->applyDefaultValues($input, $default, $result); $this->assertTrue(isset($result['name'])); $this->assertEquals('test', $result['name']); $input = array('id' => '1', '_inner' => array()); $default = array('id' => 100, 'name' => 'test'); $result = array('name' => 'notest'); TagModel::getInstance()->applyDefaultValues($input, $default, $result); }
/** * @group Model */ public function testPrepare() { /** @var TagModel $tagModel */ $tagModel = TagModel::getInstance(); $this->assertInstanceOf('Model\\TagModel', $tagModel); $this->assertInstanceOf('Model\\Cond\\TagCond', $tagModel->getCond()); $tagModel->delete(TagCond::init()->where(array('id' => 1))); $tagData = array('id' => 1, 'name' => 'test prepare'); $tagModel->import($tagData); $cond = TagCond::init()->with(TagCond::WITH_TAG_ALIAS); $tag = $tagModel->getById(1, $cond); $this->assertInstanceOf('Model\\Entity\\TagEntity', $tag); $this->assertEquals(1, $tag->getId()); }
public function testUpdateById() { /** @var TagModel $tagModel */ $tagModel = TagModel::getInstance(); $tagModel->truncate(); $id = 98223; $name = 'update test'; $tagData = array('id' => $id, 'name' => $name, 'unknown_field' => 'a-a-a-a'); $tagModel->import($tagData); $entity = $tagModel->getById($id); $this->assertEquals($id, $entity->getId()); $name = 'update2 test'; $updateTagData = array('name' => $name); $tagModel->updateById($updateTagData, $id); $entity = $tagModel->getById($id); $this->assertEquals($name, $entity->getName()); $name = 'update2 test'; $updateTagData = array('name' => $name); $tagModel->updateById($updateTagData, $entity); $entity = $tagModel->getById($id); $this->assertEquals($name, $entity->getName()); }
/** * @group Model */ public function testTableLinks() { $tagModel = TagModel::getInstance(); $this->assertInstanceOf('Model\\TagModel', $tagModel); }
public function testTagImport() { $tagModel = TagModel::getInstance(); $tagStatModel = TagStatModel::getInstance(); $tagAliasModel = TagAliasModel::getInstance(); $tagModel->truncate(); $tagStatModel->truncate(); $tagAliasModel->truncate(); $tagStatData = array('id' => 20, 'topic_count' => 30, '_tag' => array('id' => 20, 'name' => 'test_20')); $result = $tagStatModel->import($tagStatData); $tagStatCond = $tagStatModel->getCond()->with(TagStatCond::WITH_TAG); $tagStat = $tagStatModel->getById(20, $tagStatCond); $this->assertEquals(20, $tagStat->getId()); $this->assertEquals('test_20', $tagStat->getTag()->getName()); $tagModel->truncate(); $tagStatModel->truncate(); $tagAliasModel->truncate(); $tagData = array('id' => 10, 'name' => 'test', '_tag_alias' => array('id' => 11, 'name' => 'test2'), '_tag_stat' => array('topic_count' => 12)); $result = $tagModel->import($tagData); $this->assertEquals('10', $result->getResult()); $tagCond = $tagModel->getCond()->with(TagCond::WITH_TAG_ALIAS)->with(TagCond::WITH_TAG_STAT); $tag = $tagModel->getById(10, $tagCond); $this->assertEquals('test2', $tag->getTagAlias()->getName()); $this->assertEquals(10, $tag->getId()); $this->assertEquals(10, $tag->getTagStat()->getId()); $tag = $tagModel->getByTagStat(10); $this->assertEquals('test', $tag->getName()); $tag = $tagModel->getByTagAlias(11); $this->assertEquals('test', $tag->getName()); $tag = $tagModel->getByTagStat(10); $this->assertEquals('test', $tag->getName()); $tagStat = $tagStatModel->getByTag(10); $this->assertEquals(12, $tagStat->getTopicCount()); $tagStat = $tagAliasModel->getByTag(10); $this->assertEquals('test2', $tagStat->getName()); }