GitHub PullRequestReviewCommentEvent at 2014-04-06 13:23:11
Repository: cakephp
Actor: markstory
Payload: {"comment":{"url":"https://api.github.com/repos/cakephp/cakephp/pulls/comments/11326139","id":11326139,"diff_hunk":"@@ -556,4 +570,81 @@ public function testDeleteRoot() {\n \t\t$this->assertEquals($expected, $result);\n \t}\n \n+/**\n+ * Tests that a leaf can be taken out of the tree and put in as a root\n+ *\n+ * @return void\n+ */\n+\tpublic function testRemoveFromLeafFromTree() {\n+\t\t$table = TableRegistry::get('NumberTrees');\n+\t\t$table->addBehavior('Tree');\n+\t\t$entity = $table->get(10);\n+\t\t$this->assertSame($entity, $table->removeFromTree($entity));\n+\t\t$this->assertEquals(21, $entity->lft);\n+\t\t$this->assertEquals(22, $entity->rght);\n+\t\t$this->assertEquals(null, $entity->parent_id);\n+\t\t$result = $table->find()->order('lft')->hydrate(false);\n+\t\t$expected = [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 10];\n+\t\t$this->assertEquals($expected, $result->extract('id')->toArray());\n+\t\t$numbers = [];\n+\t\t$result->each(function($v) use (&$numbers) {\n+\t\t\t$numbers[] = $v['lft'];\n+\t\t\t$numbers[] = $v['rght'];\n+\t\t});\n+\t\tsort($numbers);\n+\t\t$this->assertEquals(range(1, 22), $numbers);\n+\t}\n+\n+/**\n+ * Test removing a middle node from a tree\n+ *\n+ * @return void\n+ */\n+\tpublic function testRemoveMiddleNodeFromTree() {\n+\t\t$table = TableRegistry::get('NumberTrees');\n+\t\t$table->addBehavior('Tree');\n+\t\t$entity = $table->get(6);\n+\t\t$this->assertSame($entity, $table->removeFromTree($entity));\n+\t\t$result = $table->find('threaded')->order('lft')->hydrate(false)->toArray();\n+\t\t$this->assertEquals(21, $entity->lft);\n+\t\t$this->assertEquals(22, $entity->rght);\n+\t\t$this->assertEquals(null, $entity->parent_id);\n+\t\t$result = $table->find()->order('lft')->hydrate(false);\n+\t\t$expected = [1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 6];\n+\t\t$this->assertEquals($expected, $result->extract('id')->toArray());\n+\t\t$numbers = [];\n+\t\t$result->each(function($v) use (&$numbers) {\n+\t\t\t$numbers[] = $v['lft'];\n+\t\t\t$numbers[] = $v['rght'];\n+\t\t});\n+\t\tsort($numbers);","path":"tests/TestCase/Model/Behavior/TreeBehaviorTest.php","position":241,"original_position":241,"commit_id":"2b16cc5dc0817693dbf8277055d07d31a4c1b24e","original_commit_id":"2b16cc5dc0817693dbf8277055d07d31a4c1b24e","user":{"login":"markstory","id":24086,"avatar_url":"https://avatars.githubusercontent.com/u/24086?","gravatar_id":"669144d1ab0a861af5d54175371bc586","url":"https://api.github.com/users/markstory","html_url":"https://github.com/markstory","followers_url":"https://api.github.com/users/markstory/followers","following_url":"https://api.github.com/users/markstory/following{/other_user}","gists_url":"https://api.github.com/users/markstory/gists{/gist_id}","starred_url":"https://api.github.com/users/markstory/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/markstory/subscriptions","organizations_url":"https://api.github.com/users/markstory/orgs","repos_url":"https://api.github.com/users/markstory/repos","events_url":"https://api.github.com/users/markstory/events{/privacy}","received_events_url":"https://api.github.com/users/markstory/received_events","type":"User","site_admin":false},"body":"This code appears a few times in the test, would it make sense to have an assertion method in this test for that? Something like `assertTreeNumbers`","created_at":"2014-04-06T13:23:11Z","updated_at":"2014-04-06T13:23:11Z","html_url":"https://github.com/cakephp/cakephp/pull/3241#discussion_r11326139","pull_request_url":"https://api.github.com/repos/cakephp/cakephp/pulls/3241","_links":{"self":{"href":"https://api.github.com/repos/cakephp/cakephp/pulls/comments/11326139"},"html":{"href":"https://github.com/cakephp/cakephp/pull/3241#discussion_r11326139"},"pull_request":{"href":"https://api.github.com/repos/cakephp/cakephp/pulls/3241"}}}}