Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

F/reorder list #75

Merged
merged 9 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Model/Wiki.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,11 @@ public function reorderPages($project_id, $src_wiki_id, $target_wiki_id){
}

// update moved src
$targetColumn--;
// echo "oldSourceColumn: " . $oldSourceColumn . " targetColumn: " . $targetColumn . "<br>";
if($oldSourceColumn != $targetColumn -1){
if($oldSourceColumn != $targetColumn){
// echo "updating src ". $src_wiki_id . " column to ". $targetColumn -1 . "<br>";
$result = $this->savePagePosition($src_wiki_id, $orderColumn -1);
$result = $this->savePagePosition($src_wiki_id, $targetColumn);
if(!$result){
return false;
}
Expand Down
46 changes: 37 additions & 9 deletions Test/Model/WikiPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ protected function setUp(): void

$plugin = new Loader($this->container);
$plugin->scan();

$authManager = new AuthenticationManager($this->container);
$authManager->register(new DatabaseAuth($this->container));

$_SESSION['user'] = array('id' => 1, 'username' => 'test', 'role' => 'app-admin');
}

public function testCreation()
{

$projectModel = new ProjectModel($this->container);

$this->assertEquals($projectModel->create(array('name' => 'UnitTest')), 1, 'Failed to create project');
Expand All @@ -36,8 +40,8 @@ public function testCreation()

$wikimodel = new Wiki($this->container);
// create wiki pages
$this->assertEquals($wikimodel->createpage($project['id'], "Security", "Some content", '2015-01-01'), 1, 'Failed to a create wiki page on project');
$this->assertEquals($wikimodel->createpage($project['id'], "Conventions", 'More content'), 2, 'Failed to an additional create wiki page on project');
$this->assertEquals(1, $wikimodel->createpage($project['id'], "Security", "Some content", '2015-01-01'), 'Failed to a create wiki page on project');
$this->assertEquals(2, $wikimodel->createpage($project['id'], "Conventions", 'More content'), 'Failed to an additional create wiki page on project');

// grab editions for first wiki page
$editions = $wikimodel->getEditions(1);
Expand All @@ -49,12 +53,6 @@ public function testCreation()
];

// create wiki page edition

$authManager = new AuthenticationManager($this->container);
$authManager->register(new DatabaseAuth($this->container));

$_SESSION['user'] = array('id' => 1, 'username' => 'test', 'role' => 'app-admin');

$this->assertTrue($this->container['userSession']->isLogged(), 'Failed to login');

$this->userSession = new UserSession($this->container);
Expand All @@ -68,4 +66,34 @@ public function testCreation()
$this->assertEquals('Security', $editions[0]['title']);
$this->assertEquals('Some content', $editions[0]['content']);
}

public function testReOrder(){

$projectModel = new ProjectModel($this->container);

$this->assertEquals($projectModel->create(array('name' => 'reorder')), 1, 'Failed to create project');

$project = $projectModel->getById(1);

$wikimodel = new Wiki($this->container);

// create wiki pages
$this->assertEquals(1, $wikimodel->createpage($project['id'], "Home", "", '2015-01-01'), 1, 'Failed to a create wiki page home on project');
$this->assertEquals(2, $wikimodel->createpage($project['id'], "Page 2", ""), 'Failed to a create wiki page 2 on project');
$this->assertEquals(3, $wikimodel->createpage($project['id'], "Page 3", ""), 'Failed to a create wiki page 3 on project');
$this->assertEquals(4, $wikimodel->createpage($project['id'], "Page 4", ""), 'Failed to a create wiki page 4 on project');
$this->assertEquals(5, $wikimodel->createpage($project['id'], "Page 5", ""), 'Failed to a create wiki page 5 on project');

// reorder
$wikimodel->reorderPages($project['id'], 5, 3);
// expected by id
$expectedColumnOrders = [1,2,4,5,3];

$wikiPages = $wikimodel->getWikipages($project['id']);
$this->assertEquals(count($expectedColumnOrders), count($wikiPages), 'expected column order count doesn\'t match pages');

for ($i=0; $i < count($expectedColumnOrders); $i++) {
$this->assertEquals($expectedColumnOrders[$wikiPages[$i]['id']-1], $wikiPages[$i]['ordercolumn'], 'Failed to reorder page id:'. $wikiPages[$i]['id']);
}
}
}
Loading