Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
UsesTest.php
Go to the documentation of this file.
1 <?php
7 
9 
12 class UsesTest extends \PHPUnit\Framework\TestCase
13 {
17  protected $uses;
18 
22  public function setUp()
23  {
24  $this->uses = new Uses();
25  }
26 
35  public function testHasUses($tokens)
36  {
37  foreach ($tokens as $k => $token) {
38  $this->uses->parse($token, $k);
39  }
40  $this->assertTrue($this->uses->hasUses());
41  }
42 
48  public function usesDataProvider()
49  {
50  return [
51  'simple' => [
52  [
53  0 => [T_USE, 'use '],
54  1 => [T_STRING, 'Magento'],
55  2 => [T_NS_SEPARATOR, '\\'],
56  3 => [T_STRING, 'Core'],
57  4 => [T_NS_SEPARATOR, '\\'],
58  5 => [T_STRING, 'Model'],
59  6 => [T_NS_SEPARATOR, '\\'],
60  7 => [T_STRING, 'Object'],
61  8 => ';',
62  ],
63  ],
64  'several_simple' => [
65  [
66  0 => [T_USE, 'use '],
67  1 => [T_STRING, 'Magento'],
68  2 => [T_NS_SEPARATOR, '\\'],
69  3 => [T_STRING, 'Core'],
70  4 => [T_NS_SEPARATOR, '\\'],
71  5 => [T_STRING, 'Model'],
72  6 => [T_NS_SEPARATOR, '\\'],
73  7 => [T_STRING, 'Object'],
74  8 => ';',
75  9 => [T_USE, 'use '],
76  10 => [T_STRING, 'Magento'],
77  11 => [T_NS_SEPARATOR, '\\'],
78  12 => [T_STRING, 'Core'],
79  13 => [T_NS_SEPARATOR, '\\'],
80  14 => [T_STRING, 'Model'],
81  15 => [T_NS_SEPARATOR, '\\'],
82  16 => [T_STRING, 'Object2 '],
83  17 => [T_AS, 'as '],
84  18 => [T_STRING, 'OtherObject'],
85  19 => ';',
86  ],
87  ],
88  'several_with_comma_separate' => [
89  [
90  0 => [T_USE, 'use '],
91  1 => [T_STRING, 'Magento'],
92  2 => [T_NS_SEPARATOR, '\\'],
93  3 => [T_STRING, 'Core'],
94  4 => [T_NS_SEPARATOR, '\\'],
95  5 => [T_STRING, 'Model'],
96  6 => [T_NS_SEPARATOR, '\\'],
97  7 => [T_STRING, 'Object'],
98  8 => ',',
99  9 => [T_STRING, 'Magento'],
100  10 => [T_NS_SEPARATOR, '\\'],
101  11 => [T_STRING, 'Core'],
102  12 => [T_NS_SEPARATOR, '\\'],
103  13 => [T_STRING, 'Model'],
104  14 => [T_NS_SEPARATOR, '\\'],
105  15 => [T_STRING, 'Object2 '],
106  16 => [T_AS, 'as '],
107  17 => [T_STRING, 'OtherObject'],
108  18 => ';',
109  ],
110  ]
111  ];
112  }
113 
120  {
121  $this->assertEquals(
122  '\Magento\Core\Model\Object2',
123  $this->uses->getClassNameWithNamespace('\Magento\Core\Model\Object2')
124  );
125  }
126 
134  {
135  foreach ($tokens as $k => $token) {
136  $this->uses->parse($token, $k);
137  }
138 
139  $this->assertEquals('Magento\Core\Model\Object2', $this->uses->getClassNameWithNamespace($className));
140  }
141 
147  public function classNamesDataProvider()
148  {
149  return [
150  'class_from_uses' => [
151  'Object2',
152  [
153  0 => [T_USE, 'use '],
154  1 => [T_STRING, 'Magento'],
155  2 => [T_NS_SEPARATOR, '\\'],
156  3 => [T_STRING, 'Core'],
157  4 => [T_NS_SEPARATOR, '\\'],
158  5 => [T_STRING, 'Model'],
159  6 => [T_NS_SEPARATOR, '\\'],
160  7 => [T_STRING, 'Object2'],
161  8 => ';'
162  ],
163  ],
164  'class_from_uses_with_as' => [
165  'ObjectOther',
166  [
167  0 => [T_USE, 'use '],
168  1 => [T_STRING, 'Magento'],
169  2 => [T_NS_SEPARATOR, '\\'],
170  3 => [T_STRING, 'Core'],
171  4 => [T_NS_SEPARATOR, '\\'],
172  5 => [T_STRING, 'Model'],
173  6 => [T_NS_SEPARATOR, '\\'],
174  7 => [T_STRING, 'Object2 '],
175  8 => [T_AS, 'as '],
176  9 => [T_STRING, 'ObjectOther'],
177  10 => ';'
178  ],
179  ]
180  ];
181  }
182 }
$tokens
Definition: cards_list.phtml:9
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31