PHP Class AcControllerResourceTest

Inheritance: extends AcTestCase, use trait AuthorityControllerHelpers
Show file Open project: efficiently/authority-controller

Public Methods

Method Description
setUp ( )
testBuildCollectionWhenOnIndexAction ( ) Should build a collection when on index action
testBuildNewResourceForNamespacedControllerAndNamespacedModelWithAssociativeArrayIfParamIdIsNotSpecified ( ) Should build a new resource for namespaced controller and namespaced model with hash if params[:id] is not specified
testBuildNewResourceNamespacedModelWithAssociativeArrayIfParamIdIsNotSpecified ( ) Should build a new resource for namespaced model with hash if params[:id] is not specified
testBuildNewResourceWithAssociativeArrayIfParamIdIsNotSpecified ( ) Should build a new resource with hash if params[:id] is not specified
testCreateThroughNamespacedParams ( ) Should store through the namespaced params
testHasSpecifiedNestedResourceClassWithSlashedNamespace ( ) Has the specified nested resource_class when using '/' for namespace
testLoadResourceForNamespacedController ( ) Should properly load resource for namespaced controller
testLoadResourceInstanceWithParamId ( ) Should load the resource into an instance variable if $params['id'] is specified
testLoadResourceWithSameNamespaceAsControllerWithBackslashedNamespace ( ) Should attempt to load a resource with the same namespace as the controller when using '\' for namespace
testNotLoadResourceInstanceIfAlreadySet ( ) Should not load resource into an instance variable if already set
testProperlyDetectNamespacesResourceControllerWithBackslashedNamespace ( ) Should properly detect namespaces for resource and controller when using '\' for namespace
testProperlyDetectRootNamespaceResourceNamespacedControllerWithBackslashedNamespace ( ) Should properly detect root namespace of resource for namespaced controller when using '\' for namespace
testProperlyLoadResourceNamespacedControllerWithBackslashedNamespace ( ) Should properly load resource for namespaced controller when using '\' for namespace
testShouldAllowFullFindMethodToBePassedIntoFindByOption ( ) Should allow full find method to be passed into findBy option
testShouldAlwaysConvertIdParamToString ( ) Should always convert id param to string
testShouldAuthorizeBasedOnResourceNameIfClassIsFalse ( ) Should authorize based on resource name if class is false
testShouldAuthorizeNestedResourceThroughParentAssociationOnIndexAction ( ) Should authorize nested resource through parent association on index action
testShouldAuthorizeParentResourceInCollectionAction ( ) Should authorize parent resource in collection action
testShouldBeAParentResourceWhenNameIsProvidedWhichDoesntMatchController ( ) Should be a parent resource when name is provided which doesn't match controller
testShouldBeParentIfSpecifiedInOptions ( ) // Should be parent if specified in options
testShouldBuildAResourceWhenOnCustomCreateActionEvenWhenParamsIdExists ( ) Should build a resource when on custom create action even when $this->params['id'] exists
testShouldBuildRecordThroughHasOneAssociationWithSingletonAndShallowOptions ( ) Should build record through hasOne association with 'singleton' and 'shallow' options
testShouldCallClosureWhenAnInstanceVariableIsPassed ( ) Should call Closure when an instance variable is passed
testShouldCallLoadResourceAndAuthorizeResourceForLoadAndAuthorizeResource ( ) Should call loadResource and authorizeResource for loadAndAuthorizeResource
testShouldFindRecordThroughHasOneAssociationWithSingletonAndShallowOptions ( ) Should find record through hasOne association with 'singleton' and 'shallow' options
testShouldFindRecordThroughHasOneAssociationWithSingletonOptionWithoutIdParam ( ) Should find record through hasOne association with 'singleton' option without id param
testShouldHaveTheSpecifiedResourceClassIfNameIsPassedToLoadResource ( ) Should have the specified resource_class if 'name' is passed to loadResource()
testShouldLoadACollectionResourceWhenOnCustomActionWithNoIdParam ( ) // Should load a collection resource when on custom action with no id param
testShouldLoadAndAuthorizeUsingCustomInstanceName ( ) Should load and authorize using custom instance name
testShouldLoadCollectionResourceWhenDefiningAuthorityRulesThroughClosure ( ) Should not use load collection when defining Authority rules through a Closure
testShouldLoadParentResourceThroughProperIdParameter ( ) Should load parent resource through proper id parameter
testShouldLoadResourceThroughCustomMethodOfTheController ( ) Should load resource through a custom method of the controller
testShouldLoadResourceThroughTheAssociationOfAnotherParentResourceUsingGetterMethod ( ) Should load resource through the association of another parent resource using getter method
testShouldLoadResourceThroughTheAssociationOfAnotherParentResourceUsingInstanceVariable ( ) Should load resource through the association of another parent resource using instance variable
testShouldLoadResourceThroughTheAssociationOfAnotherParentResourceUsingMethod ( ) Should load resource through the association of another parent resource using method
testShouldLoadResourceThroughTheCustomAssociationName ( ) Should load resource through the custom association name
testShouldLoadResourceUsingCustomFindByAttribute ( ) Should load resource using custom findByAttribute
testShouldLoadResourceUsingCustomIDParam ( ) Should load resource using custom ID param
testShouldLoadResourceUsingCustomQuery ( ) Should load resource using custom query where('attribute_name', $attribute);
testShouldLoadTheModelUsingACustomClass ( ) Should load the model using a custom class
testShouldLoadTheModelUsingACustomNamespacedClass ( ) Should load the model using a custom namespaced class
testShouldLoadThroughFirstMatchingIfMultipleAreGiven ( ) Should load through first matching if multiple are given
testShouldNotAuthorizeSingleResourceInCollectionAction ( ) Should not authorize single resource in collection action
testShouldNotBeAParentResourceWhenNameIsProvidedWhichMatchesController ( ) // Should not be a parent resource when name is provided which matches controller
testShouldNotBeParentIfSpecifiedInOptions ( ) // Should not be parent if specified in options
testShouldNotBuildASingleResourceWhenOnCustomCollectionActionEvenWithId ( ) Should not build a single resource when on custom collection action even with id
testShouldNotBuildRecordThroughHasOneAssociationWithSingletonOptionBecauseItCanCauseItToDeleteItInTheDatabase ( ) Should not build record through hasOne association with 'singleton' option because it can cause it to delete it in the database
testShouldNotCallClosureWhenOnlyClassNameIsPassedOnlyReturnTrue ( ) Should not call Closure when only class name is passed, only return true
testShouldNotLoadThroughParentResourceIfInstanceIsntLoadedWhenShallow ( ) Should not load through parent resource if instance isn't loaded when shallow
testShouldNotTryToLoadResourceForOtherActionIfParamsIdIsUndefined ( ) Should not try to load resource for other action if $this->params['id'] is undefined
testShouldOnlyAuthorizeShowActionOnParentResource ( ) Should only authorize 'show' action on parent resource
testShouldPerformAuthorizationUsingControllerActionAndLoadedModel ( ) Should perform authorization using controller action and loaded model
testShouldPerformAuthorizationUsingControllerActionAndNonLoadedModel ( ) Should perform authorization using controller action and non loaded model
testShouldRaiseAccessDeniedWhenAttemptingToLoadResourceThroughNull ( ) Should raise AccessDenied when attempting to load resource through null

