Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TriggerTest.php
Go to the documentation of this file.
1 <?php
7 
8 class TriggerTest extends \PHPUnit\Framework\TestCase
9 {
13  protected $_object;
14 
15  protected function setUp()
16  {
17  $this->_object = new \Magento\Framework\DB\Ddl\Trigger();
18  }
19 
23  public function testGetListOfEvents()
24  {
26  $this->assertInternalType('array', $actualEventTypes);
27  $this->assertCount(3, $actualEventTypes);
28  $this->assertTrue(in_array(\Magento\Framework\DB\Ddl\Trigger::EVENT_INSERT, $actualEventTypes));
29  $this->assertTrue(in_array(\Magento\Framework\DB\Ddl\Trigger::EVENT_UPDATE, $actualEventTypes));
30  $this->assertTrue(in_array(\Magento\Framework\DB\Ddl\Trigger::EVENT_DELETE, $actualEventTypes));
31  }
32 
36  public function testGetListOfTimes()
37  {
39  $this->assertInternalType('array', $actualTimeTypes);
40  $this->assertCount(2, $actualTimeTypes);
41  $this->assertTrue(in_array(\Magento\Framework\DB\Ddl\Trigger::TIME_AFTER, $actualTimeTypes));
42  $this->assertTrue(in_array(\Magento\Framework\DB\Ddl\Trigger::TIME_BEFORE, $actualTimeTypes));
43  }
44 
48  public function testGetNameWithSetName()
49  {
50  $triggerName = 'TEST_TRIGGER_NAME' . mt_rand(100, 999);
51 
52  $this->_object->setName($triggerName);
53  $this->assertEquals(strtolower($triggerName), $this->_object->getName());
54  }
55 
62  public function testSetNameWithException()
63  {
64  $triggerName = new \stdClass();
65  //non string
66 
67  $this->_object->setName($triggerName);
68  }
69 
76  public function testSetTableWithException()
77  {
78  $tableName = new \stdClass();
79  //non string
80 
81  $this->_object->setTable($tableName);
82  }
83 
87  public function testSetTableName()
88  {
89  $names = ['PREFIX_table', 'prefix_table'];
90  foreach ($names as $name) {
91  $this->_object->setTable($name);
92  $this->assertEquals($name, $this->_object->getTable());
93  }
94  }
95 
102  public function testGetNameWithException()
103  {
104  $tableName = 'TEST_TABLE_NAME_' . mt_rand(100, 999);
106 
107  $this->_object->setTable($tableName)->setTime(\Magento\Framework\DB\Ddl\Trigger::TIME_AFTER)->setEvent($event);
108 
109  $this->_object->getName();
110  }
111 
118  public function testGetTimeWithException()
119  {
120  $tableName = 'TEST_TABLE_NAME_' . mt_rand(100, 999);
122 
123  $this->_object->setTable($tableName)->setEvent($event);
124 
125  $this->_object->getTime();
126  }
127 
134  public function testGetTableWithException()
135  {
137 
138  $this->_object->setTime(\Magento\Framework\DB\Ddl\Trigger::TIME_AFTER)->setEvent($event);
139 
140  $this->_object->getTable();
141  }
142 
149  public function testGetEventWithException()
150  {
151  $tableName = 'TEST_TABLE_NAME_' . mt_rand(100, 999);
152 
153  $this->_object->setTable($tableName)->setTime(\Magento\Framework\DB\Ddl\Trigger::TIME_AFTER);
154 
155  $this->_object->getEvent();
156  }
157 
162  public function testWrongEventTypeException()
163  {
164  $this->_object->setEvent('UNSUPORT EVENT TYPE');
165  }
166 
171  public function testWrongTimeTypeException()
172  {
173  $this->_object->setTime('UNSUPORT TIME TYPE');
174  }
175 
183  {
184  $statement = new \stdClass();
185  //non string
186 
187  $this->_object->addStatement($statement);
188  }
189 
193  public function getStatementsDataProvider()
194  {
195  return [['SQL', ['SQL;']], ['SQL;', ['SQL;']]];
196  }
197 
203  public function testAddStatement($param, $expected)
204  {
205  $this->_object->addStatement($param);
206  $this->assertEquals($expected, $this->_object->getStatements());
207  }
208 
212  public function testGetStatements()
213  {
214  $this->assertEquals([], $this->_object->getStatements());
215  }
216 }
$tableName
Definition: trigger.php:13
if(!isset($_GET['name'])) $name
Definition: log.php:14