Example #1
0
 public function testSetSearchTerm()
 {
     $feature = new Attribute();
     $feature->setSearchTerm('MIxEd cAsE');
     $this->assertSame('mixed case', $feature->getSearchTerm(), 'the search term should be converted to lower case before setting');
     $titleAttribute = new Attribute();
     $titleAttribute->setType('title');
     $titleAttribute->setName('EIGHT53');
     $this->assertEquals('eight53', $titleAttribute->getSearchTerm(), 'the search term should be a lowercase version of the name');
     $titleAttribute->setSearchTerm('different search term');
     $this->assertEquals('different search term', $titleAttribute->getSearchTerm(), 'setting search term overrides previous set term');
     $titleAttribute->setName('eight53');
     $this->assertEquals('different search term', $titleAttribute->getSearchTerm(), 'if a term is already set, it should not be overwritten by setting the name');
     $titleAttribute->setSearchTerm(21);
     $this->assertInternalType('string', $titleAttribute->getSearchTerm(), 'make sure the search is type cast as a string');
 }
Example #2
0
 public function testAttributeMethods()
 {
     /** @var $product \Vespolina\Entity\Product\BaseProduct */
     $product = $this->getMockForAbstractClass('Vespolina\\Entity\\Product\\BaseProduct');
     $feature1 = new Attribute();
     $feature1->setType('feature1');
     $product->addAttribute($feature1);
     $this->assertCount(1, $product->getAttributes());
     $this->assertSame($feature1, $product->getAttribute('feature1'));
     $feature2 = new Attribute();
     $feature2->setType('feature2');
     $product->addAttribute($feature2);
     $this->assertCount(2, $product->getAttributes());
     $this->assertSame($feature2, $product->getAttribute('feature2'));
     $product->removeAttribute($feature2);
     $this->assertCount(1, $product->getAttributes(), 'remove by feature');
     $this->assertNull($product->getAttribute('feature2'));
     $feature3 = new Attribute();
     $feature3->setType('feature3');
     $features = array();
     $features[] = $feature2;
     $features[] = $feature3;
     $product->addAttributes($features);
     $this->assertCount(3, $product->getAttributes());
     $this->assertSame($feature2, $product->getAttribute('feature2'));
     $this->assertSame($feature3, $product->getAttribute('feature3'));
     $product->setAttributes($features);
     $this->assertCount(2, $product->getAttributes());
     $this->assertNull($product->getAttribute('feature1'));
     $this->assertSame($feature2, $product->getAttribute('feature2'));
     $this->assertSame($feature3, $product->getAttribute('feature3'));
     $product->removeAttribute('feature3');
     $this->assertCount(1, $product->getAttributes(), 'feature should be removed by type');
     $product->removeAttribute('nada');
     $this->assertCount(1, $product->getAttributes());
     $product->clearAttributes();
     $this->assertEmpty($product->getAttributes());
 }