Protected Methods

Method Description
buildModel ( $modelName, $modelAttributes = [] )

Method Details

buildModel() protected method

protected buildModel ( $modelName, $modelAttributes = [] )

setUp() public method

public setUp ( )

testBuildCollectionWhenOnIndexAction() public method

Should build a collection when on index action

testBuildNewResourceForNamespacedControllerAndNamespacedModelWithAssociativeArrayIfParamIdIsNotSpecified() public method

Should build a new resource for namespaced controller and namespaced model with hash if params[:id] is not specified

testBuildNewResourceNamespacedModelWithAssociativeArrayIfParamIdIsNotSpecified() public method

Should build a new resource for namespaced model with hash if params[:id] is not specified

testBuildNewResourceWithAssociativeArrayIfParamIdIsNotSpecified() public method

Should build a new resource with hash if params[:id] is not specified

testCreateThroughNamespacedParams() public method

Should store through the namespaced params

testHasSpecifiedNestedResourceClassWithSlashedNamespace() public method

Has the specified nested resource_class when using '/' for namespace

testLoadResourceForNamespacedController() public method

Should properly load resource for namespaced controller

testLoadResourceInstanceWithParamId() public method

Should load the resource into an instance variable if $params['id'] is specified

testLoadResourceWithSameNamespaceAsControllerWithBackslashedNamespace() public method

Should attempt to load a resource with the same namespace as the controller when using '\' for namespace

testNotLoadResourceInstanceIfAlreadySet() public method

Should not load resource into an instance variable if already set

testProperlyDetectNamespacesResourceControllerWithBackslashedNamespace() public method

Should properly detect namespaces for resource and controller when using '\' for namespace

testProperlyDetectRootNamespaceResourceNamespacedControllerWithBackslashedNamespace() public method

Should properly detect root namespace of resource for namespaced controller when using '\' for namespace

testProperlyLoadResourceNamespacedControllerWithBackslashedNamespace() public method

Should properly load resource for namespaced controller when using '\' for namespace

testShouldAllowFullFindMethodToBePassedIntoFindByOption() public method

Should allow full find method to be passed into findBy option

testShouldAlwaysConvertIdParamToString() public method

Should always convert id param to string

testShouldAuthorizeBasedOnResourceNameIfClassIsFalse() public method

Should authorize based on resource name if class is false

testShouldAuthorizeNestedResourceThroughParentAssociationOnIndexAction() public method

Should authorize nested resource through parent association on index action

