示例#1
0
 /**
  * Test for fetch aliased related data in prepare on Many To Many relation
  */
 public function testAliasedFetchWithInPrepeareDirectlyOnManyToOneLink()
 {
     /** @var TagModel $tagModel */
     $tagModel = TagModel::getInstance();
     /** @var TopicModel $tagModel */
     $topicModel = TopicModel::getInstance();
     $tagModel->delete(array('id' => 800));
     $baseTagData = array('id' => 800, 'name' => 'base_Tag test one to one', '_topic_as_base_tag' => array('id' => 801, 'title' => 'base_topic test one to one inner'), '_topic_as_additional_tag' => array('id' => 300, 'title' => 'base_topic test one to one inner'));
     $result = $tagModel->import($baseTagData);
     $cond = TopicCond::init()->with(TopicCond::WITH_BASE_TAG)->with(TopicCond::WITH_ADDITIONAL_TAG);
     $entity = $topicModel->getById(801, $cond);
     $this->assertTrue($entity->getBaseTag()->exists());
     $this->assertEquals(800, $entity->getBaseTag()->getId());
     $this->assertEquals('base_Tag test one to one', $entity->getBaseTag()->getName());
     $this->assertFalse($entity->getAdditionalTag()->exists());
     $cond = TopicCond::init()->with(TopicCond::WITH_BASE_TAG)->with(TopicCond::WITH_ADDITIONAL_TAG);
     $entity = $topicModel->getById(300, $cond);
     $this->assertFalse($entity->getBaseTag()->exists());
     $this->assertTrue($entity->getAdditionalTag()->exists());
     $this->assertEquals(800, $entity->getAdditionalTag()->getId());
     $this->assertEquals('base_Tag test one to one', $entity->getAdditionalTag()->getName());
     $topicModel->delete(array('id' => 10));
     $topicData = array('id' => 10, 'title' => 'test prepare', '_base_tag' => array('id' => 124, 'name' => 'base_tag test prepare'));
     $topicModel->import($topicData);
     $cond = TopicCond::init()->with(TopicCond::WITH_BASE_TAG);
     $entity = $topicModel->getById(10, $cond);
     $this->assertTrue($entity->getBaseTag()->exists());
     $this->assertEquals(124, $entity->getBaseTag()->getId());
     $this->assertEquals('base_tag test prepare', $entity->getBaseTag()->getName());
 }
示例#2
0
文件: LinkTest.php 项目: meniam/model
 /**
  * @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());
 }
示例#3
0
 /**
  * Тестируем выборку с помощью WITH когда связть Many To Many
  * @covers \Model\AbstractModel::__call
  */
 public function testWithFetchManyToMany()
 {
     $tagModel = TagModel::getInstance();
     $tagModel->truncate();
     $topicModel = TopicModel::getInstance();
     $topicModel->truncate();
     $topicData = array('id' => '12', 'title' => 'topic_1', '_tag_collection' => array(array('name' => 'topic_tag_1'), array('name' => 'topic_tag_2')));
     $topicModel->import($topicData);
     $topicCond = TopicCond::init()->with(TopicCond::WITH_TAG)->with(TopicCond::WITH_TAG_COLLECTION);
     $topic = $topicModel->getById(12, $topicCond);
     $this->assertEquals('topic_1', $topic->getTitle());
     $this->assertInstanceOf('Model\\Entity\\TagEntity', $topic->getTag());
     $this->assertEquals('topic_tag_1', $topic->getTag()->getName());
     $this->assertInstanceOf('Model\\Collection\\TagCollection', $topic->getTagCollection());
     $this->assertEquals(2, $topic->getTagCollection()->count());
 }