/** * @see https://github.com/yiisoft/yii2/issues/4018 */ public function testFindCompositeLink() { $articles = ArticleIndex::find()->with('sourceCompositeLink')->all(); $this->assertEquals(2, count($articles)); $this->assertTrue($articles[0]->isRelationPopulated('sourceCompositeLink')); $this->assertNotEmpty($articles[0]->sourceCompositeLink); $this->assertTrue($articles[1]->isRelationPopulated('sourceCompositeLink')); $this->assertNotEmpty($articles[1]->sourceCompositeLink); }
public function testActiveQuery() { $provider = new ActiveDataProvider(['query' => ArticleIndex::find()->orderBy('id ASC')]); $models = $provider->getModels(); $this->assertEquals(2, count($models)); $this->assertTrue($models[0] instanceof ArticleIndex); $this->assertTrue($models[1] instanceof ArticleIndex); $this->assertEquals([1, 2], $provider->getKeys()); $provider = new ActiveDataProvider(['query' => ArticleIndex::find(), 'pagination' => ['pageSize' => 1]]); $models = $provider->getModels(); $this->assertEquals(1, count($models)); }
/** * @see https://github.com/yiisoft/yii2/issues/4830 * * @depends testFind */ public function testFindQueryReuse() { $result = ArticleIndex::find()->andWhere(['author_id' => 1]); $this->assertTrue($result->one() instanceof ArticleIndex); $this->assertTrue($result->one() instanceof ArticleIndex); $result = ArticleIndex::find()->match('dogs'); $this->assertTrue($result->one() instanceof ArticleIndex); $this->assertTrue($result->one() instanceof ArticleIndex); }
public function testCallKeywords() { $text = 'table pencil'; $rows = ArticleIndex::callKeywords($text); $this->assertNotEmpty($rows, 'Unable to call keywords!'); $this->assertArrayHasKey('tokenized', $rows[0], 'No tokenized keyword!'); $this->assertArrayHasKey('normalized', $rows[0], 'No normalized keyword!'); }
/** * @depends testFindEager */ public function testFindWithSnippets() { $articles = ArticleIndex::find()->match('about')->with('source')->snippetByModel()->all(); $this->assertEquals(2, count($articles)); }
public function getIndex() { return new ActiveQuery(ArticleIndex::className(), ['primaryModel' => $this, 'link' => ['id' => 'id'], 'multiple' => false]); }