diff --git a/config/install/rabbit_hole.behavior_settings.default.yml b/config/install/rabbit_hole.behavior_settings.default.yml new file mode 100644 index 0000000..3602e5a --- /dev/null +++ b/config/install/rabbit_hole.behavior_settings.default.yml @@ -0,0 +1,2 @@ +id: default +action: "display_page" diff --git a/config/schema/behavior_settings.schema.yml b/config/schema/behavior_settings.schema.yml new file mode 100644 index 0000000..39cba35 --- /dev/null +++ b/config/schema/behavior_settings.schema.yml @@ -0,0 +1,11 @@ +rabbit_hole.behavior_settings.*: + type: config_entity + label: 'Behavior settings config' + mapping: + id: + type: string + label: 'ID' + uuid: + type: string + action: + type: string diff --git a/src/BehaviorSettingsInterface.php b/src/BehaviorSettingsInterface.php new file mode 100644 index 0000000..af94d0f --- /dev/null +++ b/src/BehaviorSettingsInterface.php @@ -0,0 +1,22 @@ +action; + } +} diff --git a/src/Tests/RabbitHoleBehaviorSettingsTest.php b/src/Tests/RabbitHoleBehaviorSettingsTest.php new file mode 100644 index 0000000..7efa46e --- /dev/null +++ b/src/Tests/RabbitHoleBehaviorSettingsTest.php @@ -0,0 +1,164 @@ +configFactory = $this->container->get('config.factory'); + // $this->testNodeType = $this->generateTestNodeType(); + // $this->testNode = $this->generateTestNode(); + } + + /** + * Test that a saved BehaviorSettings entity can be found by the config system + * and contains the correct values + */ + public function testSettings() { + $this->saveAndTestExpectedValues('test_behavior_settings', 'display_page', + TRUE); + } + + /** + * @todo This test is failing - seems defaults are not being picked up. Why? + * Some inconsistent information about path, seems most likely reason - have + * tried config/install (as stated here: https://www.drupal.org/node/2120571) + * and src/install/config (from Drupalize.me video which previously seemed + * to work) + */ + public function testSettingsDefault() { + $action = \Drupal::config('rabbit_hole.behavior_settings.default') + ->get('action'); + $this->assertEqual($action, 'display_page', 'Unexpected default action'); + } + + /** + * Test that a saved BehaviourSettings entity can be given an ID based on + * a generated bundle (a NodeType in this case) and be found based on that ID + */ + // public function testBundleSettings() { + // $this->createTestNodeType(); + // $this->saveAndTestExpectedValues($this->testNodeType->id(), + // 'page_not_found', TRUE, 'bundle_'); + // $this->deleteTestNodeType(); + // } + + /** + * Test that a saved BehaviourSettings entity can be given an ID based on + * a generated entity (a Node in this case) and be found based on that ID + */ + // public function testEntitySettings() { + // $this->createTestNodeType(); + // $this->createTestNode(); + // $this->saveAndTestExpectedValues($this->testNode->id(), 'access_denied', + // TRUE, 'entity_'); + // $this->deleteTestNode(); + // $this->deleteTestNodeType(); + // } + + // public function testLoadBundleSettingsWithDefault() {} + + // public function testLoadEntitySettingsWithDefault() {} + + private function saveAndTestExpectedValues($id, $expected_action, $id_prefix = "") { + // Delete key if it already exists + $this->configFactory->getEditable('rabbit_hole.behavior_settings.' . $id) + ->delete(); + + $entity = BehaviorSettings::create( + array( + 'id' => $id_prefix . $id, + 'action' => $expected_action, + ) + ); + $entity->save(); + + $action = \Drupal::config( + 'rabbit_hole.behavior_settings.' . $id_prefix . $id)->get('action'); + + $this->assertEqual($action, $expected_action, 'Unexpected action'); + + // Clean up the entity afterwards + $entity->delete(); + } + + // TODO + // private function generateTestNodeType() { + // return \entity_create('node_type', + // array( + // 'type' => 'test_behavior_settings_node_type', + // 'name' => 'Test Behavior Settings Node Type' + // ) + // ); + // } + + // TODO + // private function generateTestNode() { + // return Node::create( + // array( + // 'nid' => NULL, + // 'type' => $this->testNodeType->id(), + // 'title' => 'Test Behavior Settings Node', + // ) + // ); + // } + + // TODO + // private function createTestNodeType() { + // $this->testNodeType->save(); + // } + + // TODO + // private function deleteTestNodeType() { + // $this->testNodeType->delete(); + // } + + // TODO + // private function createTestNode() { + // $this->testNode->save(); + // } + + // TODO + // private function deleteTestNode() { + // $this->testNode->delete(); + // } + + // TODO + // public function testSaveBundleSettingsViaForm() {} + + // TODO + // public function testSaveEntitySettingsViaForm() {} +}