/** * @dataProvider dataProvider_Search */ public function testSearch_WithValidTerms_ReturnsExpectedResults($searchTerms, $numResults, $expectedKeys) { $this->model->setAttributes($searchTerms); $results = $this->model->search(); $data = $results->getData(); $expectedResults = array(); if (!empty($expectedKeys)) { foreach ($expectedKeys as $key) { $expectedResults[] = $this->contactmetadata($key); } } $this->assertEquals($numResults, $results->getItemCount()); $this->assertEquals($expectedResults, $data); }
public function setMetadata($key, $value) { if (!($cm = ContactMetadata::model()->find('contact_id=? and `key`=?', array($this->owner->contact_id, $key)))) { $cm = new ContactMetadata(); $cm->contact_id = $this->owner->contact_id; $cm->key = $key; } $cm->value = $value; if (!$cm->save()) { throw new Exception('Unable to save contact metadata: ' . print_r($cm->getErrors(), true)); } }