From 624f038fbf0b90dafba467af09bcb156c470e9b0 Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Fri, 28 Feb 2014 16:33:35 +0100 Subject: [PATCH] Added test for ArrayContext::isPrimaryKey() --- tests/TestCase/View/Form/ArrayContextTest.php | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/TestCase/View/Form/ArrayContextTest.php b/tests/TestCase/View/Form/ArrayContextTest.php index f259a8ebbf3..b89127160f7 100644 --- a/tests/TestCase/View/Form/ArrayContextTest.php +++ b/tests/TestCase/View/Form/ArrayContextTest.php @@ -62,6 +62,45 @@ public function testPrimaryKey() { $this->assertEquals($expected, $context->primaryKey()); } +/** + * Test isPrimaryKey. + * + * @return void + */ + public function testIsPrimaryKey() { + $context = new ArrayContext($this->request, []); + $this->assertFalse($context->isPrimaryKey('id')); + + $context = new ArrayContext($this->request, [ + 'schema' => [ + '_constraints' => 'mistake', + ] + ]); + $this->assertFalse($context->isPrimaryKey('mistake')); + + $data = [ + 'schema' => [ + '_constraints' => [ + 'primary' => ['type' => 'primary', 'columns' => ['id']] + ] + ], + ]; + $context = new ArrayContext($this->request, $data); + $this->assertTrue($context->isPrimaryKey('id')); + $this->assertFalse($context->isPrimaryKey('name')); + + $data = [ + 'schema' => [ + '_constraints' => [ + 'primary' => ['type' => 'primary', 'columns' => ['id', 'name']] + ] + ], + ]; + $context = new ArrayContext($this->request, $data); + $this->assertTrue($context->isPrimaryKey('id')); + $this->assertTrue($context->isPrimaryKey('name')); + } + /** * Test the isCreate method. *