Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ScoreBuilderTest.php
Go to the documentation of this file.
1 <?php
7 
10 
11 class ScoreBuilderTest extends \PHPUnit\Framework\TestCase
12 {
13  public function testBuild()
14  {
16  $builder = (new ObjectManager($this))->getObject(\Magento\Framework\Search\Adapter\Mysql\ScoreBuilder::class);
17 
18  $builder->startQuery(); // start one query
19 
20  $builder->addCondition('someCondition1');
21 
22  $builder->startQuery(); // start two query
23 
24  $builder->addCondition('someCondition2');
25  $builder->addCondition('someCondition3');
26 
27  $builder->startQuery(); // start three query
28 
29  $builder->addCondition('someCondition4');
30  $builder->addCondition('someCondition5');
31 
32  $builder->endQuery(10.1); // end three query
33 
34  $builder->startQuery(); // start four query
35 
36  $builder->addCondition('someCondition6');
37  $builder->addCondition('someCondition7');
38 
39  $builder->endQuery(10.2); // end four query
40  $builder->endQuery(10.3); // start two query
41  $builder->endQuery(10.4); // start one query
42 
43  $builder->startQuery();
44  $builder->endQuery(1);
45 
46  $result = $builder->build();
47 
48  $weightExpression = 'POW(2, ' . ScoreBuilder::WEIGHT_FIELD . ')';
49  $expected = '((LEAST((someCondition1), 1000000) * %1$s + (LEAST((someCondition2), 1000000) * %1$s'
50  . ' + LEAST((someCondition3), 1000000) * %1$s + '
51  . '(LEAST((someCondition4), 1000000) * %1$s + LEAST((someCondition5), 1000000) * %1$s) * 10.1'
52  . ' + (LEAST((someCondition6), 1000000) * %1$s + '
53  . 'LEAST((someCondition7), 1000000) * %1$s) * 10.2) * 10.3) * 10.4 + (0)) AS ' . $builder->getScoreAlias();
54  $expected = sprintf($expected, $weightExpression);
55  $this->assertEquals($expected, $result);
56  }
57 }