diff --git a/apps/api/lib/helper/opJsonApiHelper.php b/apps/api/lib/helper/opJsonApiHelper.php index 073cfb2de..a421bad4a 100644 --- a/apps/api/lib/helper/opJsonApiHelper.php +++ b/apps/api/lib/helper/opJsonApiHelper.php @@ -193,6 +193,21 @@ function op_api_notification($notification) $iconUrl = sf_image_path($iconUrl, array('size' => '48x48'), true); } + $url = null; + if (null !== $notification['url'] && '' !== $notification['url']) + { + if ('/' === $notification['url'][0]) + { + // Backward compatibility before OpenPNE 3.8.23. + // Basically, those URLs begin with relative URL root (ex. "/subdir/member/1"). + $url = $notification['url']; + } + else + { + $url = app_url_for('pc_frontend', $notification['url'], array('abstract' => true)); + } + } + return array( 'id' => $notification['id'], 'body' => sfContext::getInstance()->getI18N()->__($notification['body']), @@ -200,7 +215,7 @@ function op_api_notification($notification) 'unread' => $notification['unread'], 'created_at' => date('r', strtotime($notification['created_at'])), 'icon_url' => $iconUrl, - 'url' => $notification['url'] ? url_for($notification['url'], array('abstract' => true)) : null, + 'url' => $url, 'member_id_from' => $notification['member_id_from'], ); } diff --git a/test/functional/api/pushSearchActionTest.php b/test/functional/api/pushSearchActionTest.php new file mode 100644 index 000000000..3b4df6b88 --- /dev/null +++ b/test/functional/api/pushSearchActionTest.php @@ -0,0 +1,96 @@ +test(); + +Doctrine_Core::getTable('SnsConfig')->set('enable_jsonapi', true); +$member1 = Doctrine_Core::getTable('Member')->find(1); +$member1ApiKey = $member1->getApiKey(); +$member2 = Doctrine_Core::getTable('Member')->find(2); + +$testcases = array(); + +$testcases[] = function($t, $tester) +{ + global $browser, $member1, $member1ApiKey, $member2; + + $t->diag('/push/search.json - backward compatibility (url begins with "/")'); + + opNotificationCenter::notify($member2, $member1, 'test', array( + 'url' => '/member/1', + )); + + $browser->rawConfiguration['op_base_url'] = 'http://localhost/subdir'; + + $tester + ->get('/push/search.json', array('apiKey' => $member1ApiKey)) + ->isStatusCode(200); + + $json = $tester->getResponse()->getContent(); + $data = json_decode($json, true); + + $t->is($data['status'], 'success'); + $t->is($data['data'][0]['url'], '/member/1'); +}; + +$testcases[] = function($t, $tester) +{ + global $browser, $member1, $member1ApiKey, $member2; + + $t->diag('/push/search.json - internal uri (not begins with "/", "@")'); + + opNotificationCenter::notify($member2, $member1, 'test', array( + 'url' => 'member/1', + )); + + $browser->rawConfiguration['op_base_url'] = 'http://localhost/subdir'; + + $tester + ->get('/push/search.json', array('apiKey' => $member1ApiKey)) + ->isStatusCode(200); + + $json = $tester->getResponse()->getContent(); + $data = json_decode($json, true); + + $t->is($data['status'], 'success'); + $t->is($data['data'][0]['url'], 'http://localhost/subdir/pc_frontend_test.php/member/1'); +}; + +$testcases[] = function($t, $tester) +{ + global $browser, $member1, $member1ApiKey, $member2; + + $t->diag('/push/search.json - internal uri (begins with "@")'); + + opNotificationCenter::notify($member2, $member1, 'test', array( + 'url' => '@obj_member_profile?id=1', + )); + + $browser->rawConfiguration['op_base_url'] = 'http://localhost/subdir'; + + $tester + ->get('/push/search.json', array('apiKey' => $member1ApiKey)) + ->isStatusCode(200); + + $json = $tester->getResponse()->getContent(); + $data = json_decode($json, true); + + $t->is($data['status'], 'success'); + $t->is($data['data'][0]['url'], 'http://localhost/subdir/pc_frontend_test.php/member/1'); +}; + +$conn = Doctrine_Manager::connection(); + +foreach ($testcases as $testcase) +{ + $conn->beginTransaction(); + $testcase($t, $tester); + $conn->rollback(); +}