public function testUpsert() { $extid = substr(time(), 5); // create $j = new Sobject_Jyugyoin__c(); $j->Name = "Test Member" . time(); $j->JyugyoinBango__c = $extid; $j->Age__c = 30; $result = $j->upsert('JyugyoinBango__c'); $this->assertTrue($result); $this->assertNotNull($j->Id); // update $j2 = new Sobject_Jyugyoin__c(); $j2->Name = "Test Member 2" . time(); $j2->JyugyoinBango__c = $extid; $result = $j2->fieldnull('Age__c')->upsert('JyugyoinBango__c'); $this->assertTrue($result); $this->assertEqual($j->Id, $j2->Id); $j3 = Sobject_Jyugyoin__c::neu()->eq('Id', $j2->Id)->find(); $this->assertEqual($j3->Name, $j2->Name); $this->assertEqual($j3->Age__c, ""); // delete $result = Sobject_Jyugyoin__c::neu()->delete($j2->Id); $this->assertTrue($result); }
public function testUpdateAll() { $j = new Sobject_Jyugyoin__c(); $j->Name = "佐藤" . time(); $j->JyugyoinBango__c = substr(time(), 5); $j->Age__c = 30; $result = $j->insert(); $this->assertTrue($result); $this->assertNotNull($j->Id); $j2 = new Sobject_Jyugyoin__c(); $j2->Id = $j->Id; $j2->Name = "加藤"; $j2->fieldnull('Age__c'); $j3 = new Sobject_Jyugyoin__c(); $j3->Name = "Kato"; $j3->Id = '12345600'; Srecord_Schema::updateAll(array($j2, $j3)); $this->assertEqual($j2->getState(), Srecord_ActiveRecord::STATE_SUCCESS); $j4 = Sobject_Jyugyoin__c::neu()->find($j2->Id); $this->assertEqual($j4->Age__c, ""); $this->assertEqual($j4->Name, "加藤"); $this->assertEqual($j3->getState(), SRecord_ActiveRecord::STATE_FAIL); $errors = $j3->getErrors(); print_r($errors); }
public function testCopyToThis() { $value = array('Name' => 'Sato', 'Id' => '11111111111', 'JyugyoinBango__c' => '12345'); $j = new Sobject_Jyugyoin__c(); $j->copyToThis($value); $this->assertEqual($j->Name, $value['Name']); $this->assertEqual($j->Id, $value['Id']); $this->assertEqual($j->JyugyoinBango__c, $value['JyugyoinBango__c']); }
public function testUpsert() { $extid = substr(time(), 5); // create $j = new Sobject_Jyugyoin__c(); $j->Name = "Test Member" . time(); $j->JyugyoinBango__c = $extid; $j->Age__c = 30; Srecord_Schema::upsertAll('JyugyoinBango__c', array($j)); $this->assertEqual($j->getState(), Srecord_ActiveRecord::STATE_SUCCESS); $this->assertTrue(strlen($j->Id) > 1); }
public function testCreateAll() { $j = new Sobject_Jyugyoin__c(); $j->Name = "佐藤" . time(); $j2 = new Sobject_Jyugyoin__c(); $j2->Name = "Sato" . time(); $j2->JyugyoinBango__c = substr(time(), 5); // fail. Srecord_Schema::createAll(array($j, $j2)); $this->assertEqual($j->getState(), Srecord_ActiveRecord::STATE_FAIL); $this->assertEqual($j->getErrors()->statusCode, "REQUIRED_FIELD_MISSING"); $this->assertEqual($j->Id, ""); $this->assertEqual($j2->getState(), Srecord_ActiveRecord::STATE_SUCCESS); $this->assertTrue(strlen($j2->Id) > 1); print $j2->Id; }
public function testUpdateEntity() { $j = new Sobject_Jyugyoin__c(); $j->Name = "Bob" . time(); $j->JyugyoinBango__c = substr(time(), 5); $j->Age__c = 30; $result = $j->insert(); $this->assertTrue($result); $this->assertNotNull($j->Id); $j2 = Sobject_Jyugyoin__c::neu()->eq('Id', $j->Id)->find(); $j2->Name = "Cathy"; $j2->Age__c = ""; $result = $j2->updateEntity(); $this->assertTrue($result); if ($result == FALSE) { print_r($j2->getErrors()); return; } $j3 = Sobject_Jyugyoin__c::neu()->eq('Id', $j->Id)->find(); $this->assertEqual($j3->Age__c, ""); $this->assertEqual($j3->Name, "Cathy"); }
public function testBooleanField() { $j = new Sobject_Jyugyoin__c(); $j->Name = "佐藤" . time(); $j->JyugyoinBango__c = substr(time(), 5); $j->Age__c = 30; $j->health__c = TRUE; $result = $j->insert(); $this->assertTrue($result); $this->assertNotNull($j->Id); $check = Sobject_Jyugyoin__c::neu()->find($j->Id); $this->assertTrue(is_bool($check->health__c)); $this->assertTrue($check->health__c); $check = Sobject_Jyugyoin__c::neu()->eq('health__c', TRUE)->eq('Id', $j->Id)->find(); $this->assertTrue($check->health__c); $check->health__c = FALSE; $result = $check->updateEntity(); $this->assertTrue($result); $check = Sobject_Jyugyoin__c::neu()->find($j->Id); $this->assertTrue(is_bool($check->health__c)); $this->assertFalse($check->health__c); }
public function testDeleteAll() { $list = Sobject_Jyugyoin__c::neu()->limit(3)->select(); Srecord_Schema::deleteAll($list); $this->assertEqual($list[0]->getState(), Srecord_ActiveRecord::STATE_SUCCESS); $this->assertEqual($list[1]->getState(), Srecord_ActiveRecord::STATE_SUCCESS); $this->assertEqual($list[2]->getState(), Srecord_ActiveRecord::STATE_SUCCESS); print " 0: " . $list[0]->Id; print " 1: " . $list[1]->Id; print " 2: " . $list[2]->Id; array_pop($list); Srecord_Schema::undeleteAll($list); $this->assertEqual($list[0]->getState(), Srecord_ActiveRecord::STATE_SUCCESS); $this->assertEqual($list[1]->getState(), Srecord_ActiveRecord::STATE_SUCCESS); }
public function testInsert() { $j = new Sobject_Jyugyoin__c(); $j->Name = "佐藤" . time(); $result = $j->insert(); $this->assertFalse($result); $errors = $j->getErrors(); $this->assertEqual($errors->statusCode, "REQUIRED_FIELD_MISSING"); $j->JyugyoinBango__c = substr(time(), 5); $result = $j->insert(); $this->assertTrue($result); $this->assertNotNull($j->Id); $id = $j->Id; $result = $j->delete(); $this->assertTrue($result); $result = $j->undelete(); $this->assertTrue($result); }
public function testIncludesExcludes() { $srecord = new Sobject_Jyugyoin__c(); $srecord->dryrun(TRUE); $result = $srecord->includes('skill__c', 'manager;sales')->select('Id'); $this->assertEqual(trim($result), "SELECT Jyugyoin__c.Id FROM Jyugyoin__c WHERE (skill__c includes('manager;sales'))"); $result = Sobject_Jyugyoin__c::neu()->includes('skill__c', 'manager;sales')->select('Id'); $this->assertEqual(count($result), 0); $srecord = new Sobject_Jyugyoin__c(); $srecord->dryrun(TRUE); $result = $srecord->includes('skill__c', 'manager;sales', 'programer')->select('Id'); $this->assertEqual(trim($result), "SELECT Jyugyoin__c.Id FROM Jyugyoin__c WHERE (skill__c includes('manager;sales','programer'))"); $srecord = new Sobject_Jyugyoin__c(); $srecord->dryrun(TRUE); $result = $srecord->includes('skill__c', array('manager;sales', 'programer'))->select('Id'); $this->assertEqual(trim($result), "SELECT Jyugyoin__c.Id FROM Jyugyoin__c WHERE (skill__c includes('manager;sales','programer'))"); $result = Sobject_Jyugyoin__c::neu()->includes('skill__c', 'manager;sales', 'programer')->select('Id'); $this->assertEqual(count($result), 0); }