testShouldAuthorizeParentResourceInCollectionAction() public method

Should authorize parent resource in collection action

testShouldBeAParentResourceWhenNameIsProvidedWhichDoesntMatchController() public method

Should be a parent resource when name is provided which doesn't match controller

testShouldBeParentIfSpecifiedInOptions() public method

// Should be parent if specified in options

testShouldBuildAResourceWhenOnCustomCreateActionEvenWhenParamsIdExists() public method

Should build a resource when on custom create action even when $this->params['id'] exists

testShouldBuildRecordThroughHasOneAssociationWithSingletonAndShallowOptions() public method

Should build record through hasOne association with 'singleton' and 'shallow' options

testShouldCallClosureWhenAnInstanceVariableIsPassed() public method

Should call Closure when an instance variable is passed

testShouldCallLoadResourceAndAuthorizeResourceForLoadAndAuthorizeResource() public method

Should call loadResource and authorizeResource for loadAndAuthorizeResource

testShouldFindRecordThroughHasOneAssociationWithSingletonAndShallowOptions() public method

Should find record through hasOne association with 'singleton' and 'shallow' options

testShouldFindRecordThroughHasOneAssociationWithSingletonOptionWithoutIdParam() public method

Should find record through hasOne association with 'singleton' option without id param

testShouldHaveTheSpecifiedResourceClassIfNameIsPassedToLoadResource() public method

Should have the specified resource_class if 'name' is passed to loadResource()

testShouldLoadACollectionResourceWhenOnCustomActionWithNoIdParam() public method

// Should load a collection resource when on custom action with no id param

testShouldLoadAndAuthorizeUsingCustomInstanceName() public method

Should load and authorize using custom instance name

testShouldLoadCollectionResourceWhenDefiningAuthorityRulesThroughClosure() public method

Should not use load collection when defining Authority rules through a Closure

testShouldLoadParentResourceThroughProperIdParameter() public method

Should load parent resource through proper id parameter

testShouldLoadResourceThroughCustomMethodOfTheController() public method

Should load resource through a custom method of the controller

testShouldLoadResourceThroughTheAssociationOfAnotherParentResourceUsingGetterMethod() public method

Should load resource through the association of another parent resource using getter method

testShouldLoadResourceThroughTheAssociationOfAnotherParentResourceUsingInstanceVariable() public method

Should load resource through the association of another parent resource using instance variable

testShouldLoadResourceThroughTheAssociationOfAnotherParentResourceUsingMethod() public method

Should load resource through the association of another parent resource using method

testShouldLoadResourceThroughTheCustomAssociationName() public method

Should load resource through the custom association name

testShouldLoadResourceUsingCustomFindByAttribute() public method

Should load resource using custom findByAttribute

testShouldLoadResourceUsingCustomIDParam() public method

Should load resource using custom ID param

testShouldLoadResourceUsingCustomQuery() public method

Should load resource using custom query where('attribute_name', $attribute);

testShouldLoadTheModelUsingACustomClass() public method

Should load the model using a custom class

testShouldLoadTheModelUsingACustomNamespacedClass() public method

Should load the model using a custom namespaced class

testShouldLoadThroughFirstMatchingIfMultipleAreGiven() public method

Should load through first matching if multiple are given

testShouldNotAuthorizeSingleResourceInCollectionAction() public method

Should not authorize single resource in collection action

testShouldNotBeAParentResourceWhenNameIsProvidedWhichMatchesController() public method

// Should not be a parent resource when name is provided which matches controller

testShouldNotBeParentIfSpecifiedInOptions() public method

// Should not be parent if specified in options

testShouldNotBuildASingleResourceWhenOnCustomCollectionActionEvenWithId() public method

Should not build a single resource when on custom collection action even with id

testShouldNotBuildRecordThroughHasOneAssociationWithSingletonOptionBecauseItCanCauseItToDeleteItInTheDatabase() public method

Should not build record through hasOne association with 'singleton' option because it can cause it to delete it in the database

testShouldNotCallClosureWhenOnlyClassNameIsPassedOnlyReturnTrue() public method

Should not call Closure when only class name is passed, only return true

testShouldNotLoadThroughParentResourceIfInstanceIsntLoadedWhenShallow() public method

Should not load through parent resource if instance isn't loaded when shallow

testShouldNotTryToLoadResourceForOtherActionIfParamsIdIsUndefined() public method

Should not try to load resource for other action if $this->params['id'] is undefined

testShouldOnlyAuthorizeShowActionOnParentResource() public method

Should only authorize 'show' action on parent resource

testShouldPerformAuthorizationUsingControllerActionAndLoadedModel() public method

Should perform authorization using controller action and loaded model

testShouldPerformAuthorizationUsingControllerActionAndNonLoadedModel() public method

Should perform authorization using controller action and non loaded model

testShouldRaiseAccessDeniedWhenAttemptingToLoadResourceThroughNull() public method

Should raise AccessDenied when attempting to load resource through null