Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ComplexGeneratorTest.php
Go to the documentation of this file.
1 <?php
8 
11 
16 class ComplexGeneratorTest extends \PHPUnit\Framework\TestCase
17 {
23  protected $_pattern;
24 
30  protected function getPattern()
31  {
32  if (!$this->_pattern instanceof Pattern) {
33  $patternData = [
34  [
35  'id' => '%s',
36  'name' => 'Static',
37  'calculated' => function ($index) {
38  return $index * 10;
39  },
40  ],
41  [
42  'name' => 'xxx %s'
43  ],
44  [
45  'name' => 'yyy %s'
46  ],
47  ];
48  $this->_pattern = new Pattern();
49  $this->_pattern->setHeaders(array_keys($patternData[0]));
50  $this->_pattern->setRowsSet($patternData);
51  }
52  return $this->_pattern;
53  }
54 
60  public function testIteratorInterface()
61  {
62  $model = new Generator($this->getPattern(), 2);
63  $rows = [];
64  foreach ($model as $row) {
65  $rows[] = $row;
66  }
67  $this->assertEquals(
68  [
69  ['id' => '1', 'name' => 'Static', 'calculated' => 10],
70  ['id' => '', 'name' => 'xxx 1', 'calculated' => ''],
71  ['id' => '', 'name' => 'yyy 1', 'calculated' => ''],
72  ['id' => '2', 'name' => 'Static', 'calculated' => 20],
73  ['id' => '', 'name' => 'xxx 2', 'calculated' => ''],
74  ['id' => '', 'name' => 'yyy 2', 'calculated' => ''],
75  ],
76  $rows
77  );
78  }
79 
85  public function testGetIndex()
86  {
87  $model = new Generator($this->getPattern(), 4);
88  for ($i = 0; $i < 32; $i++) {
89  $this->assertEquals($model->getIndex($i), floor($i / $this->getPattern()->getRowsCount()) + 1);
90  }
91  }
92 }
$i
Definition: gallery.phtml:31
$index
Definition: list.phtml:44