コード例 #1
0
ファイル: ProductTest.php プロジェクト: vespolina/core
 public function testOptions()
 {
     $product = new Product();
     $product->setOption('color', 'colorBlue', 'Blue', 'blue');
     $product->setOption('color', 'colorGreen', 'Green', 'green');
     $product->setOption('color', 'colorRed', 'Red', 'red');
     $product->setOption('material', 'materialCotton', 'Cotton', 'cotton');
     $product->setOption('material', 'materialSmall', 'Polyester', 'polyester');
     $product->setOption('size', 'sizeLarge', 'Large', 'large');
     $product->setOption('size', 'sizeSmall', 'Small', 'small');
     $options = $product->getOptions();
     $this->assertCount(7, $options, 'all product options should be returned');
     $options = $product->getOptions('color');
     $this->assertCount(3, $options, 'all product options of color type should be returned');
     $this->assertInstanceOf('Vespolina\\Entity\\Product\\Option', array_shift($options), 'a Option object should be returned');
     $blue = $product->getOption('color', 'colorBlue');
     $this->assertInstanceOf('Vespolina\\Entity\\Product\\Option', $blue, 'the single option object should have been returned');
     $options = $product->getOptionsArray();
     $expected = ['color' => ['colorBlue' => 'Blue', 'colorGreen' => 'Green', 'colorRed' => 'Red'], 'material' => ['materialCotton' => 'Cotton', 'materialSmall' => 'Polyester'], 'size' => ['sizeLarge' => 'Large', 'sizeSmall' => 'Small']];
     $this->assertEquals($expected, $options, 'all product options should be returned');
     $options = $product->getOptionsArray('size');
     $expected = ['sizeLarge' => 'Large', 'sizeSmall' => 'Small'];
     $this->assertEquals($expected, $options, 'all product options of size type should be returned');
     $product->setOption('color', 'colorBlue', 'NewBlue', 'newblue');
     $newBlue = $product->getOption('color', 'colorBlue');
     $this->assertSame('NewBlue', $newBlue->getDisplay(), 'the display should have changed');
     $this->assertSame('newblue', $newBlue->getName(), 'the display should have changed');
     $this->assertSame(spl_object_hash($blue), spl_object_hash($newBlue), 'the object should be the same');
     return $product;
 }