1: <?php
2: namespace tests\integration\barebones\models\examples;
3:
4: use tests\integration\barebones\BarebonesTestCase;
5: use tests\integration\barebones\BarebonesConstants;
6: use barebones\models\examples\ExampleModel;
7: use PatientModel;
8: use PhysicianModel;
9: use ProviderModel;
10: use Session;
11:
12: class ExampleModelBasicsTest extends BarebonesTestCase
13: {
14: public function testSchemaFunctions()
15: {
16: error_reporting(E_ALL);
17: Session::set('usr_cur_customer_id', 8);
18: $this->assertEquals('customer', ExampleModel::getConnection());
19: $this->assertEquals('examples', ExampleModel::getTable());
20: $this->assertEquals('exa_id', ExampleModel::getPrimaryKey());
21: $this->assertTrue(ExampleModel::attributeIsNullable('exa_datetime'));
22: $this->assertTrue(ExampleModel::hasSchemaAttributeKey('exa_phone'));
23: $this->assertEquals('varchar', ExampleModel::getSchemaAttributeType('exa_phone'));
24:
25: $this->assertEquals('customer', PatientModel::getConnection());
26: $this->assertEquals('patients', PatientModel::getTable());
27: $this->assertEquals('pat_id', PatientModel::getPrimaryKey());
28:
29: $this->assertEquals('customer', PhysicianModel::getConnection());
30: $this->assertEquals('physicians', PhysicianModel::getTable());
31: $this->assertEquals('phy_id', PhysicianModel::getPrimaryKey());
32: $this->assertEquals('customer', ProviderModel::getConnection());
33: $this->assertEquals('physicians', ProviderModel::getTable());
34: $this->assertEquals('phy_id', ProviderModel::getPrimaryKey());
35: }
36:
37: public function testConstructors()
38: {
39: Session::set('usr_cur_customer_id', 8);
40: $testString = "sddsfgdsfgsfgsd";
41:
42:
43: $example = new ExampleModel();
44:
45:
46: $this->assertNotNull($example->exa_ssn);
47:
48:
49:
50:
51: $example->exa_string = $testString;
52: $example->save();
53: $this->assertNotEquals(0, $example->id);
54:
55:
56: $exampleByID = new ExampleModel($example->exa_id);
57: $this->assertEquals($example->exa_id, $exampleByID->exa_id);
58:
59:
60: $exampleByArray = new ExampleModel(['exa_string' => $testString]);
61: $this->assertEquals($example->exa_id, $exampleByArray->exa_id);
62:
63:
64: $example = new ExampleModel();
65: $example->setDatabase('_435');
66: $example->exa_string = $testString;
67: $example->save();
68: $exampleDBInConstructor = new ExampleModel('_435', $example->exa_id);
69: $this->assertEquals($example->exa_id, $exampleDBInConstructor->exa_id);
70:
71:
72:
73: $example = new ExampleModel(['exa_string' => $testString], ['fetch' => false]);
74: $this->assertEquals($testString, $example->exa_string);
75: $this->assertEquals(0, $example->id);
76: }
77:
78: public function testInsert()
79: {
80: Session::set('usr_cur_customer_id', 8);
81: $testString = "sddsfgdsfgsfgsd";
82:
83:
84: $example = new ExampleModel();
85: $example->exa_string = $testString;
86:
87: $example->exa_phone = null;
88: $example->save();
89: $this->assertNotEquals(0, $example->id);
90:
91: $exampleInsertResult = new ExampleModel($example->exa_id);
92: $this->assertEquals($testString, $exampleInsertResult->exa_string);
93: }
94:
95: public function testUpdate()
96: {
97: Session::set('usr_cur_customer_id', 8);
98: $testString = "sddsfgdsfgsfgsd";
99: $updateString = "UPDATED";
100:
101:
102: $example = new ExampleModel();
103: $example->exa_string = $testString;
104:
105: $example->exa_phone = null;
106: $example->save();
107:
108: $exampleUpdate = new ExampleModel($example->exa_id);
109: $exampleUpdate->exa_string = $updateString;
110: $exampleUpdate->save();
111:
112: $exampleUpdateResult = new ExampleModel($example->exa_id);
113: $this->assertEquals($updateString, $exampleUpdateResult->exa_string);
114: }
115:
116: public function testDestroy()
117: {
118: Session::set('usr_cur_customer_id', 8);
119: $testString = "sddsfgdsfgsfgsd";
120:
121:
122: $example = new ExampleModel();
123: $example->exa_string = $testString;
124: $example->save();
125: $this->assertNotEquals(0, $example->id);
126: $example->destroy();
127:
128: $exampleDestroyed = ExampleModel::findFirstMatch(['exa_id' => $example->id]);
129: $this->assertNull($exampleDestroyed);
130: }
131:
132: public function testAttributeSetting()
133: {
134: Session::set('usr_cur_customer_id', 8);
135: $example = new ExampleModel();
136: $example->exa_string = "Test";
137: $example->save();
138: }
139:
140: public function testAttachedPropertiesVsAttributes()
141: {
142: Session::set('usr_cur_customer_id', 8);
143: $example = new ExampleModel();
144:
145:
146: $example->delete_method = "DELETE";
147: $example->pri = "DELETE";
148: $this->assertEquals($example->getPrimaryKey(), 'exa_id');
149: $example->db_name = "DELETE";
150: }
151: }
152: