Changeset 1269

Show
Ignore:
Timestamp:
01/20/08 15:01:58 (1 year ago)
Author:
mikey
Message:

continued refactoring #118: converted tests for net::stubbles::websites::variantmanager

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/test/AllTests.php

    r1252 r1269  
    2828require_once $dir . '/php/net/stubbles/ioc/IOCTestSuite.php'; 
    2929require_once $dir . '/php/net/stubbles/websites/WebsitesTestSuite.php'; 
     30require_once $dir . '/php/net/stubbles/websites/variantmanager/VariantManagerTestSuite.php'; 
    3031/** 
    3132 * Class to organize all tests. 
     
    5758        $suite->addTestSuite('IOCTestSuite'); 
    5859        $suite->addTestSuite('WebsitesTestSuite'); 
     60        $suite->addTestSuite('VariantManagerTestSuite'); 
    5961        return $suite; 
    6062    } 
  • trunk/src/test/php/net/stubbles/websites/WebsitesTestSuite.php

    r1262 r1269  
    2626    { 
    2727        $suite = new self(); 
    28         $dir = dirname(__FILE__); 
     28        $dir   = dirname(__FILE__); 
    2929        $suite->addTestFile($dir . '/stubFrontControllerTestCase.php'); 
    3030        $suite->addTestFile($dir . '/stubPageTestCase.php'); 
  • trunk/src/test/php/net/stubbles/websites/variantmanager/VariantManagerTestSuite.php

    r551 r1269  
    1313 * @subpackage  test 
    1414 */ 
    15 class VariantManagerTestSuite extends TestSuite 
     15class VariantManagerTestSuite extends PHPUnit_Framework_TestSuite 
    1616{ 
    1717    /** 
    18      * constructor 
     18     * returns the test suite to be run 
     19     * 
     20     * @return  PHPUnit_Framework_TestSuite 
    1921     */ 
    20     public function __construct() 
     22    public static function suite() 
    2123    { 
    22         $this->TestSuite('All VariantManager tests'); 
    23         $this->addTestFile(dirname(__FILE__) . '/types/stubAbstractVariantTestCase.php'); 
    24         $this->addTestFile(dirname(__FILE__) . '/types/stubDummyVariantTestCase.php'); 
    25         $this->addTestFile(dirname(__FILE__) . '/types/stubLeadVariantTestCase.php'); 
    26         $this->addTestFile(dirname(__FILE__) . '/types/stubRandomVariantTestCase.php'); 
    27         $this->addTestFile(dirname(__FILE__) . '/types/stubRequestParamVariantTestCase.php'); 
    28         $this->addTestFile(dirname(__FILE__) . '/types/stubRootVariantTestCase.php'); 
    29         $this->addTestFile(dirname(__FILE__) . '/stubVariantsMapTestCase.php'); 
    30         $this->addTestFile(dirname(__FILE__) . '/stubVariantsPreInterceptorCookieVariantTestCase.php'); 
    31         $this->addTestFile(dirname(__FILE__) . '/stubVariantsPreInterceptorProcessTestCase.php'); 
    32         $this->addTestFile(dirname(__FILE__) . '/stubVariantXJConfFactoryTestCase.php'); 
     24        $suite = new self(); 
     25        $dir   = dirname(__FILE__); 
     26        $suite->addTestFile($dir . '/types/stubAbstractVariantTestCase.php'); 
     27        $suite->addTestFile($dir . '/types/stubDummyVariantTestCase.php'); 
     28        $suite->addTestFile($dir . '/types/stubLeadVariantTestCase.php'); 
     29        $suite->addTestFile($dir . '/types/stubRandomVariantTestCase.php'); 
     30        $suite->addTestFile($dir . '/types/stubRequestParamVariantTestCase.php'); 
     31        $suite->addTestFile($dir . '/types/stubRootVariantTestCase.php'); 
     32        $suite->addTestFile($dir . '/stubVariantsMapTestCase.php'); 
     33        $suite->addTestFile($dir . '/stubVariantsPreInterceptorCookieVariantTestCase.php'); 
     34        $suite->addTestFile($dir . '/stubVariantsPreInterceptorProcessTestCase.php'); 
     35        $suite->addTestFile($dir . '/stubVariantXJConfFactoryTestCase.php'); 
     36        return $suite; 
    3337    } 
    3438} 
  • trunk/src/test/php/net/stubbles/websites/variantmanager/stubVariantXJConfFactoryTestCase.php

    r1231 r1269  
    2828 * @subpackage  websites_variantmanager_test 
    2929 */ 
    30 class stubVariantXJConfFactoryTestCase extends UnitTestCase 
     30class stubVariantXJConfFactoryTestCase extends PHPUnit_Framework_TestCase 
    3131{ 
    3232    /** 
     
    6363    /** 
    6464     * test descriptor 
     65     * 
     66     * @test 
    6567     */ 
    66     public function testDescriptor() 
     68    public function descriptor() 
    6769    { 
    68         $this->assertEqual($this->variantXJConfFactory->getDescriptor(stubXJConfInitializer::DESCRIPTOR_CONFIG), 'variantmanager'); 
    69         $this->assertEqual($this->variantXJConfFactory->getDescriptor(stubXJConfInitializer::DESCRIPTOR_DEFINITION), 'variantmanager'); 
     70        $this->assertEquals('variantmanager', $this->variantXJConfFactory->getDescriptor(stubXJConfInitializer::DESCRIPTOR_CONFIG)); 
     71        $this->assertEquals('variantmanager', $this->variantXJConfFactory->getDescriptor(stubXJConfInitializer::DESCRIPTOR_DEFINITION)); 
    7072    } 
    7173 
    7274    /** 
    7375     * check that the cache data is correct 
     76     * 
     77     * @test 
    7478     */ 
    75     public function testGetCacheData() 
     79    public function getCacheData() 
    7680    { 
    7781        $variantsMap = new stubVariantsMap($this->rootVariant); 
     
    8084        $this->variantXJConfFactory->setVariantsMap($variantsMap); 
    8185        $cacheData = $this->variantXJConfFactory->getCacheData(); 
    82         $this->assertEqual($cacheData['name'], 'foo'); 
     86        $this->assertEquals('foo', $cacheData['name']); 
    8387        $this->assertTrue($cacheData['usePersistence']); 
    84         $this->assertIsA($cacheData['rootVariant'], 'stubSerializedObject'); 
     88        $this->assertType('stubSerializedObject', $cacheData['rootVariant']); 
    8589    } 
    8690 
    8791    /** 
    8892     * check that cache data is used correct 
     93     * 
     94     * @test 
    8995     */ 
    90     public function testSetCacheData() 
     96    public function setCacheData() 
    9197    { 
    9298        $cacheData = array('name'           => 'foo', 
     
    96102        $this->variantXJConfFactory->setCacheData($cacheData); 
    97103        $variantsMap = $this->variantXJConfFactory->getVariantsMap(); 
    98         $this->assertEqual($variantsMap->getName(), 'foo'); 
    99         $this->assertEqual($variantsMap->shouldUsePersistence(), true); 
    100         $this->assertEqual($variantsMap->getVariantNames(), array('v1', 'v2', 'v3')); 
     104        $this->assertEquals('foo', $variantsMap->getName()); 
     105        $this->assertTrue($variantsMap->shouldUsePersistence()); 
     106        $this->assertEquals(array('v1', 'v2', 'v3'), $variantsMap->getVariantNames()); 
    101107    } 
    102108} 
  • trunk/src/test/php/net/stubbles/websites/variantmanager/stubVariantsMapTestCase.php

    r1231 r1269  
    1111                      'net::stubbles::websites::variantmanager::types::stubLeadVariant' 
    1212); 
    13 Mock::generate('stubRequest'); 
    14 Mock::generate('stubSession'); 
    1513/** 
    1614 * Test for net::stubbles::websites::variantmanager::stubVariantsMap. 
     
    1917 * @subpackage  websites_variantmanager_test 
    2018 */ 
    21 class stubVariantsMapTestCase extends UnitTestCase 
     19class stubVariantsMapTestCase extends PHPUnit_Framework_TestCase 
    2220{ 
    2321    /** 
     
    3028     * the mocked session 
    3129     * 
    32      * @var  SimpleMock 
     30     * @var  PHPUnit_Framework_MockObject_MockObject 
    3331     */ 
    3432    protected $mockSession; 
     
    3634     * the mocked request 
    3735     * 
    38      * @var  SimpleMock 
     36     * @var  PHPUnit_Framework_MockObject_MockObject 
    3937     */ 
    4038    protected $mockRequest; 
     
    6462    { 
    6563        $this->variantMap  = new stubVariantsMap(); 
    66         $this->mockSession = new MockstubSession(); 
    67         $this->mockRequest = new MockstubRequest(); 
     64        $this->mockSession = $this->getMock('stubSession'); 
     65        $this->mockRequest = $this->getMock('stubRequest'); 
    6866        $this->v1          = new stubLeadVariant(); 
    6967        $this->v1->setName('v1'); 
     
    7674    /** 
    7775     * assure that name is handled correct 
    78      */ 
    79     public function testName() 
     76     * 
     77     * @test 
     78     */ 
     79    public function name() 
    8080    { 
    8181        $this->assertNull($this->variantMap->getName()); 
    8282        $this->variantMap->setName('foo'); 
    83         $this->assertEqual($this->variantMap->getName(), 'foo'); 
     83        $this->assertEquals('foo', $this->variantMap->getName()); 
    8484    } 
    8585 
    8686    /** 
    8787     * assure that persistence is handled correct 
    88      */ 
    89     public function testUsePersistence() 
     88     * 
     89     * @test 
     90     */ 
     91    public function usePersistence() 
    9092    { 
    9193        $this->assertTrue($this->variantMap->shouldUsePersistence()); 
     
    9698    /** 
    9799     * test handling with no variants configured 
    98      */ 
    99     public function testNoVariant() 
    100     { 
    101         $this->assertEqual($this->variantMap->getVariants(), array()); 
     100     * 
     101     * @test 
     102     */ 
     103    public function noVariant() 
     104    { 
     105        $this->assertEquals(array(), $this->variantMap->getVariants()); 
    102106        $this->assertNull($this->variantMap->getVariantByName('foo')); 
    103         $this->assertEqual($this->variantMap->getVariantNames(), array()); 
     107        $this->assertEquals(array(), $this->variantMap->getVariantNames()); 
    104108        $this->assertFalse($this->variantMap->variantExists('foo')); 
    105109        $this->assertFalse($this->variantMap->isVariantValid('foo', $this->mockSession, $this->mockRequest)); 
    106110        $this->assertNull($this->variantMap->getEnforcingVariant($this->mockSession, $this->mockRequest)); 
    107         $this->expectException('stubVariantConfigurationException'); 
     111    } 
     112 
     113    /** 
     114     * test handling with no variants configured 
     115     * 
     116     * @test 
     117     * @expectedException  stubVariantConfigurationException 
     118     */ 
     119    public function noVariantThrowsExceptionIfVariantIsRequested() 
     120    { 
    108121        $this->variantMap->getVariant($this->mockSession, $this->mockRequest); 
    109122    } 
     
    111124    /** 
    112125     * test handling with one variant 
    113      */ 
    114     public function testOneVariant() 
     126     * 
     127     * @test 
     128     */ 
     129    public function oneVariant() 
    115130    { 
    116131        $this->variantMap->addChild($this->v1); 
     
    118133        // $this->assertEqual($this->variantMap->getVariants(), array('v1' => $this->v1)); 
    119134        $variantTest1 = $this->variantMap->getVariantByName('v1'); 
    120         $this->assertReference($variantTest1, $this->v1); 
    121         $this->assertEqual($this->variantMap->getVariantNames(), array('v1')); 
     135        $this->assertSame($this->v1, $variantTest1); 
     136        $this->assertEquals(array('v1'), $this->variantMap->getVariantNames()); 
    122137        $this->assertTrue($this->variantMap->variantExists('v1')); 
    123138        $this->assertTrue($this->variantMap->isVariantValid('v1', $this->mockSession, $this->mockRequest)); 
    124139        $this->assertNull($this->variantMap->getEnforcingVariant($this->mockSession, $this->mockRequest)); 
    125140        $variantTest2 = $this->variantMap->getVariant($this->mockSession, $this->mockRequest); 
    126         $this->assertReference($variantTest2, $this->v1); 
     141        $this->assertSame($this->v1, $variantTest2); 
    127142    } 
    128143 
    129144    /** 
    130145     * Tests that all nested variants are found 
    131      */ 
    132     public function testNestedVariant() 
     146     * 
     147     * @test 
     148     */ 
     149    public function nestedVariant() 
    133150    { 
    134151        $this->v2->addChild($this->v3); 
     
    142159    /** 
    143160     * Test that no enforcing variant is returned when there is no enforcing variant set 
    144      */ 
    145     public function testEnforcingVariantIsNullIfRoot() 
     161     * 
     162     * @test 
     163     */ 
     164    public function enforcingVariantIsNullIfRoot() 
    146165    { 
    147166        $this->variantMap->addChild($this->v3); 
     
    154173    /** 
    155174     * Tests that the variant are handled as references and returned by their name 
    156      */ 
    157     public function testGetVariantByName() 
     175     * 
     176     * @test 
     177     */ 
     178    public function getVariantByName() 
    158179    { 
    159180        $this->variantMap->addChild($this->v3); 
     
    161182        $this->variantMap->addChild($this->v1); 
    162183         
    163         $this->assertReference($this->variantMap->getVariantByName('v1'), $this->v1); 
    164         $this->assertReference($this->variantMap->getVariantByName('v2'), $this->v2); 
    165         $this->assertReference($this->variantMap->getVariantByName('v3'), $this->v3); 
     184        $this->assertSame($this->v1, $this->variantMap->getVariantByName('v1')); 
     185        $this->assertSame($this->v2, $this->variantMap->getVariantByName('v2')); 
     186        $this->assertSame($this->v3, $this->variantMap->getVariantByName('v3')); 
    166187    } 
    167188 
    168189    /** 
    169190     * Test that all variant names will be returned 
    170      */ 
    171     public function testGetVariantNames() 
     191     * 
     192     * @test 
     193     */ 
     194    public function getVariantNames() 
    172195    { 
    173196        $this->v1->addChild($this->v2); 
     
    175198        $this->variantMap->addChild($this->v1); 
    176199         
    177         $this->assertEqual($this->variantMap->getVariantNames(), array('v1', 'v2', 'v3')); 
     200        $this->assertEquals(array('v1', 'v2', 'v3'), $this->variantMap->getVariantNames()); 
    178201    } 
    179202 
    180203    /** 
    181204     * test creating the variants map with a root variant as argument 
    182      */ 
    183     public function testWithRootArgument() 
     205     * 
     206     * @test 
     207     */ 
     208    public function withRootArgument() 
    184209    { 
    185210        $rootVariant = new stubRootVariant(); 
     
    189214        $variantMap = new stubVariantsMap($rootVariant); 
    190215         
    191         $this->assertEqual($variantMap->getVariantNames(), array('v1', 'v2', 'v3')); 
    192         $this->assertReference($variantMap->getVariantByName('v1'), $this->v1); 
    193         $this->assertReference($variantMap->getVariantByName('v2'), $this->v2); 
    194         $this->assertReference($variantMap->getVariantByName('v3'), $this->v3); 
     216        $this->assertEquals(array('v1', 'v2', 'v3'), $variantMap->getVariantNames()); 
     217        $this->assertSame($this->v1, $variantMap->getVariantByName('v1')); 
     218        $this->assertSame($this->v2, $variantMap->getVariantByName('v2')); 
     219        $this->assertSame($this->v3, $variantMap->getVariantByName('v3')); 
    195220    } 
    196221} 
  • trunk/src/test/php/net/stubbles/websites/variantmanager/stubVariantsPreInterceptorCookieVariantTestCase.php

    r1231 r1269  
    1212                      'net::stubbles::websites::variantmanager::types::stubVariant' 
    1313); 
    14 Mock::generate('stubRequest'); 
    15 Mock::generate('stubSession'); 
    16 Mock::generate('stubResponse'); 
    17 Mock::generate('stubVariant'); 
    18 Mock::generate('stubVariantFactory'); 
    19 Mock::generate('stubVariantsMap'); 
    2014class TestVariantsPreInterceptor extends stubVariantsPreInterceptor 
    2115{ 
     
    3125 * @subpackage  websites_variantmanager_test 
    3226 */ 
    33 class stubVariantsPreInterceptorCookieVariantTestCase extends UnitTestCase 
     27class stubVariantsPreInterceptorCookieVariantTestCase extends PHPUnit_Framework_TestCase 
    3428{ 
    3529    /** 
     
    4236     * the mocked request 
    4337     * 
    44      * @var  SimpleMock 
     38     * @var  PHPUnit_Framework_MockObject_MockObject 
    4539     */ 
    4640    protected $mockRequest; 
     
    4842     * the mocked session 
    4943     * 
    50      * @var  SimpleMock 
     44     * @var  PHPUnit_Framework_MockObject_MockObject 
    5145     */ 
    5246    protected $mockSession; 
     
    5448     * a mocked variant factory 
    5549     * 
    56      * @var  SimpleMock 
     50     * @var  PHPUnit_Framework_MockObject_MockObject 
    5751     */ 
    5852    protected $mockVariantFactory; 
     
    6054     * a mocked variants map 
    6155     * 
    62      * @var  SimpleMock 
     56     * @var  PHPUnit_Framework_MockObject_MockObject 
    6357     */ 
    6458    protected $mockVariantsMap; 
     
    7064    { 
    7165        $this->variantPreInterceptor = new TestVariantsPreInterceptor(); 
    72         $this->mockRequest           = new MockstubRequest(); 
    73         $this->mockSession           = new MockstubSession(); 
    74         $this->mockVariantFactory    = new MockstubVariantFactory(); 
    75         $this->mockVariantsMap       = new MockstubVariantsMap(); 
    76         $this->mockVariantFactory->setReturnValue('getVariantsMap', $this->mockVariantsMap); 
     66        $this->mockSession           = $this->getMock('stubSession'); 
     67        $this->mockRequest           = $this->getMock('stubRequest'); 
     68        $this->mockVariantFactory    = $this->getMock('stubVariantFactory'); 
     69        $this->mockVariantsMap       = $this->getMock('stubVariantsMap'); 
     70        $this->mockVariantFactory->expects($this->any()) 
     71                                 ->method('getVariantsMap') 
     72                                 ->will($this->returnValue($this->mockVariantsMap)); 
    7773    } 
    7874 
    7975    /** 
    8076     * assure that no cookie returns no variant 
     77     * 
     78     * @test 
    8179     */ 
    82     public function testNoCookie() 
     80    public function noCookie() 
    8381    { 
    84         $this->mockRequest->setReturnValue('hasValue', false); 
     82        $this->mockRequest->expects($this->once())->method('hasValue')->will($this->returnValue(false)); 
    8583        $this->assertNull($this->variantPreInterceptor->getCookieVariant($this->mockRequest, $this->mockSession, $this->mockVariantFactory, 'variant')); 
    8684    } 
     
    8886    /** 
    8987     * assure that an invalid cookie will not be used anymore 
     88     * 
     89     * @test 
    9090     */ 
    91     public function testInvalidCookie() 
     91    public function invalidCookie() 
    9292    { 
    93         $this->mockRequest->setReturnValue('hasValue', true); 
    94         $this->mockRequest->setReturnValue('getValidatedValue', null); 
    95         $this->mockVariantFactory->setReturnValue('getVariantNames', array()); 
     93        $this->mockRequest->expects($this->once())->method('hasValue')->will($this->returnValue(true)); 
     94        $this->mockRequest->expects($this->once())->method('getValidatedValue')->will($this->returnValue(null)); 
     95        $this->mockVariantFactory->expects($this->once())->method('getVariantNames')->will($this->returnValue(array())); 
    9696        $this->assertNull($this->variantPreInterceptor->getCookieVariant($this->mockRequest, $this->mockSession, $this->mockVariantFactory, 'variant')); 
    9797    } 
     
    9999    /** 
    100100     * assure that a valid cookie will be used when no enforcing variant is set 
     101     * 
     102     * @test 
    101103     */ 
    102     public function testValidCookieWithoutEnforcingVariant() 
     104    public function validCookieWithoutEnforcingVariant() 
    103105    { 
    104         $this->mockRequest->setReturnValue('hasValue', true); 
    105         $this->mockRequest->setReturnValue('getValidatedValue', 'fooVariant'); 
    106         $this->mockVariantFactory->setReturnValue('getVariantNames', array()); 
    107         $fooVariant = new MockstubVariant(); 
    108         $fooVariant->setReturnValue('getName', 'fooVariant'); 
    109         $this->mockVariantFactory->expect('getVariantByName', array('fooVariant')); 
    110         $this->mockVariantFactory->setReturnValue('getVariantByName', $fooVariant); 
    111         $this->mockVariantsMap->setReturnValue('getEnforcingVariant', null); 
     106        $this->mockRequest->expects($this->once())->method('hasValue')->will($this->returnValue(true)); 
     107        $this->mockRequest->expects($this->once())->method('getValidatedValue')->will($this->returnValue('fooVariant')); 
     108        $this->mockVariantFactory->expects($this->once())->method('getVariantNames')->will($this->returnValue(array())); 
     109        $fooVariant = $this->getMock('stubVariant'); 
     110        $fooVariant->expects($this->any())->method('getName')->will($this->returnValue('fooVariant')); 
     111        $this->mockVariantFactory->expects($this->once())->method('getVariantByName')->will($this->returnValue($fooVariant)); 
     112        $this->mockVariantsMap->expects($this->once())->method('getEnforcingVariant')->will($this->returnValue(null)); 
    112113        $resultVariant = $this->variantPreInterceptor->getCookieVariant($this->mockRequest, $this->mockSession, $this->mockVariantFactory, 'variant'); 
    113         $this->assertReference($fooVariant, $resultVariant); 
     114        $this->assertSame($fooVariant, $resultVariant); 
    114115    } 
    115116     
    116117    /** 
    117118     * assure that a valid cookie will be used when enforcing variant is not a parent variant 
     119     * 
     120     * @test 
    118121     */ 
    119     public function testValidCookieWithInvalidEnforcingVariant() 
     122    public function validCookieWithInvalidEnforcingVariant() 
    120123    { 
    121         $this->mockRequest->setReturnValue('hasValue', true); 
    122         $this->mockRequest->setReturnValue('getValidatedValue', 'fooVariant'); 
    123         $this->mockVariantFactory->setReturnValue('getVariantNames', array()); 
    124         $fooVariant = new MockstubVariant(); 
    125         $fooVariant->setReturnValue('getName', 'fooVariant'); 
    126         $this->mockVariantFactory->expect('getVariantByName', array('fooVariant')); 
    127         $this->mockVariantFactory->setReturnValue('getVariantByName', $fooVariant); 
    128         $barVariant = new MockstubVariant(); 
    129         $barVariant->setReturnValue('getName', 'barVariant'); 
    130         $this->mockVariantsMap->setReturnValue('getEnforcingVariant', $barVariant); 
     124        $this->mockRequest->expects($this->once())->method('hasValue')->will($this->returnValue(true)); 
     125        $this->mockRequest->expects($this->once())->method('getValidatedValue')->will($this->returnValue('fooVariant')); 
     126        $this->mockVariantFactory->expects($this->once())->method('getVariantNames')->will($this->returnValue(array())); 
     127        $fooVariant = $this->getMock('stubVariant'); 
     128        $fooVariant->expects($this->any())->method('getName')->will($this->returnValue('fooVariant')); 
     129        $this->mockVariantFactory->expects($this->once())->method('getVariantByName')->will($this->returnValue($fooVariant)); 
     130        $barVariant = $this->getMock('stubVariant'); 
     131        $barVariant->expects($this->any())->method('getName')->will($this->returnValue('barVariant')); 
     132        $this->mockVariantsMap->expects($this->once())->method('getEnforcingVariant')->will($this->returnValue($barVariant)); 
    131133        $resultVariant = $this->variantPreInterceptor->getCookieVariant($this->mockRequest, $this->mockSession, $this->mockVariantFactory, 'variant'); 
    132         $this->assertReference($fooVariant, $resultVariant); 
     134        $this->assertSame($fooVariant, $resultVariant); 
    133135    } 
    134136     
    135137    /** 
    136138     * assure that a enforcing variant will be used if set and cookie is valid 
     139     * 
     140     * @test 
    137141     */ 
    138     public function testValidCookieWithValidEnforcingVariant() 
     142    public function validCookieWithValidEnforcingVariant() 
    139143    { 
    140         $this->mockRequest->setReturnValue('hasValue', true); 
    141         $this->mockRequest->setReturnValue('getValidatedValue', 'fooVariant'); 
    142         $this->mockVariantFactory->setReturnValue('getVariantNames', array()); 
    143         $fooVariant = new MockstubVariant(); 
    144         $fooVariant->setReturnValue('getName', 'fooVariant'); 
    145         $this->mockVariantFactory->expect('getVariantByName', array('fooVariant')); 
    146         $this->mockVariantFactory->setReturnValue('getVariantByName', $fooVariant); 
    147         $barVariant = new MockstubVariant(); 
    148         $barVariant->setReturnValue('getName', 'foo'); 
    149         $this->mockVariantsMap->setReturnValue('getEnforcingVariant', $barVariant); 
     144        $this->mockRequest->expects($this->once())->method('hasValue')->will($this->returnValue(true)); 
     145        $this->mockRequest->expects($this->once())->method('getValidatedValue')->will($this->returnValue('fooVariant')); 
     146        $this->mockVariantFactory->expects($this->once())->method('getVariantNames')->will($this->returnValue(array())); 
     147        $fooVariant = $this->getMock('stubVariant'); 
     148        $fooVariant->expects($this->any())->method('getName')->will($this->returnValue('fooVariant')); 
     149        $this->mockVariantFactory->expects($this->once())->method('getVariantByName')->will($this->returnValue($fooVariant)); 
     150        $barVariant = $this->getMock('stubVariant'); 
     151        $barVariant->expects($this->any())->method('getName')->will($this->returnValue('foo')); 
     152        $this->mockVariantsMap->expects($this->once())->method('getEnforcingVariant')->will($this->returnValue($barVariant)); 
    150153        $resultVariant = $this->variantPreInterceptor->getCookieVariant($this->mockRequest, $this->mockSession, $this->mockVariantFactory, 'variant'); 
    151         $this->assertReference($barVariant, $resultVariant); 
     154        $this->assertSame($barVariant, $resultVariant); 
    152155    } 
    153156} 
  • trunk/src/test/php/net/stubbles/websites/variantmanager/stubVariantsPreInterceptorProcessTestCase.php

    <
    r1231 r1269  
    1212                      'net::stubbles::websites::variantmanager::types::stubVariant' 
    1313); 
    14 Mock::generate('stubRequest'); 
    15 Mock::generate('stubSession'); 
    16 Mock::generate('stubResponse'); 
    17 Mock::generate('stubVariant'); 
    18 Mock::generate('stubVariantFactory'); 
    19 Mock::generate('stubVariantsMap'); 
    20 Mock::generatePartial('stubVariantsPreInterceptor', 'PartialMockstubVariantsPreInterceptor', array('createVariantFactory', 'createCookie', 'getVariantFromCookie')); 
     14 
    2115class TestInvalidVariantFactory {} 
    2216/** 
     
    2620 * @subpackage  websites_variantmanager_test 
    2721 */ 
    28 class stubVariantsPreInterceptorProcessTestCase extends UnitTestCase 
     22class stubVariantsPreInterceptorProcessTestCase extends PHPUnit_Framework_TestCase 
    2923{ 
    3024    /** 
     
    3731     * the mocked request 
    3832     * 
    39      * @var  SimpleMock 
     33     * @var  PHPUnit_Framework_MockObject_MockObject 
    4034     */ 
    4135    protected $mockRequest; 
     
    4337     * the mocked session 
    4438     * 
    45      * @var  SimpleMock 
     39     * @var  PHPUnit_Framework_MockObject_MockObject 
    4640     */ 
    4741    protected $mockSession; 
     
    4943     * the mocked response 
    5044     * 
    51      * @var  SimpleMock 
     45     * @var  PHPUnit_Framework_MockObject_MockObject 
    5246     */ 
    5347    protected $mockResponse; 
     
    5549     * a mocked variant factory 
    5650     * 
    57      * @var  SimpleMock 
     51     * @var  PHPUnit_Framework_MockObject_MockObject 
    5852     */ 
    5953    protected $mockVariantFactory; 
     
    6155     * a mocked variants map 
    6256     * 
    63      * @var  SimpleMock 
     57     * @var  PHPUnit_Framework_MockObject_MockObject 
    6458     */ 
    6559    protected $mockVariantsMap; 
     
    7064    public function setUp() 
    7165    { 
    72         $this->variantPreInterceptor = new PartialMockstubVariantsPreInterceptor(); 
    73         $this->mockRequest           = new MockstubRequest(); 
    74         $this->mockSession           = new MockstubSession(); 
    75         $this->mockResponse          = new MockstubResponse(); 
    76         $this->mockVariantFactory = new MockstubVariantFactory(); 
    77         $this->mockVariantsMap    = new MockstubVariantsMap(); 
    78         $this->mockVariantFactory->setReturnValue('getVariantsMap', $this->mockVariantsMap); 
    79         stubRegistry::setConfig('net.stubbles.websites.variantmanager.variantfactory.class', 'MockstubVariantFactory'); 
     66        $this->variantPreInterceptor = $this->getMock('stubVariantsPreInterceptor', 
     67                                                      array('createVariantFactory', 
     68                                                            'createCookie', 
     69                                                            'getVariantFromCookie' 
     70                                                      ) 
     71                                       ); 
     72        $this->mockSession           = $this->getMock('stubSession'); 
     73        $this->mockRequest           = $this->getMock('stubRequest'); 
     74        $this->mockResponse          = $this->getMock('stubResponse'); 
     75        $this->mockVariantFactory    = $this->getMock('stubVariantFactory'); 
     76        $this->mockVariantsMap       = $this->getMock('stubVariantsMap'); 
     77        $this->mockVariantFactory->expects($this->any()) 
     78                                 ->method('getVariantsMap') 
     79                                 ->will($this->returnValue($this->mockVariantsMap)); 
     80        stubRegistry::setConfig('net.stubbles.websites.variantmanager.variantfactory.class', get_class($this->mockVariantFactory)); 
    8081    } 
    8182 
    8283    /** 
    8384     * assure that an existing variant will not be overwritten by another variant 
    84      */ 
    85     public function testVariantAlreadyExists() 
    86     { 
    87         $this->mockSession->setReturnValue('hasValue', true); 
    88         $this->mockSession->expectNever('putValue'); 
    89         $this->mockResponse->expectNever('setCookie'); 
     85     * 
     86     * @test 
     87     */ 
     88    public function variantAlreadyExists() 
     89    { 
     90        $this->mockSession->expects($this->once())->method('hasValue')->will($this->returnValue(true)); 
     91        $this->mockSession->expects($this->never())->method('putValue'); 
     92        $this->mockResponse->expects($this->never())->method('setCookie'); 
    9093        $this->variantPreInterceptor->preProcess($this->mockRequest, $this->mockSession, $this->mockResponse); 
    9194    } 
     
    9396    /** 
    9497     * assure that an invalid variant factory classname configurationt throws a stubVariantConfigurationException 
    95      */ 
    96     public function testInvalidVariantFactory() 
    97     { 
    98         $this->mockSession->setReturnValue('hasValue', false); 
    99         $this->mockSession->expectNever('putValue'); 
    100         $this->mockResponse->expectNever('setCookie'); 
     98     * 
     99     * @test 
     100     * @expectedException  stubVariantConfigurationException 
     101     */ 
     102    public function invalidVariantFactory() 
     103    { 
     104        $this->mockSession->expects($this->once())->method('hasValue')->will($this->returnValue(false)); 
     105        $this->mockSession->expects($this->never())->method('putValue'); 
     106        $this->mockResponse->expects($this->never())->method('setCookie'); 
    101107        stubRegistry::setConfig('net.stubbles.websites.variantmanager.variantfactory.class', 'TestInvalidVariantFactory'); 
    102         $this->variantPreInterceptor->expect('createVariantFactory', array('TestInvalidVariantFactory')); 
    103         $this->variantPreInterceptor->setReturnValue('createVariantFactory', new TestInvalidVariantFactory()); 
    104         $this->expectException('stubVariantConfigurationException'); 
     108        $this->variantPreInterceptor->expects($this->once())->method('createVariantFactory')->will($this->returnValue(new TestInvalidVariantFactory())); 
    105109        $this->variantPreInterceptor->preProcess($this->mockRequest, $this->mockSession, $this->mockResponse); 
    106110    } 
     
    108112    /** 
    109113     * assure that no variant cookie triggers a new variant 
    110      */ 
    111     public function testNoVariantCookieSet() 
    112     { 
    113         $mockVariant = new MockstubVariant(); 
    114         $mockVariant->setReturnValue('getName', 'variantName'); 
    115         $mockVariant->setReturnValue('getFullQualifiedName', 'foo:variantName'); 
    116         $this->mockSession->setReturnValue('hasValue', false); 
    117         $this->mockSession->expectOnce('putValue', array('net.stubbles.websites.variantmanager.variant', 'foo:variantName')); 
    118         $this->mockResponse->expectOnce('setCookie'); 
    119         $this->mockRequest->setReturnValue('hasValue', false); 
    120         $this->mockRequest->expect('hasValue', array('variant', stubRequest::SOURCE_COOKIE)); 
    121         $this->variantPreInterceptor->setReturnValue('createVariantFactory', $this->mockVariantFactory); 
    122         $this->variantPreInterceptor->setReturnValue('getVariantFromCookie', null); 
    123         $this->mockVariantsMap->setReturnValue('shouldUsePersistence', true); 
    124         $this->mockVariantsMap->setReturnValue('getVariant', $mockVariant); 
    125         $this->variantPreInterceptor->expect('createCookie', array('variant', 'variantName', '*', null, '/')); 
    126         $this->variantPreInterceptor->setReturnValue('createCookie', stubCookie::create('variant', 'variantName')); 
     114     * 
     115     * @test 
     116     */ 
     117    public function noVariantCookieSet() 
     118    { 
     119        $mockNewVariant = $this->getMock('stubVariant'); 
     120        $mockNewVariant->expects($this->any())->method('getName')->will($this->returnValue('variantName')); 
     121        $mockNewVariant->expects($this->any())->method('getFullQualifiedName')->will($this->returnValue('foo:variantName')); 
     122        $this->mockSession->expects($this->once())->method('hasValue')->will($this->returnValue(false)); 
     123        $this->mockSession->expects($this->once()) 
     124                          ->method('putValue') 
     125                          ->with($this->equalTo('net.stubbles.websites.variantmanager.variant'), 
     126                                 $this->equalTo('foo:variantName') 
     127                            ); 
     128        $this->mockResponse->expects($this->once())->method('setCookie'); 
     129        $this->variantPreInterceptor->expects($this->once())->method('createVariantFactory')->will($this->returnValue($this->mockVariantFactory)); 
     130        $this->variantPreInterceptor->expects($this->once())->method('getVariantFromCookie')->will($this->returnValue(null)); 
     131        $this->mockVariantsMap->expects($this->once())->method('shouldUsePersistence')->will($this->returnValue(true)); 
     132        $this->mockVariantsMap->expects($this->once())->method('getVariant')->will($this->returnValue($mockNewVariant)); 
     133        $this->variantPreInterceptor->expects($this->once()) 
     134                                    ->method('createCookie') 
     135                                    ->with($this->equalTo('variant'), 
     136                                           $this->equalTo('variantName'), 
     137                                           $this->anything(), 
     138                                           $this->equalTo(null), 
     139                                           $this->equalTo('/') 
     140                                      ) 
     141                                    ->will($this->returnValue(stubCookie::create('variant', 'variantName'))); 
    127142        $this->variantPreInterceptor->preProcess($this->mockRequest, $this->mockSession, $this->mockResponse); 
    128143    } 
     
    130145    /** 
    131146     * assure that disabled persistence triggers a new variant 
    132      */ 
    133     public function testNoPersistence() 
    134     { 
    135         $mockNewVariant = new MockstubVariant(); 
    136         $mockNewVariant->setReturnValue('getName', 'new'); 
    137         $mockNewVariant->setReturnValue('getFullQualifiedName', 'foo:new'); 
    138         $mockCookieVariant = new MockstubVariant(); 
    139         $mockCookieVariant->setReturnValue('getName', 'cookie'); 
    140         $mockCookieVariant->setReturnValue('getFullQualifiedName', 'foo:cookie'); 
    141         $this->mockSession->setReturnValue('hasValue', false); 
    142         $this->mockSession->expectOnce('putValue', array('net.stubbles.websites.variantmanager.variant', 'foo:new')); 
    143         $this->mockResponse->expectOnce('setCookie'); 
    144         $this->mockRequest->setReturnValue('hasValue', false); 
    145         $this->mockRequest->expect('hasValue', array('variant', stubRequest::SOURCE_COOKIE)); 
    146         $this->variantPreInterceptor->setReturnValue('createVariantFactory', $this->mockVariantFactory); 
    147         $this->variantPreInterceptor->setReturnValue('getVariantFromCookie', $mockCookieVariant); 
    148         $this->mockVariantsMap->setReturnValue('shouldUsePersistence', false); 
    149         $this->mockVariantsMap->setReturnValue('getVariant', $mockNewVariant); 
    150         $this->variantPreInterceptor->expect('createCookie', array('variant', 'new', '*', 'example.org', '/path/')); 
    151         $this->variantPreInterceptor->setReturnValue('createCookie', stubCookie::create('variant', 'new')); 
     147     * 
     148     * @test 
     149     */ 
     150    public function noPersistence() 
     151    { 
     152        $mockNewVariant = $this->getMock('stubVariant'); 
     153        $mockNewVariant->expects($this->any())->method('getName')->will($this->returnValue('new')); 
     154        $mockNewVariant->expects($this->any())->method('getFullQualifiedName')->will($this->returnValue('foo:new')); 
     155        $mockCookieVariant = $this->getMock('stubVariant'); 
     156        $mockCookieVariant->expects($this->any())->method('getName')->will($this->returnValue('cookie')); 
     157        $mockCookieVariant->expects($this->any())->method('getFullQualifiedName')->will($this->returnValue('foo:cookie')); 
     158        $this->mockSession->expects($this->once())->method('hasValue')->will($this->returnValue(false)); 
     159        $this->mockSession->expects($this->once()) 
     160                          ->method('putValue') 
     161                          ->with($this->equalTo('net.stubbles.websites.variantmanager.variant'), 
     162                                 $this->equalTo('foo:new') 
     163                            ); 
     164        $this->mockResponse->expects($this->once())->method('setCookie'); 
     165        $this->variantPreInterceptor->expects($this->once())->method('createVariantFactory')->will($this->returnValue($this->mockVariantFactory)); 
     166        $this->variantPreInterceptor->expects($this->never())->method('getVariantFromCookie'); 
     167        $this->mockVariantsMap->expects($this->once())->method('shouldUsePersistence')->will($this->returnValue(false)); 
     168        $this->mockVariantsMap->expects($this->once())->method('getVariant')->will($this->returnValue($mockNewVariant)); 
     169        $this->variantPreInterceptor->expects($this->once()) 
     170                                    ->method('createCookie') 
     171                                    ->with($this->equalTo('variant'), 
     172                                           $this->equalTo('new'), 
     173                                           $this->anything(), 
     174                                           $this->equalTo('example.org'), 
     175                                           $this->equalTo('/path/') 
     176                                      ) 
     177                                    ->will($this->returnValue(stubCookie::create('variant', 'new'))); 
    152178        stubRegistry::setConfig('net.stubbles.websites.variantmanager.cookie.url', 'example.org'); 
    153179        stubRegistry::setConfig('net.stubbles.websites.variantmanager.cookie.path', '/path/'); 
     
    157183    /** 
    158184     * assure that a cookie variant is used 
    159      */ 
    160     public function testVariantCookieSet() 
    161     { 
    162         $mockNewVariant = new MockstubVariant(); 
    163         $mockNewVariant->setReturnValue('getName', 'new'); 
    164         $mockNewVariant->setReturnValue('getFullQualifiedName', 'foo:new'); 
    165         $mockCookieVariant = new MockstubVariant(); 
    166         $mockCookieVariant->setReturnValue('getName', 'cookie'); 
    167         $mockCookieVariant->setReturnValue('getFullQualifiedName', 'foo:cookie'); 
    168         $this->mockSession->setReturnValue('hasValue', false); 
    169         $this->mockSession->expectOnce('putValue', array('net.stubbles.websites.variantmanager.variant', 'foo:cookie')); 
    170         $this->mockResponse->expectOnce('setCookie'); 
    171         $this->mockRequest->setReturnValue('hasValue', false); 
    172         $this->mockRequest->expect('hasValue', array('variant', stubRequest::SOURCE_COOKIE)); 
    173         $this->variantPreInterceptor->setReturnValue('createVariantFactory', $this->mockVariantFactory); 
    174         $this->variantPreInterceptor->setReturnValue('getVariantFromCookie', $mockCookieVariant); 
    175         $this->mockVariantsMap->setReturnValue('shouldUsePersistence', true); 
    176         $this->mockVariantsMap->setReturnValue('getVariant', $mockNewVariant); 
    177         $this->variantPreInterceptor->expect('createCookie', array('variant', 'cookie', '*', 'example.org', '/path/')); 
    178         $this->variantPreInterceptor->setReturnValue('createCookie', stubCookie::create('variant', 'variantName')); 
     185     * 
     186     * @test 
     187     */ 
     188    public function variantCookieSet() 
     189    { 
     190        $mockNewVariant = $this->getMock('stubVariant'); 
     191        $mockNewVariant->expects($this->any())->method('getName')->will($this->returnValue('new')); 
     192        $mockNewVariant->expects($this->any())->method('getFullQualifiedName')->will($this->returnValue('foo:new')); 
     193        $mockCookieVariant = $this->getMock('stubVariant'); 
     194        $mockCookieVariant->expects($this->any())->method('getName')->will($this->returnValue('cookie')); 
     195        $mockCookieVariant->expects($this->any())->method('getFullQualifiedName')->will($this->returnValue('foo:cookie')); 
     196        $this->mockSession->expects($this->once())->method('hasValue')->will($this->returnValue(false)); 
     197        $this->mockSession->expects($this->once()) 
     198                          ->method('putValue') 
     199                          ->with($this->equalTo('net.stubbles.websites.variantmanager.variant'), 
     200                                 $this->equalTo('foo:cookie') 
     201                            ); 
     202        $this->mockResponse->expects($this->once())->method('setCookie'); 
     203        $this->variantPreInterceptor->expects($this->once())->method('createVariantFactory')->will($this->returnValue($this->mockVariantFactory)); 
     204        $this->variantPreInterceptor->expects($this->once())->method('getVariantFromCookie')->will($this->returnValue($mockCookieVariant)); 
     205        $this->mockVariantsMap->expects($this->once())->method('shouldUsePersistence')->will($this->returnValue(true)); 
     206        $this->mockVariantsMap->expects($this->never())->method('getVariant'); 
     207        $this->variantPreInterceptor->expects($this->once())