From 0d74e44d8be4a5b069a89005691f2183baf32f6e Mon Sep 17 00:00:00 2001 From: Jason Adams Date: Thu, 3 Aug 2023 14:38:22 -0700 Subject: [PATCH] test: add further tests --- .../FieldsAPI/Concerns/HasPersistence.php | 6 ++ .../FieldsAPI/Concerns/HasPersistenceTest.php | 22 ++++++- .../ValueObjects/PersistenceScopeTest.php | 57 +++++++++++++++++++ 3 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 tests/Unit/Framework/FieldsAPI/ValueObjects/PersistenceScopeTest.php diff --git a/src/Framework/FieldsAPI/Concerns/HasPersistence.php b/src/Framework/FieldsAPI/Concerns/HasPersistence.php index 8978625d8d..ce133e294f 100644 --- a/src/Framework/FieldsAPI/Concerns/HasPersistence.php +++ b/src/Framework/FieldsAPI/Concerns/HasPersistence.php @@ -4,6 +4,12 @@ use Give\Framework\FieldsAPI\ValueObjects\PersistenceScope; +/** + * This provides the ability to set a scope and meta key for a field. The scope is used to determine if and where the + * field should be stored. The meta key is used to store the field in the database. + * + * @unreleased + */ trait HasPersistence { /** diff --git a/tests/Unit/Framework/FieldsAPI/Concerns/HasPersistenceTest.php b/tests/Unit/Framework/FieldsAPI/Concerns/HasPersistenceTest.php index 22b143c3b2..cc42ada640 100644 --- a/tests/Unit/Framework/FieldsAPI/Concerns/HasPersistenceTest.php +++ b/tests/Unit/Framework/FieldsAPI/Concerns/HasPersistenceTest.php @@ -27,15 +27,22 @@ public function testStoreAsDonorMetaMethods() $this->assertFalse($mock->shouldStoreAsDonorMeta()); } + /** + * @unreleased + */ public function testSettingTheScopeByString() { /** @var HasPersistence $mock */ $mock = $this->getMockForTrait(HasPersistence::class); $mock->scope('test'); - $this->assertEquals('test', $mock->getScopeValue()); + $this->assertSame('test', $mock->getScopeValue()); + $this->assertTrue($mock->getScope()->is('test')); } + /** + * @unreleased + */ public function testSettingTheScopeByInstance() { /** @var HasPersistence $mock */ @@ -43,5 +50,18 @@ public function testSettingTheScopeByInstance() $mock->scope(new PersistenceScope('test')); $this->assertEquals('test', $mock->getScopeValue()); + $this->assertTrue($mock->getScope()->is('test')); + } + + /** + * @unreleased + */ + public function testSettingTheMetaKey() + { + /** @var HasPersistence $mock */ + $mock = $this->getMockForTrait(HasPersistence::class); + + $mock->metaKey('test'); + $this->assertEquals('test', $mock->getMetaKey()); } } diff --git a/tests/Unit/Framework/FieldsAPI/ValueObjects/PersistenceScopeTest.php b/tests/Unit/Framework/FieldsAPI/ValueObjects/PersistenceScopeTest.php new file mode 100644 index 0000000000..5780e874d4 --- /dev/null +++ b/tests/Unit/Framework/FieldsAPI/ValueObjects/PersistenceScopeTest.php @@ -0,0 +1,57 @@ +isDonation()); + + self::assertInstanceOf(PersistenceScope::class, $donor); + self::assertTrue($donor->isDonor()); + } + + /** + * @unreleased + */ + public function testToString() + { + $scope = PersistenceScope::donation(); + self::assertEquals('donation', (string)$scope); + } + + /** + * @unreleased + */ + public function testIsMethods() + { + $donation = PersistenceScope::donation(); + + self::assertTrue($donation->isDonation()); + self::assertFalse($donation->isDonor()); + self::assertTrue($donation->is(PersistenceScope::DONATION)); + } + + /** + * @unreleased + */ + public function testConstructor() + { + $scope = new PersistenceScope('donation'); + self::assertTrue($scope->isDonation()); + } +}