From 278b9b4050a21db8556a30ecc0350faf90a630d0 Mon Sep 17 00:00:00 2001 From: Schlaefer Date: Tue, 10 Sep 2019 13:54:05 +0200 Subject: [PATCH] Fixes error pinned posting info missing when editing as mod --- src/Model/Behavior/PostingBehavior.php | 2 ++ tests/Fixture/EntryFixture.php | 3 +- .../Model/Behavior/PostingBehaviorTest.php | 33 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/Model/Behavior/PostingBehavior.php b/src/Model/Behavior/PostingBehavior.php index a783fee7b..7a600cf40 100644 --- a/src/Model/Behavior/PostingBehavior.php +++ b/src/Model/Behavior/PostingBehavior.php @@ -100,6 +100,8 @@ public function updatePosting(Entry $posting, array $data, CurrentUserInterface /// must be set for validation $data['locked'] = $posting->get('locked'); + $data['fixed'] = $posting->get('fixed'); + $data['pid'] = $posting->get('pid'); $data['time'] = $posting->get('time'); $data['user_id'] = $posting->get('user_id'); diff --git a/tests/Fixture/EntryFixture.php b/tests/Fixture/EntryFixture.php index 7c2291981..1a32f3486 100755 --- a/tests/Fixture/EntryFixture.php +++ b/tests/Fixture/EntryFixture.php @@ -336,7 +336,8 @@ class EntryFixture extends TestFixture 'time' => '2000-01-01 10:59:00', 'last_answer' => '2000-01-01 10:59:00', 'category_id' => 4, // accession = 1 - 'user_id' => 7 + 'user_id' => 7, + 'fixed' => true, ], // thread 6 // ------------------------------------- diff --git a/tests/TestCase/Model/Behavior/PostingBehaviorTest.php b/tests/TestCase/Model/Behavior/PostingBehaviorTest.php index 5bce40a30..a39e58491 100644 --- a/tests/TestCase/Model/Behavior/PostingBehaviorTest.php +++ b/tests/TestCase/Model/Behavior/PostingBehaviorTest.php @@ -114,6 +114,39 @@ public function testCreateNewThreadButNoCategoryProvided() $this->assertArrayHasKey('_required', $errors['category_id']); } + public function testUpdateSuccesModOnPinnedPosting() + { + $now = (string)time(); + $edit = ['subject' => $now]; + + $entity = $this->table->findById(11)->first(); + + $user = ['id' => 7, 'user_type' => 'mod', 'username' => 'bar']; + $user = CurrentUserFactory::createLoggedIn($user); + + $result = $this->table->updatePosting($entity, $edit, $user); + + $this->assertEmpty($result->getErrors()); + $this->assertEquals($now, $result->get('subject')); + } + + public function testUpdateFailureModOnOwnPosting() + { + $now = (string)time(); + $edit = ['subject' => $now]; + + $entity = $this->table->findById(11)->first(); + $entity->set('fixed', false); + + $user = ['id' => 7, 'user_type' => 'mod', 'username' => 'bar']; + $user = CurrentUserFactory::createLoggedIn($user); + + $result = $this->table->updatePosting($entity, $edit, $user); + + $errors = $result->getErrors(); + $this->assertArrayHasKey('isEditingAllowed', $errors['edited_by']); + } + public function testPrepareChildPosting() { $parent = [