Example #1
0
 public function testJsonEncodeActivityNotice()
 {
     $this->params = ['activityNotice' => ['TestModel02' => ['notifyActions' => '*', 'serializeAttributes' => 'jsonData,model1.field1,model1.field3,workCalendar,resources,projectTasks']]];
     $helper = new ActivityNoticeSerializer($this->params);
     $model = new TestModel02();
     $model->model1 = new TestModel01();
     $model->model1->field1 = "ABC";
     $model->model1->field2 = "XYZ";
     $model->model1->field3 = "GHI";
     $model->projectTasks = ['abc', 'def'];
     $config = $helper->getActivityNoticeConfig('TestModel02', 'update', null);
     $data = $helper->getSerializeData($model, $config);
     $json = JsonHelper::encode($data);
     $obj = json_decode($json);
     $this->assertNull($obj->jsonData);
     $this->assertNull($obj->workCalendar);
     $this->assertNull($obj->resources);
     $this->assertTrue(is_array($obj->projectTasks));
     $this->assertEquals("abc", $obj->projectTasks[0]);
     $this->assertEquals("def", $obj->projectTasks[1]);
     $this->assertNotNull($obj->model1);
     $this->assertEquals("ABC", $obj->model1->field1);
     $this->assertObjectNotHasAttribute("field2", $obj->model1);
     $this->assertEquals("GHI", $obj->model1->field3);
 }
 public function testGetSerializeData10_serializeDelegateFunction2()
 {
     $this->params = ['activityNotice' => ['TestModel03' => ['notifyActions' => '*', 'notSerializeAttributes' => '_explicitType', 'serializeDelegateFunction' => 'mySerializeDelegateFunction']]];
     $helper = new ActivityNoticeSerializer($this->params);
     $model = new TestModel03();
     $model->field1 = "ABC";
     $model->field2 = "XYZ";
     $model->field3 = "GHI";
     $model->myField1 = "My1";
     $model->myField2 = "My2";
     $model->_explicitType = "TestModel03";
     $config = $helper->getActivityNoticeConfig('TestModel03', 'save', null);
     $data = $helper->getSerializeData($model, $config);
     $this->assertArrayHasKey('field1', $data);
     $this->assertEquals('@@@', $data['field1']);
     $this->assertArrayHasKey('field2', $data);
     $this->assertEquals('XYZ', $data['field2']);
     $this->assertArrayHasKey('field3', $data);
     $this->assertEquals('GHI', $data['field3']);
     $this->assertArrayHasKey('myField1', $data);
     $this->assertEquals('My1', $data['myField1']);
     $this->assertArrayHasKey('myField2', $data);
     $this->assertEquals('My2', $data['myField2']);
     $this->assertArrayHasKey('_explicitType', $data);
     $this->assertEquals('TestModel03', $data['_explicitType']);
 }