/** * Test that index is updated afer saving a model * @return [type] [description] */ public function testUpdateIndexAfterSave() { $ModelClass = new ModelClass(); $ModelClass->Behaviors->Indexable->settings['ModelClass']['request']['uri']['host'] = ELASTIC_HOST; $ModelClass->Behaviors->Indexable->settings['ModelClass']['request']['uri']['port'] = ELASTIC_PORT; $id = rand(0, 1000); $datas = array('id' => $id, 'title' => 'Viva la vida', 'length' => 120, 'track' => 1); $this->HttpSocket->request(array('method' => 'PUT', 'uri' => array('host' => ELASTIC_HOST, 'port' => ELASTIC_PORT, 'path' => 'test_song/model_class/' . $id), 'body' => json_encode($datas))); $ModelClass->query("INSERT INTO model_classes (id, title) VALUES(" . $id . ", 'test')"); $datas['track'] = 2; $datas['title'] = 'Vive la vie'; $ModelClass->save(array('ModelClass' => $datas)); $response = $this->HttpSocket->request(array('method' => 'GET', 'uri' => array('host' => ELASTIC_HOST, 'port' => ELASTIC_PORT, 'path' => 'test_song/model_class/' . $id))); $response = json_decode($response, true); $source = $response['_source']; // Because we can't test the date value unset($source['created'], $source['modified']); $this->assertArrayHasKey('_source', $response); $this->assertTrue($response['exists']); $this->assertEquals($datas['id'], $source['id'], 'ID remain unchanged'); $this->assertEquals($datas['title'], $source['title'], 'Title was updated'); $this->assertEquals($datas['length'], $source['length'], 'Length remain unchanged because not in whitelist'); $this->assertEquals(1, $source['track'], 'Track remain unchanged because not in whitelist'); }