-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #7 - Multiple attribute's values
- Loading branch information
1 parent
ff968a9
commit c006b82
Showing
7 changed files
with
164 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
language: php | ||
|
||
php: | ||
- 7.0 | ||
- 7.1 | ||
- 7.2 | ||
|
||
before_script: | ||
- composer self-update | ||
- composer install --no-interaction --prefer-source | ||
- wget -O phpunit.phar https://phar.phpunit.de/phpunit-6.5.6.phar | ||
|
||
script: | ||
- php phpunit.phar --configuration ./build/travis-ci.phpunit.xml | ||
|
||
notifications: | ||
email: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit bootstrap="tests/bootstrap.php"> | ||
<testsuites> | ||
<testsuite name="phpbu"> | ||
<directory>tests/feed</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist> | ||
<directory>src</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
class ProductTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
const PRODUCT_NAMESPACE = '{http://base.google.com/ns/1.0}'; | ||
|
||
/** | ||
* Tests setting attribute | ||
*/ | ||
public function testSetAttribute() | ||
{ | ||
$product = new \Vitalybaev\GoogleMerchant\Product(); | ||
|
||
// Set some value | ||
$product->setAttribute('attr', 'value', false); | ||
$this->assertEquals([ | ||
'item' => [ | ||
['name' => "{http://base.google.com/ns/1.0}attr", "value" => "value"], | ||
], | ||
], $product->getXmlStructure(static::PRODUCT_NAMESPACE)); | ||
|
||
// Set another value to this attribute | ||
$product->setAttribute('attr', 'value_new', false); | ||
$this->assertEquals([ | ||
'item' => [ | ||
['name' => "{http://base.google.com/ns/1.0}attr", "value" => "value_new"], | ||
], | ||
], $product->getXmlStructure(static::PRODUCT_NAMESPACE)); | ||
|
||
// Check for case insensitive | ||
$product->setAttribute('Attr', 'value_2', false); | ||
$this->assertEquals([ | ||
'item' => [ | ||
['name' => "{http://base.google.com/ns/1.0}attr", "value" => "value_2"], | ||
], | ||
], $product->getXmlStructure(static::PRODUCT_NAMESPACE)); | ||
} | ||
|
||
public function testAddingAttribute() | ||
{ | ||
$product = new \Vitalybaev\GoogleMerchant\Product(); | ||
|
||
$product->addAttribute('additional_image_link', 'https://example.com/image1.jpg'); | ||
$this->assertEquals([ | ||
'item' => [ | ||
['name' => "{http://base.google.com/ns/1.0}additional_image_link", "value" => "https://example.com/image1.jpg"], | ||
], | ||
], $product->getXmlStructure(static::PRODUCT_NAMESPACE)); | ||
|
||
$product->addAttribute('additional_image_link', 'https://example.com/image2.jpg'); | ||
$this->assertEquals([ | ||
'item' => [ | ||
['name' => "{http://base.google.com/ns/1.0}additional_image_link", "value" => "https://example.com/image1.jpg"], | ||
['name' => "{http://base.google.com/ns/1.0}additional_image_link", "value" => "https://example.com/image2.jpg"], | ||
], | ||
], $product->getXmlStructure(static::PRODUCT_NAMESPACE)); | ||
} | ||
|
||
/** | ||
* Tests setting Id to product. | ||
*/ | ||
public function testProductSetsId() | ||
{ | ||
$product = new \Vitalybaev\GoogleMerchant\Product(); | ||
$product->setId('some_id'); | ||
|
||
$this->assertEquals([ | ||
'item' => [ | ||
['name' => "{http://base.google.com/ns/1.0}id", "value" => "some_id"], | ||
], | ||
], $product->getXmlStructure(static::PRODUCT_NAMESPACE)); | ||
} | ||
} |