Add ebaility to change the feed for a feed entry

This commit is contained in:
Romain Neutron
2012-06-15 14:35:53 +02:00
parent c47c3adac3
commit f4f408ef0f
2 changed files with 114 additions and 12 deletions

View File

@@ -123,6 +123,22 @@ class Feed implements ControllerProviderInterface
->set_author_name($author_name) ->set_author_name($author_name)
->set_title($title) ->set_title($title)
->set_subtitle($subtitle); ->set_subtitle($subtitle);
$current_feed_id = $entry->get_feed()->get_id();
$new_feed_id = $request->get('feed_id',$current_feed_id);
if($current_feed_id != $new_feed_id) {
try {
$new_feed = \Feed_Adapter::load_with_user($appbox, $user, $new_feed_id);
} catch(\Exception_NotFound $e) {
throw new \Exception_Forbidden('You have no access to this feed');
}
if ( ! $new_feed->is_publisher($user)) {
throw new \Exception_Forbidden('You are not publisher of this feed');
}
$entry->set_feed($new_feed);
}
$items = explode(';', $request->get('sorted_lst')); $items = explode(';', $request->get('sorted_lst'));
@@ -144,6 +160,12 @@ class Feed implements ControllerProviderInterface
} catch (\Exception_Feed_EntryNotFound $e) { } catch (\Exception_Feed_EntryNotFound $e) {
$appbox->get_connection()->rollBack(); $appbox->get_connection()->rollBack();
$datas['message'] = _('Feed entry not found'); $datas['message'] = _('Feed entry not found');
} catch (\Exception_NotFound $e) {
$appbox->get_connection()->rollBack();
$datas['message'] = _('Feed not found');
} catch (\Exception_Forbidden $e) {
$appbox->get_connection()->rollBack();
$datas['message'] = _('You are not authorized to access this feed');
} catch (\Exception $e) { } catch (\Exception $e) {
$appbox->get_connection()->rollBack(); $appbox->get_connection()->rollBack();
$datas['message'] = $e->getMessage(); $datas['message'] = $e->getMessage();

View File

@@ -95,10 +95,10 @@ class ControllerFeedApp extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function createApplication() public function createApplication()
{ {
$app = require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Prod.php'; $app = require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Prod.php';
$app['debug'] = true; $app['debug'] = true;
unset($app['exception_handler']); unset($app['exception_handler']);
return $app; return $app;
} }
@@ -195,11 +195,10 @@ class ControllerFeedApp extends \PhraseanetWebTestCaseAuthenticatedAbstract
); );
try try {
{
$crawler = $this->client->request('GET', '/feeds/entry/' . $entry->get_id() . '/edit/'); $crawler = $this->client->request('GET', '/feeds/entry/' . $entry->get_id() . '/edit/');
$this->fail('Should raise an exception'); $this->fail('Should raise an exception');
} catch(Exception_UnauthorizedAction $e) { } catch (Exception_UnauthorizedAction $e) {
} }
@@ -211,12 +210,11 @@ class ControllerFeedApp extends \PhraseanetWebTestCaseAuthenticatedAbstract
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());
$params = array( $params = array(
"feed_id" => $this->feed->get_id() "title" => "dog",
, "title" => "dog" "subtitle" => "cat",
, "subtitle" => "cat" "author_name" => "bird",
, "author_name" => "bird" "author_email" => "mouse",
, "author_email" => "mouse" 'lst' => static::$records['record_1']->get_serialize_key(),
, 'lst' => static::$records['record_1']->get_serialize_key()
); );
$crawler = $this->client->request('POST', '/feeds/entry/' . $this->entry->get_id() . '/update/', $params); $crawler = $this->client->request('POST', '/feeds/entry/' . $this->entry->get_id() . '/update/', $params);
@@ -230,6 +228,88 @@ class ControllerFeedApp extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->assertRegExp("/entry_" . $this->entry->get_id() . "/", $pageContent->datas); $this->assertRegExp("/entry_" . $this->entry->get_id() . "/", $pageContent->datas);
} }
public function testEntryUpdateChangeFeed()
{
$appbox = \appbox::get_instance(\bootstrap::getCore());
$newfeed = Feed_Adapter::create(
$appbox, self::$user, $this->feed_title, $this->feed_subtitle
);
$params = array(
"feed_id" => $newfeed->get_id(),
"title" => "dog",
"subtitle" => "cat",
"author_name" => "bird",
"author_email" => "mouse",
'lst' => static::$records['record_1']->get_serialize_key(),
);
$crawler = $this->client->request('POST', '/feeds/entry/' . $this->entry->get_id() . '/update/', $params);
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertEquals("application/json", $this->client->getResponse()->headers->get("content-type"));
$pageContent = json_decode($this->client->getResponse()->getContent());
$this->assertTrue(is_object($pageContent));
$this->assertFalse($pageContent->error);
$this->assertTrue(is_string($pageContent->message));
$this->assertTrue(is_string($pageContent->datas));
$this->assertRegExp("/entry_" . $this->entry->get_id() . "/", $pageContent->datas);
$retrievedentry = Feed_Entry_Adapter::load_from_id($appbox, $this->entry->get_id());
$this->assertEquals($newfeed->get_id(), $retrievedentry->get_feed()->get_id());
$newfeed->delete();
}
public function testEntryUpdateChangeFeedNoAccess()
{
$appbox = \appbox::get_instance(\bootstrap::getCore());
$newfeed = Feed_Adapter::create(
$appbox, self::$user, $this->feed_title, $this->feed_subtitle
);
$newfeed->set_collection(self::$collection_no_access);
$appbox = appbox::get_instance(\bootstrap::getCore());
$params = array(
"feed_id" => $newfeed->get_id(),
"title" => "dog",
"subtitle" => "cat",
"author_name" => "bird",
"author_email" => "mouse",
'lst' => static::$records['record_1']->get_serialize_key(),
);
$crawler = $this->client->request('POST', '/feeds/entry/' . $this->entry->get_id() . '/update/', $params);
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertEquals("application/json", $this->client->getResponse()->headers->get("content-type"));
$pageContent = json_decode($this->client->getResponse()->getContent());
$this->assertTrue(is_object($pageContent));
$this->assertTrue($pageContent->error);
$this->assertTrue(is_string($pageContent->message));
$newfeed->delete();
}
public function testEntryUpdateChangeFeedInvalidFeed()
{
$params = array(
"feed_id" => 0,
"title" => "dog",
"subtitle" => "cat",
"author_name" => "bird",
"author_email" => "mouse",
'lst' => static::$records['record_1']->get_serialize_key(),
);
$crawler = $this->client->request('POST', '/feeds/entry/' . $this->entry->get_id() . '/update/', $params);
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertEquals("application/json", $this->client->getResponse()->headers->get("content-type"));
$pageContent = json_decode($this->client->getResponse()->getContent());
$this->assertTrue(is_object($pageContent));
$this->assertTrue($pageContent->error);
$this->assertTrue(is_string($pageContent->message));
}
public function testEntryUpdateNotFound() public function testEntryUpdateNotFound()
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());
@@ -336,7 +416,7 @@ class ControllerFeedApp extends \PhraseanetWebTestCaseAuthenticatedAbstract
Feed_Entry_Adapter::load_from_id($appbox, $this->entry->get_id()); Feed_Entry_Adapter::load_from_id($appbox, $this->entry->get_id());
$this->fail("Failed to delete entry"); $this->fail("Failed to delete entry");
} catch (Exception $e) { } catch (Exception $e) {
} }
} }